[Lldb-commits] [PATCH] D131005: [LLDB] Add SBInstruction::GetControlFlowKind()

Jakob Johnson via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 2 11:39:05 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 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`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131005

Files:
  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


Index: lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py
===================================================================
--- lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py
+++ lldb/test/API/python_api/disassemble-raw-data/TestDisassembleRawData.py
@@ -52,16 +52,26 @@
             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)
Index: lldb/source/API/SBInstruction.cpp
===================================================================
--- lldb/source/API/SBInstruction.cpp
+++ lldb/source/API/SBInstruction.cpp
@@ -164,6 +164,25 @@
   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);
 
Index: lldb/include/lldb/API/SBInstruction.h
===================================================================
--- lldb/include/lldb/API/SBInstruction.h
+++ lldb/include/lldb/API/SBInstruction.h
@@ -43,6 +43,8 @@
 
   const char *GetComment(lldb::SBTarget target);
 
+  lldb::InstructionControlFlowKind GetControlFlowKind(lldb::SBTarget target);
+
   lldb::SBData GetData(lldb::SBTarget target);
 
   size_t GetByteSize();
Index: lldb/bindings/interface/SBInstruction.i
===================================================================
--- lldb/bindings/interface/SBInstruction.i
+++ lldb/bindings/interface/SBInstruction.i
@@ -44,6 +44,9 @@
     const char *
     GetComment (lldb::SBTarget target);
 
+    lldb::InstructionControlFlowKind
+    GetControlFlowKind(lldb::SBTarget target);
+
     lldb::SBData
     GetData (lldb::SBTarget target);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131005.449364.patch
Type: text/x-patch
Size: 3661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220802/f1ce806c/attachment.bin>


More information about the lldb-commits mailing list