[Lldb-commits] [lldb] 6cbc6e9 - [LLDB] Add SBInstruction::GetControlFlowKind()

Jakob Johnson via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 2 15:49:51 PDT 2022


Author: Jakob Johnson
Date: 2022-08-02T15:42:45-07:00
New Revision: 6cbc6e9a6d5f0ef9c406f718dd0c3e6dd6dffeef

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

LOG: [LLDB] Add SBInstruction::GetControlFlowKind()

D128477 adds the control flow kind for `Instruction` and displays this
in the `thread trace dump instruction -k` command.

This diff exposes the control flow kind via the new
`SBInstruction::GetControlFlowKind` method.

I've expanded `TestDisassembleRawData` to test this method, but please
let me know if there are any other unittests that should also be updated.

Test Plan:
`./bin/lldb-dotest -p TestDisassembleRawData`

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

Added: 
    

Modified: 
    lldb/bindings/interface/SBInstruction.i
    lldb/include/lldb/API/SBInstruction.h
    lldb/source/API/SBInstruction.cpp
    lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py

Removed: 
    


################################################################################
diff  --git a/lldb/bindings/interface/SBInstruction.i b/lldb/bindings/interface/SBInstruction.i
index e9e018b7deed0..a467a6f0d93db 100644
--- a/lldb/bindings/interface/SBInstruction.i
+++ b/lldb/bindings/interface/SBInstruction.i
@@ -44,6 +44,9 @@ public:
     const char *
     GetComment (lldb::SBTarget target);
 
+    lldb::InstructionControlFlowKind
+    GetControlFlowKind(lldb::SBTarget target);
+
     lldb::SBData
     GetData (lldb::SBTarget target);
 

diff  --git a/lldb/include/lldb/API/SBInstruction.h b/lldb/include/lldb/API/SBInstruction.h
index b9d781550b5da..def9482b02ed0 100644
--- a/lldb/include/lldb/API/SBInstruction.h
+++ b/lldb/include/lldb/API/SBInstruction.h
@@ -43,6 +43,8 @@ class LLDB_API SBInstruction {
 
   const char *GetComment(lldb::SBTarget target);
 
+  lldb::InstructionControlFlowKind GetControlFlowKind(lldb::SBTarget target);
+
   lldb::SBData GetData(lldb::SBTarget target);
 
   size_t GetByteSize();

diff  --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp
index ced22628a2979..b03d8f73d66eb 100644
--- a/lldb/source/API/SBInstruction.cpp
+++ b/lldb/source/API/SBInstruction.cpp
@@ -164,6 +164,25 @@ const char *SBInstruction::GetComment(SBTarget target) {
   return nullptr;
 }
 
+lldb::InstructionControlFlowKind SBInstruction::GetControlFlowKind(lldb::SBTarget target) {
+  LLDB_INSTRUMENT_VA(this, target);
+
+  lldb::InstructionSP inst_sp(GetOpaque());
+  if (inst_sp) {
+    ExecutionContext exe_ctx;
+    TargetSP target_sp(target.GetSP());
+    std::unique_lock<std::recursive_mutex> lock;
+    if (target_sp) {
+      lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
+
+      target_sp->CalculateExecutionContext(exe_ctx);
+      exe_ctx.SetProcessSP(target_sp->GetProcessSP());
+    }
+    return inst_sp->GetControlFlowKind(&exe_ctx);
+  }
+  return lldb::eInstructionControlFlowKindUnknown;
+}
+
 size_t SBInstruction::GetByteSize() {
   LLDB_INSTRUMENT_VA(this);
 

diff  --git a/lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py b/lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py
index 677559c4a5160..4186e6b330f08 100644
--- a/lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py
+++ b/lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py
@@ -52,16 +52,26 @@ def test_disassemble_raw_data(self):
             self.assertEqual(inst.GetMnemonic(target), "move")
             self.assertEqual(inst.GetOperands(target),
                             '$' + "fp, " + '$' + "sp")
+            self.assertEqual(inst.GetControlFlowKind(target),
+                            lldb.eInstructionControlFlowKindUnknown)
         elif re.match("powerpc64le", arch):
             self.assertEqual(inst.GetMnemonic(target), "li")
             self.assertEqual(inst.GetOperands(target), "4, 0")
+            self.assertEqual(inst.GetControlFlowKind(target),
+                            lldb.eInstructionControlFlowKindUnknown)
         elif arch in ("aarch64", "arm64"):
             self.assertEqual(inst.GetMnemonic(target), "mov")
             self.assertEqual(inst.GetOperands(target), "w0, #0x63")
+            self.assertEqual(inst.GetControlFlowKind(target),
+                            lldb.eInstructionControlFlowKindUnknown)
         elif arch == "arm":
             self.assertEqual(inst.GetMnemonic(target), "mov")
             self.assertEqual(inst.GetOperands(target), "r3, #99")
+            self.assertEqual(inst.GetControlFlowKind(target),
+                            lldb.eInstructionControlFlowKindUnknown)
         else:
             self.assertEqual(inst.GetMnemonic(target), "movq")
             self.assertEqual(inst.GetOperands(target),
                             '%' + "rsp, " + '%' + "rbp")
+            self.assertEqual(inst.GetControlFlowKind(target),
+                            lldb.eInstructionControlFlowKindOther)


        


More information about the lldb-commits mailing list