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 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 |
40#include <defs.h> 41 |
42#include "kgdb.h" 43 44static uintptr_t dumppcb; 45static int dumptid; 46 47static struct kthr *first; 48struct kthr *curkthr; 49 --- 49 unchanged lines hidden (view full) --- 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; |
109 first = kt; 110 addr = (uintptr_t)TAILQ_NEXT(&td, td_plist); 111 } 112 paddr = (uintptr_t)LIST_NEXT(&p, p_list); 113 } |
114 curkthr = kgdb_thr_lookup_tid(dumptid); |
115 if (curkthr == NULL) 116 curkthr = first; 117 return (first); 118} 119 120struct kthr * |
121kgdb_thr_lookup_tid(int tid) |
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 * |
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} |