[Lldb-commits] [lldb] 7eaae93 - [FormatEntity] Add mangled function name support

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 12 10:23:27 PST 2019


Author: Med Ismail Bennani
Date: 2019-12-12T10:22:57-08:00
New Revision: 7eaae939b9bb294d029d212d768bb38272c00936

URL: https://github.com/llvm/llvm-project/commit/7eaae939b9bb294d029d212d768bb38272c00936
DIFF: https://github.com/llvm/llvm-project/commit/7eaae939b9bb294d029d212d768bb38272c00936.diff

LOG: [FormatEntity] Add mangled function name support

Summary:
Add `function.mangled-name` key for FormatEntity to show the mangled
function names in backtraces.

rdar://54088244

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71237

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>

Added: 
    lldb/test/Shell/Settings/Inputs/main.cpp
    lldb/test/Shell/Settings/TestFrameFormatMangling.test

Modified: 
    lldb/docs/use/formatting.rst
    lldb/include/lldb/Core/FormatEntity.h
    lldb/source/Core/FormatEntity.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/docs/use/formatting.rst b/lldb/docs/use/formatting.rst
index f0b4f4ae2476..939c4e18f749 100644
--- a/lldb/docs/use/formatting.rst
+++ b/lldb/docs/use/formatting.rst
@@ -92,6 +92,8 @@ A complete list of currently supported format string variables is listed below:
 +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | ``function.name-without-args``                    | The name of the current function without arguments and values (used to include a function name in-line in the ``disassembly-format``)                                                                                                                                                       |
 +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+| ``function.mangled-name``                         | The mangled name of the current function or symbol.                                                                                                                                                                                                                                         |
++---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | ``function.pc-offset``                            | The program counter offset within the current function or symbol                                                                                                                                                                                                                            |
 +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | ``function.addr-offset``                          | The offset in bytes of the current function, formatted as " + dddd"                                                                                                                                                                                                                         |

diff  --git a/lldb/include/lldb/Core/FormatEntity.h b/lldb/include/lldb/Core/FormatEntity.h
index ae6c402a45be..8ee320b0ebb1 100644
--- a/lldb/include/lldb/Core/FormatEntity.h
+++ b/lldb/include/lldb/Core/FormatEntity.h
@@ -85,6 +85,7 @@ class FormatEntity {
       FunctionName,
       FunctionNameWithArgs,
       FunctionNameNoArgs,
+      FunctionMangledName,
       FunctionAddrOffset,
       FunctionAddrOffsetConcrete,
       FunctionLineOffset,

diff  --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index beab026e67aa..5d4dba073743 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -125,6 +125,7 @@ static FormatEntity::Entry::Definition g_function_child_entries[] = {
     ENTRY("name", FunctionName),
     ENTRY("name-without-args", FunctionNameNoArgs),
     ENTRY("name-with-args", FunctionNameWithArgs),
+    ENTRY("mangled-name", FunctionMangledName),
     ENTRY("addr-offset", FunctionAddrOffset),
     ENTRY("concrete-only-addr-offset-no-padding", FunctionAddrOffsetConcrete),
     ENTRY("line-offset", FunctionLineOffset),
@@ -351,6 +352,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
     ENUM_TO_CSTR(FunctionName);
     ENUM_TO_CSTR(FunctionNameWithArgs);
     ENUM_TO_CSTR(FunctionNameNoArgs);
+    ENUM_TO_CSTR(FunctionMangledName);
     ENUM_TO_CSTR(FunctionAddrOffset);
     ENUM_TO_CSTR(FunctionAddrOffsetConcrete);
     ENUM_TO_CSTR(FunctionLineOffset);
@@ -1745,6 +1747,31 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
   }
     return false;
 
+  case Entry::Type::FunctionMangledName: {
+    const char *name = nullptr;
+    if (sc->symbol)
+      name = sc->symbol->GetMangled()
+                 .GetName(sc->symbol->GetLanguage(), Mangled::ePreferMangled)
+                 .AsCString();
+    else if (sc->function)
+      name = sc->function->GetMangled()
+                 .GetName(sc->symbol->GetLanguage(), Mangled::ePreferMangled)
+                 .AsCString();
+
+    if (!name)
+      return false;
+    s.PutCString(name);
+
+    if (Block *inline_block = sc->block->GetContainingInlinedBlock()) {
+      if (const InlineFunctionInfo *inline_info =
+              sc->block->GetInlinedFunctionInfo()) {
+        s.PutCString(" [inlined] ");
+        inline_info->GetName(sc->function->GetLanguage()).Dump(&s);
+      }
+    }
+    return true;
+  }
+
   case Entry::Type::FunctionAddrOffset:
     if (addr) {
       if (DumpAddressOffsetFromFunction(s, sc, exe_ctx, *addr, false, false,

diff  --git a/lldb/test/Shell/Settings/Inputs/main.cpp b/lldb/test/Shell/Settings/Inputs/main.cpp
new file mode 100644
index 000000000000..98bbcd3eda07
--- /dev/null
+++ b/lldb/test/Shell/Settings/Inputs/main.cpp
@@ -0,0 +1,15 @@
+class MyClass {
+public:
+  MyClass() {}
+  void foo();
+};
+
+void MyClass::foo() {
+  return; // Set break point at this line.
+}
+
+int main() {
+  MyClass mc;
+  mc.foo();
+  return 0;
+}

diff  --git a/lldb/test/Shell/Settings/TestFrameFormatMangling.test b/lldb/test/Shell/Settings/TestFrameFormatMangling.test
new file mode 100644
index 000000000000..cc19ce4b2b9b
--- /dev/null
+++ b/lldb/test/Shell/Settings/TestFrameFormatMangling.test
@@ -0,0 +1,12 @@
+# UNSUPPORTED: system-windows
+# RUN: %clangxx_host -g -O0 %S/Inputs/main.cpp -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+br set -p "Set break"
+run
+frame info
+# CHECK: frame #0: {{.*}}MyClass::foo(
+set set frame-format "frame #${frame.index}: {${function.mangled-name}}\n"
+frame info
+# CHECK: frame #0: _ZN7MyClass3fooEv
+c
+q


        


More information about the lldb-commits mailing list