Skip to content

Commit dc82890

Browse files
committed
[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 <[email protected]>
1 parent 1d3f1eb commit dc82890

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

lldb/bindings/interface/SBTarget.i

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@ public:
579579
uint32_t column, lldb::addr_t offset,
580580
SBFileSpecList &module_list);
581581

582+
lldb::SBBreakpoint
583+
BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line,
584+
uint32_t column, lldb::addr_t offset,
585+
SBFileSpecList &module_list,
586+
bool move_to_nearest_code);
587+
582588
lldb::SBBreakpoint
583589
BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
584590

lldb/include/lldb/API/SBTarget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ class LLDB_API SBTarget {
560560
uint32_t column, lldb::addr_t offset,
561561
SBFileSpecList &module_list);
562562

563+
lldb::SBBreakpoint
564+
BreakpointCreateByLocation(const lldb::SBFileSpec &file_spec, uint32_t line,
565+
uint32_t column, lldb::addr_t offset,
566+
SBFileSpecList &module_list,
567+
bool move_to_nearest_code);
568+
563569
lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name,
564570
const char *module_name = nullptr);
565571

lldb/source/API/SBTarget.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,38 @@ SBBreakpoint SBTarget::BreakpointCreateByLocation(
787787
return LLDB_RECORD_RESULT(sb_bp);
788788
}
789789

790+
SBBreakpoint SBTarget::BreakpointCreateByLocation(
791+
const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
792+
lldb::addr_t offset, SBFileSpecList &sb_module_list,
793+
bool move_to_nearest_code) {
794+
LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
795+
(const lldb::SBFileSpec &, uint32_t, uint32_t,
796+
lldb::addr_t, lldb::SBFileSpecList &, bool),
797+
sb_file_spec, line, column, offset, sb_module_list,
798+
move_to_nearest_code);
799+
800+
SBBreakpoint sb_bp;
801+
TargetSP target_sp(GetSP());
802+
if (target_sp && line != 0) {
803+
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
804+
805+
const LazyBool check_inlines = eLazyBoolCalculate;
806+
const LazyBool skip_prologue = eLazyBoolCalculate;
807+
const bool internal = false;
808+
const bool hardware = false;
809+
const FileSpecList *module_list = nullptr;
810+
if (sb_module_list.GetSize() > 0) {
811+
module_list = sb_module_list.get();
812+
}
813+
sb_bp = target_sp->CreateBreakpoint(
814+
module_list, *sb_file_spec, line, column, offset, check_inlines,
815+
skip_prologue, internal, hardware,
816+
move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
817+
}
818+
819+
return LLDB_RECORD_RESULT(sb_bp);
820+
}
821+
790822
SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
791823
const char *module_name) {
792824
LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
@@ -2489,6 +2521,9 @@ void RegisterMethods<SBTarget>(Registry &R) {
24892521
BreakpointCreateByLocation,
24902522
(const lldb::SBFileSpec &, uint32_t, uint32_t,
24912523
lldb::addr_t, lldb::SBFileSpecList &));
2524+
LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
2525+
(const lldb::SBFileSpec &, uint32_t, uint32_t,
2526+
lldb::addr_t, lldb::SBFileSpecList &, bool));
24922527
LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
24932528
(const char *, const char *));
24942529
LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,

lldb/test/API/functionalities/breakpoint/breakpoint_by_line_and_column/TestBreakpointByLineAndColumn.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,30 @@ def testBreakpointByLine(self):
4242
self.assertEqual(b_loc.GetLine(), 11)
4343
in_condition |= b_loc.GetColumn() < 30
4444
self.assertTrue(in_condition)
45+
46+
## Skip gcc version less 7.1 since it doesn't support -gcolumn-info
47+
@skipIf(compiler="gcc", compiler_version=['<', '7.1'])
48+
def testBreakpointByLineAndColumnNearestCode(self):
49+
self.build()
50+
exe = self.getBuildArtifact("a.out")
51+
52+
main_c = lldb.SBFileSpec("main.c")
53+
line = line_number("main.c", "// Line 20.")
54+
column = len("// Line 20") # should stop at the period.
55+
indent = 2
56+
module_list = lldb.SBFileSpecList()
57+
58+
# Create a target from the debugger.
59+
target = self.dbg.CreateTarget(exe)
60+
self.assertTrue(target, VALID_TARGET)
61+
62+
valid_bpt = target.BreakpointCreateByLocation(main_c, line, column,
63+
indent, module_list, True)
64+
self.assertTrue(valid_bpt, VALID_BREAKPOINT)
65+
self.assertEqual(valid_bpt.GetNumLocations(), 1)
66+
67+
invalid_bpt = target.BreakpointCreateByLocation(main_c, line, column,
68+
indent, module_list, False)
69+
self.assertTrue(invalid_bpt, VALID_BREAKPOINT)
70+
self.assertEqual(invalid_bpt.GetNumLocations(), 0)
71+

0 commit comments

Comments
 (0)