Mercurial > projects > ldc
comparison gen/todebug.cpp @ 268:23d0d9855cad trunk
[svn r289] Fixed: right shift >> was broken for unsigned types.
Fixed: debug info for classes now started.
author | lindquist |
---|---|
date | Sun, 15 Jun 2008 18:52:27 +0200 |
parents | e3355ce5444b |
children | 297690b5d4a5 |
comparison
equal
deleted
inserted
replaced
267:c43911baea21 | 268:23d0d9855cad |
---|---|
127 | 127 |
128 ////////////////////////////////////////////////////////////////////////////////////////////////// | 128 ////////////////////////////////////////////////////////////////////////////////////////////////// |
129 | 129 |
130 static LLGlobalVariable* dwarfCompileUnit(Module* m) | 130 static LLGlobalVariable* dwarfCompileUnit(Module* m) |
131 { | 131 { |
132 std::vector<LLConstant*> vals; | 132 std::vector<LLConstant*> vals(6); |
133 vals.push_back(DBG_TAG(DW_TAG_compile_unit)); | 133 vals[0] = DBG_TAG(DW_TAG_compile_unit); |
134 vals.push_back(DBG_CAST(getDwarfAnchor(DW_TAG_compile_unit))); | 134 vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_compile_unit)); |
135 | 135 |
136 vals.push_back(DtoConstUint(DW_LANG_C));// _D)); // doesn't seem to work | 136 vals[2] = DtoConstUint(DW_LANG_C);// _D)); // doesn't seem to work |
137 vals.push_back(DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata")); | 137 vals[3] = DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata"); |
138 std::string srcpath(FileName::path(m->srcfile->name->toChars())); | 138 std::string srcpath(FileName::path(m->srcfile->name->toChars())); |
139 if (srcpath.empty()) { | 139 if (srcpath.empty()) { |
140 const char* str = get_current_dir_name(); | 140 const char* str = get_current_dir_name(); |
141 assert(str != NULL); | 141 assert(str != NULL); |
142 srcpath = str; | 142 srcpath = str; |
143 } | 143 } |
144 vals.push_back(DtoConstStringPtr(srcpath.c_str(), "llvm.metadata")); | 144 vals[4] = DtoConstStringPtr(srcpath.c_str(), "llvm.metadata"); |
145 vals.push_back(DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata")); | 145 vals[5] = DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata"); |
146 | 146 |
147 LLGlobalVariable* gv = emitDwarfGlobal(getDwarfCompileUnitType(), vals, "llvm.dbg.compile_unit"); | 147 LLGlobalVariable* gv = emitDwarfGlobal(getDwarfCompileUnitType(), vals, "llvm.dbg.compile_unit"); |
148 m->ir.irModule->dwarfCompileUnit = gv; | 148 m->ir.irModule->dwarfCompileUnit = gv; |
149 return gv; | 149 return gv; |
150 } | 150 } |
151 | 151 |
152 ////////////////////////////////////////////////////////////////////////////////////////////////// | 152 ////////////////////////////////////////////////////////////////////////////////////////////////// |
153 | 153 |
154 static LLGlobalVariable* dwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariable* compileUnit) | 154 static LLGlobalVariable* dwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariable* compileUnit) |
155 { | 155 { |
156 std::vector<LLConstant*> vals; | 156 std::vector<LLConstant*> vals(11); |
157 vals.push_back(DBG_TAG(DW_TAG_subprogram)); | 157 vals[0] = DBG_TAG(DW_TAG_subprogram); |
158 vals.push_back(DBG_CAST(getDwarfAnchor(DW_TAG_subprogram))); | 158 vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_subprogram)); |
159 | 159 |
160 vals.push_back(DBG_CAST(compileUnit)); | 160 vals[2] = DBG_CAST(compileUnit); |
161 vals.push_back(DtoConstStringPtr(fd->toPrettyChars(), "llvm.metadata")); | 161 vals[3] = DtoConstStringPtr(fd->toPrettyChars(), "llvm.metadata"); |
162 vals.push_back(vals.back()); | 162 vals[4] = vals[3]; |
163 vals.push_back(DtoConstStringPtr(fd->mangle(), "llvm.metadata")); | 163 vals[5] = DtoConstStringPtr(fd->mangle(), "llvm.metadata"); |
164 vals.push_back(DBG_CAST( DtoDwarfCompileUnit(fd->getModule()) )); | 164 vals[6] = DBG_CAST( DtoDwarfCompileUnit(fd->getModule()) ); |
165 vals.push_back(DtoConstUint(fd->loc.linnum)); | 165 vals[7] = DtoConstUint(fd->loc.linnum); |
166 vals.push_back(DBG_NULL); | 166 vals[8] = DBG_NULL; |
167 vals.push_back(DtoConstBool(fd->protection == PROTprivate)); | 167 vals[9] = DtoConstBool(fd->protection == PROTprivate); |
168 vals.push_back(DtoConstBool(fd->getModule() == gIR->dmodule)); | 168 vals[10] = DtoConstBool(fd->getModule() == gIR->dmodule); |
169 | |
170 Logger::println("emitting subprogram global"); | |
169 | 171 |
170 return emitDwarfGlobal(getDwarfSubProgramType(), vals, "llvm.dbg.subprogram"); | 172 return emitDwarfGlobal(getDwarfSubProgramType(), vals, "llvm.dbg.subprogram"); |
171 } | 173 } |
172 | 174 |
173 ////////////////////////////////////////////////////////////////////////////////////////////////// | 175 ////////////////////////////////////////////////////////////////////////////////////////////////// |
174 | 176 |
177 static LLGlobalVariable* dwarfTypeDescription_impl(Type* type, LLGlobalVariable* cu, const char* c_name); | |
175 static LLGlobalVariable* dwarfTypeDescription(Type* type, LLGlobalVariable* cu, const char* c_name); | 178 static LLGlobalVariable* dwarfTypeDescription(Type* type, LLGlobalVariable* cu, const char* c_name); |
176 | 179 |
177 ////////////////////////////////////////////////////////////////////////////////////////////////// | 180 ////////////////////////////////////////////////////////////////////////////////////////////////// |
178 | 181 |
179 static LLGlobalVariable* dwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit) | 182 static LLGlobalVariable* dwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit) |
180 { | 183 { |
181 Type* t = type->toBasetype(); | 184 Type* t = type->toBasetype(); |
182 | 185 |
183 const LLType* T = DtoType(type); | 186 const LLType* T = DtoType(type); |
184 | 187 |
185 std::vector<LLConstant*> vals; | 188 std::vector<LLConstant*> vals(10); |
186 | 189 |
187 // tag | 190 // tag |
188 vals.push_back(DBG_TAG(DW_TAG_base_type)); | 191 vals[0] = DBG_TAG(DW_TAG_base_type); |
189 | 192 |
190 // context | 193 // context |
191 vals.push_back(DBG_CAST(compileUnit)); | 194 vals[1] = DBG_CAST(compileUnit); |
192 | 195 |
193 // name | 196 // name |
194 vals.push_back(DtoConstStringPtr(type->toChars(), "llvm.metadata")); | 197 vals[2] = DtoConstStringPtr(type->toChars(), "llvm.metadata"); |
195 | 198 |
196 // compile unit where defined | 199 // compile unit where defined |
197 vals.push_back(DBG_NULL); | 200 vals[3] = DBG_NULL; |
198 | 201 |
199 // line number where defined | 202 // line number where defined |
200 vals.push_back(DtoConstInt(0)); | 203 vals[4] = DtoConstInt(0); |
201 | 204 |
202 // size in bits | 205 // size in bits |
203 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | 206 vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false); |
204 | 207 |
205 // alignment in bits | 208 // alignment in bits |
206 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | 209 vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false); |
207 | 210 |
208 // offset in bits | 211 // offset in bits |
209 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | 212 vals[7] = LLConstantInt::get(LLType::Int64Ty, 0, false); |
210 | 213 |
211 // FIXME: dont know what this is | 214 // FIXME: dont know what this is |
212 vals.push_back(DtoConstUint(0)); | 215 vals[8] = DtoConstUint(0); |
213 | 216 |
214 // dwarf type | 217 // dwarf type |
215 unsigned id; | 218 unsigned id; |
216 if (t->isintegral()) | 219 if (t->isintegral()) |
217 { | 220 { |
226 } | 229 } |
227 else | 230 else |
228 { | 231 { |
229 assert(0 && "unsupported basictype for debug info"); | 232 assert(0 && "unsupported basictype for debug info"); |
230 } | 233 } |
231 vals.push_back(DtoConstUint(id)); | 234 vals[9] = DtoConstUint(id); |
232 | 235 |
233 return emitDwarfGlobal(getDwarfBasicTypeType(), vals, "llvm.dbg.basictype"); | 236 return emitDwarfGlobal(getDwarfBasicTypeType(), vals, "llvm.dbg.basictype"); |
234 } | 237 } |
235 | 238 |
236 ////////////////////////////////////////////////////////////////////////////////////////////////// | 239 ////////////////////////////////////////////////////////////////////////////////////////////////// |
252 else | 255 else |
253 { | 256 { |
254 assert(0 && "unsupported derivedtype for debug info"); | 257 assert(0 && "unsupported derivedtype for debug info"); |
255 } | 258 } |
256 | 259 |
257 std::vector<LLConstant*> vals; | 260 std::vector<LLConstant*> vals(10); |
258 | 261 |
259 // tag | 262 // tag |
260 vals.push_back(DBG_TAG(tag)); | 263 vals[0] = DBG_TAG(tag); |
261 | 264 |
262 // context | 265 // context |
263 vals.push_back(DBG_CAST(compileUnit)); | 266 vals[1] = DBG_CAST(compileUnit); |
264 | 267 |
265 // name | 268 // name |
266 vals.push_back(name); | 269 vals[2] = name; |
267 | 270 |
268 // compile unit where defined | 271 // compile unit where defined |
269 vals.push_back(DBG_NULL); | 272 vals[3] = DBG_NULL; |
270 | 273 |
271 // line number where defined | 274 // line number where defined |
272 vals.push_back(DtoConstInt(0)); | 275 vals[4] = DtoConstInt(0); |
273 | 276 |
274 // size in bits | 277 // size in bits |
275 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | 278 vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false); |
276 | 279 |
277 // alignment in bits | 280 // alignment in bits |
278 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | 281 vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false); |
279 | 282 |
280 // offset in bits | 283 // offset in bits |
281 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | 284 vals[7] = LLConstantInt::get(LLType::Int64Ty, 0, false); |
282 | 285 |
283 // FIXME: dont know what this is | 286 // FIXME: dont know what this is |
284 vals.push_back(DtoConstUint(0)); | 287 vals[8] = DtoConstUint(0); |
285 | 288 |
286 // base type | 289 // base type |
287 Type* nt = t->nextOf(); | 290 Type* nt = t->nextOf(); |
288 LLGlobalVariable* nTD = dwarfTypeDescription(nt, compileUnit, NULL); | 291 LLGlobalVariable* nTD = dwarfTypeDescription_impl(nt, compileUnit, NULL); |
289 if (nt->ty == Tvoid || !nTD) | 292 if (nt->ty == Tvoid || !nTD) |
290 vals.push_back(DBG_NULL); | 293 vals[9] = DBG_NULL; |
291 else | 294 else |
292 vals.push_back(DBG_CAST(nTD)); | 295 vals[9] = DBG_CAST(nTD); |
293 | 296 |
294 return emitDwarfGlobal(getDwarfDerivedTypeType(), vals, "llvm.dbg.derivedtype"); | 297 return emitDwarfGlobal(getDwarfDerivedTypeType(), vals, "llvm.dbg.derivedtype"); |
295 } | 298 } |
296 | 299 |
297 ////////////////////////////////////////////////////////////////////////////////////////////////// | 300 ////////////////////////////////////////////////////////////////////////////////////////////////// |
306 if (c_name) | 309 if (c_name) |
307 name = DtoConstStringPtr(c_name, "llvm.metadata"); | 310 name = DtoConstStringPtr(c_name, "llvm.metadata"); |
308 else | 311 else |
309 name = getNullPtr(getVoidPtrType()); | 312 name = getNullPtr(getVoidPtrType()); |
310 | 313 |
311 std::vector<LLConstant*> vals; | 314 std::vector<LLConstant*> vals(10); |
312 | 315 |
313 // tag | 316 // tag |
314 vals.push_back(DBG_TAG(DW_TAG_member)); | 317 vals[0] = DBG_TAG(DW_TAG_member); |
315 | 318 |
316 // context | 319 // context |
317 vals.push_back(DBG_CAST(compileUnit)); | 320 vals[1] = DBG_CAST(compileUnit); |
318 | 321 |
319 // name | 322 // name |
320 vals.push_back(name); | 323 vals[2] = name; |
321 | 324 |
322 // compile unit where defined | 325 // compile unit where defined |
323 if (definedCU) | 326 if (definedCU) |
324 vals.push_back(DBG_CAST(definedCU)); | 327 vals[3] = DBG_CAST(definedCU); |
325 else | 328 else |
326 vals.push_back(DBG_NULL); | 329 vals[3] = DBG_NULL; |
327 | 330 |
328 // line number where defined | 331 // line number where defined |
329 vals.push_back(DtoConstInt(linnum)); | 332 vals[4] = DtoConstInt(linnum); |
330 | 333 |
331 // size in bits | 334 // size in bits |
332 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | 335 vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false); |
333 | 336 |
334 // alignment in bits | 337 // alignment in bits |
335 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | 338 vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false); |
336 | 339 |
337 // offset in bits | 340 // offset in bits |
338 vals.push_back(LLConstantInt::get(LLType::Int64Ty, offset*8, false)); | 341 vals[7] = LLConstantInt::get(LLType::Int64Ty, offset*8, false); |
339 | 342 |
340 // FIXME: dont know what this is | 343 // FIXME: dont know what this is |
341 vals.push_back(DtoConstUint(0)); | 344 vals[8] = DtoConstUint(0); |
342 | 345 |
343 // base type | 346 // base type |
344 LLGlobalVariable* nTD = dwarfTypeDescription(t, compileUnit, NULL); | 347 LLGlobalVariable* nTD = dwarfTypeDescription(t, compileUnit, NULL); |
345 if (t->ty == Tvoid || !nTD) | 348 if (t->ty == Tvoid || !nTD) |
346 vals.push_back(DBG_NULL); | 349 vals[9] = DBG_NULL; |
347 else | 350 else |
348 vals.push_back(DBG_CAST(nTD)); | 351 vals[9] = DBG_CAST(nTD); |
349 | 352 |
350 return emitDwarfGlobal(getDwarfDerivedTypeType(), vals, "llvm.dbg.derivedtype"); | 353 return emitDwarfGlobal(getDwarfDerivedTypeType(), vals, "llvm.dbg.derivedtype"); |
351 } | 354 } |
352 | 355 |
353 ////////////////////////////////////////////////////////////////////////////////////////////////// | 356 ////////////////////////////////////////////////////////////////////////////////////////////////// |
379 LLGlobalVariable* ptr = dwarfMemberType(0, t->nextOf()->pointerTo(), compileUnit, NULL, "ptr", global.params.is64bit?8:4); | 382 LLGlobalVariable* ptr = dwarfMemberType(0, t->nextOf()->pointerTo(), compileUnit, NULL, "ptr", global.params.is64bit?8:4); |
380 assert(ptr); | 383 assert(ptr); |
381 | 384 |
382 const LLArrayType* at = LLArrayType::get(DBG_TYPE, 2); | 385 const LLArrayType* at = LLArrayType::get(DBG_TYPE, 2); |
383 | 386 |
384 std::vector<LLConstant*> elems; | 387 std::vector<LLConstant*> elems(2); |
385 elems.push_back(DBG_CAST(len)); | 388 elems[0] = DBG_CAST(len); |
386 elems.push_back(DBG_CAST(ptr)); | 389 elems[1] = DBG_CAST(ptr); |
387 | 390 |
388 LLConstant* ca = LLConstantArray::get(at, elems); | 391 LLConstant* ca = LLConstantArray::get(at, elems); |
389 members = new LLGlobalVariable(ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array", gIR->module); | 392 members = new LLGlobalVariable(ca->getType(), true, LLGlobalValue::InternalLinkage, ca, ".array", gIR->module); |
390 members->setSection("llvm.metadata"); | 393 members->setSection("llvm.metadata"); |
391 | 394 |
392 name = DtoConstStringPtr(t->toChars(), "llvm.metadata"); | 395 name = DtoConstStringPtr(t->toChars(), "llvm.metadata"); |
393 } | 396 } |
394 | 397 |
395 // struct | 398 // struct/class |
396 else if (t->ty == Tstruct) | 399 else if (t->ty == Tstruct || t->ty == Tclass) |
397 { | 400 { |
398 TypeStruct* ts = (TypeStruct*)t; | 401 AggregateDeclaration* sd; |
399 StructDeclaration* sd = ts->sym; | 402 if (t->ty == Tstruct) |
403 { | |
404 TypeStruct* ts = (TypeStruct*)t; | |
405 sd = ts->sym; | |
406 } | |
407 else | |
408 { | |
409 TypeClass* tc = (TypeClass*)t; | |
410 sd = tc->sym; | |
411 } | |
400 assert(sd); | 412 assert(sd); |
401 | 413 |
402 IrStruct* ir = sd->ir.irStruct; | 414 IrStruct* ir = sd->ir.irStruct; |
403 assert(ir); | 415 assert(ir); |
404 if (ir->dwarfComposite) | 416 if (ir->dwarfComposite) |
413 name = DtoConstStringPtr(sd->toChars(), "llvm.metadata"); | 425 name = DtoConstStringPtr(sd->toChars(), "llvm.metadata"); |
414 linnum = sd->loc.linnum; | 426 linnum = sd->loc.linnum; |
415 definedCU = DtoDwarfCompileUnit(sd->getModule()); | 427 definedCU = DtoDwarfCompileUnit(sd->getModule()); |
416 | 428 |
417 std::vector<LLConstant*> elems; | 429 std::vector<LLConstant*> elems; |
430 elems.reserve(ir->offsets.size()); | |
418 for (IrStruct::OffsetMap::iterator i=ir->offsets.begin(); i!=ir->offsets.end(); ++i) | 431 for (IrStruct::OffsetMap::iterator i=ir->offsets.begin(); i!=ir->offsets.end(); ++i) |
419 { | 432 { |
420 unsigned offset = i->first; | 433 unsigned offset = i->first; |
421 IrStruct::Offset& o = i->second; | 434 IrStruct::Offset& o = i->second; |
422 | 435 |
434 else | 447 else |
435 { | 448 { |
436 assert(0 && "unsupported compositetype for debug info"); | 449 assert(0 && "unsupported compositetype for debug info"); |
437 } | 450 } |
438 | 451 |
439 std::vector<LLConstant*> vals; | 452 std::vector<LLConstant*> vals(11); |
440 | 453 |
441 // tag | 454 // tag |
442 vals.push_back(DBG_TAG(tag)); | 455 vals[0] = DBG_TAG(tag); |
443 | 456 |
444 // context | 457 // context |
445 vals.push_back(DBG_CAST(compileUnit)); | 458 vals[1] = DBG_CAST(compileUnit); |
446 | 459 |
447 // name | 460 // name |
448 vals.push_back(name); | 461 vals[2] = name; |
449 | 462 |
450 // compile unit where defined | 463 // compile unit where defined |
451 if (definedCU) | 464 if (definedCU) |
452 vals.push_back(DBG_CAST(definedCU)); | 465 vals[3] = DBG_CAST(definedCU); |
453 else | 466 else |
454 vals.push_back(DBG_NULL); | 467 vals[3] = DBG_NULL; |
455 | 468 |
456 // line number where defined | 469 // line number where defined |
457 vals.push_back(DtoConstInt(linnum)); | 470 vals[4] = DtoConstInt(linnum); |
458 | 471 |
459 // size in bits | 472 // size in bits |
460 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false)); | 473 vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false); |
461 | 474 |
462 // alignment in bits | 475 // alignment in bits |
463 vals.push_back(LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false)); | 476 vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false); |
464 | 477 |
465 // offset in bits | 478 // offset in bits |
466 vals.push_back(LLConstantInt::get(LLType::Int64Ty, 0, false)); | 479 vals[7] = LLConstantInt::get(LLType::Int64Ty, 0, false); |
467 | 480 |
468 // FIXME: dont know what this is | 481 // FIXME: dont know what this is |
469 vals.push_back(DtoConstUint(0)); | 482 vals[8] = DtoConstUint(0); |
470 | 483 |
471 // FIXME: ditto | 484 // FIXME: ditto |
472 vals.push_back(DBG_NULL); | 485 vals[9] = DBG_NULL; |
473 | 486 |
474 // members array | 487 // members array |
475 if (members) | 488 if (members) |
476 vals.push_back(DBG_CAST(members)); | 489 vals[10] = DBG_CAST(members); |
477 else | 490 else |
478 vals.push_back(DBG_NULL); | 491 vals[10] = DBG_NULL; |
479 | 492 |
480 // set initializer | 493 // set initializer |
481 if (!gv) | 494 if (!gv) |
482 gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype"); | 495 gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype"); |
483 LLConstant* initia = LLConstantStruct::get(getDwarfCompositeTypeType(), vals); | 496 LLConstant* initia = LLConstantStruct::get(getDwarfCompositeTypeType(), vals); |
491 static LLGlobalVariable* dwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) | 504 static LLGlobalVariable* dwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) |
492 { | 505 { |
493 assert(vd->isDataseg()); | 506 assert(vd->isDataseg()); |
494 LLGlobalVariable* compileUnit = DtoDwarfCompileUnit(gIR->dmodule); | 507 LLGlobalVariable* compileUnit = DtoDwarfCompileUnit(gIR->dmodule); |
495 | 508 |
496 std::vector<LLConstant*> vals; | 509 std::vector<LLConstant*> vals(12); |
497 vals.push_back(DBG_TAG(DW_TAG_variable)); | 510 vals[0] = DBG_TAG(DW_TAG_variable); |
498 vals.push_back(DBG_CAST(getDwarfAnchor(DW_TAG_variable))); | 511 vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_variable)); |
499 | 512 |
500 vals.push_back(DBG_CAST(compileUnit)); | 513 vals[2] = DBG_CAST(compileUnit); |
501 | 514 |
502 vals.push_back(DtoConstStringPtr(vd->mangle(), "llvm.metadata")); | 515 vals[3] = DtoConstStringPtr(vd->mangle(), "llvm.metadata"); |
503 vals.push_back(DtoConstStringPtr(vd->toPrettyChars(), "llvm.metadata")); | 516 vals[4] = DtoConstStringPtr(vd->toPrettyChars(), "llvm.metadata"); |
504 vals.push_back(DtoConstStringPtr(vd->toChars(), "llvm.metadata")); | 517 vals[5] = DtoConstStringPtr(vd->toChars(), "llvm.metadata"); |
505 | 518 |
506 vals.push_back(DBG_CAST(DtoDwarfCompileUnit(vd->getModule()))); | 519 vals[6] = DBG_CAST(DtoDwarfCompileUnit(vd->getModule())); |
507 vals.push_back(DtoConstUint(vd->loc.linnum)); | 520 vals[7] = DtoConstUint(vd->loc.linnum); |
508 | 521 |
509 LLGlobalVariable* TY = dwarfTypeDescription(vd->type, compileUnit, NULL); | 522 LLGlobalVariable* TY = dwarfTypeDescription_impl(vd->type, compileUnit, NULL); |
510 vals.push_back(TY ? DBG_CAST(TY) : DBG_NULL); | 523 vals[8] = TY ? DBG_CAST(TY) : DBG_NULL; |
511 vals.push_back(DtoConstBool(vd->protection == PROTprivate)); | 524 vals[9] = DtoConstBool(vd->protection == PROTprivate); |
512 vals.push_back(DtoConstBool(vd->getModule() == gIR->dmodule)); | 525 vals[10] = DtoConstBool(vd->getModule() == gIR->dmodule); |
513 | 526 |
514 vals.push_back(DBG_CAST(ll)); | 527 vals[11] = DBG_CAST(ll); |
515 | 528 |
516 return emitDwarfGlobal(getDwarfGlobalVariableType(), vals, "llvm.dbg.global_variable"); | 529 return emitDwarfGlobal(getDwarfGlobalVariableType(), vals, "llvm.dbg.global_variable"); |
517 } | 530 } |
518 | 531 |
519 ////////////////////////////////////////////////////////////////////////////////////////////////// | 532 ////////////////////////////////////////////////////////////////////////////////////////////////// |
547 | 560 |
548 ////////////////////////////////////////////////////////////////////////////////////////////////// | 561 ////////////////////////////////////////////////////////////////////////////////////////////////// |
549 | 562 |
550 static void dwarfDeclare(LLValue* var, LLGlobalVariable* varDescr) | 563 static void dwarfDeclare(LLValue* var, LLGlobalVariable* varDescr) |
551 { | 564 { |
552 LLSmallVector<LLValue*,2> args; | 565 LLSmallVector<LLValue*,2> args(2); |
553 args.push_back(DtoBitCast(var, DBG_TYPE)); | 566 args[0] = DtoBitCast(var, DBG_TYPE); |
554 args.push_back(DBG_CAST(varDescr)); | 567 args[1] = DBG_CAST(varDescr); |
555 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end()); | 568 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end()); |
556 } | 569 } |
557 | 570 |
558 ////////////////////////////////////////////////////////////////////////////////////////////////// | 571 ////////////////////////////////////////////////////////////////////////////////////////////////// |
559 | 572 |
560 static LLGlobalVariable* dwarfTypeDescription(Type* type, LLGlobalVariable* cu, const char* c_name) | 573 static LLGlobalVariable* dwarfTypeDescription_impl(Type* type, LLGlobalVariable* cu, const char* c_name) |
561 { | 574 { |
562 Type* t = type->toBasetype(); | 575 Type* t = type->toBasetype(); |
563 if (t->ty == Tvoid) | 576 if (t->ty == Tvoid) |
564 return NULL; | 577 return NULL; |
565 else if (t->isintegral() || t->isfloating()) | 578 else if (t->isintegral() || t->isfloating()) |
566 return dwarfBasicType(type, cu); | 579 return dwarfBasicType(type, cu); |
567 else if (t->ty == Tpointer) | 580 else if (t->ty == Tpointer) |
568 return dwarfDerivedType(type, cu); | 581 return dwarfDerivedType(type, cu); |
569 else if (t->ty == Tarray || t->ty == Tstruct) | 582 else if (t->ty == Tarray || t->ty == Tstruct || t->ty == Tclass) |
570 return dwarfCompositeType(type, cu); | 583 return dwarfCompositeType(type, cu); |
571 | 584 |
572 return NULL; | 585 return NULL; |
573 } | 586 } |
574 | 587 |
588 static LLGlobalVariable* dwarfTypeDescription(Type* type, LLGlobalVariable* cu, const char* c_name) | |
589 { | |
590 Type* t = type->toBasetype(); | |
591 if (t->ty == Tclass) | |
592 return dwarfTypeDescription_impl(type->pointerTo(), cu, c_name); | |
593 else | |
594 return dwarfTypeDescription_impl(type, cu, c_name); | |
595 } | |
596 | |
575 ////////////////////////////////////////////////////////////////////////////////////////////////// | 597 ////////////////////////////////////////////////////////////////////////////////////////////////// |
576 | 598 |
577 void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd) | 599 void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd) |
578 { | 600 { |
601 Logger::println("D to dwarf local variable"); | |
602 LOG_SCOPE; | |
603 | |
579 // get compile units | 604 // get compile units |
580 LLGlobalVariable* thisCU = DtoDwarfCompileUnit(gIR->dmodule); | 605 LLGlobalVariable* thisCU = DtoDwarfCompileUnit(gIR->dmodule); |
581 LLGlobalVariable* varCU = thisCU; | 606 LLGlobalVariable* varCU = thisCU; |
582 if (vd->getModule() != gIR->dmodule) | 607 if (vd->getModule() != gIR->dmodule) |
583 varCU = DtoDwarfCompileUnit(vd->getModule()); | 608 varCU = DtoDwarfCompileUnit(vd->getModule()); |
598 | 623 |
599 ////////////////////////////////////////////////////////////////////////////////////////////////// | 624 ////////////////////////////////////////////////////////////////////////////////////////////////// |
600 | 625 |
601 LLGlobalVariable* DtoDwarfCompileUnit(Module* m) | 626 LLGlobalVariable* DtoDwarfCompileUnit(Module* m) |
602 { | 627 { |
628 Logger::println("D to dwarf compile_unit"); | |
629 LOG_SCOPE; | |
630 | |
603 // we might be generating for an import | 631 // we might be generating for an import |
604 if (!m->ir.irModule) | 632 if (!m->ir.irModule) |
605 m->ir.irModule = new IrModule(m); | 633 m->ir.irModule = new IrModule(m); |
606 else if (m->ir.irModule->dwarfCompileUnit) | 634 else if (m->ir.irModule->dwarfCompileUnit) |
607 { | 635 { |
616 | 644 |
617 ////////////////////////////////////////////////////////////////////////////////////////////////// | 645 ////////////////////////////////////////////////////////////////////////////////////////////////// |
618 | 646 |
619 LLGlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd) | 647 LLGlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd) |
620 { | 648 { |
649 Logger::println("D to dwarf subprogram"); | |
650 LOG_SCOPE; | |
651 | |
621 // FIXME: duplicates ? | 652 // FIXME: duplicates ? |
622 return dwarfSubProgram(fd, DtoDwarfCompileUnit(gIR->dmodule)); | 653 return dwarfSubProgram(fd, DtoDwarfCompileUnit(gIR->dmodule)); |
623 } | 654 } |
624 | 655 |
625 ////////////////////////////////////////////////////////////////////////////////////////////////// | 656 ////////////////////////////////////////////////////////////////////////////////////////////////// |
626 | 657 |
627 LLGlobalVariable* DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) | 658 LLGlobalVariable* DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) |
628 { | 659 { |
660 Logger::println("D to dwarf global_variable"); | |
661 LOG_SCOPE; | |
662 | |
629 // FIXME: duplicates ? | 663 // FIXME: duplicates ? |
630 return dwarfGlobalVariable(ll, vd); | 664 return dwarfGlobalVariable(ll, vd); |
631 } | 665 } |
632 | 666 |
633 ////////////////////////////////////////////////////////////////////////////////////////////////// | 667 ////////////////////////////////////////////////////////////////////////////////////////////////// |
634 | 668 |
635 void DtoDwarfFuncStart(FuncDeclaration* fd) | 669 void DtoDwarfFuncStart(FuncDeclaration* fd) |
636 { | 670 { |
671 Logger::println("D to dwarf funcstart"); | |
672 LOG_SCOPE; | |
673 | |
637 assert(fd->ir.irFunc->dwarfSubProg); | 674 assert(fd->ir.irFunc->dwarfSubProg); |
638 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(fd->ir.irFunc->dwarfSubProg)); | 675 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(fd->ir.irFunc->dwarfSubProg)); |
639 } | 676 } |
640 | 677 |
641 ////////////////////////////////////////////////////////////////////////////////////////////////// | 678 ////////////////////////////////////////////////////////////////////////////////////////////////// |
642 | 679 |
643 void DtoDwarfFuncEnd(FuncDeclaration* fd) | 680 void DtoDwarfFuncEnd(FuncDeclaration* fd) |
644 { | 681 { |
682 Logger::println("D to dwarf funcend"); | |
683 LOG_SCOPE; | |
684 | |
645 assert(fd->ir.irFunc->dwarfSubProg); | 685 assert(fd->ir.irFunc->dwarfSubProg); |
646 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(fd->ir.irFunc->dwarfSubProg)); | 686 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(fd->ir.irFunc->dwarfSubProg)); |
647 } | 687 } |
648 | 688 |
649 ////////////////////////////////////////////////////////////////////////////////////////////////// | 689 ////////////////////////////////////////////////////////////////////////////////////////////////// |
650 | 690 |
651 void DtoDwarfStopPoint(unsigned ln) | 691 void DtoDwarfStopPoint(unsigned ln) |
652 { | 692 { |
653 LLSmallVector<LLValue*,3> args; | 693 Logger::println("D to dwarf stoppoint at line %u", ln); |
654 args.push_back(DtoConstUint(ln)); | 694 LOG_SCOPE; |
655 args.push_back(DtoConstUint(0)); | 695 |
696 LLSmallVector<LLValue*,3> args(3); | |
697 args[0] = DtoConstUint(ln); | |
698 args[1] = DtoConstUint(0); | |
656 FuncDeclaration* fd = gIR->func()->decl; | 699 FuncDeclaration* fd = gIR->func()->decl; |
657 args.push_back(DBG_CAST(DtoDwarfCompileUnit(fd->getModule()))); | 700 args[2] = DBG_CAST(DtoDwarfCompileUnit(fd->getModule())); |
658 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); | 701 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); |
659 } | 702 } |