annotate gen/todebug.cpp @ 1137:45d73f0a9b43

Automated merge with http://hg.dsource.org/projects/ldc
author Christian Kamm <kamm incasoftware de>
date Tue, 24 Mar 2009 14:34:16 +0100
parents 8038b106c458
children 79758fd2f48a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
1 #include "gen/llvm.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
2 #include "llvm/Support/Dwarf.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
3 #include "llvm/CodeGen/MachineModuleInfo.h"
285
297690b5d4a5 [svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents: 268
diff changeset
4 #include "llvm/System/Path.h"
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
5
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
6 #include "declaration.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
7 #include "module.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
8 #include "mars.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
9
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
10 #include "gen/todebug.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
11 #include "gen/irstate.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
12 #include "gen/tollvm.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
13 #include "gen/logger.h"
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
14 #include "gen/llvmhelpers.h"
1064
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 998
diff changeset
15 #include "gen/linkage.h"
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
16
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
17 #include "ir/irmodule.h"
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
18
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
19 using namespace llvm::dwarf;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
20
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
21 #define DBG_NULL ( LLConstant::getNullValue(DBG_TYPE) )
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
22 #define DBG_TYPE ( getPtrToType(llvm::StructType::get(NULL,NULL)) )
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
23 #define DBG_CAST(X) ( llvm::ConstantExpr::getBitCast(X, DBG_TYPE) )
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
24
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
25 #define DBG_TAG(X) ( llvm::ConstantExpr::getAdd( DtoConstUint( X ), DtoConstUint( llvm::LLVMDebugVersion ) ) )
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
26
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
27 //////////////////////////////////////////////////////////////////////////////////////////////////
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
28
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
29 /**
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
30 * Emits a global variable, LLVM Dwarf style, only declares.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
31 * @param type Type of variable.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
32 * @param name Name.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
33 * @return The global variable.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
34 */
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
35 static LLGlobalVariable* emitDwarfGlobalDecl(const LLStructType* type, const char* name, bool linkonce=false)
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
36 {
1064
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 998
diff changeset
37 LLGlobalValue::LinkageTypes linkage = linkonce
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 998
diff changeset
38 ? DEBUGINFO_LINKONCE_LINKAGE_TYPE
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 998
diff changeset
39 : LLGlobalValue::InternalLinkage;
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
40 LLGlobalVariable* gv = new LLGlobalVariable(type, true, linkage, NULL, name, gIR->module);
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
41 gv->setSection("llvm.metadata");
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
42 return gv;
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
43 }
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
44
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
45 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
46
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
47 static llvm::DIAnchor getDwarfAnchor(dwarf_constants c)
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
48 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
49 switch (c)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
50 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
51 case DW_TAG_compile_unit:
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
52 return gIR->difactory.GetOrCreateCompileUnitAnchor();
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
53 case DW_TAG_variable:
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
54 return gIR->difactory.GetOrCreateGlobalVariableAnchor();
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
55 case DW_TAG_subprogram:
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
56 return gIR->difactory.GetOrCreateSubprogramAnchor();
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
57 default:
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
58 assert(0);
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
59 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
60 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
61
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
62 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
63
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
64 static const llvm::StructType* getDwarfCompileUnitType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
65 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type"));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
66 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
67
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
68 static const llvm::StructType* getDwarfSubProgramType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
69 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type"));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
70 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
71
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
72 static const llvm::StructType* getDwarfVariableType() {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
73 return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type"));
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
74 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
75
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
76 static const llvm::StructType* getDwarfDerivedTypeType() {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
77 return isaStruct(gIR->module->getTypeByName("llvm.dbg.derivedtype.type"));
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
78 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
79
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
80 static const llvm::StructType* getDwarfBasicTypeType() {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
81 return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type"));
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
82 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
83
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
84 static const llvm::StructType* getDwarfCompositeTypeType() {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
85 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compositetype.type"));
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
86 }
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
87
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
88 static const llvm::StructType* getDwarfGlobalVariableType() {
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
89 return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type"));
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
90 }
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
91
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
92 //////////////////////////////////////////////////////////////////////////////////////////////////
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
93
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
94 // get the module the symbol is in, or - for template instances - the current module
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
95 static Module* getDefinedModule(Dsymbol* s)
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
96 {
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
97 if (!DtoIsTemplateInstance(s))
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
98 return s->getModule();
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
99 else
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
100 return gIR->dmodule;
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
101 }
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
102
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
103 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
104
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
105 static llvm::DIType dwarfTypeDescription_impl(Type* type, llvm::DICompileUnit cu, const char* c_name);
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
106 static llvm::DIType dwarfTypeDescription(Type* type, llvm::DICompileUnit cu, const char* c_name);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
107
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
108 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
109
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
110 static llvm::DIBasicType dwarfBasicType(Type* type, llvm::DICompileUnit compileUnit)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
111 {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
112 Type* t = type->toBasetype();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
113 const LLType* T = DtoType(type);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
114
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
115 // find encoding
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
116 unsigned id;
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
117 if (t->isintegral())
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
118 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
119 if (type->isunsigned())
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
120 id = DW_ATE_unsigned;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
121 else
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
122 id = DW_ATE_signed;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
123 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
124 else if (t->isfloating())
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
125 {
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
126 id = DW_ATE_float;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
127 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
128 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
129 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
130 assert(0 && "unsupported basictype for debug info");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
131 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
132
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
133 return gIR->difactory.CreateBasicType(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
134 compileUnit, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
135 type->toChars(), // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
136 llvm::DICompileUnit(NULL), // compile unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
137 0, // line number
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
138 getTypeBitSize(T), // size (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
139 getABITypeAlign(T)*8, // align (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
140 0, // offset (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
141 //FIXME: need flags?
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
142 0, // flags
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
143 id // encoding
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
144 );
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
145 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
146
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
147 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
148
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
149 static llvm::DIDerivedType dwarfDerivedType(Type* type, llvm::DICompileUnit compileUnit)
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
150 {
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
151 const LLType* T = DtoType(type);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 285
diff changeset
152 Type* t = type->toBasetype();
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
153
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
154 assert(t->ty == Tpointer && "unsupported derivedtype for debug info, only pointers allowed");
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
155
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
156 // find base type
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
157 llvm::DIType basetype;
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
158 Type* nt = t->nextOf();
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
159 basetype = dwarfTypeDescription_impl(nt, compileUnit, NULL);
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
160 if (nt->ty == Tvoid)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
161 basetype = llvm::DIType(NULL);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
162
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
163 return gIR->difactory.CreateDerivedType(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
164 DW_TAG_pointer_type, // tag
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
165 compileUnit, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
166 "", // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
167 llvm::DICompileUnit(NULL), // compile unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
168 0, // line number
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
169 getTypeBitSize(T), // size (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
170 getABITypeAlign(T)*8, // align (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
171 0, // offset (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
172 //FIXME: need flags?
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
173 0, // flags
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
174 basetype // derived from
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
175 );
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
176 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
177
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
178 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
179
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
180 static llvm::DIDerivedType dwarfMemberType(unsigned linnum, Type* type, llvm::DICompileUnit compileUnit, llvm::DICompileUnit definedCU, const char* c_name, unsigned offset)
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
181 {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
182 const LLType* T = DtoType(type);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 285
diff changeset
183 Type* t = type->toBasetype();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
184
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
185 // find base type
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
186 llvm::DIType basetype;
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
187 basetype = dwarfTypeDescription(t, compileUnit, NULL);
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
188 if (t->ty == Tvoid)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
189 basetype = llvm::DIType(NULL);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
190
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
191 return gIR->difactory.CreateDerivedType(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
192 DW_TAG_member, // tag
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
193 compileUnit, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
194 c_name, // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
195 definedCU, // compile unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
196 linnum, // line number
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
197 getTypeBitSize(T), // size (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
198 getABITypeAlign(T)*8, // align (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
199 offset*8, // offset (bits)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
200 //FIXME: need flags?
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
201 0, // flags
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
202 basetype // derived from
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
203 );
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
204 }
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
205
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
206 //////////////////////////////////////////////////////////////////////////////////////////////////
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
207
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
208 //FIXME: This does not use llvm's DIFactory as it can't
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
209 // handle recursive types properly.
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
210 static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit compileUnit)
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
211 {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
212 const LLType* T = DtoType(type);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 285
diff changeset
213 Type* t = type->toBasetype();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
214
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
215 // defaults
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
216 LLConstant* name = getNullPtr(getVoidPtrType());
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
217 LLGlobalVariable* members = NULL;
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
218 unsigned linnum = 0;
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
219 llvm::DICompileUnit definedCU;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
220
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
221 // prepare tag and members
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
222 unsigned tag;
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
223
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
224 // declare final global variable
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
225 LLGlobalVariable* gv = NULL;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
226
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
227 // dynamic array
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
228 if (t->ty == Tarray)
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
229 {
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
230 tag = DW_TAG_structure_type;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
231
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
232 LLGlobalVariable* len = dwarfMemberType(0, Type::tsize_t, compileUnit, llvm::DICompileUnit(NULL), "length", 0).getGV();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
233 assert(len);
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
234 LLGlobalVariable* ptr = dwarfMemberType(0, t->nextOf()->pointerTo(), compileUnit, llvm::DICompileUnit(NULL), "ptr", global.params.is64bit?8:4).getGV();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
235 assert(ptr);
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
236
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
237 const LLArrayType* at = LLArrayType::get(DBG_TYPE, 2);
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
238
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
239 std::vector<LLConstant*> elems(2);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
240 elems[0] = DBG_CAST(len);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
241 elems[1] = DBG_CAST(ptr);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
242
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
243 LLConstant* ca = LLConstantArray::get(at, elems);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
244 members = new LLGlobalVariable(ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array", gIR->module);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
245 members->setSection("llvm.metadata");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
246
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
247 name = DtoConstStringPtr(t->toChars(), "llvm.metadata");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
248 }
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
249
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
250 // struct/class
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
251 else if (t->ty == Tstruct || t->ty == Tclass)
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
252 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
253 AggregateDeclaration* sd;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
254 if (t->ty == Tstruct)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
255 {
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
256 TypeStruct* ts = (TypeStruct*)t;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
257 sd = ts->sym;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
258 }
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
259 else
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
260 {
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
261 TypeClass* tc = (TypeClass*)t;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
262 sd = tc->sym;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
263 }
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
264 assert(sd);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
265
904
01d9ece9982a Fix bug #177 by not attempting to define composite debug info for
Christian Kamm <kamm incasoftware de>
parents: 811
diff changeset
266 // if we don't know the aggregate's size, we don't know enough about it
01d9ece9982a Fix bug #177 by not attempting to define composite debug info for
Christian Kamm <kamm incasoftware de>
parents: 811
diff changeset
267 // to provide debug info. probably a forward-declared struct?
01d9ece9982a Fix bug #177 by not attempting to define composite debug info for
Christian Kamm <kamm incasoftware de>
parents: 811
diff changeset
268 if (sd->sizeok == 0)
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
269 return llvm::DICompositeType(NULL);
904
01d9ece9982a Fix bug #177 by not attempting to define composite debug info for
Christian Kamm <kamm incasoftware de>
parents: 811
diff changeset
270
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
271 IrStruct* ir = sd->ir.irStruct;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
272 assert(ir);
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
273 if (!ir->diCompositeType.isNull())
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
274 return ir->diCompositeType;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
275
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
276 // set to handle recursive types properly
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
277 gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype");
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
278 // set bogus initializer to satisfy asserts in DICompositeType constructor
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
279 gv->setInitializer(LLConstant::getNullValue(getDwarfCompositeTypeType()));
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
280 ir->diCompositeType = llvm::DICompositeType(gv);
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
281
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
282 tag = DW_TAG_structure_type;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
283
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
284 name = DtoConstStringPtr(sd->toChars(), "llvm.metadata");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
285 linnum = sd->loc.linnum;
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
286 definedCU = DtoDwarfCompileUnit(getDefinedModule(sd));
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
287
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
288 std::vector<LLConstant*> elems;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
289 if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
290 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
291 std::vector<VarDeclaration*>& arr = ir->varDecls;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
292 size_t narr = arr.size();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
293 elems.reserve(narr);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
294 for (int k=0; k<narr; k++)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
295 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
296 VarDeclaration* vd = arr[k];
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
297 assert(vd);
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
298
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
299 LLGlobalVariable* ptr = dwarfMemberType(vd->loc.linnum, vd->type, compileUnit, definedCU, vd->toChars(), vd->offset).getGV();
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
300 elems.push_back(DBG_CAST(ptr));
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
301 }
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
302 }
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
303
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
304 const LLArrayType* at = LLArrayType::get(DBG_TYPE, elems.size());
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
305 LLConstant* ca = LLConstantArray::get(at, elems);
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
306 members = new LLGlobalVariable(ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array", gIR->module);
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
307 members->setSection("llvm.metadata");
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
308 }
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
309
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
310 // unsupported composite type
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
311 else
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
312 {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
313 assert(0 && "unsupported compositetype for debug info");
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
314 }
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
315
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
316 std::vector<LLConstant*> vals(11);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
317
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
318 // tag
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
319 vals[0] = DBG_TAG(tag);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
320
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
321 // context
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
322 vals[1] = DBG_CAST(compileUnit.getGV());
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
323
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
324 // name
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
325 vals[2] = name;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
326
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
327 // compile unit where defined
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
328 if (definedCU.getGV())
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
329 vals[3] = DBG_CAST(definedCU.getGV());
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
330 else
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
331 vals[3] = DBG_NULL;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
332
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
333 // line number where defined
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
334 vals[4] = DtoConstInt(linnum);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
335
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
336 // size in bits
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
337 vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
338
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
339 // alignment in bits
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
340 vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
341
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
342 // offset in bits
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
343 vals[7] = LLConstantInt::get(LLType::Int64Ty, 0, false);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
344
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
345 // FIXME: dont know what this is
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
346 vals[8] = DtoConstUint(0);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
347
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
348 // FIXME: ditto
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
349 vals[9] = DBG_NULL;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
350
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
351 // members array
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
352 if (members)
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
353 vals[10] = DBG_CAST(members);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
354 else
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
355 vals[10] = DBG_NULL;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
356
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
357 // set initializer
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
358 if (!gv)
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
359 gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
360 LLConstant* initia = LLConstantStruct::get(getDwarfCompositeTypeType(), vals);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
361 gv->setInitializer(initia);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
362
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
363 return llvm::DICompositeType(gv);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
364 }
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
365
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
366 //////////////////////////////////////////////////////////////////////////////////////////////////
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
367
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
368 static llvm::DIGlobalVariable dwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd)
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
369 {
998
ff22650d0ca3 Fixed debug info for globals in D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 955
diff changeset
370 #if DMDV2
ff22650d0ca3 Fixed debug info for globals in D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 955
diff changeset
371 assert(vd->isDataseg() || (vd->storage_class & (STCconst | STCinvariant) && vd->init));
ff22650d0ca3 Fixed debug info for globals in D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 955
diff changeset
372 #else
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
373 assert(vd->isDataseg());
998
ff22650d0ca3 Fixed debug info for globals in D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 955
diff changeset
374 #endif
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
375 llvm::DICompileUnit compileUnit = DtoDwarfCompileUnit(gIR->dmodule);
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
376
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
377 return gIR->difactory.CreateGlobalVariable(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
378 compileUnit, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
379 vd->mangle(), // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
380 vd->toPrettyChars(), // displayname
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
381 vd->toChars(), // linkage name
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
382 DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
383 vd->loc.linnum, // line num
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
384 dwarfTypeDescription_impl(vd->type, compileUnit, NULL), // type
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
385 vd->protection == PROTprivate, // is local to unit
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
386 getDefinedModule(vd) == gIR->dmodule, // is definition
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
387 ll // value
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
388 );
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
389 }
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
390
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
391 //////////////////////////////////////////////////////////////////////////////////////////////////
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
392
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
393 static llvm::DIVariable dwarfVariable(VarDeclaration* vd, llvm::DIType type)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
394 {
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
395 assert(!vd->isDataseg() && "static variable");
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
396
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
397 unsigned tag;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
398 if (vd->isParameter())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
399 tag = DW_TAG_arg_variable;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
400 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
401 tag = DW_TAG_auto_variable;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
402
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
403 return gIR->difactory.CreateVariable(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
404 tag, // tag
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
405 gIR->func()->diSubprogram, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
406 vd->toChars(), // name
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
407 DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
408 vd->loc.linnum, // line num
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
409 type // type
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
410 );
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
411 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
412
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
413 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
414
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
415 static void dwarfDeclare(LLValue* var, llvm::DIVariable divar)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
416 {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
417 gIR->difactory.InsertDeclare(var, divar, gIR->scopebb());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
418 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
419
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
420 //////////////////////////////////////////////////////////////////////////////////////////////////
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
421
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
422 static llvm::DIType dwarfTypeDescription_impl(Type* type, llvm::DICompileUnit cu, const char* c_name)
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
423 {
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
424 Type* t = type->toBasetype();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
425 if (t->ty == Tvoid)
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
426 return llvm::DIType(NULL);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
427 else if (t->isintegral() || t->isfloating())
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
428 return dwarfBasicType(type, cu);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
429 else if (t->ty == Tpointer)
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
430 return dwarfDerivedType(type, cu);
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
431 else if (t->ty == Tarray || t->ty == Tstruct || t->ty == Tclass)
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
432 return dwarfCompositeType(type, cu);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
433
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
434 return llvm::DIType(NULL);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
435 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
436
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
437 static llvm::DIType dwarfTypeDescription(Type* type, llvm::DICompileUnit cu, const char* c_name)
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
438 {
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
439 Type* t = type->toBasetype();
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
440 if (t->ty == Tclass)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
441 return dwarfTypeDescription_impl(type->pointerTo(), cu, c_name);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
442 else
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
443 return dwarfTypeDescription_impl(type, cu, c_name);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
444 }
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
445
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
446 //////////////////////////////////////////////////////////////////////////////////////////////////
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
447
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
448 void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd)
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
449 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
450 Logger::println("D to dwarf local variable");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
451 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
452
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
453 // get compile units
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
454 llvm::DICompileUnit thisCU = DtoDwarfCompileUnit(gIR->dmodule);
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
455 llvm::DICompileUnit varCU = DtoDwarfCompileUnit(getDefinedModule(vd));
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
456
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
457 // get type description
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
458 llvm::DIType TD = dwarfTypeDescription(vd->type, thisCU, NULL);
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
459 if (TD.isNull())
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
460 return; // unsupported
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
461
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
462 // get variable description
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
463 llvm::DIVariable VD = dwarfVariable(vd, TD);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
464
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
465 // declare
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
466 dwarfDeclare(ll, VD);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
467 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
468
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
469 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
470
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
471 llvm::DICompileUnit DtoDwarfCompileUnit(Module* m)
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
472 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
473 Logger::println("D to dwarf compile_unit");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
474 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
475
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
476 // we might be generating for an import
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
477 if (!m->ir.irModule)
683
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
478 m->ir.irModule = new IrModule(m, m->srcfile->toChars());
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
479 else if (!m->ir.irModule->diCompileUnit.isNull())
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
480 {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
481 assert (m->ir.irModule->diCompileUnit.getGV()->getParent() == gIR->module
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
482 && "debug info compile unit belongs to incorrect llvm module!");
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
483 return m->ir.irModule->diCompileUnit;
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
484 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
485
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
486 // prepare srcpath
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
487 std::string srcpath(FileName::path(m->srcfile->name->toChars()));
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
488 if (!FileName::absolute(srcpath.c_str())) {
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
489 llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory();
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
490 tmp.appendComponent(srcpath);
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
491 srcpath = tmp.toString();
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
492 if (!srcpath.empty() && *srcpath.rbegin() != '/' && *srcpath.rbegin() != '\\')
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
493 srcpath = srcpath + '/';
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
494 }
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
495
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
496 // make compile unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
497 m->ir.irModule->diCompileUnit = gIR->difactory.CreateCompileUnit(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
498 global.params.symdebug == 2 ? DW_LANG_C : DW_LANG_D,
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
499 m->srcfile->name->toChars(),
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
500 srcpath,
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
501 "LDC (http://www.dsource.org/projects/ldc)",
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
502 //FIXME: What do these two mean?
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
503 false, // isMain,
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
504 false // isOptimized
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
505 );
1066
186d44690036 Give compile units LinkOnceLinkage to circumvent duplicate symbols with LLVM linking.
Christian Kamm <kamm incasoftware de>
parents: 998
diff changeset
506
186d44690036 Give compile units LinkOnceLinkage to circumvent duplicate symbols with LLVM linking.
Christian Kamm <kamm incasoftware de>
parents: 998
diff changeset
507 // if the linkage stays internal, we can't llvm-link the generated modules together:
186d44690036 Give compile units LinkOnceLinkage to circumvent duplicate symbols with LLVM linking.
Christian Kamm <kamm incasoftware de>
parents: 998
diff changeset
508 // llvm's DwarfWriter uses path and filename to determine the symbol name and we'd
186d44690036 Give compile units LinkOnceLinkage to circumvent duplicate symbols with LLVM linking.
Christian Kamm <kamm incasoftware de>
parents: 998
diff changeset
509 // end up with duplicate symbols
1069
8038b106c458 Make CompileUnit linkage compatible with llvm trunk.
Christian Kamm <kamm incasoftware de>
parents: 1068
diff changeset
510 m->ir.irModule->diCompileUnit.getGV()->setLinkage(DEBUGINFO_LINKONCE_LINKAGE_TYPE);
1066
186d44690036 Give compile units LinkOnceLinkage to circumvent duplicate symbols with LLVM linking.
Christian Kamm <kamm incasoftware de>
parents: 998
diff changeset
511 m->ir.irModule->diCompileUnit.getGV()->setName(std::string("llvm.dbg.compile_unit_") + srcpath + m->srcfile->name->toChars());
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
512
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
513 return m->ir.irModule->diCompileUnit;
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
514 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
515
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
516 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
517
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
518 llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd)
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
519 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
520 Logger::println("D to dwarf subprogram");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
521 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
522
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
523 llvm::DICompileUnit context = DtoDwarfCompileUnit(gIR->dmodule);
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
524 llvm::DICompileUnit definition = DtoDwarfCompileUnit(getDefinedModule(fd));
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
525
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
526 // FIXME: duplicates ?
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
527 return gIR->difactory.CreateSubprogram(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
528 context, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
529 fd->toPrettyChars(), // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
530 fd->toPrettyChars(), // display name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
531 fd->mangle(), // linkage name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
532 definition, // compile unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
533 fd->loc.linnum, // line no
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
534 //FIXME: what's this type for?
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
535 llvm::DIType(NULL), // type
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
536 fd->protection == PROTprivate, // is local to unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
537 context.getGV() == definition.getGV() // isdefinition
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
538 );
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
539 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
540
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
541 //////////////////////////////////////////////////////////////////////////////////////////////////
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
542
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
543 llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char* mangledname)
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
544 {
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
545 Logger::println("D to dwarf subprogram");
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
546 LOG_SCOPE;
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
547
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
548 llvm::DICompileUnit context = DtoDwarfCompileUnit(gIR->dmodule);
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
549
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
550 // FIXME: duplicates ?
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
551 return gIR->difactory.CreateSubprogram(
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
552 context, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
553 prettyname, // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
554 prettyname, // display name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
555 mangledname, // linkage name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
556 context, // compile unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
557 0, // line no
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
558 //FIXME: what's this type for?
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
559 llvm::DIType(NULL), // type
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
560 true, // is local to unit
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
561 true // isdefinition
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
562 );
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
563 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
564
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
565 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
566
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
567 llvm::DIGlobalVariable DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd)
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
568 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
569 Logger::println("D to dwarf global_variable");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
570 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
571
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
572 // FIXME: duplicates ?
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
573 return dwarfGlobalVariable(ll, vd);
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
574 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
575
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
576 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
577
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
578 void DtoDwarfFuncStart(FuncDeclaration* fd)
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
579 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
580 Logger::println("D to dwarf funcstart");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
581 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
582
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
583 assert(!fd->ir.irFunc->diSubprogram.isNull());
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
584 gIR->difactory.InsertSubprogramStart(fd->ir.irFunc->diSubprogram, gIR->scopebb());
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
585 }
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
586
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
587 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
588
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
589 void DtoDwarfFuncEnd(FuncDeclaration* fd)
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
590 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
591 Logger::println("D to dwarf funcend");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
592 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
593
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
594 assert(!fd->ir.irFunc->diSubprogram.isNull());
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
595 gIR->difactory.InsertRegionEnd(fd->ir.irFunc->diSubprogram, gIR->scopebb());
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
596 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
597
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
598 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
599
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
600 void DtoDwarfStopPoint(unsigned ln)
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
601 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
602 Logger::println("D to dwarf stoppoint at line %u", ln);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
603 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
604
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
605 gIR->difactory.InsertStopPoint(
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
606 DtoDwarfCompileUnit(getDefinedModule(gIR->func()->decl)), // compile unit
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
607 ln, // line no
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
608 0, // col no
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
609 gIR->scopebb()
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
610 );
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
611 }