Improve visibility/correctness of operand indices in "llvm.db" objects.

Handle 64 in DIEs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25684 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Laskey 2006-01-27 15:20:54 +00:00
parent 8aeb7c6051
commit d8f77bae03
4 changed files with 110 additions and 53 deletions

View File

@ -176,10 +176,10 @@ namespace llvm {
// //
class DIEInteger : public DIEValue { class DIEInteger : public DIEValue {
private: private:
int Integer; uint64_t Integer;
public: public:
DIEInteger(int I) : DIEValue(isInteger), Integer(I) {} DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
// Implement isa/cast/dyncast. // Implement isa/cast/dyncast.
static bool classof(const DIEInteger *) { return true; } static bool classof(const DIEInteger *) { return true; }
@ -334,10 +334,13 @@ namespace llvm {
/// sibling. /// sibling.
unsigned SiblingOffset() const { return Offset + Size; } unsigned SiblingOffset() const { return Offset + Size; }
/// AddInt - Add a simple integer attribute data and value. /// AddUInt - Add an unsigned integer attribute data and value.
/// ///
void AddInt(unsigned Attribute, unsigned Form, void AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer);
int Integer, bool IsSigned = false);
/// AddSInt - Add an signed integer attribute data and value.
///
void AddSInt(unsigned Attribute, unsigned Form, int64_t Integer);
/// AddString - Add a std::string attribute data and value. /// AddString - Add a std::string attribute data and value.
/// ///
@ -586,6 +589,10 @@ public:
/// ///
void EmitLong(int Value) const; void EmitLong(int Value) const;
/// EmitLongLong - Emit a long long directive and value.
///
void EmitLongLong(uint64_t Value) const;
/// EmitString - Emit a string with quotes and a null terminator. /// EmitString - Emit a string with quotes and a null terminator.
/// Special characters are emitted properly. (Eg. '\t') /// Special characters are emitted properly. (Eg. '\t')
void EmitString(const std::string &String) const; void EmitString(const std::string &String) const;

View File

@ -73,6 +73,19 @@ public:
/// CompileUnitWrapper - This class wraps a "lldb.compile_unit" global to /// CompileUnitWrapper - This class wraps a "lldb.compile_unit" global to
/// provide easy access to its attributes. /// provide easy access to its attributes.
class CompileUnitWrapper : public DebugInfoWrapper { class CompileUnitWrapper : public DebugInfoWrapper {
private:
// Operand indices.
enum {
Tag_op,
Version_op,
Language_op,
FileName_op,
Directory_op,
Producer_op,
Anchor_op, // ignored
N_op
};
public: public:
CompileUnitWrapper(GlobalVariable *G); CompileUnitWrapper(GlobalVariable *G);
@ -110,6 +123,20 @@ public:
/// GlobalWrapper - This class wraps a "lldb.global" global to provide easy /// GlobalWrapper - This class wraps a "lldb.global" global to provide easy
/// access to its attributes. /// access to its attributes.
class GlobalWrapper : public DebugInfoWrapper { class GlobalWrapper : public DebugInfoWrapper {
private:
// Operand indices.
enum {
Tag_op,
Context_op,
Name_op,
Anchor_op, // ignored
Type_op,
Static_op,
Definition_op,
GlobalVariable_op,
N_op
};
public: public:
GlobalWrapper(GlobalVariable *G); GlobalWrapper(GlobalVariable *G);

View File

@ -674,6 +674,7 @@ void DIEInteger::EmitValue(const DwarfWriter &DW, unsigned Form) const {
case DW_FORM_data1: DW.EmitByte(Integer); break; case DW_FORM_data1: DW.EmitByte(Integer); break;
case DW_FORM_data2: DW.EmitShort(Integer); break; case DW_FORM_data2: DW.EmitShort(Integer); break;
case DW_FORM_data4: DW.EmitLong(Integer); break; case DW_FORM_data4: DW.EmitLong(Integer); break;
case DW_FORM_data8: DW.EmitLongLong(Integer); break;
case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break; case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break;
case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break; case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break;
default: assert(0 && "DIE Value form not supported yet"); break; default: assert(0 && "DIE Value form not supported yet"); break;
@ -688,6 +689,7 @@ unsigned DIEInteger::SizeOf(const DwarfWriter &DW, unsigned Form) const {
case DW_FORM_data1: return sizeof(int8_t); case DW_FORM_data1: return sizeof(int8_t);
case DW_FORM_data2: return sizeof(int16_t); case DW_FORM_data2: return sizeof(int16_t);
case DW_FORM_data4: return sizeof(int32_t); case DW_FORM_data4: return sizeof(int32_t);
case DW_FORM_data8: return sizeof(int64_t);
case DW_FORM_udata: return DW.SizeULEB128(Integer); case DW_FORM_udata: return DW.SizeULEB128(Integer);
case DW_FORM_sdata: return DW.SizeSLEB128(Integer); case DW_FORM_sdata: return DW.SizeSLEB128(Integer);
default: assert(0 && "DIE Value form not supported yet"); break; default: assert(0 && "DIE Value form not supported yet"); break;
@ -796,20 +798,27 @@ DIE::~DIE() {
if (Context) delete Context; if (Context) delete Context;
} }
/// AddInt - Add a simple integer attribute data and value. /// AddUInt - Add an unsigned integer attribute data and value.
/// ///
void DIE::AddInt(unsigned Attribute, unsigned Form, void DIE::AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer) {
int Integer, bool IsSigned) {
if (Form == 0) { if (Form == 0) {
if (IsSigned) {
if ((char)Integer == Integer) Form = DW_FORM_data1;
else if ((short)Integer == Integer) Form = DW_FORM_data2;
else Form = DW_FORM_data4;
} else {
if ((unsigned char)Integer == Integer) Form = DW_FORM_data1; if ((unsigned char)Integer == Integer) Form = DW_FORM_data1;
else if ((unsigned short)Integer == Integer) Form = DW_FORM_data2; else if ((unsigned short)Integer == Integer) Form = DW_FORM_data2;
else Form = DW_FORM_data4; else if ((unsigned int)Integer == Integer) Form = DW_FORM_data4;
} else Form = DW_FORM_data8;
}
Abbrev->AddAttribute(Attribute, Form);
Values.push_back(new DIEInteger(Integer));
}
/// AddSInt - Add an signed integer attribute data and value.
///
void DIE::AddSInt(unsigned Attribute, unsigned Form, int64_t Integer) {
if (Form == 0) {
if ((char)Integer == Integer) Form = DW_FORM_data1;
else if ((short)Integer == Integer) Form = DW_FORM_data2;
else if ((int)Integer == Integer) Form = DW_FORM_data4;
else Form = DW_FORM_data8;
} }
Abbrev->AddAttribute(Attribute, Form); Abbrev->AddAttribute(Attribute, Form);
Values.push_back(new DIEInteger(Integer)); Values.push_back(new DIEInteger(Integer));
@ -932,8 +941,8 @@ DIE *DWContext::NewBasicType(const Type *Ty, unsigned Size, unsigned Align) {
// construct the type DIE. // construct the type DIE.
TypeDie = new DIE(DW_TAG_base_type, DW_CHILDREN_no); TypeDie = new DIE(DW_TAG_base_type, DW_CHILDREN_no);
TypeDie->AddString(DW_AT_name, DW_FORM_string, Name); TypeDie->AddString(DW_AT_name, DW_FORM_string, Name);
TypeDie->AddInt (DW_AT_byte_size, DW_FORM_data1, Size); TypeDie->AddUInt (DW_AT_byte_size, DW_FORM_data1, Size);
TypeDie->AddInt (DW_AT_encoding, DW_FORM_data1, Encoding); TypeDie->AddUInt (DW_AT_encoding, DW_FORM_data1, Encoding);
TypeDie->Complete(DW); TypeDie->Complete(DW);
// Add to context owner. // Add to context owner.
@ -958,10 +967,10 @@ DIE *DWContext::NewGlobalVariable(const std::string &Name,
// FIXME - need source file name line number. // FIXME - need source file name line number.
VariableDie = new DIE(DW_TAG_variable, DW_CHILDREN_no); VariableDie = new DIE(DW_TAG_variable, DW_CHILDREN_no);
VariableDie->AddString (DW_AT_name, DW_FORM_string, Name); VariableDie->AddString (DW_AT_name, DW_FORM_string, Name);
VariableDie->AddInt (DW_AT_decl_file, 0, 0); VariableDie->AddUInt (DW_AT_decl_file, 0, 0);
VariableDie->AddInt (DW_AT_decl_line, 0, 0); VariableDie->AddUInt (DW_AT_decl_line, 0, 0);
VariableDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type); VariableDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type);
VariableDie->AddInt (DW_AT_external, DW_FORM_flag, 1); VariableDie->AddUInt (DW_AT_external, DW_FORM_flag, 1);
// FIXME - needs to be a proper expression. // FIXME - needs to be a proper expression.
VariableDie->AddObjectLabel(DW_AT_location, DW_FORM_block1, MangledName); VariableDie->AddObjectLabel(DW_AT_location, DW_FORM_block1, MangledName);
VariableDie->Complete(DW); VariableDie->Complete(DW);
@ -1096,6 +1105,24 @@ void DwarfWriter::EmitLong(int Value) const {
PrintHex(Value); PrintHex(Value);
} }
/// EmitLongLong - Emit a long long directive and value.
///
void DwarfWriter::EmitLongLong(uint64_t Value) const {
if (Asm->Data64bitsDirective) {
O << Asm->Data64bitsDirective << "0x" << std::hex << Value << std::dec;
} else {
const TargetData &TD = Asm->TM.getTargetData();
if (TD.isBigEndian()) {
EmitLong(unsigned(Value >> 32)); O << "\n";
EmitLong(unsigned(Value));
} else {
EmitLong(unsigned(Value)); O << "\n";
EmitLong(unsigned(Value >> 32));
}
}
}
/// EmitString - Emit a string with quotes and a null terminator. /// EmitString - Emit a string with quotes and a null terminator.
/// Special characters are emitted properly. (Eg. '\t') /// Special characters are emitted properly. (Eg. '\t')
void DwarfWriter::EmitString(const std::string &String) const { void DwarfWriter::EmitString(const std::string &String) const {
@ -1249,7 +1276,7 @@ DIE *DwarfWriter::NewCompileUnit(const CompileUnitWrapper &CompileUnit) {
Unit->AddLabel (DW_AT_high_pc, DW_FORM_addr, DWLabel("text_end", 0)); Unit->AddLabel (DW_AT_high_pc, DW_FORM_addr, DWLabel("text_end", 0));
Unit->AddLabel (DW_AT_low_pc, DW_FORM_addr, DWLabel("text_begin", 0)); Unit->AddLabel (DW_AT_low_pc, DW_FORM_addr, DWLabel("text_begin", 0));
Unit->AddString(DW_AT_producer, DW_FORM_string, CompileUnit.getProducer()); Unit->AddString(DW_AT_producer, DW_FORM_string, CompileUnit.getProducer());
Unit->AddInt (DW_AT_language, DW_FORM_data1, CompileUnit.getLanguage()); Unit->AddUInt (DW_AT_language, DW_FORM_data1, CompileUnit.getLanguage());
Unit->AddString(DW_AT_name, DW_FORM_string, CompileUnit.getFileName()); Unit->AddString(DW_AT_name, DW_FORM_string, CompileUnit.getFileName());
Unit->AddString(DW_AT_comp_dir, DW_FORM_string, CompileUnit.getDirectory()); Unit->AddString(DW_AT_comp_dir, DW_FORM_string, CompileUnit.getDirectory());
Unit->Complete(*this); Unit->Complete(*this);

View File

@ -97,6 +97,19 @@ const static std::string getStringValue(Value *V, unsigned Offset = 0) {
} }
return ""; return "";
} }
/// getGlobalValue - Return either a direct or cast Global value.
///
static GlobalVariable *getGlobalValue(Value *V) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
return GV;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
return CE->getOpcode() == Instruction::Cast ? dyn_cast<GlobalVariable>(V)
: NULL;
}
return NULL;
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -112,51 +125,45 @@ CompileUnitWrapper::CompileUnitWrapper(GlobalVariable *G)
: DebugInfoWrapper(G) : DebugInfoWrapper(G)
{ {
// FIXME - should probably ease up on the number of operands (version.) // FIXME - should probably ease up on the number of operands (version.)
assert(IC->getNumOperands() == 7 && assert(IC->getNumOperands() == N_op &&
"Compile unit does not have correct number of operands"); "Compile unit does not have correct number of operands");
} }
/// getTag - Return the compile unit's tag number. Currently should be /// getTag - Return the compile unit's tag number. Currently should be
/// DW_TAG_variable. /// DW_TAG_variable.
unsigned CompileUnitWrapper::getTag() const { unsigned CompileUnitWrapper::getTag() const {
ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(0)); return cast<ConstantUInt>(IC->getOperand(Tag_op))->getValue();
assert(CI && "Compile unit tag not an unsigned integer");
return CI->getValue();
} }
/// isCorrectDebugVersion - Return true if is the correct llvm debug version. /// isCorrectDebugVersion - Return true if is the correct llvm debug version.
/// Currently the value is 0 (zero.) If the value is is not correct then /// Currently the value is 0 (zero.) If the value is is not correct then
/// ignore all debug information. /// ignore all debug information.
bool CompileUnitWrapper::isCorrectDebugVersion() const { bool CompileUnitWrapper::isCorrectDebugVersion() const {
ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(1)); return cast<ConstantUInt>(IC->getOperand(Version_op))->getValue();
assert(CI && "Compile unit debug version not an unsigned integer");
return CI->getValue() == 0;
} }
/// getLanguage - Return the compile unit's language number (ex. DW_LANG_C89.) /// getLanguage - Return the compile unit's language number (ex. DW_LANG_C89.)
/// ///
unsigned CompileUnitWrapper::getLanguage() const { unsigned CompileUnitWrapper::getLanguage() const {
ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(2)); return cast<ConstantUInt>(IC->getOperand(Language_op))->getValue();
assert(CI && "Compile unit language number not an unsigned integer");
return CI->getValue();
} }
/// getFileName - Return the compile unit's file name. /// getFileName - Return the compile unit's file name.
/// ///
const std::string CompileUnitWrapper::getFileName() const { const std::string CompileUnitWrapper::getFileName() const {
return getStringValue(IC->getOperand(3)); return getStringValue(IC->getOperand(FileName_op));
} }
/// getDirectory - Return the compile unit's file directory. /// getDirectory - Return the compile unit's file directory.
/// ///
const std::string CompileUnitWrapper::getDirectory() const { const std::string CompileUnitWrapper::getDirectory() const {
return getStringValue(IC->getOperand(4)); return getStringValue(IC->getOperand(Directory_op));
} }
/// getProducer - Return the compile unit's generator name. /// getProducer - Return the compile unit's generator name.
/// ///
const std::string CompileUnitWrapper::getProducer() const { const std::string CompileUnitWrapper::getProducer() const {
return getStringValue(IC->getOperand(5)); return getStringValue(IC->getOperand(Producer_op));
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -165,61 +172,50 @@ GlobalWrapper::GlobalWrapper(GlobalVariable *G)
: DebugInfoWrapper(G) : DebugInfoWrapper(G)
{ {
// FIXME - should probably ease up on the number of operands (version.) // FIXME - should probably ease up on the number of operands (version.)
assert(IC->getNumOperands() == 8 && assert(IC->getNumOperands() == N_op &&
"Global does not have correct number of operands"); "Global does not have correct number of operands");
} }
/// getTag - Return the global's tag number. Currently should be /// getTag - Return the global's tag number. Currently should be
/// DW_TAG_variable or DW_TAG_subprogram. /// DW_TAG_variable or DW_TAG_subprogram.
unsigned GlobalWrapper::getTag() const { unsigned GlobalWrapper::getTag() const {
ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(0)); return cast<ConstantUInt>(IC->getOperand(Tag_op))->getValue();
assert(CI && "Global tag not an unsigned integer");
return CI->getValue();
} }
/// getContext - Return the "lldb.compile_unit" context global. /// getContext - Return the "lldb.compile_unit" context global.
/// ///
GlobalVariable *GlobalWrapper::getContext() const { GlobalVariable *GlobalWrapper::getContext() const {
return cast<GlobalVariable>(IC->getOperand(1)); return getGlobalValue(IC->getOperand(Context_op));
} }
/// getName - Return the name of the global. /// getName - Return the name of the global.
/// ///
const std::string GlobalWrapper::getName() const { const std::string GlobalWrapper::getName() const {
return getStringValue(IC->getOperand(2)); return getStringValue(IC->getOperand(Name_op));
} }
/// getType - Return the type of the global. /// getType - Return the type of the global.
/// ///
const GlobalVariable *GlobalWrapper::getType() const { const GlobalVariable *GlobalWrapper::getType() const {
return cast<GlobalVariable>(IC->getOperand(4)); return getGlobalValue(IC->getOperand(Type_op));
} }
/// isStatic - Return true if the global is static. /// isStatic - Return true if the global is static.
/// ///
bool GlobalWrapper::isStatic() const { bool GlobalWrapper::isStatic() const {
ConstantBool *CB = dyn_cast<ConstantBool>(IC->getOperand(5)); return cast<ConstantBool>(IC->getOperand(Static_op))->getValue();
assert(CB && "Global static flag is not boolean");
return CB->getValue();
} }
/// isDefinition - Return true if the global is a definition. /// isDefinition - Return true if the global is a definition.
/// ///
bool GlobalWrapper::isDefinition() const { bool GlobalWrapper::isDefinition() const {
ConstantBool *CB = dyn_cast<ConstantBool>(IC->getOperand(6)); return dyn_cast<ConstantBool>(IC->getOperand(Definition_op))->getValue();
assert(CB && "Global definition flag is not boolean");
return CB->getValue();
} }
/// getGlobalVariable - Return the global variable (tag == DW_TAG_variable.) /// getGlobalVariable - Return the global variable (tag == DW_TAG_variable.)
/// ///
GlobalVariable *GlobalWrapper::getGlobalVariable() const { GlobalVariable *GlobalWrapper::getGlobalVariable() const {
ConstantExpr *CE = dyn_cast<ConstantExpr>(IC->getOperand(7)); return getGlobalValue(IC->getOperand(GlobalVariable_op));
assert(CE && CE->getOpcode() == Instruction::Cast &&
"Global location is not a cast of GlobalVariable");
GlobalVariable *GV = dyn_cast<GlobalVariable>(CE->getOperand(0));
assert(GV && "Global location is not a cast of GlobalVariable");
return GV;
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//