From: Douglas Gregor Date: Fri, 19 Mar 2010 14:49:09 +0000 (+0000) Subject: Try to improve computation of the main file name for debug X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7ad50026074776bde13fdf790bcf2f647904f1b;p=clang Try to improve computation of the main file name for debug information, to address recent gdb failures. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98959 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 323c458842..a40a5fbdce 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -105,16 +105,19 @@ void CGDebugInfo::CreateCompileUnit() { // Get absolute path name. SourceManager &SM = CGM.getContext().getSourceManager(); - std::string MainFileName; - if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) - MainFileName = MainFile->getName(); - else if (CGM.getCodeGenOpts().MainFileName.empty()) + std::string MainFileName = CGM.getCodeGenOpts().MainFileName; + if (MainFileName.empty()) MainFileName = ""; - else - MainFileName = CGM.getCodeGenOpts().MainFileName; + llvm::sys::Path AbsFileName(MainFileName); AbsFileName.makeAbsolute(); + std::string MainFileDir; + if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) + MainFileDir = MainFile->getDir()->getName(); + else + MainFileDir = AbsFileName.getDirname(); + unsigned LangTag; const LangOptions &LO = CGM.getLangOptions(); if (LO.CPlusPlus) { @@ -143,7 +146,7 @@ void CGDebugInfo::CreateCompileUnit() { // Create new compile unit. TheCU = DebugFactory.CreateCompileUnit( - LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, true, + LangTag, AbsFileName.getLast(), MainFileDir, Producer, true, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers); }