annotate gen/todebug.cpp @ 244:a95056b3c996 trunk

[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB. Did a lot of smaller cleans up here and there. Replaced more llvm::Foo with LLFoo for common stuff. Split up tollvm.cpp.
author lindquist
date Mon, 09 Jun 2008 09:37:08 +0200
parents 0806379a5eca
children d61ce72c39ab
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"
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
4
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 #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
6 #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
7 #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
8
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 #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
10 #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
11 #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
12 #include "gen/logger.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
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
14 #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
15
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
16 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
17
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
18 static const llvm::PointerType* ptrTy(const LLType* t)
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
19 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 131
diff changeset
20 return llvm::PointerType::get(t, 0);
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
21 }
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
22
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
23 static const llvm::PointerType* dbgArrTy()
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
24 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
25 return ptrTy(llvm::StructType::get(NULL,NULL));
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
26 }
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
27
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
28 static LLConstant* dbgToArrTy(LLConstant* c)
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
29 {
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
30 return llvm::ConstantExpr::getBitCast(c, dbgArrTy());
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
31 }
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
32
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
33 #define Ty(X) LLType::X
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
34
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
35 //////////////////////////////////////////////////////////////////////////////////////////////////
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
36
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
37 static llvm::GlobalVariable* dbg_compile_units = 0;
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
38 static llvm::GlobalVariable* dbg_global_variables = 0;
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
39 static llvm::GlobalVariable* dbg_subprograms = 0;
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
40
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
41 const llvm::StructType* GetDwarfAnchorType()
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
42 {
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
43 /*
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
44 %llvm.dbg.anchor.type = type {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
45 uint, ;; Tag = 0 + LLVMDebugVersion
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 uint ;; Tag of descriptors grouped by the anchor
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 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
48 */
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
49
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
50 const llvm::StructType* t = isaStruct(gIR->module->getTypeByName("llvm.dbg.anchor.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
51
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
52 /*
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
53 %llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 17 } ;; DW_TAG_compile_unit
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 %llvm.dbg.global_variables = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 52 } ;; DW_TAG_variable
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 %llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 46 } ;; DW_TAG_subprogram
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
56 */
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
57 if (!gIR->module->getNamedGlobal("llvm.dbg.compile_units")) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
58 std::vector<LLConstant*> vals;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
59 vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
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
60 vals.push_back(DtoConstUint(DW_TAG_compile_unit));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
61 LLConstant* i = llvm::ConstantStruct::get(t, vals);
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
62 dbg_compile_units = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.compile_units",gIR->module);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
63 dbg_compile_units->setSection("llvm.metadata");
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
64 }
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
65 if (!gIR->module->getNamedGlobal("llvm.dbg.global_variables")) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
66 std::vector<LLConstant*> vals;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
67 vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
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
68 vals.push_back(DtoConstUint(DW_TAG_variable));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
69 LLConstant* i = llvm::ConstantStruct::get(t, vals);
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
70 dbg_global_variables = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.global_variables",gIR->module);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
71 dbg_global_variables->setSection("llvm.metadata");
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
72 }
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
73 if (!gIR->module->getNamedGlobal("llvm.dbg.subprograms")) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
74 std::vector<LLConstant*> vals;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
75 vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
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
76 vals.push_back(DtoConstUint(DW_TAG_subprogram));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
77 LLConstant* i = llvm::ConstantStruct::get(t, vals);
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
78 dbg_subprograms = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.subprograms",gIR->module);
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
79 dbg_subprograms->setSection("llvm.metadata");
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
80 }
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
81
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
82 return t;
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
83 }
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
84
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
85 LLConstant* GetDwarfAnchor(llvm::dwarf::dwarf_constants c)
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
86 {
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
87 GetDwarfAnchorType();
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
88 switch (c)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
89 {
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
90 case DW_TAG_compile_unit:
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
91 return dbg_compile_units;
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
92 case DW_TAG_variable:
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
93 return dbg_global_variables;
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
94 case DW_TAG_subprogram:
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 return dbg_subprograms;
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 assert(0);
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
98 return 0;
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
99 }
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
100
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
101 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
102
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
103 const llvm::StructType* GetDwarfCompileUnitType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
104 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
105 }
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
106
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
107 const llvm::StructType* GetDwarfSubProgramType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
108 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
109 }
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
110
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
111 //////////////////////////////////////////////////////////////////////////////////////////////////
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
112
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
113 llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m)
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
114 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
115 if (!m->ir.irModule)
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
116 m->ir.irModule = new IrModule(m);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
117 else if (m->ir.irModule->dwarfCompileUnit)
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
118 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
119 if (m->ir.irModule->dwarfCompileUnit->getParent() == gIR->module)
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
120 return m->ir.irModule->dwarfCompileUnit;
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
121 }
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
122
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
123 // create a valid compile unit constant for the current module
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
124
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
125 LLConstant* c = NULL;
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
126
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
127 std::vector<LLConstant*> vals;
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
128 vals.push_back(llvm::ConstantExpr::getAdd(
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
129 DtoConstUint(DW_TAG_compile_unit),
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
130 DtoConstUint(llvm::LLVMDebugVersion)));
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
131 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_compile_unit)));
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
132
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
133 vals.push_back(DtoConstUint(DW_LANG_C));// _D)); // doesn't seem to work
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
134 vals.push_back(DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata"));
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
135 std::string srcpath(FileName::path(m->srcfile->name->toChars()));
140
ffcc9a2f3d9d [svn r144] fixes
lindquist
parents: 139
diff changeset
136 if (srcpath.empty()) {
ffcc9a2f3d9d [svn r144] fixes
lindquist
parents: 139
diff changeset
137 const char* str = get_current_dir_name();
ffcc9a2f3d9d [svn r144] fixes
lindquist
parents: 139
diff changeset
138 assert(str != NULL);
ffcc9a2f3d9d [svn r144] fixes
lindquist
parents: 139
diff changeset
139 srcpath = str;
ffcc9a2f3d9d [svn r144] fixes
lindquist
parents: 139
diff changeset
140 }
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
141 vals.push_back(DtoConstStringPtr(srcpath.c_str(), "llvm.metadata"));
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
142 vals.push_back(DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata"));
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
143
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
144 c = llvm::ConstantStruct::get(GetDwarfCompileUnitType(), vals);
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
145
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
146 llvm::GlobalVariable* gv = new llvm::GlobalVariable(GetDwarfCompileUnitType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.compile_unit", gIR->module);
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
147 gv->setSection("llvm.metadata");
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
148
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
149 m->ir.irModule->dwarfCompileUnit = gv;
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
150 return gv;
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
151 }
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
152
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
153 //////////////////////////////////////////////////////////////////////////////////////////////////
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
154
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
155 LLGlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariable* compileUnit)
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
156 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
157 std::vector<LLConstant*> vals;
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
158 vals.push_back(llvm::ConstantExpr::getAdd(
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
159 DtoConstUint(DW_TAG_subprogram),
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
160 DtoConstUint(llvm::LLVMDebugVersion)));
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
161 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_subprogram)));
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
162
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
163 vals.push_back(dbgToArrTy(compileUnit));
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
164 vals.push_back(DtoConstStringPtr(fd->toPrettyChars(), "llvm.metadata"));
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
165 vals.push_back(vals.back());
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
166 vals.push_back(DtoConstStringPtr(fd->mangle(), "llvm.metadata"));
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
167 vals.push_back(dbgToArrTy(compileUnit));
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
168 vals.push_back(DtoConstUint(fd->loc.linnum));
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
169 vals.push_back(llvm::ConstantPointerNull::get(dbgArrTy()));
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
170 vals.push_back(DtoConstBool(fd->protection == PROTprivate));
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
171 vals.push_back(DtoConstBool(fd->getModule() == gIR->dmodule));
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
172
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
173 LLConstant* c = llvm::ConstantStruct::get(GetDwarfSubProgramType(), vals);
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
174 llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.subprogram", gIR->module);
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
175 gv->setSection("llvm.metadata");
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
176 return gv;
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
177 }
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
178
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
179 //////////////////////////////////////////////////////////////////////////////////////////////////
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
180
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
181 void DtoDwarfFuncStart(FuncDeclaration* fd)
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
182 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
183 assert(fd->ir.irFunc->dwarfSubProg);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
184 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), dbgToArrTy(fd->ir.irFunc->dwarfSubProg));
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
185 }
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
186
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
187 void DtoDwarfFuncEnd(FuncDeclaration* fd)
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
188 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
189 assert(fd->ir.irFunc->dwarfSubProg);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 156
diff changeset
190 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), dbgToArrTy(fd->ir.irFunc->dwarfSubProg));
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
191 }
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
192
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
193 //////////////////////////////////////////////////////////////////////////////////////////////////
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
194
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
195 void DtoDwarfStopPoint(unsigned ln)
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
196 {
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
197 LLSmallVector<LLValue*,3> args;
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
198 args.push_back(DtoConstUint(ln));
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
199 args.push_back(DtoConstUint(0));
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
200 FuncDeclaration* fd = gIR->func()->decl;
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
201 args.push_back(dbgToArrTy(DtoDwarfCompileUnit(fd->getModule())));
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
202 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end());
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
203 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
204
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
205 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
206
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
207 const llvm::StructType* GetDwarfBasicTypeType() {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
208 return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
209 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
210
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
211 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
212
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
213 LLGlobalVariable* DtoDwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
214 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
215 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
216
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
217 std::vector<LLConstant*> vals;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
218 // tag
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
219 vals.push_back(llvm::ConstantExpr::getAdd(
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
220 DtoConstUint(DW_TAG_base_type),
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
221 DtoConstUint(llvm::LLVMDebugVersion)));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
222 // context
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
223 vals.push_back(dbgToArrTy(compileUnit));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
224 // name
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
225 vals.push_back(DtoConstStringPtr(type->toChars(), "llvm.metadata"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
226 // compile unit where defined
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
227 vals.push_back(getNullPtr(dbgArrTy()));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
228 // line number where defined
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
229 vals.push_back(DtoConstInt(0));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
230 // size in bits
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
231 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
232 // alignment in bits
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
233 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
234 // offset in bits
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
235 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
236 // FIXME: dont know what this is
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
237 vals.push_back(DtoConstUint(0));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
238 // dwarf type
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
239 unsigned id;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
240 if (type->isintegral())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
241 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
242 if (type->isunsigned())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
243 id = llvm::dwarf::DW_ATE_unsigned;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
244 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
245 id = llvm::dwarf::DW_ATE_signed;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
246 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
247 else if (type->isfloating())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
248 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
249 id = llvm::dwarf::DW_ATE_float;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
250 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
251 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
252 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
253 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
254 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
255 vals.push_back(DtoConstUint(id));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
256
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
257 LLConstant* c = llvm::ConstantStruct::get(GetDwarfBasicTypeType(), vals);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
258 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.basictype", gIR->module);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
259 gv->setSection("llvm.metadata");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
260 return gv;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
261 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
262
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
263 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
264
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
265 const llvm::StructType* GetDwarfVariableType() {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
266 return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
267 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
268
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
269 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
270
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
271 LLGlobalVariable* DtoDwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
272 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
273 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
274 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
275 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
276 else if (vd->isCodeseg())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
277 assert(0 && "a static variable");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
278 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
279 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
280
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
281 std::vector<LLConstant*> vals;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
282 // tag
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
283 vals.push_back(llvm::ConstantExpr::getAdd(
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
284 DtoConstUint(tag),
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
285 DtoConstUint(llvm::LLVMDebugVersion)));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
286 // context
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
287 vals.push_back(dbgToArrTy(gIR->func()->dwarfSubProg));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
288 // name
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
289 vals.push_back(DtoConstStringPtr(vd->toChars(), "llvm.metadata"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
290 // compile unit where defined
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
291 vals.push_back(dbgToArrTy(DtoDwarfCompileUnit(vd->getModule())));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
292 // line number where defined
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
293 vals.push_back(DtoConstUint(vd->loc.linnum));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
294 // type descriptor
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
295 vals.push_back(dbgToArrTy(typeDescr));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
296
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
297 LLConstant* c = llvm::ConstantStruct::get(GetDwarfVariableType(), vals);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
298 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.variable", gIR->module);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
299 gv->setSection("llvm.metadata");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
300 return gv;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
301 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
302
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
303 //////////////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
304
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
305 void DtoDwarfDeclare(LLValue* var, LLGlobalVariable* varDescr)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
306 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
307 LLSmallVector<LLValue*,2> args;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
308 args.push_back(DtoBitCast(var, dbgArrTy()));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
309 args.push_back(dbgToArrTy(varDescr));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
310 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
311 }