Commit | Line | Data |
---|---|---|
0d62e5e8 | 1 | /* libthread_db helper functions for the remote server for GDB. |
6aba47ca | 2 | Copyright (C) 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
0d62e5e8 DJ |
3 | |
4 | Contributed by MontaVista Software. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
0d62e5e8 DJ |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0d62e5e8 DJ |
20 | |
21 | #include "server.h" | |
22 | ||
23 | /* This file is currently tied to GNU/Linux. It should scale well to | |
24 | another libthread_db implementation, with the approriate gdbserver | |
25 | hooks, but for now this means we can use GNU/Linux's target data. */ | |
26 | ||
27 | #include "linux-low.h" | |
28 | ||
0050a760 | 29 | #include "gdb_proc_service.h" |
0d62e5e8 DJ |
30 | |
31 | typedef struct ps_prochandle *gdb_ps_prochandle_t; | |
32 | typedef void *gdb_ps_read_buf_t; | |
33 | typedef const void *gdb_ps_write_buf_t; | |
34 | typedef size_t gdb_ps_size_t; | |
35 | ||
fd500816 DJ |
36 | #ifdef HAVE_LINUX_REGSETS |
37 | #define HAVE_REGSETS | |
38 | #endif | |
39 | ||
40 | #ifdef HAVE_REGSETS | |
0d62e5e8 DJ |
41 | static struct regset_info * |
42 | gregset_info(void) | |
43 | { | |
44 | int i = 0; | |
45 | ||
46 | while (target_regsets[i].size != -1) | |
47 | { | |
48 | if (target_regsets[i].type == GENERAL_REGS) | |
49 | break; | |
50 | i++; | |
51 | } | |
52 | ||
53 | return &target_regsets[i]; | |
54 | } | |
0d62e5e8 DJ |
55 | #endif |
56 | ||
57 | /* Search for the symbol named NAME within the object named OBJ within | |
58 | the target process PH. If the symbol is found the address of the | |
59 | symbol is stored in SYM_ADDR. */ | |
60 | ||
61 | ps_err_e | |
62 | ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, | |
0050a760 | 63 | const char *name, psaddr_t *sym_addr) |
0d62e5e8 DJ |
64 | { |
65 | CORE_ADDR addr; | |
66 | ||
67 | if (look_up_one_symbol (name, &addr) == 0) | |
68 | return PS_NOSYM; | |
69 | ||
0050a760 | 70 | *sym_addr = (psaddr_t) (unsigned long) addr; |
0d62e5e8 DJ |
71 | return PS_OK; |
72 | } | |
73 | ||
74 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
75 | them into BUF. */ | |
76 | ||
77 | ps_err_e | |
0050a760 | 78 | ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr, |
0d62e5e8 DJ |
79 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) |
80 | { | |
0050a760 | 81 | read_inferior_memory ((unsigned long) addr, buf, size); |
0d62e5e8 DJ |
82 | return PS_OK; |
83 | } | |
84 | ||
85 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
86 | ||
87 | ps_err_e | |
0050a760 | 88 | ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr, |
0d62e5e8 DJ |
89 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) |
90 | { | |
0050a760 | 91 | return write_inferior_memory ((unsigned long) addr, buf, size); |
0d62e5e8 DJ |
92 | } |
93 | ||
94 | /* Get the general registers of LWP LWPID within the target process PH | |
95 | and store them in GREGSET. */ | |
96 | ||
97 | ps_err_e | |
98 | ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset) | |
99 | { | |
fd500816 | 100 | #ifdef HAVE_REGSETS |
8643e2ad | 101 | struct process_info *process; |
0d62e5e8 | 102 | struct thread_info *reg_inferior, *save_inferior; |
0d62e5e8 | 103 | |
8643e2ad DJ |
104 | process = (struct process_info *) find_inferior_id (&all_processes, |
105 | lwpid); | |
106 | if (process == NULL) | |
0d62e5e8 DJ |
107 | return PS_ERR; |
108 | ||
8643e2ad | 109 | reg_inferior = get_process_thread (process); |
0d62e5e8 DJ |
110 | save_inferior = current_inferior; |
111 | current_inferior = reg_inferior; | |
112 | ||
fd500816 DJ |
113 | the_target->fetch_registers (0); |
114 | gregset_info()->fill_function (gregset); | |
0d62e5e8 DJ |
115 | |
116 | current_inferior = save_inferior; | |
117 | return PS_OK; | |
fd500816 | 118 | #else |
0d62e5e8 | 119 | return PS_ERR; |
fd500816 | 120 | #endif |
0d62e5e8 DJ |
121 | } |
122 | ||
123 | /* Set the general registers of LWP LWPID within the target process PH | |
124 | from GREGSET. */ | |
125 | ||
126 | ps_err_e | |
127 | ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset) | |
128 | { | |
fd500816 | 129 | /* Unneeded. */ |
0d62e5e8 DJ |
130 | return PS_ERR; |
131 | } | |
132 | ||
133 | /* Get the floating-point registers of LWP LWPID within the target | |
134 | process PH and store them in FPREGSET. */ | |
135 | ||
136 | ps_err_e | |
0050a760 | 137 | ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset) |
0d62e5e8 | 138 | { |
fd500816 | 139 | /* Unneeded. */ |
0d62e5e8 DJ |
140 | return PS_ERR; |
141 | } | |
142 | ||
143 | /* Set the floating-point registers of LWP LWPID within the target | |
144 | process PH from FPREGSET. */ | |
145 | ||
146 | ps_err_e | |
0050a760 | 147 | ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset) |
0d62e5e8 | 148 | { |
fd500816 | 149 | /* Unneeded. */ |
0d62e5e8 DJ |
150 | return PS_ERR; |
151 | } | |
152 | ||
153 | /* Return overall process id of the target PH. Special for GNU/Linux | |
154 | -- not used on Solaris. */ | |
155 | ||
156 | pid_t | |
157 | ps_getpid (gdb_ps_prochandle_t ph) | |
158 | { | |
159 | return ph->pid; | |
160 | } | |
161 | ||
162 |