annotate gen/todebug.cpp @ 1638:0de4525a9ed6

Apply workaround for #395 by klickverbot.
author Christian Kamm <kamm incasoftware de>
date Mon, 08 Mar 2010 20:06:08 +0100
parents 8d086d552909
children 40bd4a0d4870
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"
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1069
diff changeset
16 #include "gen/utils.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
17
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
18 #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
19
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
20 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
21
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
22 #define DBG_NULL ( LLConstant::getNullValue(DBG_TYPE) )
1569
755abafbf25d Push the context through StructType::get.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
23 #define DBG_TYPE ( getPtrToType(llvm::StructType::get(gIR->context(),NULL,NULL)) )
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
24 #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
25
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1545
diff changeset
26 #define DBG_TAG(X) ( llvm::ConstantExpr::getAdd( DtoConstUint( X ), DtoConstUint( llvm::LLVMDebugVersion ) ) )
250
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
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
30 /**
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
31 * Emits a global variable, LLVM Dwarf style, only declares.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
32 * @param type Type of variable.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
33 * @param name Name.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
34 * @return The global variable.
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
35 */
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
36 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
37 {
1064
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 998
diff changeset
38 LLGlobalValue::LinkageTypes linkage = linkonce
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 998
diff changeset
39 ? DEBUGINFO_LINKONCE_LINKAGE_TYPE
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 998
diff changeset
40 : LLGlobalValue::InternalLinkage;
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1517
diff changeset
41 LLGlobalVariable* gv = new LLGlobalVariable(*gIR->module, type, true, linkage, NULL, name);
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
42 gv->setSection("llvm.metadata");
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
43 return gv;
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
44 }
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
45
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
46 //////////////////////////////////////////////////////////////////////////////////////////////////
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
47
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
48 static const llvm::StructType* getDwarfCompileUnitType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
49 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
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
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
52 static const llvm::StructType* getDwarfSubProgramType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
53 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
54 }
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
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
56 static const llvm::StructType* getDwarfVariableType() {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
57 return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type"));
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
58 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
59
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
60 static const llvm::StructType* getDwarfDerivedTypeType() {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
61 return isaStruct(gIR->module->getTypeByName("llvm.dbg.derivedtype.type"));
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
62 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
63
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
64 static const llvm::StructType* getDwarfBasicTypeType() {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
65 return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type"));
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
66 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
67
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
68 static const llvm::StructType* getDwarfCompositeTypeType() {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
69 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compositetype.type"));
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
70 }
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
71
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
72 static const llvm::StructType* getDwarfGlobalVariableType() {
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
73 return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type"));
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
74 }
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
75
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
76 //////////////////////////////////////////////////////////////////////////////////////////////////
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
77
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
78 // 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
79 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
80 {
1322
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
81 // templates are defined in current module
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
82 if (DtoIsTemplateInstance(s))
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
83 {
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
84 return gIR->dmodule;
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
85 }
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
86 // array operations as well
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
87 else if (FuncDeclaration* fd = s->isFuncDeclaration())
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
88 {
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
89 if (fd->isArrayOp)
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
90 return gIR->dmodule;
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
91 }
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
92 // otherwise use the symbol's module
b8c2f3e05b52 Fixed compile unit for debug info for array operations, fixed ticket #280 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
93 return s->getModule();
955
8a70b4381369 Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
94 }
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
95
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
96 //////////////////////////////////////////////////////////////////////////////////////////////////
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
97
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
98 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
99 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
100
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
101 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
102
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
103 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
104 {
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
105 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
106 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
107
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
108 // 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
109 unsigned id;
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
110 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
111 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
112 if (type->isunsigned())
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
113 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
114 else
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
115 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
116 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
117 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
118 {
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
119 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
120 }
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
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
122 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
123 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
124 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
125
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
126 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
127 compileUnit, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
128 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
129 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
130 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
131 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
132 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
133 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
134 //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
135 0, // flags
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
136 id // encoding
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
137 );
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
138 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
139
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
140 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
141
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
142 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
143 {
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
144 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
145 Type* t = type->toBasetype();
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
146
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
147 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
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 // 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
150 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
151 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
152 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
153 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
154 basetype = llvm::DIType(NULL);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
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 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
157 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
158 compileUnit, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
159 "", // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
160 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
161 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
162 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
163 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
164 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
165 //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
166 0, // flags
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
167 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
168 );
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
169 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
170
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
171 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
172
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
173 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
174 {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
175 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
176 Type* t = type->toBasetype();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
177
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
178 // 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
179 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
180 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
181 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
182 basetype = llvm::DIType(NULL);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
183
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
184 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
185 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
186 compileUnit, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
187 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
188 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
189 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
190 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
191 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
192 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
193 //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
194 0, // flags
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
195 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
196 );
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
197 }
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
198
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
199 //////////////////////////////////////////////////////////////////////////////////////////////////
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
200
1388
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
201 static void add_base_fields(
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
202 ClassDeclaration* sd,
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
203 llvm::DICompileUnit compileUnit,
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
204 llvm::DICompileUnit definedCU,
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
205 std::vector<LLConstant*>& elems)
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
206 {
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
207 if (sd->baseClass)
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
208 {
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
209 add_base_fields(sd->baseClass, compileUnit, definedCU, elems);
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
210 }
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
211
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
212 ArrayIter<VarDeclaration> it(sd->fields);
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
213 size_t narr = sd->fields.dim;
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
214 elems.reserve(narr);
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
215 for (; !it.done(); it.next())
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
216 {
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
217 VarDeclaration* vd = it.get();
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
218 LLGlobalVariable* ptr = dwarfMemberType(vd->loc.linnum, vd->type, compileUnit, definedCU, vd->toChars(), vd->offset).getGV();
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
219 elems.push_back(DBG_CAST(ptr));
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
220 }
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
221 }
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
222
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
223 //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
224 // 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
225 static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit compileUnit)
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
226 {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
227 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
228 Type* t = type->toBasetype();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
229
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
230 // defaults
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
231 LLConstant* name = getNullPtr(getVoidPtrType());
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
232 LLGlobalVariable* members = NULL;
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
233 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
234 llvm::DICompileUnit definedCU;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
235
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
236 // prepare tag and members
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
237 unsigned tag;
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
238
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
239 // declare final global variable
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
240 LLGlobalVariable* gv = NULL;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
241
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
242 // dynamic array
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
243 if (t->ty == Tarray)
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
244 {
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
245 tag = DW_TAG_structure_type;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
246
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
247 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
248 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
249 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
250 assert(ptr);
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
251
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
252 const LLArrayType* at = LLArrayType::get(DBG_TYPE, 2);
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
253
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
254 std::vector<LLConstant*> elems(2);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
255 elems[0] = DBG_CAST(len);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
256 elems[1] = DBG_CAST(ptr);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
257
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
258 LLConstant* ca = LLConstantArray::get(at, elems);
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1517
diff changeset
259 members = new LLGlobalVariable(*gIR->module, ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array");
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
260 members->setSection("llvm.metadata");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
261
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
262 name = DtoConstStringPtr(t->toChars(), "llvm.metadata");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
263 }
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
264
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
265 // struct/class
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
266 else if (t->ty == Tstruct || t->ty == Tclass)
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
267 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
268 AggregateDeclaration* sd;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
269 if (t->ty == Tstruct)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
270 {
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
271 TypeStruct* ts = (TypeStruct*)t;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
272 sd = ts->sym;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
273 }
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
274 else
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
275 {
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
276 TypeClass* tc = (TypeClass*)t;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
277 sd = tc->sym;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
278 }
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
279 assert(sd);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
280
1237
73b56541152c Make sure aggregates are resolved before outputting their debug info.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
281 // make sure it's resolved
73b56541152c Make sure aggregates are resolved before outputting their debug info.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
282 sd->codegen(Type::sir);
73b56541152c Make sure aggregates are resolved before outputting their debug info.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
283
904
01d9ece9982a Fix bug #177 by not attempting to define composite debug info for
Christian Kamm <kamm incasoftware de>
parents: 811
diff changeset
284 // 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
285 // 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
286 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
287 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
288
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
289 IrStruct* ir = sd->ir.irStruct;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
290 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
291 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
292 return ir->diCompositeType;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
293
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
294 // set to handle recursive types properly
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
295 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
296 // set bogus initializer to satisfy asserts in DICompositeType constructor
1517
a7a9e461512a Make debug info work with newer LLVM.
Christian Kamm <kamm incasoftware de>
parents: 1504
diff changeset
297 std::vector<LLConstant*> initvals(11);
a7a9e461512a Make debug info work with newer LLVM.
Christian Kamm <kamm incasoftware de>
parents: 1504
diff changeset
298 initvals[0] = DBG_TAG(DW_TAG_structure_type);
a7a9e461512a Make debug info work with newer LLVM.
Christian Kamm <kamm incasoftware de>
parents: 1504
diff changeset
299 for (int i = 1; i < initvals.size(); ++i)
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
300 initvals[i] = LLConstant::getNullValue(getDwarfCompositeTypeType()->getContainedType(i));
1517
a7a9e461512a Make debug info work with newer LLVM.
Christian Kamm <kamm incasoftware de>
parents: 1504
diff changeset
301 gv->setInitializer(LLConstantStruct::get(getDwarfCompositeTypeType(), initvals));
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
302 ir->diCompositeType = llvm::DICompositeType(gv);
252
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 tag = DW_TAG_structure_type;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
305
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
306 name = DtoConstStringPtr(sd->toChars(), "llvm.metadata");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
307 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
308 definedCU = DtoDwarfCompileUnit(getDefinedModule(sd));
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 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
311 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
312 {
1388
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
313 if (t->ty == Tstruct)
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 736
diff changeset
314 {
1388
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
315 ArrayIter<VarDeclaration> it(sd->fields);
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
316 size_t narr = sd->fields.dim;
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
317 elems.reserve(narr);
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
318 for (; !it.done(); it.next())
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
319 {
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
320 VarDeclaration* vd = it.get();
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
321 LLGlobalVariable* ptr = dwarfMemberType(vd->loc.linnum, vd->type, compileUnit, definedCU, vd->toChars(), vd->offset).getGV();
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
322 elems.push_back(DBG_CAST(ptr));
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
323 }
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
324 }
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
325 else
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
326 {
5a54b39af6d6 Add debug info for all class fields, including those from super classes...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1322
diff changeset
327 add_base_fields(ir->aggrdecl->isClassDeclaration(), compileUnit, definedCU, 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
328 }
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
329 }
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
330
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
331 const LLArrayType* at = LLArrayType::get(DBG_TYPE, elems.size());
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
332 LLConstant* ca = LLConstantArray::get(at, elems);
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1517
diff changeset
333 members = new LLGlobalVariable(*gIR->module, ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array");
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
334 members->setSection("llvm.metadata");
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
335 }
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
336
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
337 // unsupported composite type
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
338 else
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
339 {
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
340 assert(0 && "unsupported compositetype for debug info");
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
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
343 std::vector<LLConstant*> vals(11);
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 // tag
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
346 vals[0] = DBG_TAG(tag);
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 // context
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
349 vals[1] = DBG_CAST(compileUnit.getGV());
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 // name
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
352 vals[2] = name;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
353
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
354 // 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
355 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
356 vals[3] = DBG_CAST(definedCU.getGV());
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
357 else
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
358 vals[3] = DBG_NULL;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
359
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
360 // line number where defined
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
361 vals[4] = DtoConstInt(linnum);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
362
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
363 // size in bits
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
364 vals[5] = LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getTypeBitSize(T), false);
246
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 // alignment in bits
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
367 vals[6] = LLConstantInt::get(LLType::getInt64Ty(gIR->context()), getABITypeAlign(T)*8, false);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
368
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
369 // offset in bits
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
370 vals[7] = LLConstantInt::get(LLType::getInt64Ty(gIR->context()), 0, false);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
371
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
372 // FIXME: dont know what this is
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
373 vals[8] = DtoConstUint(0);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
374
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
375 // FIXME: ditto
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
376 vals[9] = DBG_NULL;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
377
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
378 // members array
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
379 if (members)
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
380 vals[10] = DBG_CAST(members);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
381 else
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
382 vals[10] = DBG_NULL;
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
383
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
384 // set initializer
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
385 if (!gv)
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
386 gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype");
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
387 LLConstant* initia = LLConstantStruct::get(getDwarfCompositeTypeType(), vals);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
388 gv->setInitializer(initia);
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
389
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
390 return llvm::DICompositeType(gv);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
391 }
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
392
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
393 //////////////////////////////////////////////////////////////////////////////////////////////////
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
394
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
395 static llvm::DIGlobalVariable dwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd)
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
396 {
998
ff22650d0ca3 Fixed debug info for globals in D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 955
diff changeset
397 #if DMDV2
1504
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1388
diff changeset
398 assert(vd->isDataseg() || (vd->storage_class & (STCconst | STCimmutable) && vd->init));
998
ff22650d0ca3 Fixed debug info for globals in D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 955
diff changeset
399 #else
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
400 assert(vd->isDataseg());
998
ff22650d0ca3 Fixed debug info for globals in D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 955
diff changeset
401 #endif
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
402 llvm::DICompileUnit compileUnit = DtoDwarfCompileUnit(gIR->dmodule);
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
403
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
404 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
405 compileUnit, // 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->mangle(), // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414 ll // value
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
415 );
247
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
416 }
56199753e637 [svn r264] Fixed debug info for global variables.
lindquist
parents: 246
diff changeset
417
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
418 //////////////////////////////////////////////////////////////////////////////////////////////////
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
419
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
420 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
421 {
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
422 assert(!vd->isDataseg() && "static variable");
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
423
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
424 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
425 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
426 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
427 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
428 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
429
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
430 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
431 tag, // tag
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
432 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
433 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
434 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
435 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
436 type // type
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
437 );
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
438 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
439
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
440 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
441
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
442 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
443 {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
444 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
445 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
446
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
447 //////////////////////////////////////////////////////////////////////////////////////////////////
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
448
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
449 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
450 {
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
451 Type* t = type->toBasetype();
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
452 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
453 return llvm::DIType(NULL);
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
454 else if (t->isintegral() || t->isfloating())
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
455 return dwarfBasicType(type, cu);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
456 else if (t->ty == Tpointer)
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
457 return dwarfDerivedType(type, cu);
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
458 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
459 return dwarfCompositeType(type, cu);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
460
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
461 return llvm::DIType(NULL);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
462 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
463
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
464 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
465 {
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
466 Type* t = type->toBasetype();
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
467 if (t->ty == Tclass)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
468 return dwarfTypeDescription_impl(type->pointerTo(), cu, c_name);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
469 else
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
470 return dwarfTypeDescription_impl(type, cu, c_name);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
471 }
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
472
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
473 //////////////////////////////////////////////////////////////////////////////////////////////////
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
474
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
475 void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd)
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
476 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
477 Logger::println("D to dwarf local variable");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
478 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
479
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
480 // 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
481 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
482 llvm::DICompileUnit varCU = DtoDwarfCompileUnit(getDefinedModule(vd));
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
483
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
484 // 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
485 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
486 if (TD.isNull())
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
487 return; // unsupported
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
488
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
489 // 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
490 llvm::DIVariable VD = dwarfVariable(vd, TD);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
491
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
492 // declare
246
b604c56945b0 [svn r263] Changed *** ATTENTION *** to warnings.
lindquist
parents: 245
diff changeset
493 dwarfDeclare(ll, VD);
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
494 }
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
495
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
496 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
497
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
498 llvm::DICompileUnit DtoDwarfCompileUnit(Module* m)
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
499 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
500 Logger::println("D to dwarf compile_unit");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
501 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
502
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
503 // we might be generating for an import
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
504 IrModule* irmod = getIrModule(m);
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
505
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
506 if (!irmod->diCompileUnit.isNull())
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
507 {
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
508 assert (irmod->diCompileUnit.getGV()->getParent() == gIR->module
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
509 && "debug info compile unit belongs to incorrect llvm module!");
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
510 return irmod->diCompileUnit;
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
511 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
512
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
513 // prepare srcpath
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
514 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
515 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
516 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
517 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
518 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
519 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
520 srcpath = srcpath + '/';
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
521 }
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
522
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
523 // make compile unit
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
524 irmod->diCompileUnit = gIR->difactory.CreateCompileUnit(
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
525 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
526 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
527 srcpath,
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
528 "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
529 //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
530 false, // isMain,
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
531 false // isOptimized
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
532 );
1066
186d44690036 Give compile units LinkOnceLinkage to circumvent duplicate symbols with LLVM linking.
Christian Kamm <kamm incasoftware de>
parents: 998
diff changeset
533
186d44690036 Give compile units LinkOnceLinkage to circumvent duplicate symbols with LLVM linking.
Christian Kamm <kamm incasoftware de>
parents: 998
diff changeset
534 // 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
535 // 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
536 // end up with duplicate symbols
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
537 irmod->diCompileUnit.getGV()->setLinkage(DEBUGINFO_LINKONCE_LINKAGE_TYPE);
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
538 irmod->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
539
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1237
diff changeset
540 return irmod->diCompileUnit;
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
541 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
542
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
543 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
544
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
545 llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd)
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
546 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
547 Logger::println("D to dwarf subprogram");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
548 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
549
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
550 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
551 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
552
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
553 // 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
554 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
555 context, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
556 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
557 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
558 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
559 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
560 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
561 //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
562 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
563 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
564 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
565 );
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
566 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
567
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
568 //////////////////////////////////////////////////////////////////////////////////////////////////
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
569
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
570 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
571 {
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
572 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
573 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
574
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
575 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
576
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
577 // 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
578 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
579 context, // context
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
580 prettyname, // name
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
581 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
582 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
583 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
584 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
585 //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
586 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
587 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
588 true // isdefinition
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
589 );
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
590 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
591
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
592 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
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 llvm::DIGlobalVariable DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd)
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
595 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
596 Logger::println("D to dwarf global_variable");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
597 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
598
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
599 // FIXME: duplicates ?
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
600 return dwarfGlobalVariable(ll, vd);
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
601 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
602
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
603 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
604
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
605 void DtoDwarfFuncStart(FuncDeclaration* fd)
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
606 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
607 Logger::println("D to dwarf funcstart");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
608 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
609
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
610 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
611 gIR->difactory.InsertSubprogramStart(fd->ir.irFunc->diSubprogram, gIR->scopebb());
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
612 }
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
613
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
614 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
615
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
616 void DtoDwarfFuncEnd(FuncDeclaration* fd)
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
617 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
618 Logger::println("D to dwarf funcend");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
619 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
620
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
621 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
622 gIR->difactory.InsertRegionEnd(fd->ir.irFunc->diSubprogram, gIR->scopebb());
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
623 }
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
624
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
625 //////////////////////////////////////////////////////////////////////////////////////////////////
245
d61ce72c39ab [svn r262] Fixed debug info for normal function parameters.
lindquist
parents: 244
diff changeset
626
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
627 void DtoDwarfStopPoint(unsigned ln)
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
628 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
629 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
630 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 252
diff changeset
631
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
632 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
633 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
634 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
635 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
636 gIR->scopebb()
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 904
diff changeset
637 );
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 247
diff changeset
638 }