2 * Copyright (c) 2004 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/signal.h>
42 static uintptr_t dumppcb;
45 static struct kthr *first;
49 lookup(const char *sym)
53 nl[0].n_name = (char *)(uintptr_t)sym;
55 if (kvm_nlist(kvm, nl) != 0) {
56 warnx("kvm_nlist(%s): %s", sym, kvm_geterr(kvm));
59 return (nl[0].n_value);
74 uintptr_t addr, paddr;
76 addr = lookup("_allproc");
79 kvm_read(kvm, addr, &paddr, sizeof(paddr));
81 dumppcb = lookup("_dumppcb");
85 addr = lookup("_dumptid");
87 kvm_read(kvm, addr, &dumptid, sizeof(dumptid));
92 if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p))
93 warnx("kvm_read: %s", kvm_geterr(kvm));
94 addr = (uintptr_t)TAILQ_FIRST(&p.p_threads);
96 if (kvm_read(kvm, addr, &td, sizeof(td)) != sizeof(td))
97 warnx("kvm_read: %s", kvm_geterr(kvm));
98 kt = malloc(sizeof(*kt));
101 kt->pcb = (td.td_tid == dumptid) ? dumppcb :
102 (uintptr_t)td.td_pcb;
103 kt->kstack = td.td_kstack;
106 addr = (uintptr_t)TAILQ_NEXT(&td, td_plist);
108 paddr = (uintptr_t)LIST_NEXT(&p, p_list);
110 curkthr = kgdb_thr_lookup(dumptid);
117 kgdb_thr_lookup(int tid)
122 while (kt != NULL && kt->tid != tid)
128 kgdb_thr_next(struct kthr *kt)
134 kgdb_thr_select(struct kthr *kt)