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 210852 2010-08-04 21:02:04Z jhb $"); |
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 CORE_ADDR dumppcb; |
48static int dumptid; 49 |
50static CORE_ADDR stoppcbs; |
51static __cpumask_t stopped_cpus; 52 53static struct kthr *first; 54struct kthr *curkthr; 55 |
56CORE_ADDR |
57kgdb_lookup(const char *sym) 58{ |
59 CORE_ADDR addr; 60 char *name; |
61 |
62 asprintf(&name, "&%s", sym); 63 addr = kgdb_parse(name); 64 free(name); 65 return (addr); |
66} 67 68struct kthr * 69kgdb_thr_first(void) 70{ 71 return (first); 72} 73 74struct kthr * 75kgdb_thr_init(void) 76{ 77 struct proc p; 78 struct thread td; 79 struct kthr *kt; |
80 CORE_ADDR addr; 81 uintptr_t 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 return (NULL); |
92 kvm_read(kvm, addr, &paddr, sizeof(paddr)); 93 |
94 dumppcb = kgdb_lookup("dumppcb"); 95 if (dumppcb == 0) |
96 return (NULL); |
97 |
98 addr = kgdb_lookup("dumptid"); |
99 if (addr != 0) 100 kvm_read(kvm, addr, &dumptid, sizeof(dumptid)); 101 else 102 dumptid = -1; 103 |
104 addr = kgdb_lookup("stopped_cpus"); |
105 if (addr != 0) 106 kvm_read(kvm, addr, &stopped_cpus, sizeof(stopped_cpus)); 107 else 108 stopped_cpus = 0; 109 |
110 stoppcbs = kgdb_lookup("stoppcbs"); |
111 112 while (paddr != 0) { 113 if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p)) { 114 warnx("kvm_read: %s", kvm_geterr(kvm)); 115 break; 116 } 117 addr = (uintptr_t)TAILQ_FIRST(&p.p_threads); 118 while (addr != 0) { --- 120 unchanged lines hidden --- |