diff options
author | Devang Patel <dpatel@apple.com> | 2010-01-14 00:36:21 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-01-14 00:36:21 +0000 |
commit | 9c6c3a0e3ae09626d2d4b04e4ffa42c3d7cab32b (patch) | |
tree | df62bc1b0263bee27eff73b449e525455a8155de /lib/CodeGen/CGDebugInfo.cpp | |
parent | abfd83e74ca8a7553e375dd4631d2570f33648b4 (diff) |
Emit human readable names for c/c++ functions. Avoid emitting linkage name if it matches regular name.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93383 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 89f3820d39..8b03ca92af 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -65,6 +65,25 @@ llvm::DIDescriptor CGDebugInfo::getContext(const VarDecl *Decl, return CompileUnit; } +/// getFunctionName - Get function name for the given FunctionDecl. If the +/// name is constructred on demand (e.g. C++ destructor) then the name +/// is stored on the side. +llvm::StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { + assert (FD && "Invalid FunctionDecl!"); + IdentifierInfo *FII = FD->getIdentifier(); + if (FII) + return FII->getName(); + + // Otherwise construct human readable name for debug info. + std::string NS = FD->getNameAsString(); + + // Copy this name on the side and use its reference. + unsigned Length = NS.length() + 1; + char *StrPtr = FunctionNames.Allocate<char>(Length); + strncpy(StrPtr, NS.c_str(), Length); + return llvm::StringRef(StrPtr); +} + /// getOrCreateCompileUnit - Get the compile unit from the cache or create a new /// one if necessary. This returns null for invalid source locations. llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { @@ -972,16 +991,28 @@ llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, /// EmitFunctionStart - Constructs the debug code for entering a function - /// "llvm.dbg.func.start.". -void CGDebugInfo::EmitFunctionStart(llvm::StringRef Name, QualType FnType, +void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, llvm::Function *Fn, CGBuilderTy &Builder) { - llvm::StringRef LinkageName(Name); - // Skip the asm prefix if it exists. - // - // FIXME: This should probably be the unmangled name? - if (Name[0] == '\01') - Name = Name.substr(1); + llvm::StringRef Name; + llvm::StringRef LinkageName; + + const Decl *D = GD.getDecl(); + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + Name = getFunctionName(FD); + // Use mangled name as linkage name for c/c++ functions. + llvm::StringRef MangledName(CGM.getMangledName(GD)); + if (!Name.equals(MangledName)) + LinkageName = MangledName; + } else { + // Use llvm function name as linkage name. + Name = Fn->getName(); + // Skip the asm prefix if it exists. + if (Name[0] == '\01') + Name = Name.substr(1); + LinkageName = Name; + } // FIXME: Why is this using CurLoc??? llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); |