[lldb] Change synthetic symbol names to have file address (#138416)

* Changes the default synthetic symbol names to contain their file
address

This is a new PR after the first PR (#137512) was reverted because it
didn't update the way unnamed symbols were searched in the symbol table,
which relied on the index being in the name.

This time also added extra test to make sure the symbol is found as
expected
This commit is contained in:
Ely Ronnen
2025-05-23 08:26:46 +02:00
committed by GitHub
parent 32805964fc
commit 044929d075
9 changed files with 84 additions and 12 deletions

View File

@@ -0,0 +1,23 @@
C_SOURCES := main.c
include Makefile.rules
all: a.out.stripped
ifeq "$(OS)" "Darwin"
STRIP_COMMAND = $(STRIP) -s keep_symbols.txt
else
STRIP_COMMAND = $(STRIP) --keep-symbol=main
endif
a.out.stripped: a.out
ifeq "$(OS)" "Darwin"
echo "_main" > keep_symbols.txt
$(STRIP) -s keep_symbols.txt -o a.out.stripped a.out
else
$(STRIP) --keep-symbol=main -o a.out.stripped a.out
endif
ifneq "$(CODESIGN)" ""
$(CODESIGN) -fs - a.out.stripped
endif

View File

@@ -0,0 +1,40 @@
"""
Test lookup unnamed symbols.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestUnnamedSymbolLookup(TestBase):
def test_unnamed_symbol_lookup(self):
"""Test looking up unnamed symbol synthetic name"""
self.build()
(target, process, thread, bkpt) = lldbutil.run_to_name_breakpoint(
self, "main", exe_name="a.out.stripped"
)
main_frame = thread.GetFrameAtIndex(0)
# Step until reaching the unnamed symbol called from main
for _ in range(100):
thread.StepInto()
if thread.GetFrameAtIndex(0) != main_frame:
break
thread.StepInto()
self.assertEqual(
main_frame, thread.GetFrameAtIndex(1), "Expected to be called from main"
)
symbol = thread.GetFrameAtIndex(0).GetSymbol()
self.assertIsNotNone(symbol, "unnamed symbol called from main not reached")
self.assertTrue(symbol.name.startswith("___lldb_unnamed_symbol"))
exe_module = symbol.GetStartAddress().GetModule()
found_symbols = exe_module.FindSymbols(symbol.name)
self.assertIsNotNone(found_symbols)
self.assertEqual(found_symbols.GetSize(), 1)

View File

@@ -0,0 +1,6 @@
__attribute__((nodebug)) int stripped_function(int val) { return val * val; }
int main(void) {
stripped_function(10);
return 0;
}