Solved Debuggers not working?

I have been writing some C codes lately and found that both lldb and gdb are not working as expected. Perhaps I am doing something wrong? In the following, I am running a freshly installed FreeBSD 11.0-RELEASE on bhyve, but I have the same problem on my host machine as well.

%freebsd-version; uname -a

FreeBSD fake.hostname.local 11.0-RELEASE-p2 FreeBSD 11.0-RELEASE-p2 #0: Mon Oct 24 06:55:27 UTC 2016  amd64

%cat hello.c
#include <stdio.h>

int main(){
        printf("Hello, world!\n");

%cc -g hello.c
%lldb a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) breakpoint set --name main
Breakpoint 1: where = a.out`main + 18 at hello.c:4, address = 0x0000000000400752
(lldb) r
error: process launch failed: Child ptrace failed.
(lldb) quit
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y

%gdb a.out
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) break main
Breakpoint 1 at 0x400752: file hello.c, line 4.
(gdb) run
Starting program: /usr/home/hongj37/a.out
Hello, world!
Program exited normally.
You can't do that without a process to debug.
(gdb) quit
Last edited by a moderator:
That is very strange. I repeated successfully your commands on my FreeBSD 11.0-RELEASE-p7 system utilizing lldb:
root@server:~ #    cc -g hello.c
root@server:~ #    lldb -- a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) breakpoint set --name main
Breakpoint 1: where = a.out`main + 18 at hello.c:6, address = 0x0000000000400752
(lldb) r
Process 79706 launching
Process 79706 launched: '/root/a.out' (x86_64)
Process 79706 stopped
* thread #1: tid = 100232, 0x0000000000400752 a.out`main + 18 at hello.c:6, stop reason = breakpoint 1.1
    frame #0: 0x0000000000400752 a.out`main + 18 at hello.c:6
   4       int main(){
-> 6       printf("Hello, world!\n");
   8       }
(lldb) c
Process 79706 resuming
Hello, world!
Process 79706 exited with status = 0 (0x00000000)
The difference is that I ran everything as the root user. This is an arbitrary shot into the dark, however, I read somewhere in the long distant past that ptrace does not work well when executed by a mean user, it seemed to obey root only.
obsigna, thank you very much! You made me realize that a system security hardening option was turned on to prevent unprivileged users from debugging. #sysctl security.bsd.unprivileged_proc_debug=1 fixes the problem. I wonder if there is a way to allow selected unprivileged user to debug though.