gdb.sh: start gdb with useful facilities
This commit is contained in:
parent
8649dcc9b6
commit
a14a0f9224
|
@ -0,0 +1,4 @@
|
|||
*
|
||||
!.gitignore
|
||||
!init
|
||||
!functions
|
|
@ -0,0 +1,112 @@
|
|||
# This file is part of Jehanne.
|
||||
#
|
||||
# Copyright (C) 2016-2017 Giacomo Tesio <giacomo@tesio.it>
|
||||
|
||||
set $__pendingUserBreak = 0
|
||||
|
||||
define jhn-print-with-context
|
||||
if up != 0
|
||||
printf "%s %d ", up->text, up->pid
|
||||
end
|
||||
if m != 0
|
||||
printf "(mach %d) ", m->machno
|
||||
end
|
||||
if $argc == 1
|
||||
p $arg0
|
||||
end
|
||||
if $argc == 2
|
||||
printf $arg0, $arg1
|
||||
end
|
||||
if $argc == 3
|
||||
printf $arg0, $arg1, $arg2
|
||||
end
|
||||
if $argc == 4
|
||||
printf $arg0, $arg1, $arg2, $arg3
|
||||
end
|
||||
printf "\n"
|
||||
end
|
||||
|
||||
define jhn-log-syscalls
|
||||
b syscall
|
||||
commands
|
||||
jhn-print-with-context " pc = 0x%x " ureg->ip
|
||||
c
|
||||
end
|
||||
end
|
||||
|
||||
define jhn-break-errors
|
||||
b errorl
|
||||
commands
|
||||
jhn-print-with-context
|
||||
bt 4
|
||||
c
|
||||
end
|
||||
end
|
||||
|
||||
define jhn-break-cmd
|
||||
if $argc < 2 || $argc > 3
|
||||
printf "usage: jhn-break-cmd symbol/path \"programName\" [address]\n"
|
||||
else
|
||||
if $__pendingUserBreak > 0
|
||||
printf "jhn-break-cmd: cannot set a new breakpoint in user space until the previous one is recorded at\n "
|
||||
info line *$__breakAddr
|
||||
else
|
||||
add-symbol-file $arg0 0x4000c0
|
||||
set __onExecFaultBreakForCMD = $arg1
|
||||
set $__breakAddr = (uintptr_t)0x4000c0
|
||||
set $__breakPageStart = (uintptr_t)0x400000
|
||||
set $__breakPageEnd = (uintptr_t)0x401000
|
||||
if $argc == 3
|
||||
set $__breakAddr = (uintptr_t)$arg2
|
||||
set $__breakPageStart = (uintptr_t)($__breakAddr & ~(0x1000-1))
|
||||
set $__breakPageEnd = (uintptr_t)($__breakAddr + 0x1000)
|
||||
end
|
||||
b *peekAtExecFaults+114 if addr >= $__breakPageStart && addr < $__breakPageEnd
|
||||
set $__pendingUserBreak = $bpnum
|
||||
commands
|
||||
d $__pendingUserBreak
|
||||
set $__pendingUserBreak = 0
|
||||
b *$__breakAddr
|
||||
c
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
define jhn-break-pid
|
||||
if $argc < 2 || $argc > 3
|
||||
printf "usage: jhn-break-pid symbol/path pid [address]\n"
|
||||
else
|
||||
if $__pendingUserBreak > 0
|
||||
printf "jhn-break-pid: cannot set a new breakpoint in user space until the previous one is recorded at\n "
|
||||
info line *$__breakAddr
|
||||
else
|
||||
add-symbol-file $arg0 0x4000c0
|
||||
set __onExecFaultBreakForPID = $arg1
|
||||
set $__breakAddr = (uintptr_t)0x4000c0
|
||||
set $__breakPageStart = (uintptr_t)0x400000
|
||||
set $__breakPageEnd = (uintptr_t)0x401000
|
||||
if $argc == 3
|
||||
set $__breakAddr = (uintptr_t)$arg2
|
||||
set $__breakPageStart = (uintptr_t)($__breakAddr & ~(0x1000-1))
|
||||
set $__breakPageEnd = (uintptr_t)($__breakAddr + 0x1000)
|
||||
end
|
||||
b *peekAtExecFaults+64 if addr >= $__breakPageStart && addr < $__breakPageEnd
|
||||
set $__pendingUserBreak = $bpnum
|
||||
commands
|
||||
d $__pendingUserBreak
|
||||
set $__pendingUserBreak = 0
|
||||
b *$__breakAddr
|
||||
c
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
define jhn-connect
|
||||
target remote :1234
|
||||
printf "connected to QEMU\n"
|
||||
if $pc == waitdebugger+22
|
||||
set var c = 1
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
# This file is part of Jehanne.
|
||||
#
|
||||
# Copyright (C) 2016-2017 Giacomo Tesio <giacomo@tesio.it>
|
||||
|
||||
source ./hacking/_gdb/env
|
||||
source ./hacking/_gdb/functions
|
||||
|
||||
printf "\nThank you for debugging Jehanne!\n\n"
|
||||
printf "TIP: You can find some useful functions typing jh<TAB>\n"
|
||||
printf "TIP: Setup your own gdbinit at $JEHANNE_DEVELOPER_DIR\n\n"
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
# This file is part of Jehanne.
|
||||
#
|
||||
# Copyright (C) 2016-2017 Giacomo Tesio <giacomo@tesio.it>
|
||||
|
||||
if [ "$JEHANNE" = "" ]; then
|
||||
echo $0 requires the shell started by ./hacking/devshell.sh
|
||||
exit 1
|
||||
fi
|
||||
|
||||
KERNEL_TO_LOAD=$1
|
||||
|
||||
if [ "$KERNEL_TO_LOAD" = "" ]; then
|
||||
KERNEL_TO_LOAD=$JEHANNE/arch/amd64/kern/jehanne
|
||||
fi
|
||||
|
||||
echo > $JEHANNE/hacking/_gdb/env
|
||||
echo "set \$JEHANNE = \"$JEHANNE\"" >> $JEHANNE/hacking/_gdb/env
|
||||
|
||||
if [ "$JEHANNE_GDB_LOGS" != "" ]; then
|
||||
git rev-parse HEAD > $JEHANNE_GDB_LOGS
|
||||
git status --porcelain -b >> $JEHANNE_GDB_LOGS
|
||||
|
||||
echo "set pagination off" >> $JEHANNE/hacking/_gdb/env
|
||||
echo "set logging file $JEHANNE_GDB_LOGS" >> $JEHANNE/hacking/_gdb/env
|
||||
echo "set logging overwrite off" >> $JEHANNE/hacking/_gdb/env
|
||||
echo "set logging on" >> $JEHANNE/hacking/_gdb/env
|
||||
fi
|
||||
|
||||
if [ "$JEHANNE_DEVELOPER_DIR" != "" ]; then
|
||||
echo "set \$JEHANNE_DEVELOPER_DIR = \"$JEHANNE_DEVELOPER_DIR\"" >> $JEHANNE/hacking/_gdb/env
|
||||
if [ -a $JEHANNE_DEVELOPER_DIR/gdbinit ]; then
|
||||
echo source $JEHANNE_DEVELOPER_DIR/gdbinit >> $JEHANNE/hacking/_gdb/env
|
||||
fi
|
||||
else
|
||||
echo "set \$JEHANNE_DEVELOPER_DIR = \"$HOME/.jehanne\"" >> $JEHANNE/hacking/_gdb/env
|
||||
fi
|
||||
|
||||
gdb -x $JEHANNE/hacking/_gdb/init $KERNEL_TO_LOAD
|
||||
|
||||
rm $JEHANNE/hacking/_gdb/env
|
290
gdbinit
290
gdbinit
|
@ -1,290 +0,0 @@
|
|||
set pagination off
|
||||
set logging file ../qemu-gdb.log
|
||||
set logging overwrite on
|
||||
set logging on
|
||||
|
||||
define log_mach_proc
|
||||
if up != 0
|
||||
printf "%s %d ", up->text, up->pid
|
||||
end
|
||||
if m != 0
|
||||
printf "(mach %d) ", m->machno
|
||||
end
|
||||
end
|
||||
|
||||
define log_syscall
|
||||
log_mach_proc
|
||||
printf "\n"
|
||||
c
|
||||
end
|
||||
|
||||
define log_syscalls
|
||||
|
||||
# sysbind
|
||||
b ../port/sysfile.c:1167
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syschdir
|
||||
b ../port/sysfile.c:1027
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysclose
|
||||
b ../port/sysfile.c:375
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syscreate
|
||||
b ../port/sysfile.c:1263
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysdup
|
||||
b ../port/sysfile.c:263
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysfd2path
|
||||
b ../port/sysfile.c:191
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysfstat
|
||||
b ../port/sysfile.c:999
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysfwstat
|
||||
b ../port/sysfile.c:1371
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysmount
|
||||
b ../port/sysfile.c:1192
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysopen
|
||||
b ../port/sysfile.c:311
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syspipe
|
||||
b ../port/sysfile.c:214
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syspread
|
||||
b ../port/sysfile.c:787
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syspwrite
|
||||
b ../port/sysfile.c:857
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysremove
|
||||
b ../port/sysfile.c:1293
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysseek
|
||||
b ../port/sysfile.c:929
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysunmount
|
||||
b ../port/sysfile.c:1210
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysfversion
|
||||
b ../port/sysauth.c:50
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysfauth
|
||||
b ../port/sysauth.c:83
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysrfork
|
||||
b ../port/sysproc.c:36
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysalarm
|
||||
b ../port/sysproc.c:656
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysawake
|
||||
b ../port/sysproc.c:682
|
||||
commands
|
||||
printf "sys->ticks %lld ms %lld \n", sys->ticks, ms
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysawait
|
||||
b ../port/sysproc.c:729
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syserrstr
|
||||
b ../port/sysproc.c:791
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysnotify
|
||||
b ../port/sysproc.c:809
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysexec
|
||||
b ../port/sysproc.c:284
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysexits
|
||||
b ../port/sysproc.c:702
|
||||
commands
|
||||
if status != 0
|
||||
printf "status: %s", status
|
||||
else
|
||||
printf "status: (nil)"
|
||||
end
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysnoted
|
||||
b ../port/sysproc.c:840
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysrendezvous
|
||||
b ../port/sysproc.c:861
|
||||
commands
|
||||
printf "tag %llu rendval %llu\n", tag, rendval
|
||||
printf "sys->ticks %lld lastWakeup %lld pendingWakeup %lld \n", sys->ticks, up->lastWakeup, up->pendingWakeup
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysnotify
|
||||
b ../port/sysproc.c:820
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysnsec
|
||||
b ../port/sysproc.c:1233
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syssemacquire
|
||||
b ../port/sysproc.c:1167
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syssemrelease
|
||||
b ../port/sysproc.c:1222
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# syssleep
|
||||
b ../port/sysproc.c:640
|
||||
commands
|
||||
printf "ms %lld\n", ms
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# systsemacquire
|
||||
b ../port/sysproc.c:1193
|
||||
commands
|
||||
log_syscall
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
define debug_awake
|
||||
# awakekproc
|
||||
b ../port/awake.c:139
|
||||
commands
|
||||
printf "%s %d ", p->text, p->pid
|
||||
printf "p->state %d p->lastWakeup %lld toAwake->time %d \n", p->state, p->lastWakeup, toAwake->time
|
||||
c
|
||||
end
|
||||
|
||||
# sysawake
|
||||
b ../port/sysproc.c:682
|
||||
commands
|
||||
printf "sys->ticks %lld ms %lld \n", sys->ticks, ms
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysrendezvous
|
||||
b ../port/sysproc.c:861
|
||||
commands
|
||||
printf "ENTER: \n tag %llu rendval %llu\n", tag, rendval
|
||||
printf "sys->ticks %lld lastWakeup %lld pendingWakeup %lld \n", sys->ticks, up->lastWakeup, up->pendingWakeup
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysrendezvous
|
||||
b ../port/sysproc.c:879
|
||||
commands
|
||||
printf "EXIT on match: \n tag %llu rendval %llu\n", tag, rendval
|
||||
printf "sys->ticks %lld lastWakeup %lld pendingWakeup %lld \n", sys->ticks, up->lastWakeup, up->pendingWakeup
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysrendezvous
|
||||
b ../port/sysproc.c:886
|
||||
commands
|
||||
printf "EXIT on awaken: \n tag %llu rendval %llu\n", tag, rendval
|
||||
printf "sys->ticks %lld lastWakeup %lld pendingWakeup %lld \n", sys->ticks, up->lastWakeup, up->pendingWakeup
|
||||
log_syscall
|
||||
end
|
||||
|
||||
# sysrendezvous
|
||||
b ../port/sysproc.c:902
|
||||
commands
|
||||
printf "EXIT after wait: \n tag %llu rendval %llu\n", tag, rendval
|
||||
printf "sys->ticks %lld lastWakeup %lld pendingWakeup %lld \n", sys->ticks, up->lastWakeup, up->pendingWakeup
|
||||
log_syscall
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#log_syscalls
|
||||
|
||||
|
Loading…
Reference in New Issue