Index: etc/mtree/BSD.usr.dist =================================================================== --- etc/mtree/BSD.usr.dist +++ etc/mtree/BSD.usr.dist @@ -150,6 +150,8 @@ .. hyperv .. + kgdb + .. lpr ru .. Index: libexec/Makefile =================================================================== --- libexec/Makefile +++ libexec/Makefile @@ -10,6 +10,7 @@ ${_dma} \ flua \ getty \ + kgdb \ ${_mail.local} \ ${_makewhatis.local} \ ${_mknetid} \ Index: libexec/kgdb/Makefile =================================================================== --- /dev/null +++ libexec/kgdb/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +FILESDIR?= /usr/libexec/kgdb + +FILES= acttrace.py + +.include Index: libexec/kgdb/acttrace.py =================================================================== --- /dev/null +++ libexec/kgdb/acttrace.py @@ -0,0 +1,56 @@ +import gdb + + +def symval(name): + return gdb.lookup_global_symbol(name).value() + + +def tid_to_gdb_thread(tid): + for thread in gdb.inferiors()[0].threads(): + if thread.ptid[2] == tid: + return thread + else: + return None + + +def all_pcpus(): + mp_maxid = symval("mp_maxid") + cpuid_to_pcpu = symval("cpuid_to_pcpu") + + cpu = 0 + while cpu <= mp_maxid: + pcpu = cpuid_to_pcpu[cpu] + if pcpu: + yield pcpu + cpu = cpu + 1 + + +class acttrace(gdb.Command): + def __init__(self): + super(acttrace, self).__init__("acttrace", gdb.COMMAND_USER) + + def invoke(self, arg, from_tty): + # Save the current thread so that we can switch back after. + curthread = gdb.selected_thread() + + for pcpu in all_pcpus(): + td = pcpu['pc_curthread'] + tid = td['td_tid'] + + gdb_thread = tid_to_gdb_thread(tid) + if gdb_thread is None: + print("failed to find GDB thread with TID {}".format(tid)) + else: + gdb_thread.switch() + + p = td['td_proc'] + print("Tracing command {} pid {} tid {} (CPU {})".format( + p['p_comm'], p['p_pid'], td['td_tid'], pcpu['pc_cpuid'])) + gdb.execute("bt") + print() + + curthread.switch() + + +# Registers the command with gdb, doesn't do anything. +acttrace() Index: usr.sbin/crashinfo/crashinfo.sh =================================================================== --- usr.sbin/crashinfo/crashinfo.sh +++ usr.sbin/crashinfo/crashinfo.sh @@ -233,13 +233,15 @@ sed -ne '/^ Panic String: /{s//panic: /;p;}' $INFO echo -# XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to -# kgdb via stdin and have to use a temporary file instead. file=`mktemp /tmp/crashinfo.XXXXXX` if [ $? -eq 0 ]; then + scriptdir=/usr/libexec/kgdb + echo "bt" >> $file + echo "source ${scriptdir}/acttrace.py" >> $file + echo "acttrace" >> $file echo "quit" >> $file - ${GDB%gdb}kgdb $KERNEL $VMCORE < $file + ${GDB%gdb}kgdb -q $KERNEL $VMCORE < $file rm -f $file echo fi