[lldb-dev] Using LLDB to catch a spurious segfault: scripting, etc.

Johnny Chen johnny.chen at apple.com
Fri Apr 1 18:26:59 PDT 2011


Hi William,

Wonder if:

URL: http://llvm.org/viewvc/llvm-project?rev=128755&view=rev
Log:
Add a Python script which launches a program from within lldb and loop until the
process stops for some reason.  main.c (compiled into a.out) is used as an example in
the README-run-until-faulted file.

Added:
   lldb/trunk/utils/test/README-run-until-faulted
   lldb/trunk/utils/test/main.c
   lldb/trunk/utils/test/run-until-faulted.py   (with props)

is a good enough start for your need?

Thanks.

On Mar 31, 2011, at 6:15 PM, William Knop wrote:

> Hello all,
> 
> I am attempting to use lldb to debug a segfault in my program that
> happens sporadically. For instance, running `for ((i=0;i<1000;i++)) {
> ./myprogram; };` at a shell prompt may show one. It seems there is no
> way to set lldb to run automatically and exit upon success from the
> CLI, so I've been exploring lldb's python scripting.
> 
> The goal of the script is to loop, launching the process until
> completion or error; if there's an error, I need the script to dump me
> back into the lldb interpreter to investigate the bug. Here's what
> I've come up with so far:
> 
>> import time
>> dbg = lldb.SBDebugger.FindDebuggerWithID(lldb.debugger_unique_id)
>> ci = dbg.GetCommandInterpreter()
>> res = lldb.SBCommandReturnObject()
>> dbg.SetAsync(False)
>> for i in range(1, 1000):
>>  ci.HandleCommand("process launch", res)
>>  while (not res.Succeeded()) : time.sleep(0.1)
>>  res.Clear()
> 
> Unfortunately, however, it seems the command does not run to
> completion, no matter how long I wait. Then when I call
> `HandleCommand` a second time, lldb deadlocks. I intended to
> eventually check `res.GetError()` or `res.GetStatus()` and call
> `quit()` when the error appeared, but I haven't made it that far. I
> also initially explored calling `dbg.GetTargetAtIndex(0).Launch()`
> rather than `HandleCommand`, but I wasn't entirely sure how to go
> about it. Any help would be much appreciated!
> 
> Will
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20110401/6dceb91e/attachment.html>


More information about the lldb-dev mailing list