[Lldb-commits] [lldb] 0470169 - [lldb/API] Expose Target::CreateBreakpoint(..., move_to_nearest_code) overload

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 14 19:24:56 PST 2020


Author: Med Ismail Bennani
Date: 2020-12-15T04:24:44+01:00
New Revision: 04701698ebaff8d0c108e590a7e55c3c5bcd4d9e

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

LOG: [lldb/API] Expose Target::CreateBreakpoint(..., move_to_nearest_code) overload

This patch exposes the Target::CreateBreakpoint overload with the
boolean argument to move to the neareast code to the SBAPI.

This is useful when creating column breakpoints to restrict lldb's
resolution to the pointed source location, preventing it to go to the next
line.

rdar://72196842

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

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>

Added: 
    

Modified: 
    lldb/bindings/interface/SBTarget.i
    lldb/include/lldb/API/SBTarget.h
    lldb/source/API/SBTarget.cpp
    lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py

Removed: 
    


################################################################################
diff  --git a/lldb/bindings/interface/SBTarget.i b/lldb/bindings/interface/SBTarget.i
index 57b5ccea6399..41b9be2bf1fb 100644
--- a/lldb/bindings/interface/SBTarget.i
+++ b/lldb/bindings/interface/SBTarget.i
@@ -579,6 +579,12 @@ public:
                                 uint32_t column, lldb::addr_t offset,
                                 SBFileSpecList &module_list);
 
+    lldb::SBBreakpoint
+    BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line,
+                                uint32_t column, lldb::addr_t offset,
+                                SBFileSpecList &module_list,
+                                bool move_to_nearest_code);
+
     lldb::SBBreakpoint
     BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
 

diff  --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index fad842c9cb1c..bf423726f080 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -9,6 +9,8 @@
 #ifndef LLDB_API_SBTARGET_H
 #define LLDB_API_SBTARGET_H
 
+#include "lldb/lldb-private-enumerations.h"
+
 #include "lldb/API/SBAddress.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBreakpoint.h"
@@ -560,6 +562,12 @@ class LLDB_API SBTarget {
                              uint32_t column, lldb::addr_t offset,
                              SBFileSpecList &module_list);
 
+  lldb::SBBreakpoint
+  BreakpointCreateByLocation(const lldb::SBFileSpec &file_spec, uint32_t line,
+                             uint32_t column, lldb::addr_t offset,
+                             SBFileSpecList &module_list,
+                             bool move_to_nearest_code);
+
   lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name,
                                             const char *module_name = nullptr);
 
@@ -858,6 +866,11 @@ class LLDB_API SBTarget {
   void SetSP(const lldb::TargetSP &target_sp);
 
 private:
+  lldb::SBBreakpoint BreakpointCreateByLocationImpl(
+      const lldb::SBFileSpec &file_spec, uint32_t line, uint32_t column,
+      lldb::addr_t offset, SBFileSpecList &module_list,
+      const lldb_private::LazyBool move_to_nearest_code);
+
   lldb::TargetSP m_opaque_sp;
 };
 

diff  --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 2a305159bbb5..d0761d69c667 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -757,14 +757,10 @@ SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
                                                        offset, sb_module_list));
 }
 
-SBBreakpoint SBTarget::BreakpointCreateByLocation(
-    const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
-    lldb::addr_t offset, SBFileSpecList &sb_module_list) {
-  LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
-                     (const lldb::SBFileSpec &, uint32_t, uint32_t,
-                      lldb::addr_t, lldb::SBFileSpecList &),
-                     sb_file_spec, line, column, offset, sb_module_list);
-
+SBBreakpoint SBTarget::BreakpointCreateByLocationImpl(
+    const lldb::SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
+    lldb::addr_t offset, SBFileSpecList &sb_module_list,
+    const LazyBool move_to_nearest_code) {
   SBBreakpoint sb_bp;
   TargetSP target_sp(GetSP());
   if (target_sp && line != 0) {
@@ -774,7 +770,6 @@ SBBreakpoint SBTarget::BreakpointCreateByLocation(
     const LazyBool skip_prologue = eLazyBoolCalculate;
     const bool internal = false;
     const bool hardware = false;
-    const LazyBool move_to_nearest_code = eLazyBoolCalculate;
     const FileSpecList *module_list = nullptr;
     if (sb_module_list.GetSize() > 0) {
       module_list = sb_module_list.get();
@@ -784,7 +779,34 @@ SBBreakpoint SBTarget::BreakpointCreateByLocation(
         skip_prologue, internal, hardware, move_to_nearest_code);
   }
 
-  return LLDB_RECORD_RESULT(sb_bp);
+  return sb_bp;
+}
+
+SBBreakpoint SBTarget::BreakpointCreateByLocation(
+    const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
+    lldb::addr_t offset, SBFileSpecList &sb_module_list) {
+  LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
+                     (const lldb::SBFileSpec &, uint32_t, uint32_t,
+                      lldb::addr_t, lldb::SBFileSpecList &),
+                     sb_file_spec, line, column, offset, sb_module_list);
+
+  return LLDB_RECORD_RESULT(BreakpointCreateByLocationImpl(
+      sb_file_spec, line, column, offset, sb_module_list, eLazyBoolCalculate));
+}
+
+SBBreakpoint SBTarget::BreakpointCreateByLocation(
+    const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
+    lldb::addr_t offset, SBFileSpecList &sb_module_list,
+    bool move_to_nearest_code) {
+  LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
+                     (const lldb::SBFileSpec &, uint32_t, uint32_t,
+                      lldb::addr_t, lldb::SBFileSpecList &, bool),
+                     sb_file_spec, line, column, offset, sb_module_list,
+                     move_to_nearest_code);
+
+  return LLDB_RECORD_RESULT(BreakpointCreateByLocationImpl(
+      sb_file_spec, line, column, offset, sb_module_list,
+      move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo));
 }
 
 SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
@@ -2489,6 +2511,9 @@ void RegisterMethods<SBTarget>(Registry &R) {
                        BreakpointCreateByLocation,
                        (const lldb::SBFileSpec &, uint32_t, uint32_t,
                         lldb::addr_t, lldb::SBFileSpecList &));
+  LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
+                       (const lldb::SBFileSpec &, uint32_t, uint32_t,
+                        lldb::addr_t, lldb::SBFileSpecList &, bool));
   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
                        (const char *, const char *));
   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,

diff  --git a/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py b/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py
index a03e2addbe97..1a0e9c69dd95 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py
@@ -42,3 +42,30 @@ def testBreakpointByLine(self):
             self.assertEqual(b_loc.GetLine(), 11)
             in_condition |= b_loc.GetColumn() < 30
         self.assertTrue(in_condition)
+
+    ## Skip gcc version less 7.1 since it doesn't support -gcolumn-info
+    @skipIf(compiler="gcc", compiler_version=['<', '7.1'])
+    def testBreakpointByLineAndColumnNearestCode(self):
+        self.build()
+        exe = self.getBuildArtifact("a.out")
+
+        main_c = lldb.SBFileSpec("main.c")
+        line = line_number("main.c", "// Line 20.")
+        column = len("// Line 20") # should stop at the period.
+        indent = 2
+        module_list = lldb.SBFileSpecList()
+
+        # Create a target from the debugger.
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        valid_bpt = target.BreakpointCreateByLocation(main_c, line, column,
+                                                      indent, module_list, True)
+        self.assertTrue(valid_bpt, VALID_BREAKPOINT)
+        self.assertEqual(valid_bpt.GetNumLocations(), 1)
+
+        invalid_bpt = target.BreakpointCreateByLocation(main_c, line, column,
+                                                      indent, module_list, False)
+        self.assertTrue(invalid_bpt, VALID_BREAKPOINT)
+        self.assertEqual(invalid_bpt.GetNumLocations(), 0)
+


        


More information about the lldb-commits mailing list