Remote debug a program running on FreeBSD from Mac OS X

I built lldb (+clang/llvm) from trunk on the FreeBSD 10.1-RELEASE-p9 box and on the Mac OS X 10.10.3 client. Is remote debugging of an executable on FreeBSD possible from within lldb on Mac OS X? Considering the simple "hello.c" below, I can launch the executable which resides on FreeBSD remotely via lldb on the Mac OS X client, but the session is then immediately stopped with the following message:

Process 17299 exited with status = -1 (0xffffffff) lost connection

What am I doing wrong? Here comes, what I achieved so far:

hello.c:

#include <stdio.h>

int main(int argc, const char *argv)
{
   printf("Hello, World!\n");
   getchar();
   return 0;
}

On the FreeBSD box:

# cd ~/helloworld
# clang -O0 -g hello.c -o hello
# ~/install/LLVM/llvm/build/bin/lldb-server platform —listen *:1234

On the Mac OS X client:

$ scp -rp root@server:helloworld helloworld
$ cd helloworld
$ ~/install/LLVM/build/bin/lldb
(lldb) version
lldb-340.99.0
(lldb) platform select remote-freebsd
      Host: Darwin 14.3.0 (MBPRJ.local)
Host: Darwin 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64
  Platform: remote-freebsd
Connected: no
(lldb) target create ./hello
Current executable set to './hello' (x86_64).
(lldb) platform connect connect://192.168.222.35:1234
      Host: Darwin 14.3.0 (MBPRJ.local)
Host: Darwin 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64
  Platform: remote-freebsd
    Triple: x86_64-unknown-freebsd10.1
OS Version: 10.1 (00199506)
    Kernel: FreeBSD 10.1-RELEASE-p9 #1: Fri Apr 10 07:28:09 BRT 2015 root@server.mydomain.org:/usr/obj/usr/src/sys/GENERIC_IPsec
  Hostname: server.mydomain.org
Connected: yes
(lldb) b hello.c:5
Breakpoint 1: where = hello`main + 30 at hello.c:5, address = 0x000000000040086e
(lldb) platform process launch
(lldb) Process 17299 exited with status = -1 (0xffffffff) lost connection

Best regards

Rolf

Check the gdb-remote packet log. It seems you are losing connection to your lldb-server and that causes the process to die with -1 and "lost connection". To see the log:

(lldb) log enable -t -f /tmp/packet.log gdb-remote packets

This will log all GDB remote packets, including the ones that the "lldb-server platform" is sending, but you might be able to see how far your program is making it...

Greg

We are actively working on getting the test suite to pass from OSX host to a Linux target but there are still a lot of failures. I don’t think remote debugging is supported at all on FreeBSD today. (Even FreeBSD to FreeBSD)

I built lldb (+clang/llvm) from trunk on the FreeBSD 10.1-RELEASE-p9 box and on the Mac OS X 10.10.3 client. Is remote debugging of an executable on FreeBSD possible from within lldb on Mac OS X? Considering the simple “hello.c” below, I can launch the executable which resides on FreeBSD remotely via lldb on the Mac OS X client, but the session is then immediately stopped with the following message:

Process 17299 exited with status = -1 (0xffffffff) lost connection

What am I doing wrong? Here comes, what I achieved so far:

hello.c:

#include <stdio.h>

int main(int argc, const char *argv)
{
printf(“Hello, World!\n”);
getchar();
return 0;
}

On the FreeBSD box:

cd ~/helloworld

clang -O0 -g hello.c -o hello

~/install/LLVM/llvm/build/bin/lldb-server platform —listen *:1234

On the Mac OS X client:

$ scp -rp root@server:helloworld helloworld
$ cd helloworld
$ ~/install/LLVM/build/bin/lldb
(lldb) version
lldb-340.99.0
(lldb) platform select remote-freebsd
Host: Darwin 14.3.0 (MBPRJ.local)
Host: Darwin 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64
Platform: remote-freebsd
Connected: no
(lldb) target create ./hello
Current executable set to ‘./hello’ (x86_64).
(lldb) platform connect connect://192.168.222.35:1234
Host: Darwin 14.3.0 (MBPRJ.local)
Host: Darwin 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64
Platform: remote-freebsd
Triple: x86_64-unknown-freebsd10.1
OS Version: 10.1 (00199506)
Kernel: FreeBSD 10.1-RELEASE-p9 #1: Fri Apr 10 07:28:09 BRT 2015 root@server.mydomain.org:/usr/obj/usr/src/sys/GENERIC_IPsec
Hostname: server.mydomain.org
Connected: yes
(lldb) b hello.c:5
Breakpoint 1: where = hello`main + 30 at hello.c:5, address = 0x000000000040086e
(lldb) platform process launch
(lldb) Process 17299 exited with status = -1 (0xffffffff) lost connection

Best regards

Rolf

Remote debugging using a FreeBSD LLDB debugserver is indeed not yet
implemented. (FreeBSD as the host should work fine.)

I entered the log enable command and then I repeated exactly the same debug session of my initial post up to " … lost connection". Here comes the content of the log file (s. below). I am a little bit lost with that. However I, learned from another post, that remote debugging of a program running on FreeBSD from an external client is not possible, and I guess, that it isn't very promising starting debugging at the end of the pipe. Therefore, I stop my efforts for now.

Anyway, thank you very much for taking your time to respond to my message.

Best regards

Rolf

< 1> send packet: +
history[1] tid=0x0513 < 1> send packet: +
< 19> send packet: $QStartNoAckMode#b0
< 1> read packet: +
< 6> read packet: $OK#9a
< 1> send packet: +
< 13> send packet: $qHostInfo#9b
< 482> read packet: $triple:7838365f36342d756e6b6e6f776e2d6672656562736431302e31;ptrsize:8;watchpoint_exceptions_received:after;endian:little;os_version:10.1;os_build:3030313939353036;os_kernel:467265654253442031302e312d52454c454153452d70392023313a20467269204170722031302030373a32383a30392042525420323031352020202020726f6f74407365727665722e70726f6a656374776f726c642e6e65743a2f7573722f6f626a2f7573722f7372632f7379732f47454e455249435f4950736563;hostname:7365727665722e70726f6a656374776f726c642e6e6574;#57
< 21> send packet: $QSetDisableASLR:0#cd
< 4> read packet: $#00
< 23> send packet: $QSetDetachOnError:0#f7
< 6> read packet: $OK#9a
< 50> send packet: $QLaunchArch:x86_64-unknown-freebsd10.1-unknown#55
< 6> read packet: $OK#9a
< 24> send packet: $A14,0,2e2f68656c6c6f#04
< 6> read packet: $OK#9a
< 18> send packet: $qLaunchSuccess#a5
< 6> read packet: $OK#9a
< 16> send packet: $qProcessInfo#dc
< 186> read packet: $pid:859a;parent-pid:858e;real-uid:0;real-gid:0;effective-uid:0;effective-gid:0;triple:7838365f36342d756e6b6e6f776e2d6672656562736431302e31;ostype:freebsd10.1;endian:little;ptrsize:8;#55
< 48> send packet: $qLaunchGDBServer;host:rolf.mydomain.org;#f3
< 25> read packet: $pid:34203;port:16158;#ed
< 1> send packet: +
history[1] tid=0x0513 < 1> send packet: +
< 19> send packet: $QStartNoAckMode#b0
< 1> read packet: +
< 6> read packet: $OK#9a
< 1> send packet: +
< 26> send packet: $QThreadSuffixSupported#e4
< 6> read packet: $OK#9a
< 27> send packet: $QListThreadsInStopReply#21
< 6> read packet: $OK#9a
< 13> send packet: $qHostInfo#9b
< 482> read packet: $triple:7838365f36342d756e6b6e6f776e2d6672656562736431302e31;ptrsize:8;watchpoint_exceptions_received:after;endian:little;os_version:10.1;os_build:3030313939353036;os_kernel:467265654253442031302e312d52454c454153452d70392023313a20467269204170722031302030373a32383a30392042525420323031352020202020726f6f74407365727665722e70726f6a656374776f726c642e6e65743a2f7573722f6f626a2f7573722f7372632f7379732f47454e455249435f4950736563;hostname:7365727665722e70726f6a656374776f726c642e6e6574;#57
< 10> send packet: $vCont?#49
< 17> read packet: $vCont;c;C;s;S#62
< 27> send packet: $qVAttachOrWaitSupported#38
< 4> read packet: $#00
< 16> send packet: $qProcessInfo#dc
< 7> read packet: $E44#ad
< 6> send packet: $qC#b4
< 7> read packet: $E44#ad
< 23> send packet: $QSetDetachOnError:0#f7
< 6> read packet: $OK#9a
< 16> send packet: $vAttach;859a#0d
< 7> read packet: $E01#a6

Vince and Ed,

thank you very much for your clear statements. that safe me from running more unnecessary trials. For the time being I will stop the efforts. I will loosely follow the progress of lldb on FreeBSD, and I will come back when debugging of an executable running on FreeBSD remotely from an external client seems to be promising.

Best regards

Rolf

Shouldn't it be very easy to get lldb-server working on FreeBSD? The lldb-server uses the ProcessMonitor and the same kind of stuff that linux uses. Am I wrong about this?

We originally had fairly similar ProcessFreeBSD and ProcessLinux
plugins (with, unfortunately, a lot of cut-and-pasted code). Todd
Fiala later implemented the Native*Linux plugin to support lldb-server
-- it's an improvement over the original implementation, but needs to
be ported again. It's not trivial but shouldn't be too difficult. I
just haven't been able to find time to work on it yet.

There's also another remote debugserver, Facebook's ds2, with an
in-progress FreeBSD port. We could make use of that instead.

-Ed