Open Quuxplusone opened 3 years ago
So lldb-server has a way to return better error messages. If lldb-server is
being used in this case, LLDB will send a "QEnableErrorStrings" packet that
allows errors that used to be returned as "E08" ("E" = error, with code = "08")
to also have an error message as hex encoded ASCII like "E08;313233" where
"313233" is the string "123".
The "A" packet seems to be returning only an error code with no error message.
If you can get the native FreeBSD NativeProcessFreeBSD.cpp or
NativeThreadFreeBSD.cpp to figure out this is the error, you can modify the
error message that should be returned back up to LLDB and it should be
propagated.
The first step is to see what is currently happening. Can you enable GDB remote
packet logging with:
(lldb) log enable -f /tmp/packets.txt gdb-remote packets
(lldb) target create "./exec-stack"
(lldb) run
Then attach the packets so we can see what is currently happening?
Does FreeBSD debugging use lldb-server now? If so, can we remove the old native ProcessFreeBSD process plug-in?
Attached packets.txt
(2595 bytes, text/plain): packet log
(In reply to Greg Clayton from comment #2)
> Does FreeBSD debugging use lldb-server now? If so, can we remove the old
> native ProcessFreeBSD process plug-in?
We now use lldb-server on FreeBSD/x86, but not yet other CPU architectures.
Over the next few months the remaining architectures should be switched over
and we can remove the native process plug-in.
As an aside, looking at the packet log I see another TODO for FreeBSD -
disabling ASLR:
lldb < 21> send packet: $QSetDisableASLR:1#ce
lldb < 6> read packet: $OK#9a
I guess we're ignoring this at the moment.
Another TODO from looking at `ktrace -i lldb ...`:
12735 lldb-server CALL getrlimit(RLIMIT_NOFILE,0x7fffffe74d20)
12735 lldb-server RET getrlimit 0
12735 lldb-server CALL close(0x3)
12735 lldb-server RET close -1 errno 9 Bad file descriptor
12735 lldb-server CALL getrlimit(RLIMIT_NOFILE,0x7fffffe74d20)
12735 lldb-server RET getrlimit 0
12735 lldb-server CALL close(0x4)
12735 lldb-server RET close 0
12735 lldb-server CALL getrlimit(RLIMIT_NOFILE,0x7fffffe74d20)
12735 lldb-server RET getrlimit 0
12735 lldb-server CALL close(0x5)
12735 lldb-server RET close 0
12735 lldb-server CALL getrlimit(RLIMIT_NOFILE,0x7fffffe74d20)
12735 lldb-server RET getrlimit 0
12735 lldb-server CALL close(0x6)
12735 lldb-server RET close -1 errno 9 Bad file descriptor
...
12735 lldb-server CALL getrlimit(RLIMIT_NOFILE,0x7fffffe74d20)
12735 lldb-server RET getrlimit 0
12735 lldb-server CALL close(0x718f0)
12735 lldb-server RET close -1 errno 9 Bad file descriptor
12735 lldb-server CALL getrlimit(RLIMIT_NOFILE,0x7fffffe74d20)
12735 lldb-server RET getrlimit 0
12735 lldb-server CALL close(0x718f1)
12735 lldb-server RET close -1 errno 9 Bad file descriptor
12735 lldb-server CALL getrlimit(RLIMIT_NOFILE,0x7fffffe74d20)
12735 lldb-server RET getrlimit 0
we need to use closefrom or close_range instead of calling close() in a loop
for about 1M syscalls to close fds
... to close fds before execve
The failed execve looks like:
12735 lldb-server CALL ptrace(PT_TRACE_ME,0,0,0)
12735 lldb-server RET ptrace 0
12735 lldb-server CALL execve(0x80e1739c0,0x80e1c4060,0x80e21d000)
12735 lldb-server NAMI "/usr/home/emaste/src/freebsd-git/head/exec-stack"
12734 lldb-server GIO fd 6 read 0 bytes
""
12734 lldb-server RET read 0
12734 lldb-server CALL close(0x6)
12734 lldb-server RET close 0
12734 lldb-server CALL wait4(0x31bf,0x7fffffe75804,0,0)
12734 lldb-server RET wait4 12735/0x31bf
12734 lldb-server CALL write(0x7,0x7fffffe75861,0x7)
12734 lldb-server GIO fd 7 wrote 7 bytes
"$E08#ad"
12734 lldb-server RET write 7
Looks like error strings are successfully enabled:
lldb < 23> send packet: $QEnableErrorStrings#8c
lldb < 6> read packet: $OK#9a
But there is no extra error info from the "A" packet which launches the
executable:
lldb < 106> send packet:
$A96,0,2f7573722f686f6d652f656d617374652f7372632f667265656273642d6769742f686561642f657865632d737461636b#85
lldb < 7> read packet: $E08#ad
So it should be an easy fix if you can make lldb-server figure out what went wrong and can add the error message.
I am experiencing this with lldb 13 on linux (debian unstable) in a chroot
(/proc & /dev/shm are mounted):
$ /usr/bin/clang++-13 -g -o foo a.cpp
$ /usr/bin/lldb-13 -s cmd.in foo
(lldb) target create "/check/build/tests/Output/basic_lldb2.cpp.tmp"
Current executable set to '/check/build/tests/Output/basic_lldb2.cpp.tmp'
(x86_64).
(lldb) command source -s 0 '/check/tests/basic_lldb2.in'
Executing commands in '/check/tests/basic_lldb2.in'.
(lldb) b main
Breakpoint 1: where = basic_lldb2.cpp.tmp`main + 16 at basic_lldb2.cpp:7:21,
address = 0x00000000004011c0
(lldb) r
error: 'A' packet returned an error: 8
mounting /dev/pts fixed the issue ( mount --bind /dev/pts
/srv/chroot/stretch/dev/pts )
packets.txt
(2595 bytes, text/plain)