Skip to content

Commit c32f0e8

Browse files
committed
[lldb] Preserve original symbol of Mangled function names (llvm#152201)
Fixes a bug that surfaces in frame recognizers. Details about the bug: A new frame recognizer is configured to match a specific symbol (`swift_willThrow`). This is an `extern "C"` symbol defined in a C++ source file. When Swift is built with debug info, the function `ParseFunctionFromDWARF` will use the debug info to construct a function name that looks like a C++ declaration (`::swift_willThrow(void *, SwiftError**)`). The `Mangled` instance will have this string as its `m_demangled` field, and have _no_ string for its `m_mangled` field. The result is the frame recognizer would not match the symbol to the name (`swift_willThrow` != `::swift_willThrow(void *, SwiftError**)`. By changing `ParseFunctionFromDWARF` to assign both a demangled name and a mangled, frame recognizers can successfully match symbols in this configuration. (cherry picked from commit 2959051)
1 parent 597e12e commit c32f0e8

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,9 @@ DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
25432543
// If the mangled name is not present in the DWARF, generate the
25442544
// demangled name using the decl context. We skip if the function is
25452545
// "main" as its name is never mangled.
2546-
func_name.SetValue(ConstructDemangledNameFromDWARF(die));
2546+
func_name.SetDemangledName(ConstructDemangledNameFromDWARF(die));
2547+
// Ensure symbol is preserved (as the mangled name).
2548+
func_name.SetMangledName(ConstString(name));
25472549
} else
25482550
func_name.SetValue(ConstString(name));
25492551

lldb/test/API/lang/cpp/extern_c/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ extern "C"
88

99
int foo()
1010
{
11-
puts("foo");
12-
return 2;
11+
puts("foo"); //% self.expect("image lookup -va $pc",
12+
//% substrs=[' name = "::foo()"',
13+
//% ' mangled = "foo"'])
14+
return 2;
1315
}
1416

1517
int main (int argc, char const *argv[], char const *envp[])

lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-address-ranges.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# RUN: %lldb %t -o "image lookup -a 0x48000 -v" -o exit | FileCheck %s
1212

1313
# CHECK: CompileUnit: id = {0x00000001}, file = "/tmp/a.cc", language = "c++"
14-
# CHECK: Function: id = {0x0000006a}, name = "::_start({{.*}})", range = [0x0000000000048000-0x000000000004800c)
14+
# CHECK: Function: id = {0x0000006a}, name = "::_start({{.*}})", mangled = "_start", range = [0x0000000000048000-0x000000000004800c)
1515
# CHECK: LineEntry: [0x0000000000048000-0x000000000004800a): /tmp/a.cc:4
1616
# CHECK: Symbol: id = {0x00000002}, range = [0x0000000000048000-0x000000000004800c), name="_start"
1717
# CHECK: Variable: id = {0x00000075}, name = "v1", {{.*}} decl = a.cc:4

0 commit comments

Comments
 (0)