https://github.com/eronnen updated https://github.com/llvm/llvm-project/pull/137512
>From 10d4c2497a55ccac91c27009ceafc2042476e7ab Mon Sep 17 00:00:00 2001 From: Ely Ronnen <elyron...@gmail.com> Date: Sun, 27 Apr 2025 13:48:45 +0200 Subject: [PATCH] [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 | 7 +++++++ lldb/source/Core/ModuleList.cpp | 8 ++++++++ lldb/source/Symbol/Symbol.cpp | 13 ++++++++++++- 5 files changed, 48 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..84326abc650b6 100644 --- a/lldb/source/Core/CoreProperties.td +++ b/lldb/source/Core/CoreProperties.td @@ -46,6 +46,13 @@ 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())); } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits