0

I want to implement set-breakpoints function through LLDB, I have read the lldb source code and understood part of the implementation. My question is where is the source code set breakpoint implemented? How does lldb interact with DWARF?

sven
  • 86
  • 6

1 Answers1

1

This sort of question is maybe more appropriately addressed to the lldb-dev mailing list (lldb-dev@lists.llvm.org). If you end up doing something you want to submit to lldb, you'll need to discuss it there anyway...

But, in brief: the part of the lldb Breakpoint that handles actually setting breakpoints is the breakpoint search kernel. Search kernels for breakpoint setting in lldb are always subclasses of the BreakpointResolver class. You can read the comments in BreakpointResolver.h for more details on how this works. The File & Line breakpoint setting resolver is BreakpointResolverFileLine (in BreakpointResolverFileLine.cpp).

Then this overload of Target::CreateBreakpoint:

  lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules,
                                      const FileSpec &file, uint32_t line_no,
                                      lldb::addr_t offset,
                                      LazyBool check_inlines,
                                      LazyBool skip_prologue, bool internal,
                                      bool request_hardware,
                                      LazyBool move_to_nearest_code);

works to take the specifications for a file & line breakpoint and construct the appropriate BreakpointResolver, and make a Breakpoint out of it. Finally, CommandObjectBreakpoint::CommandObjectBreakpointSet marshals the command line arguments and passes them to the appropriate Target::CreateBreakpoint function to make a breakpoint from the command line.

Asking "how lldb interacts with DWARF" is a little too unfocused to give a coherent answer. DWARF has a lot of moving parts and lldb uses DWARF in many ways... Can you ask more specifically what you want to know? BTW, if you haven't perused the DWARF spec (from http://dwarfstd.org) you probably want to do that before diving into lldb's use of DWARF.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • Thanks very much. I have read lldb source code again, I am confused with how the lldb set the breakpoint(INT 3) in memory and have not find the implement, can you help figure it out? Thanks again. – sven Aug 06 '18 at 04:32
  • The code in lldb to directly set breakpoints is in Process::EnableSoftwareBreakpoint. But note, lldb doesn't do that directly if it can avoid it. For instance, when talking to a gdb-remote protocol stub (the norm on macOS & Linux) it queries the stub (debugserver on macOS/iOS or lldb-server on Linux) to see whether it supports the zZ packet, and if so it uses that instead. It's better if the debug stub knows about the breakpoints (so it can for instance remove them if lldb goes away unexpectedly). – Jim Ingham Aug 06 '18 at 19:19
  • Thank you for your patience. I found BroadcasterImpl::BroadcaseEvent() and PrivateBroadcaseEvent was invoked when add a breakpoint, can you help me figure out the code implementation of the event response ? – sven Aug 07 '18 at 03:23
  • In the case of breakpoint events, lldb doesn't require that anybody listen to them. Beyond sending them, lldb does nothing with the events. They are there so that an IDE (e.g. Xcode) that uses lldb and and also provides an lldb command-line interface, can get informed about changes to breakpoint state done with command-line commands and reflect them in its UI. – Jim Ingham Aug 08 '18 at 17:46