mirror of
https://github.com/intel/llvm.git
synced 2026-01-25 01:07:04 +08:00
[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:
23
lldb/test/API/python_api/unnamed_symbol_lookup/Makefile
Normal file
23
lldb/test/API/python_api/unnamed_symbol_lookup/Makefile
Normal 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
|
||||
@@ -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)
|
||||
6
lldb/test/API/python_api/unnamed_symbol_lookup/main.c
Normal file
6
lldb/test/API/python_api/unnamed_symbol_lookup/main.c
Normal file
@@ -0,0 +1,6 @@
|
||||
__attribute__((nodebug)) int stripped_function(int val) { return val * val; }
|
||||
|
||||
int main(void) {
|
||||
stripped_function(10);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user