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 | |
10 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
19 | along with this program; if not, write to the Free Software | |
6f0f660e EZ |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. */ | |
0d62e5e8 DJ |
22 | |
23 | #include "server.h" | |
24 | ||
25 | /* This file is currently tied to GNU/Linux. It should scale well to | |
26 | another libthread_db implementation, with the approriate gdbserver | |
27 | hooks, but for now this means we can use GNU/Linux's target data. */ | |
28 | ||
29 | #include "linux-low.h" | |
30 | ||
0050a760 | 31 | #include "gdb_proc_service.h" |
0d62e5e8 DJ |
32 | |
33 | typedef struct ps_prochandle *gdb_ps_prochandle_t; | |
34 | typedef void *gdb_ps_read_buf_t; | |
35 | typedef const void *gdb_ps_write_buf_t; | |
36 | typedef size_t gdb_ps_size_t; | |
37 | ||
fd500816 DJ |
38 | #ifdef HAVE_LINUX_REGSETS |
39 | #define HAVE_REGSETS | |
40 | #endif | |
41 | ||
42 | #ifdef HAVE_REGSETS | |
0d62e5e8 DJ |
43 | static struct regset_info * |
44 | gregset_info(void) | |
45 | { | |
46 | int i = 0; | |
47 | ||
48 | while (target_regsets[i].size != -1) | |
49 | { | |
50 | if (target_regsets[i].type == GENERAL_REGS) | |
51 | break; | |
52 | i++; | |
53 | } | |
54 | ||
55 | return &target_regsets[i]; | |
56 | } | |
0d62e5e8 DJ |
57 | #endif |
58 | ||
59 | /* Search for the symbol named NAME within the object named OBJ within | |
60 | the target process PH. If the symbol is found the address of the | |
61 | symbol is stored in SYM_ADDR. */ | |
62 | ||
63 | ps_err_e | |
64 | ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, | |
0050a760 | 65 | const char *name, psaddr_t *sym_addr) |
0d62e5e8 DJ |
66 | { |
67 | CORE_ADDR addr; | |
68 | ||
69 | if (look_up_one_symbol (name, &addr) == 0) | |
70 | return PS_NOSYM; | |
71 | ||
0050a760 | 72 | *sym_addr = (psaddr_t) (unsigned long) addr; |
0d62e5e8 DJ |
73 | return PS_OK; |
74 | } | |
75 | ||
76 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
77 | them into BUF. */ | |
78 | ||
79 | ps_err_e | |
0050a760 | 80 | ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr, |
0d62e5e8 DJ |
81 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) |
82 | { | |
0050a760 | 83 | read_inferior_memory ((unsigned long) addr, buf, size); |
0d62e5e8 DJ |
84 | return PS_OK; |
85 | } | |
86 | ||
87 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
88 | ||
89 | ps_err_e | |
0050a760 | 90 | ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr, |
0d62e5e8 DJ |
91 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) |
92 | { | |
0050a760 | 93 | return write_inferior_memory ((unsigned long) addr, buf, size); |
0d62e5e8 DJ |
94 | } |
95 | ||
96 | /* Get the general registers of LWP LWPID within the target process PH | |
97 | and store them in GREGSET. */ | |
98 | ||
99 | ps_err_e | |
100 | ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset) | |
101 | { | |
fd500816 | 102 | #ifdef HAVE_REGSETS |
8643e2ad | 103 | struct process_info *process; |
0d62e5e8 | 104 | struct thread_info *reg_inferior, *save_inferior; |
0d62e5e8 | 105 | |
8643e2ad DJ |
106 | process = (struct process_info *) find_inferior_id (&all_processes, |
107 | lwpid); | |
108 | if (process == NULL) | |
0d62e5e8 DJ |
109 | return PS_ERR; |
110 | ||
8643e2ad | 111 | reg_inferior = get_process_thread (process); |
0d62e5e8 DJ |
112 | save_inferior = current_inferior; |
113 | current_inferior = reg_inferior; | |
114 | ||
fd500816 DJ |
115 | the_target->fetch_registers (0); |
116 | gregset_info()->fill_function (gregset); | |
0d62e5e8 DJ |
117 | |
118 | current_inferior = save_inferior; | |
119 | return PS_OK; | |
fd500816 | 120 | #else |
0d62e5e8 | 121 | return PS_ERR; |
fd500816 | 122 | #endif |
0d62e5e8 DJ |
123 | } |
124 | ||
125 | /* Set the general registers of LWP LWPID within the target process PH | |
126 | from GREGSET. */ | |
127 | ||
128 | ps_err_e | |
129 | ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset) | |
130 | { | |
fd500816 | 131 | /* Unneeded. */ |
0d62e5e8 DJ |
132 | return PS_ERR; |
133 | } | |
134 | ||
135 | /* Get the floating-point registers of LWP LWPID within the target | |
136 | process PH and store them in FPREGSET. */ | |
137 | ||
138 | ps_err_e | |
0050a760 | 139 | ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset) |
0d62e5e8 | 140 | { |
fd500816 | 141 | /* Unneeded. */ |
0d62e5e8 DJ |
142 | return PS_ERR; |
143 | } | |
144 | ||
145 | /* Set the floating-point registers of LWP LWPID within the target | |
146 | process PH from FPREGSET. */ | |
147 | ||
148 | ps_err_e | |
0050a760 | 149 | ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset) |
0d62e5e8 | 150 | { |
fd500816 | 151 | /* Unneeded. */ |
0d62e5e8 DJ |
152 | return PS_ERR; |
153 | } | |
154 | ||
155 | /* Return overall process id of the target PH. Special for GNU/Linux | |
156 | -- not used on Solaris. */ | |
157 | ||
158 | pid_t | |
159 | ps_getpid (gdb_ps_prochandle_t ph) | |
160 | { | |
161 | return ph->pid; | |
162 | } | |
163 | ||
164 |