mib created this revision.
Herald added a project: LLDB.
mib added a reviewer: LLDB.

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

rdar://54088244

Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71237

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/Language.h
  lldb/source/Core/FormatEntity.cpp
  lldb/test/Shell/Settings/Inputs/main.cpp
  lldb/test/Shell/Settings/TestFrameFormatMangling.test

Index: lldb/test/Shell/Settings/TestFrameFormatMangling.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Settings/TestFrameFormatMangling.test
@@ -0,0 +1,11 @@
+# RUN: %clangxx_host -std=c++14 -g -O0 %S/Inputs/main.cpp -o %t.out
+# RUN: %lldb -x -b -s %s %t.out | FileCheck %s
+br set -p "Set break"
+run
+frame info
+# CHECK: frame #0: {{.*}}C::C(this=
+set set frame-format "frame #${frame.index}: ${ansi.fg.yellow}${frame.pc}${ansi.normal}{ ${module.file.basename}{\`${function.mangled-name}{${frame.no-debug}${function.pc-offset}}}}{ at ${ansi.fg.cyan}${line.file.basename}${ansi.normal}:${ansi.fg.yellow}${line.number}${ansi.normal}{:${ansi.fg.yellow}${line.column}${ansi.normal}}}{${function.is-optimized} [opt]}{${frame.is-artificial} [artificial]}\n"
+frame info
+# CHECK: frame #0: {{.*}}_ZN1CC2Eiii
+c
+q
Index: lldb/test/Shell/Settings/Inputs/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/Shell/Settings/Inputs/main.cpp
@@ -0,0 +1,125 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+class Conversion
+{
+public:
+    Conversion (int i) :
+      m_i (i)
+      {}
+
+    operator bool()
+    {
+        return m_i != 0;
+    }
+    
+private:
+    int m_i;
+};
+
+class A
+{
+public:
+    A(int i=0):
+        m_a_int(i),
+        m_aa_int(i+1)
+    {
+    }
+
+    //virtual
+    ~A()
+    {
+    }
+
+    int
+    GetInteger() const
+    {
+        return m_a_int;
+    }
+    void
+    SetInteger(int i)
+    {
+        m_a_int = i;
+    }
+
+protected:
+    int m_a_int;
+    int m_aa_int;
+};
+
+class B : public A
+{
+public:
+    B(int ai, int bi) :
+        A(ai),
+        m_b_int(bi)
+    {
+    }
+
+    //virtual
+    ~B()
+    {
+    }
+
+    int
+    GetIntegerB() const
+    {
+        return m_b_int;
+    }
+    void
+    SetIntegerB(int i)
+    {
+        m_b_int = i;
+    }
+
+protected:
+    int m_b_int;
+};
+
+#include <cstdio>
+class C : public B
+{
+public:
+    C(int ai, int bi, int ci) :
+        B(ai, bi),
+        m_c_int(ci)
+    {
+      std::printf("Within C::ctor() m_c_int=%d\n", m_c_int); // Set break point at this line.
+    }
+
+    //virtual
+    ~C()
+    {
+    }
+
+    int
+    GetIntegerC() const
+    {
+        return m_c_int;
+    }
+    void
+    SetIntegerC(int i)
+    {
+        m_c_int = i;
+    }
+
+protected:
+    int m_c_int;
+};
+
+int
+main (int argc, char const *argv[])
+{
+    A a(12);
+    B b(22,33);
+    C c(44,55,66);
+    Conversion conv(1);
+    if (conv)
+        return b.GetIntegerB() - a.GetInteger() + c.GetInteger();
+    return 0;
+}
Index: lldb/source/Core/FormatEntity.cpp
===================================================================
--- lldb/source/Core/FormatEntity.cpp
+++ lldb/source/Core/FormatEntity.cpp
@@ -125,6 +125,7 @@
     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 @@
     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,58 @@
   }
     return false;
 
+  case Entry::Type::FunctionMangledName: {
+    Language *language_plugin = nullptr;
+    bool language_plugin_handled = false;
+    StreamString ss;
+    if (sc->function)
+      language_plugin = Language::FindPlugin(sc->function->GetLanguage());
+    else if (sc->symbol)
+      language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
+    if (language_plugin) {
+      language_plugin_handled = language_plugin->GetFunctionDisplayName(
+          sc, exe_ctx, Language::FunctionNameRepresentation::eMangledName, ss);
+    }
+    if (language_plugin_handled) {
+      s << ss.GetString();
+      return true;
+    } else {
+      const char *mangled_name = nullptr;
+      if (sc->function)
+        mangled_name = sc->function->GetMangled().GetMangledName().AsCString();
+      else if (sc->symbol)
+        mangled_name = sc->symbol->GetMangled().GetMangledName().AsCString();
+      const char *name = nullptr;
+      if (!mangled_name) {
+        if (sc->function)
+          name = sc->function->GetName().AsCString();
+        else if (sc->symbol)
+          name = sc->symbol->GetName().AsCString();
+        
+      } else {
+        name = mangled_name;
+      }
+      
+      if (name) {
+        s.PutCString(name);
+
+        if (sc->block) {
+          Block *inline_block = sc->block->GetContainingInlinedBlock();
+          if (inline_block) {
+            const InlineFunctionInfo *inline_info =
+                sc->block->GetInlinedFunctionInfo();
+            if (inline_info) {
+              s.PutCString(" [inlined] ");
+              inline_info->GetName(sc->function->GetLanguage()).Dump(&s);
+            }
+          }
+        }
+        return true;
+      }
+    }
+  }
+    return false;
+
   case Entry::Type::FunctionAddrOffset:
     if (addr) {
       if (DumpAddressOffsetFromFunction(s, sc, exe_ctx, *addr, false, false,
Index: lldb/include/lldb/Target/Language.h
===================================================================
--- lldb/include/lldb/Target/Language.h
+++ lldb/include/lldb/Target/Language.h
@@ -142,7 +142,8 @@
   enum class FunctionNameRepresentation {
     eName,
     eNameWithArgs,
-    eNameWithNoArgs
+    eNameWithNoArgs,
+    eMangledName
   };
 
   ~Language() override;
Index: lldb/include/lldb/Core/FormatEntity.h
===================================================================
--- lldb/include/lldb/Core/FormatEntity.h
+++ lldb/include/lldb/Core/FormatEntity.h
@@ -85,6 +85,7 @@
       FunctionName,
       FunctionNameWithArgs,
       FunctionNameNoArgs,
+      FunctionMangledName,
       FunctionAddrOffset,
       FunctionAddrOffsetConcrete,
       FunctionLineOffset,
Index: lldb/docs/use/formatting.rst
===================================================================
--- lldb/docs/use/formatting.rst
+++ lldb/docs/use/formatting.rst
@@ -92,6 +92,8 @@
 +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | ``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"                                                                                                                                                                                                                         |
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to