[Lldb-commits] [PATCH] D130607: [trace] Add instruction control flow kind to JSON trace dumper's output

Jakob Johnson via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 26 16:26:28 PDT 2022


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

D128477 <https://reviews.llvm.org/D128477> adds a '-k' flag which displays each instruction's control flow in the `thread trace dump instructions` command's non-json  output (ie no '-j' or '-J' flag)
This diff adds the instruction control flow kind to the `thread trace dump instructions` command's JSON output (ie '-j' or '-J' flag)

Test Plan:
Confirm "controlFlowKind" is present in JSON when '-k' is provided

  (lldb) thread trace dump instructions -J -k
  [
    {                                                                                                                                                                                                                                                                                 [141/1952]
      "id": 7755,
      "loadAddress": "0x400868",
      "module": "test.out",
      "symbol": "main",
      "mnemonic": "jmp",
      "controlFlowKind": "jump",
      "source": "/home/jakobjohnson/jakob-dev/test.cpp",
      "line": 41,
      "column": 29
    },
    {
      "id": 7753,
      "loadAddress": "0x7ffff7b54dab",
      "module": "libstdc++.so.6",
      "symbol": "std::ostream::flush()",
      "mnemonic": "retq",
      "controlFlowKind": "return"
    },
    {
      "id": 7752,
      "loadAddress": "0x7ffff7b54daa",
      "module": "libstdc++.so.6",
      "symbol": "std::ostream::flush()",
      "mnemonic": "popq",
      "controlFlowKind": "other"
    },
    ...
  ]

Confirm "controlFlowKind" is not present when '-k' isn't provided

  (lldb) thread trace dump instructions -J
  [
    {
      "id": 7755,
      "loadAddress": "0x400868",
      "module": "test.out",
      "symbol": "main",
      "mnemonic": "jmp",
      "source": "/home/jakobjohnson/jakob-dev/test.cpp",
      "line": 41,
      "column": 29
    },
    {
      "id": 7753,
      "loadAddress": "0x7ffff7b54dab",
      "module": "libstdc++.so.6",
      "symbol": "std::ostream::flush()",
      "mnemonic": "retq"
    },
    {
      "id": 7752,
      "loadAddress": "0x7ffff7b54daa",
      "module": "libstdc++.so.6",
      "symbol": "std::ostream::flush()",
      "mnemonic": "popq"
    },


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130607

Files:
  lldb/source/Target/TraceDumper.cpp


Index: lldb/source/Target/TraceDumper.cpp
===================================================================
--- lldb/source/Target/TraceDumper.cpp
+++ lldb/source/Target/TraceDumper.cpp
@@ -199,6 +199,7 @@
       "column"?: decimal,
       "source"?: string,
       "mnemonic"?: string,
+      "controlFlowKind"?: string,
     }
   */
 public:
@@ -234,10 +235,18 @@
           "symbol",
           ToOptionalString(item.symbol_info->sc.GetFunctionName().AsCString()));
 
-      if (item.symbol_info->instruction) {
+      if (lldb::InstructionSP instruction = item.symbol_info->instruction) {
+        ExecutionContext exe_ctx = item.symbol_info->exe_ctx;
         m_j.attribute("mnemonic",
-                      ToOptionalString(item.symbol_info->instruction->GetMnemonic(
-                          &item.symbol_info->exe_ctx)));
+                      ToOptionalString(instruction->GetMnemonic(&exe_ctx)));
+        if (m_options.show_control_flow_kind) {
+          lldb::InstructionControlFlowKind instruction_control_flow_kind =
+              instruction->GetControlFlowKind(&exe_ctx);
+          m_j.attribute("controlFlowKind",
+                        ToOptionalString(
+                            Instruction::GetNameForInstructionControlFlowKind(
+                                instruction_control_flow_kind)));
+        }
       }
 
       if (IsLineEntryValid(item.symbol_info->sc.line_entry)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130607.447875.patch
Type: text/x-patch
Size: 1416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220726/2ba3a937/attachment-0001.bin>


More information about the lldb-commits mailing list