mib created this revision.
mib added a project: 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>

LanguageRuntime: Simplify NSException::GetSummary() output

Right now, NSException::GetSummary() output is the following:
"name: $exception_name - reason: $exception_reason"

It would be better to simplify the output by removing the name and only
showing the exception's reason. This way, annotations would look nicer in
the editor, and would be a shorter summary in the Variables Inspector.

Accessing the exception's name can still be done by expanding the
NSException object in the Variables Inspector.

rdar://54770115

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71309

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  
lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/Core/FormatEntity.cpp
  lldb/source/Plugins/Language/ObjC/NSException.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,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: {{.*}}Increment::GetValue()
+set set frame-format "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}{\`${function.mangled-name}}\n"
+frame info
+# CHECK: frame #0: {{.*}}_ZN9Increment8GetValueEv
+c
+q
Index: lldb/test/Shell/Settings/Inputs/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/Shell/Settings/Inputs/main.cpp
@@ -0,0 +1,29 @@
+//===-- 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 Increment {
+public:
+  Increment(int value) { Increment::value += value; }
+
+  static const int GetValue();
+
+private:
+  static int value;
+};
+
+int Increment::value = 40;
+
+const int Increment::GetValue() {
+  return value; // Set break point at this line.
+}
+
+int main() {
+  Increment i(2);
+  const int new_val = Increment::GetValue();
+  return new_val;
+}
Index: lldb/source/Plugins/Language/ObjC/NSException.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/NSException.cpp
+++ lldb/source/Plugins/Language/ObjC/NSException.cpp
@@ -96,21 +96,17 @@
 
 bool lldb_private::formatters::NSException_SummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  lldb::ValueObjectSP name_sp;
   lldb::ValueObjectSP reason_sp;
-  if (!ExtractFields(valobj, &name_sp, &reason_sp, nullptr, nullptr))
+  if (!ExtractFields(valobj, nullptr, &reason_sp, nullptr, nullptr))
     return false;
 
-  if (!name_sp || !reason_sp)
+  if (!reason_sp)
     return false;
-
-  StreamString name_str_summary;
+  
   StreamString reason_str_summary;
-  if (NSStringSummaryProvider(*name_sp, name_str_summary, options) &&
-      NSStringSummaryProvider(*reason_sp, reason_str_summary, options) &&
-      !name_str_summary.Empty() && !reason_str_summary.Empty()) {
-    stream.Printf("name: %s - reason: %s", name_str_summary.GetData(),
-                  reason_str_summary.GetData());
+  if (NSStringSummaryProvider(*reason_sp, reason_str_summary, options) &&
+      !reason_str_summary.Empty()) {
+    stream.Printf("%s", reason_str_summary.GetData());
     return true;
   } else
     return false;
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,37 @@
   }
     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;
+    else {
+      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;
+    }
+  }
+
   case Entry::Type::FunctionAddrOffset:
     if (addr) {
       if (DumpAddressOffsetFromFunction(s, sc, exe_ctx, *addr, false, false,
Index: lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
+++ lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
@@ -31,7 +31,7 @@
 
         self.expect('thread exception', substrs=[
                 '(NSException *) exception = ',
-                'name: "ThrownException" - reason: "SomeReason"',
+                '"SomeReason"',
             ])
 
         target = self.dbg.GetSelectedTarget()
@@ -63,7 +63,7 @@
             'frame variable e1',
             substrs=[
                 '(NSException *) e1 = ',
-                'name: "ExceptionName" - reason: "SomeReason"'
+                '"SomeReason"'
             ])
 
         self.expect(
@@ -79,7 +79,7 @@
         e1 = frame.FindVariable("e1")
         self.assertTrue(e1)
         self.assertEqual(e1.type.name, "NSException *")
-        self.assertEqual(e1.GetSummary(), 'name: "ExceptionName" - reason: "SomeReason"')
+        self.assertEqual(e1.GetSummary(), '"SomeReason"')
         self.assertEqual(e1.GetChildMemberWithName("name").description, "ExceptionName")
         self.assertEqual(e1.GetChildMemberWithName("reason").description, "SomeReason")
         userInfo = e1.GetChildMemberWithName("userInfo").dynamic
@@ -92,7 +92,7 @@
             'frame variable e2',
             substrs=[
                 '(NSException *) e2 = ',
-                'name: "ThrownException" - reason: "SomeReason"'
+                '"SomeReason"'
             ])
 
         self.expect(
@@ -108,7 +108,7 @@
         e2 = frame.FindVariable("e2")
         self.assertTrue(e2)
         self.assertEqual(e2.type.name, "NSException *")
-        self.assertEqual(e2.GetSummary(), 'name: "ThrownException" - reason: "SomeReason"')
+        self.assertEqual(e2.GetSummary(), '"SomeReason"')
         self.assertEqual(e2.GetChildMemberWithName("name").description, "ThrownException")
         self.assertEqual(e2.GetChildMemberWithName("reason").description, "SomeReason")
         userInfo = e2.GetChildMemberWithName("userInfo").dynamic
@@ -141,7 +141,7 @@
 
         self.expect('thread exception', substrs=[
                 '(NSException *) exception = ',
-                'name: "ThrownException" - reason: "SomeReason"',
+                '"SomeReason"',
                 'libobjc.A.dylib`objc_exception_throw',
                 'a.out`foo', 'at main.mm:24',
                 'a.out`rethrow', 'at main.mm:35',
Index: lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
+++ lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
@@ -25,11 +25,11 @@
             'frame variable except0 except1 except2 except3',
             substrs=[
                 '(NSException *) except0 = ',
-                'name: @"TheGuyWhoHasNoName" - reason: @"cuz it\'s funny"',
+                '@"cuz it\'s funny"',
                 '(NSException *) except1 = ',
-                'name: @"TheGuyWhoHasNoName~1" - reason: @"cuz it\'s funny"',
+                '@"cuz it\'s funny"',
                 '(NSException *) except2 = ',
-                'name: @"TheGuyWhoHasNoName`2" - reason: @"cuz it\'s funny"',
+                ' @"cuz it\'s funny"',
                 '(NSException *) except3 = ',
-                'name: @"TheGuyWhoHasNoName/3" - reason: @"cuz it\'s funny"'
+                ' @"cuz it\'s funny"'
             ])
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
  • [Lldb-commits] [PATCH]... Med Ismail Bennani via Phabricator via lldb-commits

Reply via email to