Author: marcel Date: Sun Feb 17 02:15:19 2013 New Revision: 246893 URL: http://svnweb.freebsd.org/changeset/base/246893
Log: In kthr.c, obtain the address of the PCB for threads that were running on a core, when the core was stopped, by calling kgdb_trgt_core_pcb(). This has 2 advantages: 1. We don't need to include a machine-specific header anymore and as such kthr.c is truly machine independent. This allows the code to be used in a cross-debugger. 2. We don't need to lookup stoppcbs in generic code when it's an inherently target-spicific symbol. It does not exist for ia64. Implement kgdb_trgt_core_pcb() for all architectures, except ia64, by calling a common function called kgdb_trgt_stop_pcb(). This function differs from kgdb_trgt_core_pcb() in that it gets the size of the PCB structure as an argument and as such remains machine independent. On ia64 the PCB for stopped cores is in the PCPU structure itself. This for better scaling. The implementation of kgdb_trgt_core_pcb() for ia64 uses the cpuid_to_pcpu[] array to to obtain the address of the PCB structure. Modified: head/gnu/usr.bin/gdb/kgdb/kgdb.h head/gnu/usr.bin/gdb/kgdb/kthr.c head/gnu/usr.bin/gdb/kgdb/trgt.c head/gnu/usr.bin/gdb/kgdb/trgt_amd64.c head/gnu/usr.bin/gdb/kgdb/trgt_arm.c head/gnu/usr.bin/gdb/kgdb/trgt_i386.c head/gnu/usr.bin/gdb/kgdb/trgt_ia64.c head/gnu/usr.bin/gdb/kgdb/trgt_mips.c head/gnu/usr.bin/gdb/kgdb/trgt_powerpc.c head/gnu/usr.bin/gdb/kgdb/trgt_powerpc64.c head/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c Modified: head/gnu/usr.bin/gdb/kgdb/kgdb.h ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/kgdb.h Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/kgdb.h Sun Feb 17 02:15:19 2013 (r246893) @@ -49,6 +49,8 @@ extern struct kthr *curkthr; void initialize_kld_target(void); void initialize_kgdb_target(void); void kgdb_dmesg(void); +CORE_ADDR kgdb_trgt_core_pcb(u_int); +CORE_ADDR kgdb_trgt_stop_pcb(u_int, u_int); void kgdb_trgt_new_objfile(struct objfile *); void kgdb_trgt_fetch_registers(int); void kgdb_trgt_store_registers(int); Modified: head/gnu/usr.bin/gdb/kgdb/kthr.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/kthr.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/kthr.c Sun Feb 17 02:15:19 2013 (r246893) @@ -44,12 +44,10 @@ __FBSDID("$FreeBSD$"); #include <frame-unwind.h> #include "kgdb.h" -#include <machine/pcb.h> static CORE_ADDR dumppcb; static int dumptid; -static CORE_ADDR stoppcbs; static cpuset_t stopped_cpus; static struct kthr *first; @@ -98,10 +96,9 @@ kgdb_thr_add_procs(uintptr_t paddr) kt->kaddr = addr; if (td.td_tid == dumptid) kt->pcb = dumppcb; - else if (td.td_state == TDS_RUNNING && stoppcbs != 0 && + else if (td.td_state == TDS_RUNNING && CPU_ISSET(td.td_oncpu, &stopped_cpus)) - kt->pcb = (uintptr_t)stoppcbs + - sizeof(struct pcb) * td.td_oncpu; + kt->pcb = kgdb_trgt_core_pcb(td.td_oncpu); else kt->pcb = (uintptr_t)td.td_pcb; kt->kstack = td.td_kstack; @@ -152,8 +149,6 @@ kgdb_thr_init(void) addr != 0) kvm_read(kvm, addr, &stopped_cpus, cpusetsize); - stoppcbs = kgdb_lookup("stoppcbs"); - kgdb_thr_add_procs(paddr); addr = kgdb_lookup("zombproc"); if (addr != 0) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt.c Sun Feb 17 02:15:19 2013 (r246893) @@ -53,6 +53,8 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +static CORE_ADDR stoppcbs; + static void kgdb_core_cleanup(void *); static char *vmcore; @@ -352,3 +354,18 @@ initialize_kgdb_target(void) add_com ("tid", class_obscure, kgdb_set_tid_cmd, "Set current thread context"); } + +CORE_ADDR +kgdb_trgt_stop_pcb(u_int cpuid, u_int pcbsz) +{ + static int once = 0; + + if (stoppcbs == 0 && !once) { + once = 1; + stoppcbs = kgdb_lookup("stoppcbs"); + } + if (stoppcbs == 0) + return 0; + + return (stoppcbs + pcbsz * cpuid); +} Modified: head/gnu/usr.bin/gdb/kgdb/trgt_amd64.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_amd64.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_amd64.c Sun Feb 17 02:15:19 2013 (r246893) @@ -44,6 +44,12 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); +} + void kgdb_trgt_fetch_registers(int regno __unused) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt_arm.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_arm.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_arm.c Sun Feb 17 02:15:19 2013 (r246893) @@ -47,6 +47,12 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); +} + void kgdb_trgt_fetch_registers(int regno __unused) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt_i386.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_i386.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_i386.c Sun Feb 17 02:15:19 2013 (r246893) @@ -49,6 +49,12 @@ __FBSDID("$FreeBSD$"); static int ofs_fix; +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); +} + void kgdb_trgt_fetch_registers(int regno __unused) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt_ia64.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_ia64.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_ia64.c Sun Feb 17 02:15:19 2013 (r246893) @@ -52,6 +52,18 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + CORE_ADDR addr; + char *expr; + + asprintf(&expr, "&cpuid_to_pcpu[%d]->pc_md.pcb", cpuid); + addr = kgdb_parse(expr); + free(expr); + return (addr); +} + void kgdb_trgt_fetch_registers(int regno __unused) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt_mips.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_mips.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_mips.c Sun Feb 17 02:15:19 2013 (r246893) @@ -52,6 +52,12 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); +} + void kgdb_trgt_fetch_registers(int regno __unused) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt_powerpc.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_powerpc.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_powerpc.c Sun Feb 17 02:15:19 2013 (r246893) @@ -49,6 +49,12 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); +} + void kgdb_trgt_fetch_registers(int regno __unused) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt_powerpc64.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_powerpc64.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_powerpc64.c Sun Feb 17 02:15:19 2013 (r246893) @@ -44,6 +44,12 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); +} + void kgdb_trgt_fetch_registers(int regno __unused) { Modified: head/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c ============================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c Sun Feb 17 01:34:41 2013 (r246892) +++ head/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c Sun Feb 17 02:15:19 2013 (r246893) @@ -46,6 +46,12 @@ __FBSDID("$FreeBSD$"); #include "kgdb.h" +CORE_ADDR +kgdb_trgt_core_pcb(u_int cpuid) +{ + return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); +} + void kgdb_trgt_fetch_registers(int regno __unused) { _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"