<div dir="ltr">I'm able to attach to the process now, however when I try to run a simple command and it crashes<div><br></div><div><div>if target.IsValid():</div><div> process = target.ConnectRemote(debugger.GetListener(), "connect://localhost:1235", "gdb-remote", error)</div>
<div> if process.IsValid():</div><div> debugger.HandleCommand('po [UIApplication sharedApplication]')</div><div> process.Continue()</div></div><div><br></div><div>Crash log:</div><div><br></div><div>
<div>Crashed Thread: 0 Dispatch queue: com.apple.main-thread</div><div><br></div><div>Exception Type: EXC_BAD_ACCESS (SIGSEGV)</div><div>Exception Codes: KERN_INVALID_ADDRESS at 0x00000000000000f8</div><div><br></div>
<div>
VM Regions Near 0xf8:</div><div>--> </div><div> __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</div>
<div><br></div><div>Application Specific Information:</div><div>HandleCommand(command = "po [UIApplication sharedApplication]")</div></div><div><br></div><div>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.</div>
<div class="gmail_extra"><br clear="all"><div><br>Jason</div>
<br><br><div class="gmail_quote">On Fri, May 16, 2014 at 2:07 AM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It might be a good idea to handle the process events yourself. We have some great sample code:<br>
<br>
svn cat <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py" target="_blank">http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py</a><br>
<br>
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.<br>
<br>
Greg<br>
<div><div><br>
> On May 15, 2014, at 11:03 AM, Greg Clayton <<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>> wrote:<br>
><br>
><br>
>> On May 15, 2014, at 10:52 AM, Jason Dinh Ba Thanh <<a href="mailto:bathanh@gmail.com" target="_blank">bathanh@gmail.com</a>> wrote:<br>
>><br>
>> Should it be:<br>
>><br>
>> target = debugger.CreateTarget (filename, triple, platform, False, error)<br>
><br>
> Yes "debugger." is required before CreateTarget<br>
><br>
>><br>
>> I tried that and get error on this line<br>
>> process = target.ConnectRemote(debugger, "connect://localhost:1234", "gdb-remote", error)<br>
><br>
> This should have been:<br>
> process = target.ConnectRemote(debugger.GetListener(), "connect://localhost:1234", "gdb-remote", error)<br>
><br>
>><br>
>> File "lldbControl.py", line 54, in <module><br>
>> process = target.ConnectRemote(debugger, "connect://localhost:1234", "gdb-remote", error)<br>
>> File "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/__init__.py", line 7773, in ConnectRemote<br>
>> return _lldb.SBTarget_ConnectRemote(self, *args)<br>
>><br>
>> This is an iPhone 4 running iOS 7 so I guess it's armv7, right?<br>
><br>
> I believe so.<br>
><br>
>><br>
>><br>
>> Jason<br>
>><br>
>><br>
>> On Fri, May 16, 2014 at 1:31 AM, Greg Clayton <<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>> wrote:<br>
>><br>
>>> On May 15, 2014, at 9:30 AM, Jason Dinh Ba Thanh <<a href="mailto:bathanh@gmail.com" target="_blank">bathanh@gmail.com</a>> wrote:<br>
>>><br>
>>> 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.<br>
>>><br>
>>> The code: <a href="http://pastebin.com/Yi380xFe" target="_blank">http://pastebin.com/Yi380xFe</a><br>
>>><br>
>>> I tried to get the attached process by "process = debugger.GetSelectedTarget().GetProcess()" and call "process.Continue()" but I'm getting the same result.<br>
>><br>
>><br>
>> I would try using the API a bit more instead of HandleCommand. Your original code:<br>
>><br>
>> import lldb<br>
>> debugger = lldb.SBDebugger.Create()<br>
>> debugger.SetAsync(False)<br>
>> debugger.HandleCommand('platform select remote-ios')<br>
>> debugger.HandleCommand('process connect connect://localhost:1234')<br>
>> debugger.HandleCommand('process continue')<br>
>><br>
>> New code using the API is a much better way:<br>
>><br>
>> import lldb<br>
>> debugger = lldb.SBDebugger.Create()<br>
>> filename = None # fill this in if you know the local version of the executable file, else leave as None<br>
>> triple = 'armv7s-apple-ios' # Modify the ARM architecture to match<br>
>> platform = 'remote-ios'<br>
>> error = lldb.SBError()<br>
>> target = CreateTarget (filename, triple, platform, False, error)<br>
>> if target.IsValid():<br>
>> process = target.ConnectRemote(debugger, "connect://localhost:1234", "gdb-remote", error)<br>
>> if process.IsValid():<br>
>> process.Continue()<br>
>><br>
>><br>
><br>
</div></div>> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div><br></div></div>