Mercurial > projects > ldc
comparison gen/todebug.cpp @ 246:b604c56945b0 trunk
[svn r263] Changed *** ATTENTION *** to warnings.
Implemented debug info for dynamic arrays, start of general composite support.
author | lindquist |
---|---|
date | Mon, 09 Jun 2008 15:52:22 +0200 |
parents | d61ce72c39ab |
children | 56199753e637 |
comparison
equal
deleted
inserted
replaced
245:d61ce72c39ab | 246:b604c56945b0 |
---|---|
13 | 13 |
14 #include "ir/irmodule.h" | 14 #include "ir/irmodule.h" |
15 | 15 |
16 using namespace llvm::dwarf; | 16 using namespace llvm::dwarf; |
17 | 17 |
18 static const llvm::PointerType* ptrTy(const LLType* t) | 18 #define DBG_NULL ( LLConstant::getNullValue(DBG_TYPE) ) |
19 { | 19 #define DBG_TYPE ( getPtrToType(llvm::StructType::get(NULL,NULL)) ) |
20 return llvm::PointerType::get(t, 0); | 20 #define DBG_CAST(X) ( llvm::ConstantExpr::getBitCast(X, DBG_TYPE) ) |
21 } | |
22 | |
23 static const llvm::PointerType* dbgArrTy() | |
24 { | |
25 return ptrTy(llvm::StructType::get(NULL,NULL)); | |
26 } | |
27 | |
28 static LLConstant* dbgToArrTy(LLConstant* c) | |
29 { | |
30 return llvm::ConstantExpr::getBitCast(c, dbgArrTy()); | |
31 } | |
32 | |
33 #define Ty(X) LLType::X | |
34 | 21 |
35 ////////////////////////////////////////////////////////////////////////////////////////////////// | 22 ////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 23 |
37 static llvm::GlobalVariable* dbg_compile_units = 0; | 24 static llvm::GlobalVariable* dbg_compile_units = 0; |
38 static llvm::GlobalVariable* dbg_global_variables = 0; | 25 static llvm::GlobalVariable* dbg_global_variables = 0; |
98 return 0; | 85 return 0; |
99 } | 86 } |
100 | 87 |
101 ////////////////////////////////////////////////////////////////////////////////////////////////// | 88 ////////////////////////////////////////////////////////////////////////////////////////////////// |
102 | 89 |
103 static const llvm::StructType* GetDwarfCompileUnitType() { | 90 static const llvm::StructType* getDwarfCompileUnitType() { |
104 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type")); | 91 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type")); |
105 } | 92 } |
106 | 93 |
107 static const llvm::StructType* GetDwarfSubProgramType() { | 94 static const llvm::StructType* getDwarfSubProgramType() { |
108 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type")); | 95 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type")); |
109 } | 96 } |
110 | 97 |
111 static const llvm::StructType* GetDwarfVariableType() { | 98 static const llvm::StructType* getDwarfVariableType() { |
112 return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type")); | 99 return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type")); |
113 } | 100 } |
114 | 101 |
115 static const llvm::StructType* GetDwarfDerivedTypeType() { | 102 static const llvm::StructType* getDwarfDerivedTypeType() { |
116 return isaStruct(gIR->module->getTypeByName("llvm.dbg.derivedtype.type")); | 103 return isaStruct(gIR->module->getTypeByName("llvm.dbg.derivedtype.type")); |
117 } | 104 } |
118 | 105 |
119 static const llvm::StructType* GetDwarfBasicTypeType() { | 106 static const llvm::StructType* getDwarfBasicTypeType() { |
120 return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type")); | 107 return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type")); |
108 } | |
109 | |
110 static const llvm::StructType* getDwarfCompositeTypeType() { | |
111 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compositetype.type")); | |
121 } | 112 } |
122 | 113 |
123 ////////////////////////////////////////////////////////////////////////////////////////////////// | 114 ////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 115 |
125 LLGlobalVariable* DtoDwarfCompileUnit(Module* m) | 116 LLGlobalVariable* DtoDwarfCompileUnit(Module* m) |
138 | 129 |
139 std::vector<LLConstant*> vals; | 130 std::vector<LLConstant*> vals; |
140 vals.push_back(llvm::ConstantExpr::getAdd( | 131 vals.push_back(llvm::ConstantExpr::getAdd( |
141 DtoConstUint(DW_TAG_compile_unit), | 132 DtoConstUint(DW_TAG_compile_unit), |
142 DtoConstUint(llvm::LLVMDebugVersion))); | 133 DtoConstUint(llvm::LLVMDebugVersion))); |
143 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_compile_unit))); | 134 vals.push_back(DBG_CAST(GetDwarfAnchor(DW_TAG_compile_unit))); |
144 | 135 |
145 vals.push_back(DtoConstUint(DW_LANG_C));// _D)); // doesn't seem to work | 136 vals.push_back(DtoConstUint(DW_LANG_C));// _D)); // doesn't seem to work |
146 vals.push_back(DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata")); | 137 vals.push_back(DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata")); |
147 std::string srcpath(FileName::path(m->srcfile->name->toChars())); | 138 std::string srcpath(FileName::path(m->srcfile->name->toChars())); |
148 if (srcpath.empty()) { | 139 if (srcpath.empty()) { |
151 srcpath = str; | 142 srcpath = str; |
152 } | 143 } |
153 vals.push_back(DtoConstStringPtr(srcpath.c_str(), "llvm.metadata")); | 144 vals.push_back(DtoConstStringPtr(srcpath.c_str(), "llvm.metadata")); |
154 vals.push_back(DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata")); | 145 vals.push_back(DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata")); |
155 | 146 |
156 c = llvm::ConstantStruct::get(GetDwarfCompileUnitType(), vals); | 147 c = llvm::ConstantStruct::get(getDwarfCompileUnitType(), vals); |
157 | 148 |
158 llvm::GlobalVariable* gv = new llvm::GlobalVariable(GetDwarfCompileUnitType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.compile_unit", gIR->module); | 149 llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.compile_unit", gIR->module); |
159 gv->setSection("llvm.metadata"); | 150 gv->setSection("llvm.metadata"); |
160 | 151 |
161 m->ir.irModule->dwarfCompileUnit = gv; | 152 m->ir.irModule->dwarfCompileUnit = gv; |
162 return gv; | 153 return gv; |
163 } | 154 } |
168 { | 159 { |
169 std::vector<LLConstant*> vals; | 160 std::vector<LLConstant*> vals; |
170 vals.push_back(llvm::ConstantExpr::getAdd( | 161 vals.push_back(llvm::ConstantExpr::getAdd( |
171 DtoConstUint(DW_TAG_subprogram), | 162 DtoConstUint(DW_TAG_subprogram), |
172 DtoConstUint(llvm::LLVMDebugVersion))); | 163 DtoConstUint(llvm::LLVMDebugVersion))); |
173 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_subprogram))); | 164 vals.push_back(DBG_CAST(GetDwarfAnchor(DW_TAG_subprogram))); |
174 | 165 |
175 vals.push_back(dbgToArrTy(compileUnit)); | 166 vals.push_back(DBG_CAST(compileUnit)); |
176 vals.push_back(DtoConstStringPtr(fd->toPrettyChars(), "llvm.metadata")); | 167 vals.push_back(DtoConstStringPtr(fd->toPrettyChars(), "llvm.metadata")); |
177 vals.push_back(vals.back()); | 168 vals.push_back(vals.back()); |
178 vals.push_back(DtoConstStringPtr(fd->mangle(), "llvm.metadata")); | 169 vals.push_back(DtoConstStringPtr(fd->mangle(), "llvm.metadata")); |
179 vals.push_back(dbgToArrTy(compileUnit)); | 170 vals.push_back(DBG_CAST(compileUnit)); |
180 vals.push_back(DtoConstUint(fd->loc.linnum)); | 171 vals.push_back(DtoConstUint(fd->loc.linnum)); |
181 vals.push_back(llvm::ConstantPointerNull::get(dbgArrTy())); | 172 vals.push_back(DBG_NULL); |
182 vals.push_back(DtoConstBool(fd->protection == PROTprivate)); | 173 vals.push_back(DtoConstBool(fd->protection == PROTprivate)); |
183 vals.push_back(DtoConstBool(fd->getModule() == gIR->dmodule)); | 174 vals.push_back(DtoConstBool(fd->getModule() == gIR->dmodule)); |
184 | 175 |
185 LLConstant* c = llvm::ConstantStruct::get(GetDwarfSubProgramType(), vals); | 176 LLConstant* c = llvm::ConstantStruct::get(getDwarfSubProgramType(), vals); |
186 llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.subprogram", gIR->module); | 177 llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.subprogram", gIR->module); |
187 gv->setSection("llvm.metadata"); | 178 gv->setSection("llvm.metadata"); |
188 return gv; | 179 return gv; |
189 } | 180 } |
190 | 181 |
191 ////////////////////////////////////////////////////////////////////////////////////////////////// | 182 ////////////////////////////////////////////////////////////////////////////////////////////////// |
192 | 183 |
193 void DtoDwarfFuncStart(FuncDeclaration* fd) | 184 void DtoDwarfFuncStart(FuncDeclaration* fd) |
194 { | 185 { |
195 assert(fd->ir.irFunc->dwarfSubProg); | 186 assert(fd->ir.irFunc->dwarfSubProg); |
196 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), dbgToArrTy(fd->ir.irFunc->dwarfSubProg)); | 187 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(fd->ir.irFunc->dwarfSubProg)); |
197 } | 188 } |
198 | 189 |
199 void DtoDwarfFuncEnd(FuncDeclaration* fd) | 190 void DtoDwarfFuncEnd(FuncDeclaration* fd) |
200 { | 191 { |
201 assert(fd->ir.irFunc->dwarfSubProg); | 192 assert(fd->ir.irFunc->dwarfSubProg); |
202 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), dbgToArrTy(fd->ir.irFunc->dwarfSubProg)); | 193 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(fd->ir.irFunc->dwarfSubProg)); |
203 } | 194 } |
204 | 195 |
205 ////////////////////////////////////////////////////////////////////////////////////////////////// | 196 ////////////////////////////////////////////////////////////////////////////////////////////////// |
206 | 197 |
207 void DtoDwarfStopPoint(unsigned ln) | 198 void DtoDwarfStopPoint(unsigned ln) |
208 { | 199 { |
209 LLSmallVector<LLValue*,3> args; | 200 LLSmallVector<LLValue*,3> args; |
210 args.push_back(DtoConstUint(ln)); | 201 args.push_back(DtoConstUint(ln)); |
211 args.push_back(DtoConstUint(0)); | 202 args.push_back(DtoConstUint(0)); |
212 FuncDeclaration* fd = gIR->func()->decl; | 203 FuncDeclaration* fd = gIR->func()->decl; |
213 args.push_back(dbgToArrTy(DtoDwarfCompileUnit(fd->getModule()))); | 204 args.push_back(DBG_CAST(DtoDwarfCompileUnit(fd->getModule()))); |
214 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); | 205 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); |
215 } | 206 } |
216 | 207 |
217 ////////////////////////////////////////////////////////////////////////////////////////////////// | 208 ////////////////////////////////////////////////////////////////////////////////////////////////// |
218 | 209 |
219 static LLGlobalVariable* DtoDwarfTypeDescription(Loc loc, Type* type, LLGlobalVariable* cu); | 210 static LLGlobalVariable* dwarfTypeDescription(Loc loc, Type* type, LLGlobalVariable* cu, const char* c_name); |
220 | 211 |
221 ////////////////////////////////////////////////////////////////////////////////////////////////// | 212 ////////////////////////////////////////////////////////////////////////////////////////////////// |
222 | 213 |
223 static LLGlobalVariable* DtoDwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit) | 214 static LLGlobalVariable* dwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit) |
224 { | 215 { |
225 Type* t = type->toBasetype(); | 216 Type* t = type->toBasetype(); |
226 | |
227 | 217 |
228 const LLType* T = DtoType(type); | 218 const LLType* T = DtoType(type); |
229 | 219 |
230 std::vector<LLConstant*> vals; | 220 std::vector<LLConstant*> vals; |
221 | |
231 // tag | 222 // tag |
232 vals.push_back(llvm::ConstantExpr::getAdd( | 223 vals.push_back(llvm::ConstantExpr::getAdd( |
233 DtoConstUint(DW_TAG_base_type), | 224 DtoConstUint(DW_TAG_base_type), |
234 DtoConstUint(llvm::LLVMDebugVersion))); | 225 DtoConstUint(llvm::LLVMDebugVersion))); |
226 | |
235 // context | 227 // context |
236 vals.push_back(dbgToArrTy(compileUnit)); | 228 vals.push_back(DBG_CAST(compileUnit)); |
229 | |
237 // name | 230 // name |
238 vals.push_back(DtoConstStringPtr(type->toChars(), "llvm.metadata")); | 231 vals.push_back(DtoConstStringPtr(type->toChars(), "llvm.metadata")); |
232 | |
239 // compile unit where defined | 233 // compile unit where defined |
240 vals.push_back(getNullPtr(dbgArrTy())); | 234 vals.push_back(DBG_NULL); |
235 | |
241 // line number where defined | 236 // line number where defined |
242 vals.push_back(DtoConstInt(0)); | 237 vals.push_back(DtoConstInt(0)); |
238 | |
243 // size in bits | 239 // size in bits |
244 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | 240 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); |
241 | |
245 // alignment in bits | 242 // alignment in bits |
246 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | 243 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); |
244 | |
247 // offset in bits | 245 // offset in bits |
248 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | 246 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); |
247 | |
249 // FIXME: dont know what this is | 248 // FIXME: dont know what this is |
250 vals.push_back(DtoConstUint(0)); | 249 vals.push_back(DtoConstUint(0)); |
250 | |
251 // dwarf type | 251 // dwarf type |
252 unsigned id; | 252 unsigned id; |
253 if (t->isintegral()) | 253 if (t->isintegral()) |
254 { | 254 { |
255 if (type->isunsigned()) | 255 if (type->isunsigned()) |
265 { | 265 { |
266 assert(0 && "unsupported basictype for debug info"); | 266 assert(0 && "unsupported basictype for debug info"); |
267 } | 267 } |
268 vals.push_back(DtoConstUint(id)); | 268 vals.push_back(DtoConstUint(id)); |
269 | 269 |
270 LLConstant* c = llvm::ConstantStruct::get(GetDwarfBasicTypeType(), vals); | 270 LLConstant* c = llvm::ConstantStruct::get(getDwarfBasicTypeType(), vals); |
271 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.basictype", gIR->module); | 271 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.basictype", gIR->module); |
272 gv->setSection("llvm.metadata"); | 272 gv->setSection("llvm.metadata"); |
273 return gv; | 273 return gv; |
274 } | 274 } |
275 | 275 |
276 ////////////////////////////////////////////////////////////////////////////////////////////////// | 276 ////////////////////////////////////////////////////////////////////////////////////////////////// |
277 | 277 |
278 static LLGlobalVariable* DtoDwarfDerivedType(Loc loc, Type* type, llvm::GlobalVariable* compileUnit) | 278 static LLGlobalVariable* dwarfDerivedType(Loc loc, Type* type, llvm::GlobalVariable* compileUnit) |
279 { | 279 { |
280 const LLType* T = DtoType(type); | 280 const LLType* T = DtoType(type); |
281 Type* t = DtoDType(type); | 281 Type* t = DtoDType(type); |
282 | 282 |
283 // defaults | 283 // defaults |
293 { | 293 { |
294 assert(0 && "unsupported derivedtype for debug info"); | 294 assert(0 && "unsupported derivedtype for debug info"); |
295 } | 295 } |
296 | 296 |
297 std::vector<LLConstant*> vals; | 297 std::vector<LLConstant*> vals; |
298 | |
298 // tag | 299 // tag |
299 vals.push_back(llvm::ConstantExpr::getAdd( | 300 vals.push_back(llvm::ConstantExpr::getAdd( |
300 DtoConstUint(tag), | 301 DtoConstUint(tag), |
301 DtoConstUint(llvm::LLVMDebugVersion))); | 302 DtoConstUint(llvm::LLVMDebugVersion))); |
303 | |
302 // context | 304 // context |
303 vals.push_back(dbgToArrTy(compileUnit)); | 305 vals.push_back(DBG_CAST(compileUnit)); |
306 | |
304 // name | 307 // name |
305 vals.push_back(name); | 308 vals.push_back(name); |
309 | |
306 // compile unit where defined | 310 // compile unit where defined |
307 vals.push_back(getNullPtr(dbgArrTy())); | 311 vals.push_back(DBG_NULL); |
312 | |
308 // line number where defined | 313 // line number where defined |
309 vals.push_back(DtoConstInt(0)); | 314 vals.push_back(DtoConstInt(0)); |
315 | |
310 // size in bits | 316 // size in bits |
311 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | 317 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); |
318 | |
312 // alignment in bits | 319 // alignment in bits |
313 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | 320 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); |
321 | |
314 // offset in bits | 322 // offset in bits |
315 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | 323 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); |
324 | |
316 // FIXME: dont know what this is | 325 // FIXME: dont know what this is |
317 vals.push_back(DtoConstUint(0)); | 326 vals.push_back(DtoConstUint(0)); |
327 | |
318 // base type | 328 // base type |
319 Type* nt = t->nextOf(); | 329 Type* nt = t->nextOf(); |
320 LLGlobalVariable* nTD = DtoDwarfTypeDescription(loc, nt, compileUnit); | 330 LLGlobalVariable* nTD = dwarfTypeDescription(loc, nt, compileUnit, NULL); |
321 if (nt->ty == Tvoid || !nTD) | 331 if (nt->ty == Tvoid || !nTD) |
322 vals.push_back(getNullPtr(dbgArrTy())); | 332 vals.push_back(DBG_NULL); |
323 else | 333 else |
324 vals.push_back(dbgToArrTy(nTD)); | 334 vals.push_back(DBG_CAST(nTD)); |
325 | 335 |
326 LLConstant* c = llvm::ConstantStruct::get(GetDwarfDerivedTypeType(), vals); | 336 LLConstant* c = llvm::ConstantStruct::get(getDwarfDerivedTypeType(), vals); |
327 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.derivedtype", gIR->module); | 337 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.derivedtype", gIR->module); |
328 gv->setSection("llvm.metadata"); | 338 gv->setSection("llvm.metadata"); |
329 return gv; | 339 return gv; |
330 } | 340 } |
331 | 341 |
332 ////////////////////////////////////////////////////////////////////////////////////////////////// | 342 ////////////////////////////////////////////////////////////////////////////////////////////////// |
333 | 343 |
334 static LLGlobalVariable* DtoDwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) | 344 static LLGlobalVariable* dwarfMemberType(Loc loc, Type* type, llvm::GlobalVariable* compileUnit, const char* c_name, unsigned offset) |
345 { | |
346 const LLType* T = DtoType(type); | |
347 Type* t = DtoDType(type); | |
348 | |
349 // defaults | |
350 LLConstant* name; | |
351 if (c_name) | |
352 name = DtoConstStringPtr(c_name, "llvm.metadata"); | |
353 else | |
354 name = getNullPtr(getVoidPtrType()); | |
355 | |
356 std::vector<LLConstant*> vals; | |
357 | |
358 // tag | |
359 vals.push_back(llvm::ConstantExpr::getAdd( | |
360 DtoConstUint(llvm::dwarf::DW_TAG_member), | |
361 DtoConstUint(llvm::LLVMDebugVersion))); | |
362 | |
363 // context | |
364 vals.push_back(DBG_CAST(compileUnit)); | |
365 | |
366 // name | |
367 vals.push_back(name); | |
368 | |
369 // compile unit where defined | |
370 vals.push_back(DBG_NULL); | |
371 | |
372 // line number where defined | |
373 vals.push_back(DtoConstInt(0)); | |
374 | |
375 // size in bits | |
376 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | |
377 | |
378 // alignment in bits | |
379 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | |
380 | |
381 // offset in bits | |
382 vals.push_back(LLConstantInt::get(LLType::Int64Ty, offset*8, false)); | |
383 | |
384 // FIXME: dont know what this is | |
385 vals.push_back(DtoConstUint(0)); | |
386 | |
387 // base type | |
388 LLGlobalVariable* nTD = dwarfTypeDescription(loc, t, compileUnit, NULL); | |
389 if (t->ty == Tvoid || !nTD) | |
390 vals.push_back(DBG_NULL); | |
391 else | |
392 vals.push_back(DBG_CAST(nTD)); | |
393 | |
394 LLConstant* c = llvm::ConstantStruct::get(getDwarfDerivedTypeType(), vals); | |
395 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.derivedtype", gIR->module); | |
396 gv->setSection("llvm.metadata"); | |
397 return gv; | |
398 } | |
399 | |
400 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
401 | |
402 static LLGlobalVariable* dwarfCompositeType(Loc loc, Type* type, llvm::GlobalVariable* compileUnit) | |
403 { | |
404 const LLType* T = DtoType(type); | |
405 Type* t = DtoDType(type); | |
406 | |
407 // defaults | |
408 LLConstant* name = getNullPtr(getVoidPtrType()); | |
409 LLGlobalVariable* members = NULL; | |
410 | |
411 // find tag | |
412 unsigned tag; | |
413 if (t->ty == Tarray) | |
414 { | |
415 tag = llvm::dwarf::DW_TAG_structure_type; | |
416 | |
417 LLGlobalVariable* len = dwarfMemberType(loc, Type::tsize_t, compileUnit, "length", 0); | |
418 assert(len); | |
419 LLGlobalVariable* ptr = dwarfMemberType(loc, t->nextOf()->pointerTo(), compileUnit, "ptr", global.params.is64bit?8:4); | |
420 assert(ptr); | |
421 | |
422 const LLArrayType* at = LLArrayType::get(DBG_TYPE, 2); | |
423 | |
424 std::vector<LLConstant*> elems; | |
425 elems.push_back(DBG_CAST(len)); | |
426 elems.push_back(DBG_CAST(ptr)); | |
427 | |
428 // elems[0]->dump(); | |
429 // elems[1]->dump(); | |
430 // at->dump(); | |
431 | |
432 LLConstant* ca = LLConstantArray::get(at, elems); | |
433 members = new LLGlobalVariable(ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array", gIR->module); | |
434 members->setSection("llvm.metadata"); | |
435 } | |
436 else | |
437 { | |
438 assert(0 && "unsupported compositetype for debug info"); | |
439 } | |
440 | |
441 std::vector<LLConstant*> vals; | |
442 | |
443 // tag | |
444 vals.push_back(llvm::ConstantExpr::getAdd( | |
445 DtoConstUint(tag), | |
446 DtoConstUint(llvm::LLVMDebugVersion))); | |
447 | |
448 // context | |
449 vals.push_back(DBG_CAST(compileUnit)); | |
450 | |
451 // name | |
452 vals.push_back(name); | |
453 | |
454 // compile unit where defined | |
455 vals.push_back(DBG_NULL); | |
456 | |
457 // line number where defined | |
458 vals.push_back(DtoConstInt(0)); | |
459 | |
460 // size in bits | |
461 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | |
462 | |
463 // alignment in bits | |
464 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | |
465 | |
466 // offset in bits | |
467 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | |
468 | |
469 // FIXME: dont know what this is | |
470 vals.push_back(DtoConstUint(0)); | |
471 | |
472 // FIXME: ditto | |
473 vals.push_back(DBG_NULL); | |
474 | |
475 // members array | |
476 if (members) | |
477 vals.push_back(DBG_CAST(members)); | |
478 else | |
479 vals.push_back(DBG_NULL); | |
480 | |
481 LLConstant* c = llvm::ConstantStruct::get(getDwarfCompositeTypeType(), vals); | |
482 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.compositetype", gIR->module); | |
483 gv->setSection("llvm.metadata"); | |
484 return gv; | |
485 } | |
486 | |
487 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
488 | |
489 static LLGlobalVariable* dwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) | |
335 { | 490 { |
336 unsigned tag; | 491 unsigned tag; |
337 if (vd->isParameter()) | 492 if (vd->isParameter()) |
338 tag = DW_TAG_arg_variable; | 493 tag = DW_TAG_arg_variable; |
339 else if (vd->isCodeseg()) | 494 else if (vd->isCodeseg()) |
345 // tag | 500 // tag |
346 vals.push_back(llvm::ConstantExpr::getAdd( | 501 vals.push_back(llvm::ConstantExpr::getAdd( |
347 DtoConstUint(tag), | 502 DtoConstUint(tag), |
348 DtoConstUint(llvm::LLVMDebugVersion))); | 503 DtoConstUint(llvm::LLVMDebugVersion))); |
349 // context | 504 // context |
350 vals.push_back(dbgToArrTy(gIR->func()->dwarfSubProg)); | 505 vals.push_back(DBG_CAST(gIR->func()->dwarfSubProg)); |
351 // name | 506 // name |
352 vals.push_back(DtoConstStringPtr(vd->toChars(), "llvm.metadata")); | 507 vals.push_back(DtoConstStringPtr(vd->toChars(), "llvm.metadata")); |
353 // compile unit where defined | 508 // compile unit where defined |
354 vals.push_back(dbgToArrTy(DtoDwarfCompileUnit(vd->getModule()))); | 509 vals.push_back(DBG_CAST(DtoDwarfCompileUnit(vd->getModule()))); |
355 // line number where defined | 510 // line number where defined |
356 vals.push_back(DtoConstUint(vd->loc.linnum)); | 511 vals.push_back(DtoConstUint(vd->loc.linnum)); |
357 // type descriptor | 512 // type descriptor |
358 vals.push_back(dbgToArrTy(typeDescr)); | 513 vals.push_back(DBG_CAST(typeDescr)); |
359 | 514 |
360 LLConstant* c = llvm::ConstantStruct::get(GetDwarfVariableType(), vals); | 515 LLConstant* c = llvm::ConstantStruct::get(getDwarfVariableType(), vals); |
361 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.variable", gIR->module); | 516 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.variable", gIR->module); |
362 gv->setSection("llvm.metadata"); | 517 gv->setSection("llvm.metadata"); |
363 return gv; | 518 return gv; |
364 } | 519 } |
365 | 520 |
366 ////////////////////////////////////////////////////////////////////////////////////////////////// | 521 ////////////////////////////////////////////////////////////////////////////////////////////////// |
367 | 522 |
368 static void DtoDwarfDeclare(LLValue* var, LLGlobalVariable* varDescr) | 523 static void dwarfDeclare(LLValue* var, LLGlobalVariable* varDescr) |
369 { | 524 { |
370 LLSmallVector<LLValue*,2> args; | 525 LLSmallVector<LLValue*,2> args; |
371 args.push_back(DtoBitCast(var, dbgArrTy())); | 526 args.push_back(DtoBitCast(var, DBG_TYPE)); |
372 args.push_back(dbgToArrTy(varDescr)); | 527 args.push_back(DBG_CAST(varDescr)); |
373 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end()); | 528 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end()); |
374 } | 529 } |
375 | 530 |
376 ////////////////////////////////////////////////////////////////////////////////////////////////// | 531 ////////////////////////////////////////////////////////////////////////////////////////////////// |
377 | 532 |
378 static LLGlobalVariable* DtoDwarfTypeDescription(Loc loc, Type* type, LLGlobalVariable* cu) | 533 static LLGlobalVariable* dwarfTypeDescription(Loc loc, Type* type, LLGlobalVariable* cu, const char* c_name) |
379 { | 534 { |
380 Type* t = type->toBasetype(); | 535 Type* t = type->toBasetype(); |
381 if (t->isintegral() || t->isfloating()) | 536 if (t->ty == Tvoid) |
382 return DtoDwarfBasicType(type, cu); | 537 return NULL; |
538 else if (t->isintegral() || t->isfloating()) | |
539 return dwarfBasicType(type, cu); | |
383 else if (t->ty == Tpointer) | 540 else if (t->ty == Tpointer) |
384 return DtoDwarfDerivedType(loc, type, cu); | 541 return dwarfDerivedType(loc, type, cu); |
385 | 542 else if (t->ty == Tarray) |
386 Logger::attention(loc, "unsupport type for debug info: %s", type->toChars()); | 543 return dwarfCompositeType(loc, type, cu); |
544 | |
545 if (global.params.warnings) | |
546 warning("%s: unsupported type for debug info: %s", loc.toChars(), type->toChars()); | |
387 return NULL; | 547 return NULL; |
388 } | 548 } |
549 | |
550 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
389 | 551 |
390 void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd) | 552 void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd) |
391 { | 553 { |
392 // get compile units | 554 // get compile units |
393 LLGlobalVariable* thisCU = DtoDwarfCompileUnit(gIR->dmodule); | 555 LLGlobalVariable* thisCU = DtoDwarfCompileUnit(gIR->dmodule); |
395 if (vd->getModule() != gIR->dmodule) | 557 if (vd->getModule() != gIR->dmodule) |
396 varCU = DtoDwarfCompileUnit(vd->getModule()); | 558 varCU = DtoDwarfCompileUnit(vd->getModule()); |
397 | 559 |
398 // get type description | 560 // get type description |
399 Type* t = vd->type->toBasetype(); | 561 Type* t = vd->type->toBasetype(); |
400 LLGlobalVariable* TD = DtoDwarfTypeDescription(vd->loc, vd->type, thisCU); | 562 LLGlobalVariable* TD = dwarfTypeDescription(vd->loc, vd->type, thisCU, NULL); |
401 if (TD == NULL) | 563 if (TD == NULL) |
402 return; // unsupported | 564 return; // unsupported |
403 | 565 |
404 // get variable description | 566 // get variable description |
405 LLGlobalVariable* VD; | 567 LLGlobalVariable* VD; |
406 VD = DtoDwarfVariable(vd, TD); | 568 VD = dwarfVariable(vd, TD); |
407 | 569 |
408 // declare | 570 // declare |
409 DtoDwarfDeclare(ll, VD); | 571 dwarfDeclare(ll, VD); |
410 } | 572 } |
411 | 573 |
412 | 574 |
413 | 575 |
414 | 576 |
415 | 577 |
416 | 578 |
417 | 579 |
418 | 580 |
419 | 581 |
420 | 582 |
421 | 583 |
422 | 584 |
423 | 585 |
424 | 586 |