1/*
2 * Copyright (c) 2004 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
--- 11 unchanged lines hidden (view full) ---
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/gnu/usr.bin/gdb/kgdb/kthr.c 203823 2010-02-13 11:47:04Z avg $");
29
30#include <sys/param.h>
31#include <sys/proc.h>
32#include <sys/types.h>
33#include <sys/signal.h>
34#include <err.h>
35#include <inttypes.h>
36#include <kvm.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40
41#include <defs.h>
42#include <frame-unwind.h>
43
44#include "kgdb.h"
45#include <machine/pcb.h>
46
47static uintptr_t dumppcb;
48static int dumptid;
49
50static uintptr_t stoppcbs;
51static __cpumask_t stopped_cpus;
52
53static struct kthr *first;
54struct kthr *curkthr;
55
56uintptr_t
57kgdb_lookup(const char *sym)
58{
59 struct nlist nl[2];
60
61 nl[0].n_type = N_UNDF;
62 nl[0].n_name = (char *)(uintptr_t)sym;
63 nl[1].n_name = NULL;
64 if (kvm_nlist(kvm, nl) != 0)
65 return (0);
66 return (nl[0].n_value);
67}
68
69struct kthr *
70kgdb_thr_first(void)
71{
72 return (first);
73}
74
75struct kthr *
76kgdb_thr_init(void)
77{
78 struct proc p;
79 struct thread td;
80 struct kthr *kt;
81 uintptr_t addr, paddr;
82
83 while (first != NULL) {
84 kt = first;
85 first = kt->next;
86 free(kt);
87 }
88
89 addr = kgdb_lookup("_allproc");
90 if (addr == 0) {
91 warnx("kvm_nlist(_allproc): %s", kvm_geterr(kvm));
92 return (NULL);
93 }
94 kvm_read(kvm, addr, &paddr, sizeof(paddr));
95
96 dumppcb = kgdb_lookup("_dumppcb");
97 if (dumppcb == 0) {
98 warnx("kvm_nlist(_dumppcb): %s", kvm_geterr(kvm));
99 return (NULL);
100 }
101
102 addr = kgdb_lookup("_dumptid");
103 if (addr != 0)
104 kvm_read(kvm, addr, &dumptid, sizeof(dumptid));
105 else
106 dumptid = -1;
107
108 addr = kgdb_lookup("_stopped_cpus");
109 if (addr != 0)
110 kvm_read(kvm, addr, &stopped_cpus, sizeof(stopped_cpus));
111 else
112 stopped_cpus = 0;
113
114 stoppcbs = kgdb_lookup("_stoppcbs");
115
116 while (paddr != 0) {
117 if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p)) {
118 warnx("kvm_read: %s", kvm_geterr(kvm));
119 break;
120 }
121 addr = (uintptr_t)TAILQ_FIRST(&p.p_threads);
122 while (addr != 0) {
--- 120 unchanged lines hidden ---
2 * Copyright (c) 2004 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
--- 11 unchanged lines hidden (view full) ---
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/gnu/usr.bin/gdb/kgdb/kthr.c 203823 2010-02-13 11:47:04Z avg $");
29
30#include <sys/param.h>
31#include <sys/proc.h>
32#include <sys/types.h>
33#include <sys/signal.h>
34#include <err.h>
35#include <inttypes.h>
36#include <kvm.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40
41#include <defs.h>
42#include <frame-unwind.h>
43
44#include "kgdb.h"
45#include <machine/pcb.h>
46
47static uintptr_t dumppcb;
48static int dumptid;
49
50static uintptr_t stoppcbs;
51static __cpumask_t stopped_cpus;
52
53static struct kthr *first;
54struct kthr *curkthr;
55
56uintptr_t
57kgdb_lookup(const char *sym)
58{
59 struct nlist nl[2];
60
61 nl[0].n_type = N_UNDF;
62 nl[0].n_name = (char *)(uintptr_t)sym;
63 nl[1].n_name = NULL;
64 if (kvm_nlist(kvm, nl) != 0)
65 return (0);
66 return (nl[0].n_value);
67}
68
69struct kthr *
70kgdb_thr_first(void)
71{
72 return (first);
73}
74
75struct kthr *
76kgdb_thr_init(void)
77{
78 struct proc p;
79 struct thread td;
80 struct kthr *kt;
81 uintptr_t addr, paddr;
82
83 while (first != NULL) {
84 kt = first;
85 first = kt->next;
86 free(kt);
87 }
88
89 addr = kgdb_lookup("_allproc");
90 if (addr == 0) {
91 warnx("kvm_nlist(_allproc): %s", kvm_geterr(kvm));
92 return (NULL);
93 }
94 kvm_read(kvm, addr, &paddr, sizeof(paddr));
95
96 dumppcb = kgdb_lookup("_dumppcb");
97 if (dumppcb == 0) {
98 warnx("kvm_nlist(_dumppcb): %s", kvm_geterr(kvm));
99 return (NULL);
100 }
101
102 addr = kgdb_lookup("_dumptid");
103 if (addr != 0)
104 kvm_read(kvm, addr, &dumptid, sizeof(dumptid));
105 else
106 dumptid = -1;
107
108 addr = kgdb_lookup("_stopped_cpus");
109 if (addr != 0)
110 kvm_read(kvm, addr, &stopped_cpus, sizeof(stopped_cpus));
111 else
112 stopped_cpus = 0;
113
114 stoppcbs = kgdb_lookup("_stoppcbs");
115
116 while (paddr != 0) {
117 if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p)) {
118 warnx("kvm_read: %s", kvm_geterr(kvm));
119 break;
120 }
121 addr = (uintptr_t)TAILQ_FIRST(&p.p_threads);
122 while (addr != 0) {
--- 120 unchanged lines hidden ---