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 * 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. 14 * 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. 25 */ 26 27#include <sys/cdefs.h>
| 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 * 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. 14 * 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. 25 */ 26 27#include <sys/cdefs.h>
|
28__FBSDID("$FreeBSD: head/gnu/usr.bin/gdb/kgdb/kthr.c 132624 2004-07-25 05:29:15Z marcel $");
| 28__FBSDID("$FreeBSD: head/gnu/usr.bin/gdb/kgdb/kthr.c 142151 2005-02-20 22:55:07Z kan $");
|
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
| 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
|
| 40#include <defs.h> 41
|
40#include "kgdb.h" 41 42static uintptr_t dumppcb; 43static int dumptid; 44 45static struct kthr *first; 46struct kthr *curkthr; 47 48static uintptr_t 49lookup(const char *sym) 50{ 51 struct nlist nl[2]; 52 53 nl[0].n_name = (char *)(uintptr_t)sym; 54 nl[1].n_name = NULL; 55 if (kvm_nlist(kvm, nl) != 0) { 56 warnx("kvm_nlist(%s): %s", sym, kvm_geterr(kvm)); 57 return (0); 58 } 59 return (nl[0].n_value); 60} 61 62struct kthr * 63kgdb_thr_first(void) 64{ 65 return (first); 66} 67 68struct kthr * 69kgdb_thr_init(void) 70{ 71 struct proc p; 72 struct thread td; 73 struct kthr *kt; 74 uintptr_t addr, paddr; 75 76 addr = lookup("_allproc"); 77 if (addr == 0) 78 return (NULL); 79 kvm_read(kvm, addr, &paddr, sizeof(paddr)); 80 81 dumppcb = lookup("_dumppcb"); 82 if (dumppcb == 0) 83 return (NULL); 84 85 addr = lookup("_dumptid"); 86 if (addr != 0) 87 kvm_read(kvm, addr, &dumptid, sizeof(dumptid)); 88 else 89 dumptid = -1; 90 91 while (paddr != 0) { 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); 95 while (addr != 0) { 96 if (kvm_read(kvm, addr, &td, sizeof(td)) != sizeof(td)) 97 warnx("kvm_read: %s", kvm_geterr(kvm)); 98 kt = malloc(sizeof(*kt)); 99 kt->next = first; 100 kt->kaddr = addr; 101 kt->pcb = (td.td_tid == dumptid) ? dumppcb : 102 (uintptr_t)td.td_pcb; 103 kt->kstack = td.td_kstack; 104 kt->tid = td.td_tid;
| 42#include "kgdb.h" 43 44static uintptr_t dumppcb; 45static int dumptid; 46 47static struct kthr *first; 48struct kthr *curkthr; 49 50static uintptr_t 51lookup(const char *sym) 52{ 53 struct nlist nl[2]; 54 55 nl[0].n_name = (char *)(uintptr_t)sym; 56 nl[1].n_name = NULL; 57 if (kvm_nlist(kvm, nl) != 0) { 58 warnx("kvm_nlist(%s): %s", sym, kvm_geterr(kvm)); 59 return (0); 60 } 61 return (nl[0].n_value); 62} 63 64struct kthr * 65kgdb_thr_first(void) 66{ 67 return (first); 68} 69 70struct kthr * 71kgdb_thr_init(void) 72{ 73 struct proc p; 74 struct thread td; 75 struct kthr *kt; 76 uintptr_t addr, paddr; 77 78 addr = lookup("_allproc"); 79 if (addr == 0) 80 return (NULL); 81 kvm_read(kvm, addr, &paddr, sizeof(paddr)); 82 83 dumppcb = lookup("_dumppcb"); 84 if (dumppcb == 0) 85 return (NULL); 86 87 addr = lookup("_dumptid"); 88 if (addr != 0) 89 kvm_read(kvm, addr, &dumptid, sizeof(dumptid)); 90 else 91 dumptid = -1; 92 93 while (paddr != 0) { 94 if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p)) 95 warnx("kvm_read: %s", kvm_geterr(kvm)); 96 addr = (uintptr_t)TAILQ_FIRST(&p.p_threads); 97 while (addr != 0) { 98 if (kvm_read(kvm, addr, &td, sizeof(td)) != sizeof(td)) 99 warnx("kvm_read: %s", kvm_geterr(kvm)); 100 kt = malloc(sizeof(*kt)); 101 kt->next = first; 102 kt->kaddr = addr; 103 kt->pcb = (td.td_tid == dumptid) ? dumppcb : 104 (uintptr_t)td.td_pcb; 105 kt->kstack = td.td_kstack; 106 kt->tid = td.td_tid;
|
| 107 kt->pid = p.p_pid; 108 kt->paddr = paddr;
|
105 first = kt; 106 addr = (uintptr_t)TAILQ_NEXT(&td, td_plist); 107 } 108 paddr = (uintptr_t)LIST_NEXT(&p, p_list); 109 }
| 109 first = kt; 110 addr = (uintptr_t)TAILQ_NEXT(&td, td_plist); 111 } 112 paddr = (uintptr_t)LIST_NEXT(&p, p_list); 113 }
|
110 curkthr = kgdb_thr_lookup(dumptid);
| 114 curkthr = kgdb_thr_lookup_tid(dumptid);
|
111 if (curkthr == NULL) 112 curkthr = first; 113 return (first); 114} 115 116struct kthr *
| 115 if (curkthr == NULL) 116 curkthr = first; 117 return (first); 118} 119 120struct kthr *
|
117kgdb_thr_lookup(int tid)
| 121kgdb_thr_lookup_tid(int tid)
|
118{ 119 struct kthr *kt; 120 121 kt = first; 122 while (kt != NULL && kt->tid != tid) 123 kt = kt->next; 124 return (kt); 125} 126 127struct kthr *
| 122{ 123 struct kthr *kt; 124 125 kt = first; 126 while (kt != NULL && kt->tid != tid) 127 kt = kt->next; 128 return (kt); 129} 130 131struct kthr *
|
| 132kgdb_thr_lookup_taddr(uintptr_t taddr) 133{ 134 struct kthr *kt; 135 136 kt = first; 137 while (kt != NULL && kt->kaddr != taddr) 138 kt = kt->next; 139 return (kt); 140} 141 142struct kthr * 143kgdb_thr_lookup_pid(int pid) 144{ 145 struct kthr *kt; 146 147 kt = first; 148 while (kt != NULL && kt->pid != pid) 149 kt = kt->next; 150 return (kt); 151} 152 153struct kthr * 154kgdb_thr_lookup_paddr(uintptr_t paddr) 155{ 156 struct kthr *kt; 157 158 kt = first; 159 while (kt != NULL && kt->paddr != paddr) 160 kt = kt->next; 161 return (kt); 162} 163 164struct kthr *
|
128kgdb_thr_next(struct kthr *kt) 129{ 130 return (kt->next); 131} 132 133struct kthr * 134kgdb_thr_select(struct kthr *kt) 135{ 136 struct kthr *pcur; 137 138 pcur = curkthr; 139 curkthr = kt; 140 return (pcur); 141}
| 165kgdb_thr_next(struct kthr *kt) 166{ 167 return (kt->next); 168} 169 170struct kthr * 171kgdb_thr_select(struct kthr *kt) 172{ 173 struct kthr *pcur; 174 175 pcur = curkthr; 176 curkthr = kt; 177 return (pcur); 178}
|
| 179 180char * 181kgdb_thr_extra_thread_info(int tid) 182{ 183 struct kthr *kt; 184 struct proc *p; 185 static char comm[MAXCOMLEN + 1]; 186 187 kt = kgdb_thr_lookup_tid(tid); 188 if (kt == NULL) 189 return (NULL); 190 p = (struct proc *)kt->paddr; 191 if (kvm_read(kvm, (uintptr_t)&p->p_comm[0], &comm, sizeof(comm)) != 192 sizeof(comm)) 193 return (NULL); 194 195 return (comm); 196}
|
| |