PERFORCE change 54840 for review
Marcel Moolenaar
marcel at FreeBSD.org
Sun Jun 13 19:15:59 GMT 2004
http://perforce.freebsd.org/chv.cgi?CH=54840
Change 54840 by marcel at marcel_nfs on 2004/06/13 19:15:17
Use the PCB instead of the trapframe for thread context.
Add support for using dumppcb and dumptid. This allows
us to set the current thread to the one that did the
kernel dump and also use the saved context. Note that
the kernel currently doesn't save dumptid.
Affected files ...
.. //depot/projects/gdb/usr.bin/kgdb/kgdb.h#7 edit
.. //depot/projects/gdb/usr.bin/kgdb/kthr.c#4 edit
.. //depot/projects/gdb/usr.bin/kgdb/md_i386.c#5 edit
Differences ...
==== //depot/projects/gdb/usr.bin/kgdb/kgdb.h#7 (text+ko) ====
@@ -107,13 +107,13 @@
extern kvm_t *kvm;
extern int verbose;
-struct trapframe;
+struct pcb;
struct kthr {
struct kthr *next;
uintptr_t kaddr;
- struct trapframe *td_frame;
uintptr_t td_kstack;
+ struct pcb *td_pcb;
int td_tid;
};
==== //depot/projects/gdb/usr.bin/kgdb/kthr.c#4 (text+ko) ====
@@ -37,10 +37,13 @@
#include <stdio.h>
#include <stdlib.h>
-#include <machine/frame.h>
+#include <machine/pcb.h>
#include "kgdb.h"
+struct pcb *dumppcb;
+int dumptid;
+
static struct kthr *first;
struct kthr *curkthr;
@@ -53,7 +56,7 @@
struct kthr *
kgdb_thr_init(void)
{
- struct nlist nl[2];
+ struct nlist nl[3];
struct proc p;
struct thread td;
struct kthr *thr;
@@ -67,25 +70,38 @@
}
kvm_read(kvm, nl[0].n_value, &paddr, sizeof(paddr));
+ nl[0].n_name = (char *)(uintptr_t)"_dumppcb";
+ nl[1].n_name = (char *)(uintptr_t)"_dumptid";
+ nl[2].n_name = NULL;
+ if (kvm_nlist(kvm, nl) != 0) {
+ warnx(kvm_geterr(kvm));
+ dumppcb = NULL;
+ dumptid = -1;
+ } else {
+ dumppcb = (struct pcb *)(nl[0].n_value);
+ kvm_read(kvm, nl[1].n_value, &dumptid, sizeof(dumptid));
+ }
+
while (paddr != 0) {
kvm_read(kvm, paddr, &p, sizeof(p));
tdaddr = (uintptr_t)TAILQ_FIRST(&p.p_threads);
while (tdaddr != 0) {
kvm_read(kvm, tdaddr, &td, sizeof(td));
- if (td.td_last_frame != NULL) {
- thr = malloc(sizeof(*thr));
- thr->next = first;
- thr->kaddr = tdaddr;
- thr->td_frame = td.td_last_frame;
- thr->td_kstack = td.td_kstack;
- thr->td_tid = td.td_tid;
- first = thr;
- }
+ thr = malloc(sizeof(*thr));
+ thr->next = first;
+ thr->kaddr = tdaddr;
+ thr->td_pcb = (td.td_tid == dumptid) ? dumppcb :
+ td.td_pcb;
+ thr->td_kstack = td.td_kstack;
+ thr->td_tid = td.td_tid;
+ first = thr;
tdaddr = (uintptr_t)TAILQ_NEXT(&td, td_plist);
}
paddr = (uintptr_t)LIST_NEXT(&p, p_list);
}
- curkthr = first;
+ curkthr = kgdb_thr_lookup(dumptid);
+ if (curkthr == NULL)
+ curkthr = first;
return (first);
}
==== //depot/projects/gdb/usr.bin/kgdb/md_i386.c#5 (text+ko) ====
@@ -33,60 +33,32 @@
#include <inttypes.h>
#include <kvm.h>
#include <stdio.h>
-#include <machine/frame.h>
#include <machine/gdb_machdep.h>
+#include <machine/pcb.h>
#include <machine/psl.h>
#include <machine/segments.h>
#include "kgdb.h"
-static int
-getreg(int *addr)
-{
- int val;
-
- kvm_read(kvm, (uintptr_t)addr, &val, sizeof(val));
- return (val);
-}
-
void *
gdb_cpu_getreg(int regnum, size_t *regsz)
{
- struct trapframe *tf = curkthr->td_frame;
- int cs;
*regsz = gdb_cpu_regsz(regnum);
switch (regnum) {
- case 0: return (&tf->tf_eax);
- case 1: return (&tf->tf_ecx);
- case 2: return (&tf->tf_edx);
- case 3: return (&tf->tf_ebx);
- case 5: return (&tf->tf_ebp);
- case 6: return (&tf->tf_esi);
- case 7: return (&tf->tf_edi);
- case 8: return (&tf->tf_eip);
- case 9: return (&tf->tf_eflags);
- case 10: return (&tf->tf_cs);
- case 12: return (&tf->tf_ds);
- case 13: return (&tf->tf_es);
- case 4:
- cs = getreg(&tf->tf_cs);
- return (!ISPL(cs)) ? &tf->tf_ebp : &tf->tf_esp;
- case 11:
- cs = getreg(&tf->tf_cs);
- return (!ISPL(cs)) ? &tf->tf_ds : &tf->tf_ss;
+ case 3: return (&curkthr->td_pcb->pcb_ebx);
+ case 4: return (&curkthr->td_pcb->pcb_esp);
+ case 5: return (&curkthr->td_pcb->pcb_ebp);
+ case 6: return (&curkthr->td_pcb->pcb_esi);
+ case 7: return (&curkthr->td_pcb->pcb_edi);
+ case 8: return (&curkthr->td_pcb->pcb_eip);
}
return (NULL);
}
void
-gdb_cpu_setreg(int regnum, register_t val)
+gdb_cpu_setreg(int regnum __unused, register_t val __unused)
{
- struct trapframe *tf = curkthr->td_frame;
-
- switch (regnum) {
- case GDB_REG_PC: tf->tf_eip = val; break;
- }
}
int
More information about the p4-projects
mailing list