trgt.c (132624) | trgt.c (142151) |
---|---|
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> | 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/trgt.c 132624 2004-07-25 05:29:15Z marcel $"); | 28__FBSDID("$FreeBSD: head/gnu/usr.bin/gdb/kgdb/trgt.c 142151 2005-02-20 22:55:07Z kan $"); |
29 | 29 |
30#include <sys/types.h> | 30#include <sys/param.h> 31#include <sys/proc.h> 32#include <sys/sysctl.h> 33#include <sys/user.h> |
31#include <kvm.h> 32 | 34#include <kvm.h> 35 |
33#include "kgdb.h" 34 | |
35#include <defs.h> | 36#include <defs.h> |
37#include <command.h> |
|
36#include <gdbthread.h> 37#include <inferior.h> | 38#include <gdbthread.h> 39#include <inferior.h> |
40#include <regcache.h> |
|
38#include <target.h> 39 | 41#include <target.h> 42 |
43#include "kgdb.h" 44 |
|
40static struct target_ops kgdb_trgt_ops; 41 | 45static struct target_ops kgdb_trgt_ops; 46 |
47#define KERNOFF (kgdb_kernbase ()) 48#define INKERNEL(x) ((x) >= KERNOFF) 49 50static CORE_ADDR 51kgdb_kernbase (void) 52{ 53 static CORE_ADDR kernbase; 54 struct minimal_symbol *sym; 55 56 if (kernbase == 0) 57 { 58 sym = lookup_minimal_symbol ("kernbase", NULL, NULL); 59 if (sym == NULL) { 60 kernbase = KERNBASE; 61 } else { 62 kernbase = SYMBOL_VALUE_ADDRESS (sym); 63 } 64 } 65 return kernbase; 66} 67 |
|
42static char * | 68static char * |
43kgdb_trgt_extra_thread_info(struct thread_info *ti __unused) | 69kgdb_trgt_extra_thread_info(struct thread_info *ti) |
44{ | 70{ |
45 return (NULL); | 71 return (kgdb_thr_extra_thread_info(ptid_get_tid(ti->ptid))); |
46} 47 48static void 49kgdb_trgt_find_new_threads(void) 50{ 51} 52 53static char * 54kgdb_trgt_pid_to_str(ptid_t ptid) 55{ | 72} 73 74static void 75kgdb_trgt_find_new_threads(void) 76{ 77} 78 79static char * 80kgdb_trgt_pid_to_str(ptid_t ptid) 81{ |
56 static char buf[16]; | 82 static char buf[33]; |
57 | 83 |
58 snprintf(buf, sizeof(buf), "TID %d", ptid_get_pid(ptid)); | 84 snprintf(buf, sizeof(buf), "PID %5d TID %5ld", ptid_get_pid(ptid), 85 ptid_get_tid(ptid)); |
59 return (buf); 60} 61 62static int 63kgdb_trgt_thread_alive(ptid_t ptid) 64{ | 86 return (buf); 87} 88 89static int 90kgdb_trgt_thread_alive(ptid_t ptid) 91{ |
65 return (kgdb_thr_lookup(ptid_get_pid(ptid)) != NULL); | 92 return (kgdb_thr_lookup_tid(ptid_get_tid(ptid)) != NULL); |
66} 67 68static int 69kgdb_trgt_xfer_memory(CORE_ADDR memaddr, char *myaddr, int len, int write, 70 struct mem_attrib *attrib __unused, struct target_ops *target __unused) 71{ 72 if (len == 0) 73 return (0); 74 75 if (!write) 76 return (kvm_read(kvm, memaddr, myaddr, len)); 77 else 78 return (kvm_write(kvm, memaddr, myaddr, len)); 79} 80 | 93} 94 95static int 96kgdb_trgt_xfer_memory(CORE_ADDR memaddr, char *myaddr, int len, int write, 97 struct mem_attrib *attrib __unused, struct target_ops *target __unused) 98{ 99 if (len == 0) 100 return (0); 101 102 if (!write) 103 return (kvm_read(kvm, memaddr, myaddr, len)); 104 else 105 return (kvm_write(kvm, memaddr, myaddr, len)); 106} 107 |
108static void 109kgdb_switch_to_thread(struct kthr *thr) 110{ 111 if (thr->tid == ptid_get_tid(inferior_ptid)) 112 return; 113 114 inferior_ptid = ptid_build(thr->pid, 0, thr->tid); 115 flush_cached_frames (); 116 registers_changed (); 117 stop_pc = read_pc (); 118 select_frame (get_current_frame ()); 119} 120 121static void 122kgdb_set_proc_cmd (char *arg, int from_tty) 123{ 124 CORE_ADDR addr; 125 struct kthr *thr; 126 127 if (!arg) 128 error_no_arg ("proc address for the new context"); 129 130 if (kvm == NULL) 131 error ("no kernel core file"); 132 133 addr = (CORE_ADDR) parse_and_eval_address (arg); 134 135 if (!INKERNEL (addr)) { 136 thr = kgdb_thr_lookup_pid((int)addr); 137 if (thr == NULL) 138 error ("invalid pid"); 139 } else { 140 thr = kgdb_thr_lookup_paddr(addr); 141 if (thr == NULL) 142 error("invalid proc address"); 143 } 144 kgdb_switch_to_thread(thr); 145} 146 147static void 148kgdb_set_tid_cmd (char *arg, int from_tty) 149{ 150 CORE_ADDR addr; 151 struct kthr *thr; 152 153 if (!arg) 154 error_no_arg ("TID or thread address for the new context"); 155 156 if (kvm == NULL) 157 error ("no kernel core file"); 158 159 addr = (CORE_ADDR) parse_and_eval_address (arg); 160 161 if (!INKERNEL (addr)) { 162 thr = kgdb_thr_lookup_tid((int)addr); 163 if (thr == NULL) 164 error ("invalid TID"); 165 } else { 166 thr = kgdb_thr_lookup_taddr(addr); 167 if (thr == NULL) 168 error("invalid thread address"); 169 } 170 kgdb_switch_to_thread(thr); 171} 172 |
|
81void 82kgdb_target(void) 83{ 84 struct kthr *kt; 85 struct thread_info *ti; 86 87 kgdb_trgt_ops.to_magic = OPS_MAGIC; 88 kgdb_trgt_ops.to_shortname = "kernel"; --- 11 unchanged lines hidden (view full) --- 100 kgdb_trgt_ops.to_store_registers = kgdb_trgt_store_registers; 101 kgdb_trgt_ops.to_thread_alive = kgdb_trgt_thread_alive; 102 kgdb_trgt_ops.to_xfer_memory = kgdb_trgt_xfer_memory; 103 add_target(&kgdb_trgt_ops); 104 push_target(&kgdb_trgt_ops); 105 106 kt = kgdb_thr_first(); 107 while (kt != NULL) { | 173void 174kgdb_target(void) 175{ 176 struct kthr *kt; 177 struct thread_info *ti; 178 179 kgdb_trgt_ops.to_magic = OPS_MAGIC; 180 kgdb_trgt_ops.to_shortname = "kernel"; --- 11 unchanged lines hidden (view full) --- 192 kgdb_trgt_ops.to_store_registers = kgdb_trgt_store_registers; 193 kgdb_trgt_ops.to_thread_alive = kgdb_trgt_thread_alive; 194 kgdb_trgt_ops.to_xfer_memory = kgdb_trgt_xfer_memory; 195 add_target(&kgdb_trgt_ops); 196 push_target(&kgdb_trgt_ops); 197 198 kt = kgdb_thr_first(); 199 while (kt != NULL) { |
108 ti = add_thread(ptid_build(kt->tid, 0, 0)); | 200 ti = add_thread(ptid_build(kt->pid, 0, kt->tid)); |
109 kt = kgdb_thr_next(kt); 110 } | 201 kt = kgdb_thr_next(kt); 202 } |
111 inferior_ptid = ptid_build(curkthr->tid, 0, 0); | 203 inferior_ptid = ptid_build(curkthr->pid, 0, curkthr->tid); 204 add_com ("proc", class_obscure, kgdb_set_proc_cmd, 205 "Set current process context"); 206 add_com ("tid", class_obscure, kgdb_set_tid_cmd, 207 "Set current process context"); |
112} | 208} |