Jac1494 created this revision. Jac1494 added reviewers: dblaikie, vsk, echristo. Jac1494 added a project: debug-info. Herald added subscribers: cfe-commits, hiraditya, aprantl. Herald added projects: clang, LLVM.
Hi Devs, Consider below testcases, $cat shlib.c int var; int test() { return var++; } $cat test.c extern int test(); extern int var; int main() { var++; printf("%d\n",test()); } $clang -fpic shlib.c -g -shared -o libshared.so $clang -L`pwd` test.c -lshared -g $export LD_LIBRARY_PATH=`pwd` $ gdb a.out GNU gdb (GDB) 8.2.50.20190204-git Copyright (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out... (gdb) b main Breakpoint 1 at 0x400718: file test.c, line 6. (gdb) pt var type = <data variable, no debug info> As per above debugging ,for global extern variable "var" type info is missing because variable DebugInfo is not there in executable. This is case where we don't run it, it means sharelib is not loaded. We can't get variable type. LLVM is not adding debuginfo for externs with -g because this debug_info may increase final binary size. So ,that i have given support for declaration of global extern variable with "-fstandalone-debug". Thanks, Jaydeep. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D71451 Files: clang/include/clang/Basic/TargetInfo.h clang/lib/CodeGen/CGDebugInfo.cpp llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -171,7 +171,11 @@ if (!GV->isDefinition()) addFlag(*VariableDIE, dwarf::DW_AT_declaration); else + { + // Add location. + addLocationAttribute(VariableDIE, GV, GlobalExprs); addGlobalName(GV->getName(), *VariableDIE, DeclContext); + } if (uint32_t AlignInBytes = GV->getAlignInBytes()) addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, @@ -180,9 +184,6 @@ if (MDTuple *TP = GV->getTemplateParams()) addTemplateParams(*VariableDIE, DINodeArray(TP)); - // Add location. - addLocationAttribute(VariableDIE, GV, GlobalExprs); - return VariableDIE; } Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -4594,6 +4594,8 @@ assert(DebugKind >= codegenoptions::LimitedDebugInfo); if (D->hasAttr<NoDebugAttr>()) return; + if (!(DebugKind == clang::codegenoptions::FullDebugInfo)) + return; auto Align = getDeclAlignIfRequired(D, CGM.getContext()); llvm::DIFile *Unit = getOrCreateFile(D->getLocation()); Index: clang/include/clang/Basic/TargetInfo.h =================================================================== --- clang/include/clang/Basic/TargetInfo.h +++ clang/include/clang/Basic/TargetInfo.h @@ -1390,7 +1390,7 @@ virtual void setAuxTarget(const TargetInfo *Aux) {} /// Whether target allows debuginfo types for decl only variables. - virtual bool allowDebugInfoForExternalVar() const { return false; } + virtual bool allowDebugInfoForExternalVar() const { return true; } protected: /// Copy type and layout related info.
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -171,7 +171,11 @@ if (!GV->isDefinition()) addFlag(*VariableDIE, dwarf::DW_AT_declaration); else + { + // Add location. + addLocationAttribute(VariableDIE, GV, GlobalExprs); addGlobalName(GV->getName(), *VariableDIE, DeclContext); + } if (uint32_t AlignInBytes = GV->getAlignInBytes()) addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, @@ -180,9 +184,6 @@ if (MDTuple *TP = GV->getTemplateParams()) addTemplateParams(*VariableDIE, DINodeArray(TP)); - // Add location. - addLocationAttribute(VariableDIE, GV, GlobalExprs); - return VariableDIE; } Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -4594,6 +4594,8 @@ assert(DebugKind >= codegenoptions::LimitedDebugInfo); if (D->hasAttr<NoDebugAttr>()) return; + if (!(DebugKind == clang::codegenoptions::FullDebugInfo)) + return; auto Align = getDeclAlignIfRequired(D, CGM.getContext()); llvm::DIFile *Unit = getOrCreateFile(D->getLocation()); Index: clang/include/clang/Basic/TargetInfo.h =================================================================== --- clang/include/clang/Basic/TargetInfo.h +++ clang/include/clang/Basic/TargetInfo.h @@ -1390,7 +1390,7 @@ virtual void setAuxTarget(const TargetInfo *Aux) {} /// Whether target allows debuginfo types for decl only variables. - virtual bool allowDebugInfoForExternalVar() const { return false; } + virtual bool allowDebugInfoForExternalVar() const { return true; } protected: /// Copy type and layout related info.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits