llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Ely Ronnen (eronnen)

<details>
<summary>Changes</summary>

Adds a setting that makes lldb generate synthetic symbol names according to the 
file address of the function instead of the index, this could make it easier 
when debugging crashes and stack traces to understand which function the 
unnamed symbols corrresponds to

---
Full diff: https://github.com/llvm/llvm-project/pull/137512.diff


6 Files Affected:

- (modified) lldb/include/lldb/Core/ModuleList.h (+14) 
- (modified) lldb/include/lldb/Symbol/Symbol.h (+1) 
- (modified) lldb/include/lldb/lldb-enumerations.h (+6) 
- (modified) lldb/source/Core/CoreProperties.td (+5) 
- (modified) lldb/source/Core/ModuleList.cpp (+7) 
- (modified) lldb/source/Symbol/Symbol.cpp (+9-1) 


``````````diff
diff --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index 909ee08f9ba62..23f64a153d47d 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -67,6 +67,19 @@ 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 +104,7 @@ class ModuleListProperties : public Properties {
   bool GetLoadSymbolOnDemand();
 
   lldb::SymbolDownload GetSymbolAutoDownload() const;
+  lldb::SyntheticSymbolsNameStyle GetSyntheticSymbolsNameStyle() const;
 
   PathMappingList GetSymlinkMappings() const;
 };
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index e05c845a69f3e..5c37b33e7442e 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -339,6 +339,7 @@ class Symbol : public SymbolContextScope {
       m_is_weak : 1,
       m_type : 6;            // Values from the lldb::SymbolType enum.
   mutable Mangled m_mangled; // uniqued symbol name/mangled name pair
+  
   AddressRange m_addr_range; // Contains the value, or the section offset
                              // address when the value is an address in a
                              // section, and the size (if any)
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..a507d1c2efaf5 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -115,6 +115,13 @@ 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..0e17662ee14ba 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -639,7 +639,15 @@ 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()));
   }
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/137512
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to