[Lldb-commits] [PATCH] D129588: [trace] Avoid a crash in the dumper when disassembling fails

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 12 13:14:21 PDT 2022


wallace created this revision.
wallace added reviewers: jj10306, persona0220.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

In rare situations, disassemblying would fail that produce an invalid
InstructionSP object. We need to check that it's valid before using.

With this change, now the dumper doesn't crash with dumping instructions of
ioctl. In fact, it now dumps this output

{

  "id": 6135,
  "loadAddress": "0x7f4bfe5c7515",
  "module": "libc.so.6",
  "symbol": "ioctl",
  "source": "glibc/2.34/src/glibc-2.34/sysdeps/unix/syscall-template.S",
  "line": 120,
  "column": 0

}

Anyway, we need to investigate why the diassembler failed disassembling that
instruction. From over 2B instructions I was disassembling today, just this
one failed, so this could be a bug in LLVM's core disassembler.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129588

Files:
  lldb/source/Target/TraceDumper.cpp


Index: lldb/source/Target/TraceDumper.cpp
===================================================================
--- lldb/source/Target/TraceDumper.cpp
+++ lldb/source/Target/TraceDumper.cpp
@@ -143,7 +143,7 @@
       m_s << "(error) " << *item.error;
     } else {
       m_s.Format("{0:x+16}", item.load_address);
-      if (item.symbol_info) {
+      if (item.symbol_info && item.symbol_info->instruction) {
         m_s << "    ";
         item.symbol_info->instruction->Dump(&m_s, /*max_opcode_byte_size=*/0,
                                             /*show_address=*/false,
@@ -213,9 +213,12 @@
       m_j.attribute(
           "symbol",
           ToOptionalString(item.symbol_info->sc.GetFunctionName().AsCString()));
-      m_j.attribute("mnemonic",
-                    ToOptionalString(item.symbol_info->instruction->GetMnemonic(
-                        &item.symbol_info->exe_ctx)));
+
+      if (item.symbol_info->instruction) {
+        m_j.attribute("mnemonic",
+                      ToOptionalString(item.symbol_info->instruction->GetMnemonic(
+                          &item.symbol_info->exe_ctx)));
+      }
 
       if (IsLineEntryValid(item.symbol_info->sc.line_entry)) {
         m_j.attribute(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129588.444063.patch
Type: text/x-patch
Size: 1219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220712/51c83682/attachment.bin>


More information about the lldb-commits mailing list