Skip to content

Commit 9e6927b

Browse files
authored
Merge pull request #2243 from medismailben/apple/stable/20200714
[lldb/API] Expose Target::CreateBreakpoint(..., move_to_nearest_code)…
2 parents e70a527 + 95dcfb5 commit 9e6927b

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
@@ -786,6 +786,38 @@ SBBreakpoint SBTarget::BreakpointCreateByLocation(
786786
return LLDB_RECORD_RESULT(sb_bp);
787787
}
788788

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