Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 13319ce

Browse files
author
Devang Patel
committed
The debugger sometimes lookup dynamically in the runtime to find ivar info of any Objective-C classes. It would be very helpful to debugger if the compiler encodes runtime version number in DWARF.
Add support for two additional DWARF attributes to encode Objective-C runtime version number. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64834 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent fdc40a0 commit 13319ce

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

include/llvm/Analysis/DebugInfo.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ namespace llvm {
118118
/// code generator accepts maximum one main compile unit per module. If a
119119
/// module does not contain any main compile unit then the code generator
120120
/// will emit multiple compile units in the output object file.
121+
121122
bool isMain() const { return getUnsignedField(6); }
122123
bool isOptimized() const { return getUnsignedField(7); }
123124
std::string getFlags() const { return getStringField(8); }
125+
unsigned getRunTimeVersion() const { return getUnsignedField(9); }
124126

125127
/// Verify - Verify that a compile unit is well formed.
126128
bool Verify() const;
@@ -231,6 +233,7 @@ namespace llvm {
231233
public:
232234
explicit DICompositeType(GlobalVariable *GV);
233235
DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
236+
unsigned getRunTimeLang() const { return getUnsignedField(11); }
234237

235238
/// Verify - Verify that a composite type descriptor is well formed.
236239
bool Verify() const;
@@ -381,7 +384,8 @@ namespace llvm {
381384
const std::string &Producer,
382385
bool isMain = false,
383386
bool isOptimized = false,
384-
const char *Flags = "");
387+
const char *Flags = "",
388+
unsigned RunTimeVer = 0);
385389

386390
/// CreateEnumerator - Create a single enumerator value.
387391
DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
@@ -412,7 +416,8 @@ namespace llvm {
412416
uint64_t AlignInBits,
413417
uint64_t OffsetInBits, unsigned Flags,
414418
DIType DerivedFrom,
415-
DIArray Elements);
419+
DIArray Elements,
420+
unsigned RunTimeLang = 0);
416421

417422
/// CreateSubprogram - Create a new descriptor for the specified subprogram.
418423
/// See comments in DISubprogram for descriptions of these fields.

include/llvm/Support/Dwarf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ enum dwarf_constants {
225225
// Apple extensions.
226226
DW_AT_APPLE_optimized = 0x3fe1,
227227
DW_AT_APPLE_flags = 0x3fe2,
228+
DW_AT_APPLE_major_runtime_vers = 0x3fe5,
229+
DW_AT_APPLE_runtime_class = 0x3fe6,
228230

229231
// Attribute form encodings
230232
DW_FORM_addr = 0x01,

lib/Analysis/DebugInfo.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
453453
const std::string &Producer,
454454
bool isMain,
455455
bool isOptimized,
456-
const char *Flags) {
456+
const char *Flags,
457+
unsigned RunTimeVer) {
457458
Constant *Elts[] = {
458459
GetTagConstant(dwarf::DW_TAG_compile_unit),
459460
getCastToEmpty(GetOrCreateCompileUnitAnchor()),
@@ -463,7 +464,8 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
463464
GetStringConstant(Producer),
464465
ConstantInt::get(Type::Int1Ty, isMain),
465466
ConstantInt::get(Type::Int1Ty, isOptimized),
466-
GetStringConstant(Flags)
467+
GetStringConstant(Flags),
468+
ConstantInt::get(Type::Int32Ty, RunTimeVer)
467469
};
468470

469471
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
@@ -573,7 +575,8 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
573575
uint64_t OffsetInBits,
574576
unsigned Flags,
575577
DIType DerivedFrom,
576-
DIArray Elements) {
578+
DIArray Elements,
579+
unsigned RuntimeLang) {
577580

578581
Constant *Elts[] = {
579582
GetTagConstant(Tag),
@@ -586,7 +589,8 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
586589
ConstantInt::get(Type::Int64Ty, OffsetInBits),
587590
ConstantInt::get(Type::Int32Ty, Flags),
588591
getCastToEmpty(DerivedFrom),
589-
getCastToEmpty(Elements)
592+
getCastToEmpty(Elements),
593+
ConstantInt::get(Type::Int32Ty, RuntimeLang)
590594
};
591595

592596
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));

lib/CodeGen/AsmPrinter/DwarfWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,9 @@ class DwarfDebug : public Dwarf {
17701770
DIDerivedType(Element.getGV()));
17711771
Buffer.AddChild(ElemDie);
17721772
}
1773+
unsigned RLang = CTy.getRunTimeLang();
1774+
if (RLang)
1775+
AddUInt(&Buffer, DW_AT_APPLE_runtime_class, DW_FORM_data1, RLang);
17731776
}
17741777
break;
17751778
default:
@@ -2800,6 +2803,9 @@ class DwarfDebug : public Dwarf {
28002803
const std::string &Flags = DIUnit.getFlags();
28012804
if (!Flags.empty())
28022805
AddString(Die, DW_AT_APPLE_flags, DW_FORM_string, Flags);
2806+
unsigned RVer = DIUnit.getRunTimeVersion();
2807+
if (RVer)
2808+
AddUInt(Die, DW_AT_APPLE_major_runtime_vers, DW_FORM_data1, RVer);
28032809

28042810
CompileUnit *Unit = new CompileUnit(ID, Die);
28052811
if (DIUnit.isMain()) {

lib/Support/Dwarf.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ const char *AttributeString(unsigned Attribute) {
200200
case DW_AT_hi_user: return "DW_AT_hi_user";
201201
case DW_AT_APPLE_optimized: return "DW_AT_APPLE_optimized";
202202
case DW_AT_APPLE_flags: return "DW_AT_APPLE_flags";
203+
case DW_AT_APPLE_major_runtime_vers: return "DW_AT_APPLE_major_runtime_vers";
204+
case DW_AT_APPLE_runtime_class: return "DW_AT_APPLE_runtime_class";
203205
}
204206
assert(0 && "Unknown Dwarf Attribute");
205207
return "";

tools/lto/LTOCodeGenerator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
356356
// Add an appropriate TargetData instance for this module...
357357
passes.add(new TargetData(*_target->getTargetData()));
358358

359+
std::string targetTriple = _linker.getModule()->getTargetTriple();
360+
// if ( targetTriple.find("darwin") != targetTriple.size() )
361+
passes.add(createStripSymbolsPass(true /* strip debug info only */));
362+
359363
// Propagate constants at call sites into the functions they call. This
360364
// opens opportunities for globalopt (and inlining) by substituting function
361365
// pointers passed as arguments to direct uses of functions.
@@ -412,6 +416,8 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
412416
// Make sure everything is still good.
413417
passes.add(createVerifierPass());
414418

419+
setCodeGenDebugOptions("-debug-pass=Structure");
420+
415421
FunctionPassManager* codeGenPasses =
416422
new FunctionPassManager(new ExistingModuleProvider(mergedModule));
417423

0 commit comments

Comments
 (0)