[lldb-dev] Using LLDB C++ API for automated debugging sessions

Jim Ingham via lldb-dev lldb-dev at lists.llvm.org
Wed Jun 26 10:22:35 PDT 2019


By default, the SB API's run in "asynchronous" mode, where calls that cause the target to run (launch, continue, etc) return when the target has started running, and then you have to wait on the listener that you registered with the process when you launched it to get notified of state changes.  If you don't wait then you'll be asking questions of a process that only make sense when it's stopped, but it likely is still running...

Here's an example of handling events in async mode:

http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/python/process_events.py

Otherwise, you can set the debugger into "synchronous" mode (using SBDebugger.SetAsync(False)) and then all the calls that cause the target to proceed will block till the target stops again.

Which mode you want to use really depends on whether you want to have control while the process is running or not.

Jim


> On Jun 26, 2019, at 4:58 AM, Jayvee Neumann via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> 
> Dear LLDB developers,
> 
> I am currently stuck while using the C++ API of LLDB. I am unable to correctly launch a process.
> The code I have written looks as follows:
> 
> int main(int argc, char *argv[]){
> LLDBSentry senty;
> SBDebugger dbg(SBDebugger::Create());
> ...
> const char *exeFilePath = "./target";
> const char *arch = "x86_64";
> const char *platform = "";
> const char *dependentLibs = "";	
> SBError error;
> SBTarget tgt = dbg.CreateTarget(exeFilePath, arch, platform, dependentLibs, error);
> ...
> SBListener listen;
> SBProcess proc = tgt.Launch(
> listen,
> nullptr,
> nullptr,
> nullptr,
> "targetout.txt",
> nullptr,
> "./",
> eLaunchFlagExec | eLaunchFlagDebug,
> false,
> error
> );
> ...
> SBThread thread = proc.GetSelectedThread(); // (1)
> ...
> }
> 
> The complete code (usr.cpp) is added as an attachment to this email.
> Its output is also added as a text file (stdout.txt) to this email.
> 
> The problem I have is, that thread.IsValid() returns null after line (1). Furthermore, the process says, that its state is eStateStopped, when asked via proc.IsStopped() it answers "false", however.
> The debugging target is a simple file that writes a hexadecimal number every 10us to stdout. I can see that the target is running, because targetout.txt is growing in size and its content is valid output from "target".
> Can you tell me what my mistake is?
> 
> Kind Regards
> Jayvee
> 
> <usr.cpp><stdout.txt>_______________________________________________
> 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