Commit | Line | Data |
---|---|---|
0d62e5e8 | 1 | /* libthread_db helper functions for the remote server for GDB. |
7b6bb8da | 2 | Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
9b254dd1 | 3 | Free Software Foundation, Inc. |
0d62e5e8 DJ |
4 | |
5 | Contributed by MontaVista Software. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
0d62e5e8 DJ |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0d62e5e8 DJ |
21 | |
22 | #include "server.h" | |
23 | ||
24 | /* This file is currently tied to GNU/Linux. It should scale well to | |
25 | another libthread_db implementation, with the approriate gdbserver | |
26 | hooks, but for now this means we can use GNU/Linux's target data. */ | |
27 | ||
28 | #include "linux-low.h" | |
29 | ||
0050a760 | 30 | #include "gdb_proc_service.h" |
0d62e5e8 DJ |
31 | |
32 | typedef struct ps_prochandle *gdb_ps_prochandle_t; | |
33 | typedef void *gdb_ps_read_buf_t; | |
34 | typedef const void *gdb_ps_write_buf_t; | |
35 | typedef size_t gdb_ps_size_t; | |
36 | ||
fd500816 DJ |
37 | #ifdef HAVE_LINUX_REGSETS |
38 | #define HAVE_REGSETS | |
39 | #endif | |
40 | ||
41 | #ifdef HAVE_REGSETS | |
0d62e5e8 DJ |
42 | static struct regset_info * |
43 | gregset_info(void) | |
44 | { | |
45 | int i = 0; | |
46 | ||
47 | while (target_regsets[i].size != -1) | |
48 | { | |
49 | if (target_regsets[i].type == GENERAL_REGS) | |
50 | break; | |
51 | i++; | |
52 | } | |
53 | ||
54 | return &target_regsets[i]; | |
55 | } | |
0d62e5e8 DJ |
56 | #endif |
57 | ||
58 | /* Search for the symbol named NAME within the object named OBJ within | |
59 | the target process PH. If the symbol is found the address of the | |
60 | symbol is stored in SYM_ADDR. */ | |
61 | ||
62 | ps_err_e | |
63 | ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, | |
0050a760 | 64 | const char *name, psaddr_t *sym_addr) |
0d62e5e8 DJ |
65 | { |
66 | CORE_ADDR addr; | |
67 | ||
9836d6ea | 68 | if (thread_db_look_up_one_symbol (name, &addr) == 0) |
0d62e5e8 DJ |
69 | return PS_NOSYM; |
70 | ||
0050a760 | 71 | *sym_addr = (psaddr_t) (unsigned long) addr; |
0d62e5e8 DJ |
72 | return PS_OK; |
73 | } | |
74 | ||
75 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
76 | them into BUF. */ | |
77 | ||
78 | ps_err_e | |
0050a760 | 79 | ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr, |
0d62e5e8 DJ |
80 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) |
81 | { | |
0050a760 | 82 | read_inferior_memory ((unsigned long) addr, buf, size); |
0d62e5e8 DJ |
83 | return PS_OK; |
84 | } | |
85 | ||
86 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
87 | ||
88 | ps_err_e | |
0050a760 | 89 | ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr, |
0d62e5e8 DJ |
90 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) |
91 | { | |
0050a760 | 92 | return write_inferior_memory ((unsigned long) addr, buf, size); |
0d62e5e8 DJ |
93 | } |
94 | ||
95 | /* Get the general registers of LWP LWPID within the target process PH | |
96 | and store them in GREGSET. */ | |
97 | ||
98 | ps_err_e | |
99 | ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset) | |
100 | { | |
fd500816 | 101 | #ifdef HAVE_REGSETS |
54a0b537 | 102 | struct lwp_info *lwp; |
0d62e5e8 | 103 | struct thread_info *reg_inferior, *save_inferior; |
442ea881 | 104 | struct regcache *regcache; |
0d62e5e8 | 105 | |
95954743 | 106 | lwp = find_lwp_pid (pid_to_ptid (lwpid)); |
54a0b537 | 107 | if (lwp == NULL) |
0d62e5e8 DJ |
108 | return PS_ERR; |
109 | ||
54a0b537 | 110 | reg_inferior = get_lwp_thread (lwp); |
0d62e5e8 DJ |
111 | save_inferior = current_inferior; |
112 | current_inferior = reg_inferior; | |
442ea881 | 113 | regcache = get_thread_regcache (current_inferior, 1); |
442ea881 | 114 | gregset_info ()->fill_function (regcache, 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 | { | |
95954743 | 159 | return pid_of (get_thread_lwp (current_inferior)); |
0d62e5e8 | 160 | } |