Mercurial > projects > ldc
comparison gen/todebug.cpp @ 245:d61ce72c39ab trunk
[svn r262] Fixed debug info for normal function parameters.
Fixed debug info for pointers to basic types.
author | lindquist |
---|---|
date | Mon, 09 Jun 2008 12:43:16 +0200 |
parents | a95056b3c996 |
children | b604c56945b0 |
comparison
equal
deleted
inserted
replaced
244:a95056b3c996 | 245:d61ce72c39ab |
---|---|
98 return 0; | 98 return 0; |
99 } | 99 } |
100 | 100 |
101 ////////////////////////////////////////////////////////////////////////////////////////////////// | 101 ////////////////////////////////////////////////////////////////////////////////////////////////// |
102 | 102 |
103 const llvm::StructType* GetDwarfCompileUnitType() { | 103 static const llvm::StructType* GetDwarfCompileUnitType() { |
104 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type")); | 104 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type")); |
105 } | 105 } |
106 | 106 |
107 const llvm::StructType* GetDwarfSubProgramType() { | 107 static const llvm::StructType* GetDwarfSubProgramType() { |
108 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type")); | 108 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type")); |
109 } | 109 } |
110 | 110 |
111 ////////////////////////////////////////////////////////////////////////////////////////////////// | 111 static const llvm::StructType* GetDwarfVariableType() { |
112 | 112 return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type")); |
113 llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m) | 113 } |
114 | |
115 static const llvm::StructType* GetDwarfDerivedTypeType() { | |
116 return isaStruct(gIR->module->getTypeByName("llvm.dbg.derivedtype.type")); | |
117 } | |
118 | |
119 static const llvm::StructType* GetDwarfBasicTypeType() { | |
120 return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type")); | |
121 } | |
122 | |
123 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
124 | |
125 LLGlobalVariable* DtoDwarfCompileUnit(Module* m) | |
114 { | 126 { |
115 if (!m->ir.irModule) | 127 if (!m->ir.irModule) |
116 m->ir.irModule = new IrModule(m); | 128 m->ir.irModule = new IrModule(m); |
117 else if (m->ir.irModule->dwarfCompileUnit) | 129 else if (m->ir.irModule->dwarfCompileUnit) |
118 { | 130 { |
202 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); | 214 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); |
203 } | 215 } |
204 | 216 |
205 ////////////////////////////////////////////////////////////////////////////////////////////////// | 217 ////////////////////////////////////////////////////////////////////////////////////////////////// |
206 | 218 |
207 const llvm::StructType* GetDwarfBasicTypeType() { | 219 static LLGlobalVariable* DtoDwarfTypeDescription(Loc loc, Type* type, LLGlobalVariable* cu); |
208 return isaStruct(gIR->module->getTypeByName("llvm.dbg.basictype.type")); | 220 |
209 } | 221 ////////////////////////////////////////////////////////////////////////////////////////////////// |
210 | 222 |
211 ////////////////////////////////////////////////////////////////////////////////////////////////// | 223 static LLGlobalVariable* DtoDwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit) |
212 | 224 { |
213 LLGlobalVariable* DtoDwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit) | 225 Type* t = type->toBasetype(); |
214 { | 226 |
227 | |
215 const LLType* T = DtoType(type); | 228 const LLType* T = DtoType(type); |
216 | 229 |
217 std::vector<LLConstant*> vals; | 230 std::vector<LLConstant*> vals; |
218 // tag | 231 // tag |
219 vals.push_back(llvm::ConstantExpr::getAdd( | 232 vals.push_back(llvm::ConstantExpr::getAdd( |
235 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | 248 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); |
236 // FIXME: dont know what this is | 249 // FIXME: dont know what this is |
237 vals.push_back(DtoConstUint(0)); | 250 vals.push_back(DtoConstUint(0)); |
238 // dwarf type | 251 // dwarf type |
239 unsigned id; | 252 unsigned id; |
240 if (type->isintegral()) | 253 if (t->isintegral()) |
241 { | 254 { |
242 if (type->isunsigned()) | 255 if (type->isunsigned()) |
243 id = llvm::dwarf::DW_ATE_unsigned; | 256 id = llvm::dwarf::DW_ATE_unsigned; |
244 else | 257 else |
245 id = llvm::dwarf::DW_ATE_signed; | 258 id = llvm::dwarf::DW_ATE_signed; |
246 } | 259 } |
247 else if (type->isfloating()) | 260 else if (t->isfloating()) |
248 { | 261 { |
249 id = llvm::dwarf::DW_ATE_float; | 262 id = llvm::dwarf::DW_ATE_float; |
250 } | 263 } |
251 else | 264 else |
252 { | 265 { |
260 return gv; | 273 return gv; |
261 } | 274 } |
262 | 275 |
263 ////////////////////////////////////////////////////////////////////////////////////////////////// | 276 ////////////////////////////////////////////////////////////////////////////////////////////////// |
264 | 277 |
265 const llvm::StructType* GetDwarfVariableType() { | 278 static LLGlobalVariable* DtoDwarfDerivedType(Loc loc, Type* type, llvm::GlobalVariable* compileUnit) |
266 return isaStruct(gIR->module->getTypeByName("llvm.dbg.variable.type")); | 279 { |
267 } | 280 const LLType* T = DtoType(type); |
268 | 281 Type* t = DtoDType(type); |
269 ////////////////////////////////////////////////////////////////////////////////////////////////// | 282 |
270 | 283 // defaults |
271 LLGlobalVariable* DtoDwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) | 284 LLConstant* name = getNullPtr(getVoidPtrType()); |
285 | |
286 // find tag | |
287 unsigned tag; | |
288 if (t->ty == Tpointer) | |
289 { | |
290 tag = llvm::dwarf::DW_TAG_pointer_type; | |
291 } | |
292 else | |
293 { | |
294 assert(0 && "unsupported derivedtype for debug info"); | |
295 } | |
296 | |
297 std::vector<LLConstant*> vals; | |
298 // tag | |
299 vals.push_back(llvm::ConstantExpr::getAdd( | |
300 DtoConstUint(tag), | |
301 DtoConstUint(llvm::LLVMDebugVersion))); | |
302 // context | |
303 vals.push_back(dbgToArrTy(compileUnit)); | |
304 // name | |
305 vals.push_back(name); | |
306 // compile unit where defined | |
307 vals.push_back(getNullPtr(dbgArrTy())); | |
308 // line number where defined | |
309 vals.push_back(DtoConstInt(0)); | |
310 // size in bits | |
311 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | |
312 // alignment in bits | |
313 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | |
314 // offset in bits | |
315 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | |
316 // FIXME: dont know what this is | |
317 vals.push_back(DtoConstUint(0)); | |
318 // base type | |
319 Type* nt = t->nextOf(); | |
320 LLGlobalVariable* nTD = DtoDwarfTypeDescription(loc, nt, compileUnit); | |
321 if (nt->ty == Tvoid || !nTD) | |
322 vals.push_back(getNullPtr(dbgArrTy())); | |
323 else | |
324 vals.push_back(dbgToArrTy(nTD)); | |
325 | |
326 LLConstant* c = llvm::ConstantStruct::get(GetDwarfDerivedTypeType(), vals); | |
327 LLGlobalVariable* gv = new LLGlobalVariable(c->getType(), true, LLGlobalValue::InternalLinkage, c, "llvm.dbg.derivedtype", gIR->module); | |
328 gv->setSection("llvm.metadata"); | |
329 return gv; | |
330 } | |
331 | |
332 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
333 | |
334 static LLGlobalVariable* DtoDwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) | |
272 { | 335 { |
273 unsigned tag; | 336 unsigned tag; |
274 if (vd->isParameter()) | 337 if (vd->isParameter()) |
275 tag = DW_TAG_arg_variable; | 338 tag = DW_TAG_arg_variable; |
276 else if (vd->isCodeseg()) | 339 else if (vd->isCodeseg()) |
300 return gv; | 363 return gv; |
301 } | 364 } |
302 | 365 |
303 ////////////////////////////////////////////////////////////////////////////////////////////////// | 366 ////////////////////////////////////////////////////////////////////////////////////////////////// |
304 | 367 |
305 void DtoDwarfDeclare(LLValue* var, LLGlobalVariable* varDescr) | 368 static void DtoDwarfDeclare(LLValue* var, LLGlobalVariable* varDescr) |
306 { | 369 { |
307 LLSmallVector<LLValue*,2> args; | 370 LLSmallVector<LLValue*,2> args; |
308 args.push_back(DtoBitCast(var, dbgArrTy())); | 371 args.push_back(DtoBitCast(var, dbgArrTy())); |
309 args.push_back(dbgToArrTy(varDescr)); | 372 args.push_back(dbgToArrTy(varDescr)); |
310 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end()); | 373 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end()); |
311 } | 374 } |
375 | |
376 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
377 | |
378 static LLGlobalVariable* DtoDwarfTypeDescription(Loc loc, Type* type, LLGlobalVariable* cu) | |
379 { | |
380 Type* t = type->toBasetype(); | |
381 if (t->isintegral() || t->isfloating()) | |
382 return DtoDwarfBasicType(type, cu); | |
383 else if (t->ty == Tpointer) | |
384 return DtoDwarfDerivedType(loc, type, cu); | |
385 | |
386 Logger::attention(loc, "unsupport type for debug info: %s", type->toChars()); | |
387 return NULL; | |
388 } | |
389 | |
390 void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd) | |
391 { | |
392 // get compile units | |
393 LLGlobalVariable* thisCU = DtoDwarfCompileUnit(gIR->dmodule); | |
394 LLGlobalVariable* varCU = thisCU; | |
395 if (vd->getModule() != gIR->dmodule) | |
396 varCU = DtoDwarfCompileUnit(vd->getModule()); | |
397 | |
398 // get type description | |
399 Type* t = vd->type->toBasetype(); | |
400 LLGlobalVariable* TD = DtoDwarfTypeDescription(vd->loc, vd->type, thisCU); | |
401 if (TD == NULL) | |
402 return; // unsupported | |
403 | |
404 // get variable description | |
405 LLGlobalVariable* VD; | |
406 VD = DtoDwarfVariable(vd, TD); | |
407 | |
408 // declare | |
409 DtoDwarfDeclare(ll, VD); | |
410 } | |
411 | |
412 | |
413 | |
414 | |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | |
421 | |
422 | |
423 | |
424 |