Skip to content

[lldb/API] Expose Target::CreateBreakpoint(..., move_to_nearest_code)… #2243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lldb/bindings/interface/SBTarget.i
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions lldb/include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,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);

Expand Down
35 changes: 35 additions & 0 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,38 @@ SBBreakpoint SBTarget::BreakpointCreateByLocation(
return LLDB_RECORD_RESULT(sb_bp);
}

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);

SBBreakpoint sb_bp;
TargetSP target_sp(GetSP());
if (target_sp && line != 0) {
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());

const LazyBool check_inlines = eLazyBoolCalculate;
const LazyBool skip_prologue = eLazyBoolCalculate;
const bool internal = false;
const bool hardware = false;
const FileSpecList *module_list = nullptr;
if (sb_module_list.GetSize() > 0) {
module_list = sb_module_list.get();
}
sb_bp = target_sp->CreateBreakpoint(
module_list, *sb_file_spec, line, column, offset, check_inlines,
skip_prologue, internal, hardware,
move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
}

return LLDB_RECORD_RESULT(sb_bp);
}

SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
const char *module_name) {
LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
Expand Down Expand Up @@ -2488,6 +2520,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)