summaryrefslogtreecommitdiff
path: root/lib/Analysis/DebugInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Analysis/DebugInfo.cpp')
-rw-r--r--lib/Analysis/DebugInfo.cpp75
1 files changed, 37 insertions, 38 deletions
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp
index 901455700e..d9f0aa53e9 100644
--- a/lib/Analysis/DebugInfo.cpp
+++ b/lib/Analysis/DebugInfo.cpp
@@ -35,16 +35,24 @@ DIDescriptor::DIDescriptor(GlobalVariable *gv, unsigned RequiredTag) {
GV = 0;
}
-const char *DIDescriptor::getStringField(unsigned Elt) const {
- if (GV == 0)
- return 0;
+const std::string &
+DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
+ if (GV == 0) {
+ Result.clear();
+ return Result;
+ }
Constant *C = GV->getInitializer();
- if (C == 0 || Elt >= C->getNumOperands())
- return 0;
+ if (C == 0 || Elt >= C->getNumOperands()) {
+ Result.clear();
+ return Result;
+ }
// Fills in the string if it succeeds
- return GetConstantStringInfo(C->getOperand(Elt));
+ if (!GetConstantStringInfo(C->getOperand(Elt), Result))
+ Result.clear();
+
+ return Result;
}
uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
@@ -182,9 +190,11 @@ unsigned DIArray::getNumElements() const {
bool DICompileUnit::Verify() const {
if (isNull())
return false;
-
+ std::string Res;
+ if (getFilename(Res).empty())
+ return false;
// It is possible that directory and produce string is empty.
- return getFilename();
+ return true;
}
/// Verify - Verify that a type descriptor is well formed.
@@ -495,7 +505,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
/// CreateBasicType - Create a basic type like int, float, etc.
DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
- const std::string &Name,
+ const std::string &Name,
DICompileUnit CompileUnit,
unsigned LineNumber,
uint64_t SizeInBits,
@@ -884,7 +894,8 @@ namespace llvm {
}
bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type,
- unsigned &LineNo, std::string &File, std::string &Dir) {
+ unsigned &LineNo, std::string &File, std::string &Dir)
+ {
DICompileUnit Unit;
DIType TypeD;
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
@@ -892,11 +903,7 @@ namespace llvm {
if (!DIGV)
return false;
DIGlobalVariable Var(cast<GlobalVariable>(DIGV));
- const char *DN = Var.getDisplayName();
- if (DN)
- DisplayName = DN;
- else
- DisplayName.clear();
+ Var.getDisplayName(DisplayName);
LineNo = Var.getLineNumber();
Unit = Var.getCompileUnit();
TypeD = Var.getType();
@@ -905,24 +912,14 @@ namespace llvm {
if (!DDI)
return false;
DIVariable Var(cast<GlobalVariable>(DDI->getVariable()));
- const char *DN = Var.getName();
- if (DN)
- DisplayName = DN;
- else
- DisplayName.clear();
+ Var.getName(DisplayName);
LineNo = Var.getLineNumber();
Unit = Var.getCompileUnit();
TypeD = Var.getType();
}
- Type.clear();
- File.clear();
- Dir.clear();
- const char *Str = TypeD.getName();
- if (Str) Type = Str;
- Str = Unit.getFilename();
- if (Str) File = Str;
- Str = Unit.getDirectory();
- if (Str) Dir = Str;
+ TypeD.getName(Type);
+ Unit.getFilename(File);
+ Unit.getDirectory(Dir);
return true;
}
}
@@ -932,17 +929,17 @@ void DICompileUnit::dump() const {
if (getLanguage())
cerr << " [" << dwarf::LanguageString(getLanguage()) << "] ";
- const char *Dir = getDirectory();
- const char *FN = getFilename();
- cerr << " [" << (Dir ? Dir : "") << "/" << (FN ? FN : "") << " ]";
+ std::string Res1, Res2;
+ cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]";
}
/// dump - print type.
void DIType::dump() const {
if (isNull()) return;
- if (const char *N = getName())
- cerr << " [" << N << "] ";
+ std::string Res;
+ if (!getName(Res).empty())
+ cerr << " [" << Res << "] ";
unsigned Tag = getTag();
cerr << " [" << dwarf::TagString(Tag) << "] ";
@@ -999,8 +996,9 @@ void DICompositeType::dump() const {
/// dump - print global.
void DIGlobal::dump() const {
- if (const char *N = getName())
- cerr << " [" << N << "] ";
+ std::string Res;
+ if (!getName(Res).empty())
+ cerr << " [" << Res << "] ";
unsigned Tag = getTag();
cerr << " [" << dwarf::TagString(Tag) << "] ";
@@ -1033,8 +1031,9 @@ void DIGlobalVariable::dump() const {
/// dump - print variable.
void DIVariable::dump() const {
- if (const char *N = getName())
- cerr << " [" << N << "] ";
+ std::string Res;
+ if (!getName(Res).empty())
+ cerr << " [" << Res << "] ";
getCompileUnit().dump();
cerr << " [" << getLineNumber() << "] ";