[Lldb-commits] [lldb] dde3cf2 - [trace] Add instruction control flow kind to JSON trace dumper's output

Jakob Johnson via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 27 05:24:50 PDT 2022


Author: Jakob Johnson
Date: 2022-07-27T05:23:59-07:00
New Revision: dde3cf2e83d2a2aec5b46bdac64efbc28a3b2b20

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

LOG: [trace] Add instruction control flow kind to JSON trace dumper's output

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"
  },
```

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

Added: 
    

Modified: 
    lldb/source/Target/TraceDumper.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/TraceDumper.cpp b/lldb/source/Target/TraceDumper.cpp
index 5b71e9e4e97a8..872530b657a1b 100644
--- a/lldb/source/Target/TraceDumper.cpp
+++ b/lldb/source/Target/TraceDumper.cpp
@@ -199,6 +199,7 @@ class OutputWriterJSON : public TraceDumper::OutputWriter {
       "column"?: decimal,
       "source"?: string,
       "mnemonic"?: string,
+      "controlFlowKind"?: string,
     }
   */
 public:
@@ -234,10 +235,18 @@ class OutputWriterJSON : public TraceDumper::OutputWriter {
           "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)) {


        


More information about the lldb-commits mailing list