[lldb-dev] Python script stuck when trying to continue process in lldb

Jason Dinh Ba Thanh bathanh at gmail.com
Thu May 15 11:36:28 PDT 2014


I'm able to attach to the process now, however when I try to run a simple
command and it crashes

if target.IsValid():
    process = target.ConnectRemote(debugger.GetListener(),
"connect://localhost:1235", "gdb-remote", error)
    if process.IsValid():
        debugger.HandleCommand('po [UIApplication sharedApplication]')
        process.Continue()

Crash log:

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000000000f8

 VM Regions Near 0xf8:
-->
    __TEXT                 0000000104926000-0000000104928000 [    8K]
r-x/rwx SM=COW
 /usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

Application Specific Information:
HandleCommand(command = "po [UIApplication sharedApplication]")

Regarding the stuck script in original post, it seems
like debugger.SetAsync(False) make process.Continue() never return, is it a
bug? Sorry if I'm asking a lot of simple questions, I just started with
this.


Jason


On Fri, May 16, 2014 at 2:07 AM, Greg Clayton <gclayton at apple.com> wrote:

> It might be a good idea to handle the process events yourself. We have
> some great sample code:
>
> svn cat
> http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py
>
> This sample code shows you how to run a debug session and actually respond
> to all the events required to run a session. You should be able to insert
> your target create + connect code straight into this code and make it your
> own.
>
> Greg
>
> > On May 15, 2014, at 11:03 AM, Greg Clayton <gclayton at apple.com> wrote:
> >
> >
> >> On May 15, 2014, at 10:52 AM, Jason Dinh Ba Thanh <bathanh at gmail.com>
> wrote:
> >>
> >> Should it be:
> >>
> >> target = debugger.CreateTarget (filename, triple, platform, False,
> error)
> >
> > Yes "debugger." is required before CreateTarget
> >
> >>
> >> I tried that and get error on this line
> >>    process = target.ConnectRemote(debugger, "connect://localhost:1234",
> "gdb-remote", error)
> >
> > This should have been:
> >    process = target.ConnectRemote(debugger.GetListener(),
> "connect://localhost:1234", "gdb-remote", error)
> >
> >>
> >> File "lldbControl.py", line 54, in <module>
> >>    process = target.ConnectRemote(debugger, "connect://localhost:1234",
> "gdb-remote", error)
> >>  File
> "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/__init__.py",
> line 7773, in ConnectRemote
> >>    return _lldb.SBTarget_ConnectRemote(self, *args)
> >>
> >> This is an iPhone 4 running iOS  7 so I guess it's armv7, right?
> >
> > I believe so.
> >
> >>
> >>
> >> Jason
> >>
> >>
> >> On Fri, May 16, 2014 at 1:31 AM, Greg Clayton <gclayton at apple.com>
> wrote:
> >>
> >>> On May 15, 2014, at 9:30 AM, Jason Dinh Ba Thanh <bathanh at gmail.com>
> wrote:
> >>>
> >>> I'm trying to do some research on iOS and it involves attaching lldb
> to a process. I'm able to do it with lldb console, however when I'm trying
> to convert it to a python script, it stuck at "process continue" for the
> first time and never reach the commands at the end. Can anyone helps?
> Thanks.
> >>>
> >>> The code: http://pastebin.com/Yi380xFe
> >>>
> >>> I tried to get the attached process by "process =
> debugger.GetSelectedTarget().GetProcess()" and call "process.Continue()"
> but I'm getting the same result.
> >>
> >>
> >> I would try using the API a bit more instead of HandleCommand. Your
> original code:
> >>
> >> import lldb
> >> debugger = lldb.SBDebugger.Create()
> >> debugger.SetAsync(False)
> >> debugger.HandleCommand('platform select remote-ios')
> >> debugger.HandleCommand('process connect connect://localhost:1234')
> >> debugger.HandleCommand('process continue')
> >>
> >> New code using the API is a much better way:
> >>
> >> import lldb
> >> debugger = lldb.SBDebugger.Create()
> >> filename = None # fill this in if you know the local version of the
> executable file, else leave as None
> >> triple = 'armv7s-apple-ios' # Modify the ARM architecture to match
> >> platform = 'remote-ios'
> >> error = lldb.SBError()
> >> target = CreateTarget (filename, triple, platform, False, error)
> >> if target.IsValid():
> >>    process = target.ConnectRemote(debugger, "connect://localhost:1234",
> "gdb-remote", error)
> >>    if process.IsValid():
> >>        process.Continue()
> >>
> >>
> >
> > _______________________________________________
> > 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/20140516/c52819d9/attachment.html>


More information about the lldb-dev mailing list