comparison gen/todebug.cpp @ 955:8a70b4381369

Make sure debug info uses the right compilation units - in particular the current cu if a symbol is a template instance. Fixes #211.
author Christian Kamm <kamm incasoftware de>
date Sat, 14 Feb 2009 21:18:47 +0100
parents 1714836f2c0b
children ff22650d0ca3
comparison
equal deleted inserted replaced
954:e048e36bc155 955:8a70b4381369
9 9
10 #include "gen/todebug.h" 10 #include "gen/todebug.h"
11 #include "gen/irstate.h" 11 #include "gen/irstate.h"
12 #include "gen/tollvm.h" 12 #include "gen/tollvm.h"
13 #include "gen/logger.h" 13 #include "gen/logger.h"
14 #include "gen/llvmhelpers.h"
14 15
15 #include "ir/irmodule.h" 16 #include "ir/irmodule.h"
16 17
17 using namespace llvm::dwarf; 18 using namespace llvm::dwarf;
18 19
83 84
84 static const llvm::StructType* getDwarfGlobalVariableType() { 85 static const llvm::StructType* getDwarfGlobalVariableType() {
85 return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type")); 86 return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type"));
86 } 87 }
87 88
89 //////////////////////////////////////////////////////////////////////////////////////////////////
90
91 // get the module the symbol is in, or - for template instances - the current module
92 static Module* getDefinedModule(Dsymbol* s)
93 {
94 if (!DtoIsTemplateInstance(s))
95 return s->getModule();
96 else
97 return gIR->dmodule;
98 }
88 99
89 ////////////////////////////////////////////////////////////////////////////////////////////////// 100 //////////////////////////////////////////////////////////////////////////////////////////////////
90 101
91 static llvm::DIType dwarfTypeDescription_impl(Type* type, llvm::DICompileUnit cu, const char* c_name); 102 static llvm::DIType dwarfTypeDescription_impl(Type* type, llvm::DICompileUnit cu, const char* c_name);
92 static llvm::DIType dwarfTypeDescription(Type* type, llvm::DICompileUnit cu, const char* c_name); 103 static llvm::DIType dwarfTypeDescription(Type* type, llvm::DICompileUnit cu, const char* c_name);
267 278
268 tag = DW_TAG_structure_type; 279 tag = DW_TAG_structure_type;
269 280
270 name = DtoConstStringPtr(sd->toChars(), "llvm.metadata"); 281 name = DtoConstStringPtr(sd->toChars(), "llvm.metadata");
271 linnum = sd->loc.linnum; 282 linnum = sd->loc.linnum;
272 definedCU = DtoDwarfCompileUnit(sd->getCompilationModule()); 283 definedCU = DtoDwarfCompileUnit(getDefinedModule(sd));
273 284
274 std::vector<LLConstant*> elems; 285 std::vector<LLConstant*> elems;
275 if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one 286 if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one
276 { 287 {
277 std::vector<VarDeclaration*>& arr = ir->varDecls; 288 std::vector<VarDeclaration*>& arr = ir->varDecls;
359 return gIR->difactory.CreateGlobalVariable( 370 return gIR->difactory.CreateGlobalVariable(
360 compileUnit, // context 371 compileUnit, // context
361 vd->mangle(), // name 372 vd->mangle(), // name
362 vd->toPrettyChars(), // displayname 373 vd->toPrettyChars(), // displayname
363 vd->toChars(), // linkage name 374 vd->toChars(), // linkage name
364 DtoDwarfCompileUnit(vd->getCompilationModule()), // compile unit 375 DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit
365 vd->loc.linnum, // line num 376 vd->loc.linnum, // line num
366 dwarfTypeDescription_impl(vd->type, compileUnit, NULL), // type 377 dwarfTypeDescription_impl(vd->type, compileUnit, NULL), // type
367 vd->protection == PROTprivate, // is local to unit 378 vd->protection == PROTprivate, // is local to unit
368 vd->getCompilationModule() == gIR->dmodule, // is definition 379 getDefinedModule(vd) == gIR->dmodule, // is definition
369 ll // value 380 ll // value
370 ); 381 );
371 } 382 }
372 383
373 ////////////////////////////////////////////////////////////////////////////////////////////////// 384 //////////////////////////////////////////////////////////////////////////////////////////////////
384 395
385 return gIR->difactory.CreateVariable( 396 return gIR->difactory.CreateVariable(
386 tag, // tag 397 tag, // tag
387 gIR->func()->diSubprogram, // context 398 gIR->func()->diSubprogram, // context
388 vd->toChars(), // name 399 vd->toChars(), // name
389 DtoDwarfCompileUnit(vd->getCompilationModule()), // compile unit 400 DtoDwarfCompileUnit(getDefinedModule(vd)), // compile unit
390 vd->loc.linnum, // line num 401 vd->loc.linnum, // line num
391 type // type 402 type // type
392 ); 403 );
393 } 404 }
394 405
432 Logger::println("D to dwarf local variable"); 443 Logger::println("D to dwarf local variable");
433 LOG_SCOPE; 444 LOG_SCOPE;
434 445
435 // get compile units 446 // get compile units
436 llvm::DICompileUnit thisCU = DtoDwarfCompileUnit(gIR->dmodule); 447 llvm::DICompileUnit thisCU = DtoDwarfCompileUnit(gIR->dmodule);
437 llvm::DICompileUnit varCU = thisCU; 448 llvm::DICompileUnit varCU = DtoDwarfCompileUnit(getDefinedModule(vd));
438 if (vd->getCompilationModule() != gIR->dmodule)
439 varCU = DtoDwarfCompileUnit(vd->getCompilationModule());
440 449
441 // get type description 450 // get type description
442 llvm::DIType TD = dwarfTypeDescription(vd->type, thisCU, NULL); 451 llvm::DIType TD = dwarfTypeDescription(vd->type, thisCU, NULL);
443 if (TD.isNull()) 452 if (TD.isNull())
444 return; // unsupported 453 return; // unsupported
497 { 506 {
498 Logger::println("D to dwarf subprogram"); 507 Logger::println("D to dwarf subprogram");
499 LOG_SCOPE; 508 LOG_SCOPE;
500 509
501 llvm::DICompileUnit context = DtoDwarfCompileUnit(gIR->dmodule); 510 llvm::DICompileUnit context = DtoDwarfCompileUnit(gIR->dmodule);
502 llvm::DICompileUnit definition = DtoDwarfCompileUnit(fd->getCompilationModule()); 511 llvm::DICompileUnit definition = DtoDwarfCompileUnit(getDefinedModule(fd));
503 512
504 // FIXME: duplicates ? 513 // FIXME: duplicates ?
505 return gIR->difactory.CreateSubprogram( 514 return gIR->difactory.CreateSubprogram(
506 context, // context 515 context, // context
507 fd->toPrettyChars(), // name 516 fd->toPrettyChars(), // name
579 { 588 {
580 Logger::println("D to dwarf stoppoint at line %u", ln); 589 Logger::println("D to dwarf stoppoint at line %u", ln);
581 LOG_SCOPE; 590 LOG_SCOPE;
582 591
583 gIR->difactory.InsertStopPoint( 592 gIR->difactory.InsertStopPoint(
584 DtoDwarfCompileUnit(gIR->func()->decl->getCompilationModule()), // compile unit 593 DtoDwarfCompileUnit(getDefinedModule(gIR->func()->decl)), // compile unit
585 ln, // line no 594 ln, // line no
586 0, // col no 595 0, // col no
587 gIR->scopebb() 596 gIR->scopebb()
588 ); 597 );
589 } 598 }