[lldb-dev] Getting the file and line location of a break point via lldb python api

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Wed Apr 8 15:38:56 PDT 2020


As Jim said, we have many different kinds of breakpoints and breakpoints can have N SBBreakpointLocations and that number can change as your process runs and more shared libraries are loaded.

If you set a source file and line breakpoint to begin with, then iterating over the locations is the best way to see what you ended up with.

bp = target.BreakpointCreateByLocation("/tmp/main.cpp", 12)
for bp_loc in bp:
  addr = bp_loc.GetAddress()
  line_entry = addr.GetLineEntry()
  file_spec = line_entry.GetFileSpec()
  line = line_entry.GetLine()
  column = line_entry.GetColumn()


If you just want the breakpoint source file, line and column as a string value, just run str() on the line_entry:

>>> bp = lldb.target.BreakpointCreateByLocation("main.cpp", 6)
>>> for l in bp:
...   print(l.GetAddress().GetLineEntry())
... 
/Users/gclayton/Documents/src/args/main.cpp:6:14

It will print everything out for you into a single string. Note the print() statement above calls str() on "l.GetAddress().GetLineEntry()" for you.

Greg

> On Apr 8, 2020, at 10:15 AM, Tom Weaver via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> 
> I've been trying to get at the file path, line and column information of a break point via the python API but have been struggling.
> 
> given the following method :
> 
> def do_thing_with_bp_in_file_on_line(file_path, line_no):
>   ... do something with breakpoints on line_no in file at file_path
> 
> what would be the best way to find the break points that match the file_path and line number so I can act on them?
> 
> I've tried iterating through them and checking the file path and line number of one of a break points SBBreakpointLocation and drilling down the file spec and line entry information to compare with the parameters, but this seems long winded and has a bunch of assumptions baked into it.
> 
> Is there a more canonical way of doing this?
> 
> thanks in advance,
> Tom W
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev



More information about the lldb-dev mailing list