Hi everyone, I’m doing a GUI frontend using lldb api, but the breakpoint created by code cannot make the program stop.
The code for creating the breakpoint is:
lldb::SBBreakpoint bp = target_.BreakpointCreateByLocation(target_.GetExecutable().GetFilename(), lineNumber);
The breakpoint is valid, and I can get its description, but the program does not stop on that breakpoint.
lldb-mi uses public API too and it works. Try to look how it implemented there (see tools/lldb-mi/MICmdCmdBreak.cpp:232).
Breakpoints in lldb have three stages. There is an SBBreakpoint, which is some specification of how to set places to stop in your code. When that specification generates some actual address on which to stop, an SBBreakpointLocations is added to the SBBreakpoint. One SBBreakpoint can result in multiple locations at which to stop. But a breakpoint can be valid and have a description even if it has not yet generated any actual stop addresses. So the first thing to do is to check if your breakpoint has one or more locations (SBBreakpoint::GetNumLocations/GetLocationAtIndex).
Breakpoints send events to the Target that owns them when locations get added or removed or changed. You can listen for those events. There isn't a notification for "wasn't set at exactly the location you expected since for many breakpoint types that wouldn't really be possible to calculate. You'll just have to watch for the breakpoint events and then check the changed locations for whatever you want to know.
Question: why are you trying to set a breakpoint in the executable file? You need to set the breakpoint in a valid source file ("/tmp/main.c"), not in the executable ("/tmp/a.out"). I can tell you why that isn't working...