https://github.com/eronnen updated https://github.com/llvm/llvm-project/pull/137512
>From fd74de70151567d402eb7c0326a6234a21cb2db7 Mon Sep 17 00:00:00 2001 From: Ely Ronnen <elyron...@gmail.com> Date: Sun, 27 Apr 2025 13:48:45 +0200 Subject: [PATCH 1/5] [lldb] add settings to control how synthetic symbol names are generated --- lldb/include/lldb/Core/ModuleList.h | 15 +++++++++++++++ lldb/include/lldb/lldb-enumerations.h | 6 ++++++ lldb/source/Core/CoreProperties.td | 5 +++++ lldb/source/Core/ModuleList.cpp | 8 ++++++++ lldb/source/Symbol/Symbol.cpp | 13 ++++++++++++- 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 909ee08f9ba62..baed175be5313 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -67,6 +67,20 @@ static constexpr OptionEnumValueElement g_auto_download_enum_values[] = { }, }; +static constexpr OptionEnumValueElement + g_synthetic_symbols_name_style_values[] = { + { + lldb::eSyntheticSymbolsNameStyleIndex, + "index", + "Function index style", + }, + { + lldb::eSyntheticSymbolsNameStyleFileAddress, + "file-address", + "Function file address in module style", + }, +}; + class ModuleListProperties : public Properties { mutable llvm::sys::RWMutex m_symlink_paths_mutex; PathMappingList m_symlink_paths; @@ -91,6 +105,7 @@ class ModuleListProperties : public Properties { bool GetLoadSymbolOnDemand(); lldb::SymbolDownload GetSymbolAutoDownload() const; + lldb::SyntheticSymbolsNameStyle GetSyntheticSymbolsNameStyle() const; PathMappingList GetSymlinkMappings() const; }; diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index 6d10cc8bcffcb..26e83cefbe571 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -1391,6 +1391,12 @@ enum StopDisassemblyType { eStopDisassemblyTypeAlways }; +/// Format to use for unknown symbols. +enum SyntheticSymbolsNameStyle { + eSyntheticSymbolsNameStyleIndex = 0, + eSyntheticSymbolsNameStyleFileAddress = 1, +}; + } // namespace lldb #endif // LLDB_LLDB_ENUMERATIONS_H diff --git a/lldb/source/Core/CoreProperties.td b/lldb/source/Core/CoreProperties.td index a1a4e994c3b9c..7eaecb729c36d 100644 --- a/lldb/source/Core/CoreProperties.td +++ b/lldb/source/Core/CoreProperties.td @@ -46,6 +46,11 @@ let Definition = "modulelist" in { Global, DefaultFalse, Desc<"Enable on demand symbol loading in LLDB. LLDB will load debug info on demand for each module based on various conditions (e.g. matched breakpoint, resolved stack frame addresses and matched global variables/function symbols in symbol table) to improve performance. Please refer to docs/use/ondemand.rst for details.">; + def SyntheticSymbolsNameStyle: Property<"synthetic-symbols-name-style", "Enum">, + Global, + DefaultEnumValue<"eSyntheticSymbolsNameStyleIndex">, + EnumValues<"OptionEnumValues(g_synthetic_symbols_name_style_values)">, + Desc<"Determines the way synthetic symbol names are generated for unknown symbols">; } let Definition = "debugger" in { diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 6052cc151744d..c48c5bbfb5e92 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -115,6 +115,14 @@ SymbolDownload ModuleListProperties::GetSymbolAutoDownload() const { g_modulelist_properties[idx].default_uint_value)); } +lldb::SyntheticSymbolsNameStyle +ModuleListProperties::GetSyntheticSymbolsNameStyle() const { + const uint32_t idx = ePropertySyntheticSymbolsNameStyle; + return GetPropertyAtIndexAs<lldb::SyntheticSymbolsNameStyle>( + idx, static_cast<lldb::SyntheticSymbolsNameStyle>( + g_modulelist_properties[idx].default_uint_value)); +} + FileSpec ModuleListProperties::GetClangModulesCachePath() const { const uint32_t idx = ePropertyClangModulesCachePath; return GetPropertyAtIndexAs<FileSpec>(idx, {}); diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index 4828de4fdfa37..825ca5babe28e 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -639,7 +639,18 @@ void Symbol::SynthesizeNameIfNeeded() const { // breakpoints on them. llvm::SmallString<256> name; llvm::raw_svector_ostream os(name); - os << GetSyntheticSymbolPrefix() << GetID(); + os << GetSyntheticSymbolPrefix(); + switch (ModuleList::GetGlobalModuleListProperties() + .GetSyntheticSymbolsNameStyle()) { + case eSyntheticSymbolsNameStyleIndex: + os << GetID(); + break; + case eSyntheticSymbolsNameStyleFileAddress: + os << "_" + << llvm::format_hex_no_prefix( + m_addr_range.GetBaseAddress().GetFileAddress(), 0); + break; + } m_mangled.SetDemangledName(ConstString(os.str())); } } >From c9d20d723ae3e80cb3742d7e0900a00a9bba98b6 Mon Sep 17 00:00:00 2001 From: Ely Ronnen <elyron...@gmail.com> Date: Wed, 30 Apr 2025 09:50:15 +0200 Subject: [PATCH 2/5] [lldb] Generate synthetic symbols with file address by default --- lldb/include/lldb/Core/ModuleList.h | 15 --------------- lldb/include/lldb/lldb-enumerations.h | 6 ------ lldb/source/Core/CoreProperties.td | 5 ----- lldb/source/Core/ModuleList.cpp | 8 -------- lldb/source/Symbol/Symbol.cpp | 13 +------------ 5 files changed, 1 insertion(+), 46 deletions(-) diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index baed175be5313..909ee08f9ba62 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -67,20 +67,6 @@ static constexpr OptionEnumValueElement g_auto_download_enum_values[] = { }, }; -static constexpr OptionEnumValueElement - g_synthetic_symbols_name_style_values[] = { - { - lldb::eSyntheticSymbolsNameStyleIndex, - "index", - "Function index style", - }, - { - lldb::eSyntheticSymbolsNameStyleFileAddress, - "file-address", - "Function file address in module style", - }, -}; - class ModuleListProperties : public Properties { mutable llvm::sys::RWMutex m_symlink_paths_mutex; PathMappingList m_symlink_paths; @@ -105,7 +91,6 @@ class ModuleListProperties : public Properties { bool GetLoadSymbolOnDemand(); lldb::SymbolDownload GetSymbolAutoDownload() const; - lldb::SyntheticSymbolsNameStyle GetSyntheticSymbolsNameStyle() const; PathMappingList GetSymlinkMappings() const; }; diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index 26e83cefbe571..6d10cc8bcffcb 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -1391,12 +1391,6 @@ enum StopDisassemblyType { eStopDisassemblyTypeAlways }; -/// Format to use for unknown symbols. -enum SyntheticSymbolsNameStyle { - eSyntheticSymbolsNameStyleIndex = 0, - eSyntheticSymbolsNameStyleFileAddress = 1, -}; - } // namespace lldb #endif // LLDB_LLDB_ENUMERATIONS_H diff --git a/lldb/source/Core/CoreProperties.td b/lldb/source/Core/CoreProperties.td index 7eaecb729c36d..a1a4e994c3b9c 100644 --- a/lldb/source/Core/CoreProperties.td +++ b/lldb/source/Core/CoreProperties.td @@ -46,11 +46,6 @@ let Definition = "modulelist" in { Global, DefaultFalse, Desc<"Enable on demand symbol loading in LLDB. LLDB will load debug info on demand for each module based on various conditions (e.g. matched breakpoint, resolved stack frame addresses and matched global variables/function symbols in symbol table) to improve performance. Please refer to docs/use/ondemand.rst for details.">; - def SyntheticSymbolsNameStyle: Property<"synthetic-symbols-name-style", "Enum">, - Global, - DefaultEnumValue<"eSyntheticSymbolsNameStyleIndex">, - EnumValues<"OptionEnumValues(g_synthetic_symbols_name_style_values)">, - Desc<"Determines the way synthetic symbol names are generated for unknown symbols">; } let Definition = "debugger" in { diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index c48c5bbfb5e92..6052cc151744d 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -115,14 +115,6 @@ SymbolDownload ModuleListProperties::GetSymbolAutoDownload() const { g_modulelist_properties[idx].default_uint_value)); } -lldb::SyntheticSymbolsNameStyle -ModuleListProperties::GetSyntheticSymbolsNameStyle() const { - const uint32_t idx = ePropertySyntheticSymbolsNameStyle; - return GetPropertyAtIndexAs<lldb::SyntheticSymbolsNameStyle>( - idx, static_cast<lldb::SyntheticSymbolsNameStyle>( - g_modulelist_properties[idx].default_uint_value)); -} - FileSpec ModuleListProperties::GetClangModulesCachePath() const { const uint32_t idx = ePropertyClangModulesCachePath; return GetPropertyAtIndexAs<FileSpec>(idx, {}); diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index 825ca5babe28e..27173d562e0bb 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -639,18 +639,7 @@ void Symbol::SynthesizeNameIfNeeded() const { // breakpoints on them. llvm::SmallString<256> name; llvm::raw_svector_ostream os(name); - os << GetSyntheticSymbolPrefix(); - switch (ModuleList::GetGlobalModuleListProperties() - .GetSyntheticSymbolsNameStyle()) { - case eSyntheticSymbolsNameStyleIndex: - os << GetID(); - break; - case eSyntheticSymbolsNameStyleFileAddress: - os << "_" - << llvm::format_hex_no_prefix( - m_addr_range.GetBaseAddress().GetFileAddress(), 0); - break; - } + os << GetSyntheticSymbolPrefix() << "_" << llvm::format_hex_no_prefix(m_addr_range.GetBaseAddress().GetFileAddress(), 0); m_mangled.SetDemangledName(ConstString(os.str())); } } >From c825e7da07e236b3cbbc4a1611b8837744687b19 Mon Sep 17 00:00:00 2001 From: Ely Ronnen <elyron...@gmail.com> Date: Wed, 30 Apr 2025 09:52:13 +0200 Subject: [PATCH 3/5] format --- lldb/source/Symbol/Symbol.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index 27173d562e0bb..da74707c75e13 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -639,7 +639,9 @@ void Symbol::SynthesizeNameIfNeeded() const { // breakpoints on them. llvm::SmallString<256> name; llvm::raw_svector_ostream os(name); - os << GetSyntheticSymbolPrefix() << "_" << llvm::format_hex_no_prefix(m_addr_range.GetBaseAddress().GetFileAddress(), 0); + os << GetSyntheticSymbolPrefix() << "_" + << llvm::format_hex_no_prefix( + m_addr_range.GetBaseAddress().GetFileAddress(), 0); m_mangled.SetDemangledName(ConstString(os.str())); } } >From 73fe03d6dbdcfd77efdaf7cb5c06c84ed4f36d45 Mon Sep 17 00:00:00 2001 From: Ely Ronnen <elyron...@gmail.com> Date: Wed, 30 Apr 2025 10:09:53 +0200 Subject: [PATCH 4/5] update test using synthetic symbol name --- lldb/test/Shell/SymbolFile/Breakpad/symtab-sorted-by-size.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/Shell/SymbolFile/Breakpad/symtab-sorted-by-size.test b/lldb/test/Shell/SymbolFile/Breakpad/symtab-sorted-by-size.test index 98052ea20bedd..00e04eb39a98e 100644 --- a/lldb/test/Shell/SymbolFile/Breakpad/symtab-sorted-by-size.test +++ b/lldb/test/Shell/SymbolFile/Breakpad/symtab-sorted-by-size.test @@ -3,7 +3,7 @@ # RUN: -s %s | FileCheck %s # CHECK: num_symbols = 4 (sorted by size): -# CHECK: [ 0] 0 SX Code 0x0000000000400000 0x00000000000000b0 0x00000000 ___lldb_unnamed_symbol0 +# CHECK: [ 0] 0 SX Code 0x0000000000400000 0x00000000000000b0 0x00000000 ___lldb_unnamed_symbol_400000 # CHECK: [ 1] 0 X Code 0x00000000004000d0 0x0000000000000022 0x00000000 _start # CHECK: [ 2] 0 X Code 0x00000000004000b0 0x0000000000000010 0x00000000 f1 # CHECK: [ 3] 0 X Code 0x00000000004000c0 0x0000000000000010 0x00000000 f2 >From ff2eb07dcf04ef81119ff3fb40474a1f053a4e14 Mon Sep 17 00:00:00 2001 From: Ely Ronnen <elyron...@gmail.com> Date: Wed, 30 Apr 2025 10:11:06 +0200 Subject: [PATCH 5/5] update synthetic unnamed symbols regex in tests --- lldb/test/Shell/ObjectFile/ELF/eh_frame-symbols.yaml | 4 ++-- lldb/test/Shell/SymbolFile/Breakpad/symtab.test | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/test/Shell/ObjectFile/ELF/eh_frame-symbols.yaml b/lldb/test/Shell/ObjectFile/ELF/eh_frame-symbols.yaml index 0dcc9fb76bd4f..4525d33ee4419 100644 --- a/lldb/test/Shell/ObjectFile/ELF/eh_frame-symbols.yaml +++ b/lldb/test/Shell/ObjectFile/ELF/eh_frame-symbols.yaml @@ -3,8 +3,8 @@ # CHECK: Index UserID DSX Type File Address/Value Load Address Size Flags Name # CHECK: [ 0] 1 SourceFile 0x0000000000000000 0x0000000000000000 0x00000004 - -# CHECK: [ 1] 2 SX Code 0x0000000000201180 0x0000000000000010 0x00000000 ___lldb_unnamed_symbol{{[0-9]*}} -# CHECK: [ 2] 3 SX Code 0x0000000000201190 0x0000000000000006 0x00000000 ___lldb_unnamed_symbol{{[0-9]*}} +# CHECK: [ 1] 2 SX Code 0x0000000000201180 0x0000000000000010 0x00000000 ___lldb_unnamed_symbol{{[0-9a-f]*}} +# CHECK: [ 2] 3 SX Code 0x0000000000201190 0x0000000000000006 0x00000000 ___lldb_unnamed_symbol{{[0-9a-f]*}} --- !ELF FileHeader: diff --git a/lldb/test/Shell/SymbolFile/Breakpad/symtab.test b/lldb/test/Shell/SymbolFile/Breakpad/symtab.test index ef41bb3bea955..b9e9c132e3193 100644 --- a/lldb/test/Shell/SymbolFile/Breakpad/symtab.test +++ b/lldb/test/Shell/SymbolFile/Breakpad/symtab.test @@ -5,7 +5,7 @@ # CHECK-LABEL: (lldb) image dump symtab symtab.out # CHECK: Symtab, file = {{.*}}symtab.out, num_symbols = 4: # CHECK: Index UserID DSX Type File Address/Value Load Address Size Flags Name -# CHECK: [ 0] 0 SX Code 0x0000000000400000 0x00000000000000b0 0x00000000 ___lldb_unnamed_symbol{{[0-9]*}} +# CHECK: [ 0] 0 SX Code 0x0000000000400000 0x00000000000000b0 0x00000000 ___lldb_unnamed_symbol{{[0-9a-f]*}} # CHECK: [ 1] 0 X Code 0x00000000004000b0 0x0000000000000010 0x00000000 f1 # CHECK: [ 2] 0 X Code 0x00000000004000c0 0x0000000000000010 0x00000000 f2 # CHECK: [ 3] 0 X Code 0x00000000004000d0 0x0000000000000022 0x00000000 _start _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits