On 02/02/18 04:31, David Gwynne wrote:
On 28 Jan 2018, at 04:07, bijan <bijanebrah...@riseup.net> wrote:

Thank you (for the quick response) and sorry if I was not as clear
as I should have been! what I meant and was hoping to find was
a source code debugger support, like gdb[1], where one can debug
a running kernel with full access to the source code in a gdb session
environment from a remote machine.

I'm new to OpenBSD and found kgdb(7)[2] manual from 6.1 describing
the process very similar to what I do daily with FreeBSD but (as I
mentioned earlier) the code seems to be removed since 6.2.

So, is there any alternative for remote debugging a running OpenBSD
kernel using gdb? anyhow, I appreciate it if one can point me to the
right direction and I don't mind any hard work in the process :-)
i dont think we support kgdb anymore, but we do support running gdb inside a 
system against its running kernel. to do this, you need to have the 
kern.allowkmem sysctl set, which is best done via /etc/sysctl.conf.
Great ... Thanks :-) I should definitely try this one

Anyhow, I recently studied the FreeBSD source code for it's implementation of kdb and briefly examined the implementation and changes of ddb(4) in OpenBSD source code. It seems to me that it's possible to add support for multiple debuggers like gdb (as a standalone back-end or as a ddb command) to OpenBSD kernel as well (since the remote protocol is quiet small and the infrastructures looks pretty much the same as FreeBSD to me).

I'm not quiet sure if I'm capable of porting the code, but if no-one is interested (or is free to do the job), I will definitely give it a try. So, is there anything one should know why such feature is missing? Or any reason to prevent such effort in the first place?

after that you'll need a kernel with debug symbols in it. the easiest way to 
get that is just build a kernel. there'll be a bsd.gdb next to the bsd it 
produces. then you can do this:

dlg@v215 GENERIC.MP$ pwd
dlg@v215 GENERIC.MP$ ls bsd bsd.gdb
-rwxrwx---  1 dlg  wobj  10193351 Feb  2 10:58 bsd
-rwxrwx---  1 dlg  wobj  39133335 Feb  2 10:58 bsd.gdb
dlg@v215 GENERIC.MP$ cat /etc/sysctl.conf
dlg@v215 GENERIC.MP$ sysctl kern.allowkmem
dlg@v215 GENERIC.MP$ sudo gdb bsd.gdb
GNU gdb 6.3
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 "sparc64-unknown-openbsd6.2"...
(gdb) target kvm
#0  mi_switch () at /usr/src/sys/kern/sched_bsd.c:410
410                     cpu_switchto(p, nextproc);
(gdb) print copyright
$1 = "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of 
California.  All rights reserved.\nCopyright (c) 1995-2017 OpenBSD. All rights reserved.  

the important thing is the "target kvm" inside gdb, which relies on allowkmem.

because of the allowkmem requirement, this recommended for use on development 
boxes only.


Reply via email to