[lldb-dev] Remotely debugging a process on an ios device via command line LLDB

Mario Zechner badlogicgames at gmail.com
Mon Sep 29 04:39:25 PDT 2014


Hi Greg,

awesome, this works like a charm! Thanks for the help.

ciao,
Mario

On Fri, Sep 19, 2014 at 8:04 PM, Greg Clayton <gclayton at apple.com> wrote:

> Try creating your target first, then give the platform file spec _before_
> connecting, then connect remote
>
> local_path = "/host/machine/path/com.robovm.test.IOSDemo.app"
> triple = "armv7-apple-ios"
> platform = "remote-ios"
> add_dependent_modules = False
> error = lldb.SBError()
>
> target = debugger.CreateTarget (local_path, triple, platform,
> add_dependent_modules, error)
>
> lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec("/private/var/mobile/Containers/Bundle/Application/D26F7D18-CEBA-472A-9BD9-2978FB1D8E46/com.robovm.test.IOSDemo.app"))
> process =
> lldb.target.ConnectRemote(lldb.target.GetDebugger().GetListener(),
> "connect://localhost:8889", None, error)
> if process.IsValid():
>     target.Launch(lldb.SBLaunchInfo([]), error)
>
> Don't use the LLDB globals (lldb.target or lldb.process), use your local
> variables.
>
> Let me know if this helps. Send another full packet log. It seems like
> your packets tried to start the process which should have worked. You might
> also want to check the device console to make sure the device was happy
> with the app and its entitlements and code signing. Also make sure the
> program finger launches first to make sure it is signed correctly.
>
> Greg
>
> >
>
> > On Sep 19, 2014, at 10:53 AM, Mario Zechner <badlogicgames at gmail.com>
> wrote:
> >
> > Hi,
> >
> > i've removed any and all intervention between lldb and the debug server
> on the device, but i'm at a loss at how to set up the target and process.
> >
> > Currently this happens:
> > 1) i fire up a debug server on the ios device (through
> libimobiledevice). This debug server does not attach or launch any process
> on the device, it just waits for someone to connect.
> > 2) i start a forwarding server on my local machine at some port which
> forwards any messages to the debug server on the device verbatim, and also
> returns any messages from the debug server to the connected client.
> > 3) i start lldb, and do the following:
> > platform select remote-ios // no errors, sdks are resolved, platform is
> not connected
> >
> > 4) i create a target to the executable on the local disk via
> >
> > (lldb) target create
> /tmp/robovm.HelloWorld.ios/com.robovm.test.IOSDemo.app
> > Current executable set to
> '/tmp/robovm.HelloWorld.ios/com.robovm.test.IOSDemo.app' (armv7).
> >
> > 5) launch the target on the device through calling into the LLDB API
> from within the LLDB CLI.
> >
> > error = lldb.SBError()
> > process =
> lldb.target.ConnectRemote(lldb.target.GetDebugger().GetListener(),
> "connect://localhost:8889", None, error)
> >
> lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec("/private/var/mobile/Containers/Bundle/Application/D26F7D18-CEBA-472A-9BD9-2978FB1D8E46/com.robovm.test.IOSDemo.app"))
> > lldb.target.Launch(lldb.SBLaunchInfo([]), error)
> >
> >
> > Which also doesn't seem to work:
> > Sending packet (client): +
> > Sending packet (client): $QStartNoAckMode#b0
> > Received packet: +$OK#9a
> > Sending packet (client): +$QThreadSuffixSupported#e4
> > Received packet: $OK#00
> > Sending packet (client): $QListThreadsInStopReply#21
> > Received packet: $OK#00
> > Sending packet (client): $qHostInfo#9b
> > Received packet:
> $cputype:12;cpusubtype:10;ostype:ios;watchpoint_exceptions_received:before;vendor:apple;endian:little;ptrsize:4;#00
> > Sending packet (client): $vCont?#49
> > Received packet: $vCont;c;C;s;S#00
> > Sending packet (client): $qVAttachOrWaitSupported#38
> > Received packet: $OK#00
> > Sending packet (client): $qProcessInfo#dc
> > Received packet: $E68#00
> > Sending packet (client): $qC#b4
> > Received packet: $QC0#00
> > Sending packet (client): $QSetDisableASLR:1#ce$QSetDetachOnError:0#f7
> > Received packet: $OK#00
> > Received packet: $#00
> > Sending packet (client): $QLaunchArch:armv7#51
> > Received packet: $OK#00
> > Sending packet (client):
> $A228,0,2f707269766174652f7661722f6d6f62696c652f436f6e7461696e6572732f42756e646c652f4170706c69636174696f6e2f44323646374431382d434542412d343732412d394244392d3239373846423144384534362f636f6d2e726f626f766d2e746573742e494f5344656d6f2e617070#c9
> > Received packet: $OK#00
> > Sending packet (client): $qLaunchSuccess#a5
> > Received packet: $OK#00
> > Sending packet (client): $qProcessInfo#dc
> > Received packet:
> $pid:112;parent-pid:110;real-uid:1f5;real-gid:1f5;effective-uid:1f5;effective-gid:1f5;cputype:c;cpusubtype:b;ostype:ios;vendor:apple;endian:little;ptrsize:4;#00
> > Sending packet (client): $qC#b4
> > Received packet: $QC3e96#00
> >
> > The app launches, but lldb closes the connection to the debug server and
> hangs on the lldb.target.Launch() command.
> >
> > I'm terribly sorry for bugging this list, i know this is not something
> that usually comes up. i've tried to exhaust all available material on this
> problem (web, lldb source) but am none the wiser. I'd appreciate any
> guidance on how to remotely start and debug an ios app on a device via the
> LLDB command line tool.
> >
> > Thanks,
> > Mario
> >
> >
> >
> >
> > On Fri, Sep 19, 2014 at 6:41 PM, Greg Clayton <gclayton at apple.com>
> wrote:
> >
> > > On Sep 19, 2014, at 9:06 AM, Mario Zechner <badlogicgames at gmail.com>
> wrote:
> > >
> > > Hi,
> > >
> > > i'm trying to spin up an app on an ios device and then remotely
> connect to it. I'm starting starting a debug server on the device, then
> tell it to launch a specific app via the gdb-remote protocol, e.g.
> > >
> > > Sending packet: +
> > > Sending packet: $QStartNoAckMode#b0
> > > Received ack: +
> > > Received packet: $OK#9a
> > > Sending packet: +
> > > Sending packet: $QEnvironment:NSUnbufferedIO=YES#8d
> > > Received packet: $OK#00
> > > Sending packet: $QListThreadsInStopReply#21
> > > Received packet: $OK#00
> > > Sending packet:
> $A228,0,2f707269766174652f7661722f6d6f62696c652f436f6e7461696e6572732f42756e646c652f4170706c69636174696f6e2f44323736423144342d363135372d343837372d383839332d3338334630434437354233392f636f6d2e726f626f766d2e746573742e494f5344656d6f2e617070,28,1,2d72766d3a6c6f673d7472616365#ca
> > > Received packet: $OK#00
> > > Sending packet: $qLaunchSuccess#a5
> > > Received packet: $OK#00
> > >
> > > The app launches successfully. Next i setup a local server socket
> which then forwards the communication between lldb and the debugserver.
> > >
> > > In lldb, i set the platform to remote-ios, and create at target
> pointing at the local version of the executable file of the ios app, and
> then call gdb-remote which connects to the local forwarding socket:
> > >
> > > (lldb) platform select remote-ios
> > >   Platform: remote-ios
> > >  Connected: no
> > >   SDK Path:
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/8.0
> (12A365)"
> > >  SDK Roots: [ 0]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2"
> > >  SDK Roots: [ 1]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3"
> > >  SDK Roots: [ 2]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0"
> > >  SDK Roots: [ 3]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.1"
> > >  SDK Roots: [ 4]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/6.0"
> > >  SDK Roots: [ 5]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/6.1"
> > >  SDK Roots: [ 6]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/7.0"
> > >  SDK Roots: [ 7]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/7.1"
> > >  SDK Roots: [ 8]
> "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/8.0
> (12A365)"
> > >  SDK Roots: [ 9] "/Users/badlogic/Library/Developer/Xcode/iOS
> DeviceSupport/7.1.1 (11D201)"
> > >  SDK Roots: [10] "/Users/badlogic/Library/Developer/Xcode/iOS
> DeviceSupport/8.0 (12A365)"
> > > (lldb) target create
> /tmp/robovm.HelloWorld.ios/com.robovm.test.IOSDemo.app/com.robovm.test.IOSDemo
> > > Current executable set to
> '/tmp/robovm.HelloWorld.ios/com.robovm.test.IOSDemo.app/com.robovm.test.IOSDemo'
> (armv7).
> > > (lldb) gdb-remote 8889
> > >
> > > The debugserver and lldb then exchange a few messages:
> > >
> > > Sending packet (client): $QListThreadsInStopReply#21$qHostInfo#9b
> > > Received packet: $OK#00
> > > Received packet:
> $cputype:12;cpusubtype:10;ostype:ios;watchpoint_exceptions_received:before;vendor:apple;endian:little;ptrsize:4;#00
> > > Sending packet (client): $vCont?#49
> > > Received packet: $vCont;c;C;s;S#00
> > > Sending packet (client): $qVAttachOrWaitSupported#38
> > > Received packet: $OK#00
> > > Sending packet (client): $qProcessInfo#dc
> > > Received packet:
> $pid:2e9;parent-pid:2e8;real-uid:1f5;real-gid:1f5;effective-uid:1f5;effective-gid:1f5;cputype:c;cpusubtype:b;ostype:ios;vendor:apple;endian:little;ptrsize:4;#00
> > > Sending packet (client): $qC#b4
> > > Received packet: $QC108d6#00
> > >
> > > Note that the +$QStartNoAckMode#b0 message is not forwarded to the
> debug server but directly replied to by the forwarding server.
> >
> > That is your problem. If you reply "OK" to "QStartNoAckMode", we stop
> sending ACK and NACK packets. This will obviously hose up any communication
> you do after that.
> >
> > >
> > > LLDB seems be confused from this point onwards. It seems to think that
> a process has been launched but is unable to provide any information on the
> process or interrupt it or interact with it in any other way.
> > >
> > > I'd be greatful if somebody could point out any errors in the above
> workflow (apart from not using XCode, which is sadly not an option)
> > >
> > > Thanks,
> > > Mario
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > 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/20140929/0f6c8724/attachment.html>


More information about the lldb-dev mailing list