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 AUTHOR ``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 AUTHOR 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.
26 * $FreeBSD: src/gnu/usr.bin/gdb/kgdb/trgt.c,v 1.4 2005/09/10 18:25:53 marcel Exp $
27 * $DragonFly: src/gnu/usr.bin/gdb/kgdb/trgt.c,v 1.2 2008/01/14 21:36:38 corecode Exp $
30 #include <sys/cdefs.h>
32 #include <sys/param.h>
33 /*#include <sys/proc.h>*/
34 #include <sys/sysctl.h>
40 #include <frame-unwind.h>
41 #include <gdbthread.h>
48 static struct target_ops kgdb_trgt_ops;
51 kgdb_trgt_extra_thread_info(struct thread_info *ti)
56 p = buf + snprintf(buf, sizeof(buf), "PID=%d", ptid_get_pid(ti->ptid));
57 s = kgdb_thr_extra_thread_info(ptid_get_tid(ti->ptid));
59 snprintf(p, sizeof(buf) - (p - buf), ": %s", s);
64 kgdb_trgt_files_info(struct target_ops *target)
66 struct target_ops *tb;
68 tb = find_target_beneath(target);
69 if (tb->to_files_info != NULL)
70 tb->to_files_info(tb);
74 kgdb_trgt_find_new_threads(void)
76 struct target_ops *tb;
81 tb = find_target_beneath(&kgdb_trgt_ops);
82 if (tb->to_find_new_threads != NULL)
83 tb->to_find_new_threads();
87 kgdb_trgt_pid_to_str(ptid_t ptid)
91 snprintf(buf, sizeof(buf), "Thread %#lx", ptid_get_tid(ptid));
96 kgdb_trgt_thread_alive(ptid_t ptid)
98 return (kgdb_thr_lookup_tid(ptid_get_tid(ptid)) != NULL);
102 kgdb_trgt_xfer_partial(struct target_ops *ops, enum target_object object,
103 const char *annex, gdb_byte *readbuf,
104 const gdb_byte *writebuf,
105 ULONGEST offset, LONGEST len)
110 if (writebuf != NULL)
111 return (kvm_write(kvm, offset, writebuf, len));
113 return (kvm_read(kvm, offset, readbuf, len));
115 return (ops->beneath->to_xfer_partial(ops->beneath, object, annex,
116 readbuf, writebuf, offset, len));
123 struct thread_info *ti;
125 kgdb_trgt_ops.to_magic = OPS_MAGIC;
126 kgdb_trgt_ops.to_shortname = "kernel";
127 kgdb_trgt_ops.to_longname = "kernel core files.";
128 kgdb_trgt_ops.to_doc = "Kernel core files.";
129 kgdb_trgt_ops.to_stratum = thread_stratum;
130 kgdb_trgt_ops.to_has_memory = 1;
131 kgdb_trgt_ops.to_has_registers = 1;
132 kgdb_trgt_ops.to_has_stack = 1;
134 kgdb_trgt_ops.to_extra_thread_info = kgdb_trgt_extra_thread_info;
135 kgdb_trgt_ops.to_fetch_registers = kgdb_trgt_fetch_registers;
136 kgdb_trgt_ops.to_files_info = kgdb_trgt_files_info;
137 kgdb_trgt_ops.to_find_new_threads = kgdb_trgt_find_new_threads;
138 kgdb_trgt_ops.to_pid_to_str = kgdb_trgt_pid_to_str;
139 kgdb_trgt_ops.to_store_registers = kgdb_trgt_store_registers;
140 kgdb_trgt_ops.to_thread_alive = kgdb_trgt_thread_alive;
141 kgdb_trgt_ops.to_xfer_partial = kgdb_trgt_xfer_partial;
142 add_target(&kgdb_trgt_ops);
143 push_target(&kgdb_trgt_ops);
145 kt = kgdb_thr_first();
147 ti = add_thread(ptid_build(kt->pid, 0, kt->tid));
148 kt = kgdb_thr_next(kt);
151 inferior_ptid = ptid_build(curkthr->pid, 0, curkthr->tid);