]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/gdbserver/proc-service.c
a8c29ab6f1379965b2563218dfd550c88ee5e2cb
[thirdparty/binutils-gdb.git] / gdb / gdbserver / proc-service.c
1 /* libthread_db helper functions for the remote server for GDB.
2 Copyright 2002, 2004, 2005
3 Free Software Foundation, Inc.
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
11 the Free Software Foundation; either version 2 of the License, or
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
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24 #include "server.h"
25
26 /* This file is currently tied to GNU/Linux. It should scale well to
27 another libthread_db implementation, with the approriate gdbserver
28 hooks, but for now this means we can use GNU/Linux's target data. */
29
30 #include "linux-low.h"
31
32 /* Correct for all GNU/Linux targets (for quite some time). */
33 #define GDB_GREGSET_T elf_gregset_t
34 #define GDB_FPREGSET_T elf_fpregset_t
35
36 #ifndef HAVE_ELF_FPREGSET_T
37 /* Make sure we have said types. Not all platforms bring in <linux/elf.h>
38 via <sys/procfs.h>. */
39 #ifdef HAVE_LINUX_ELF_H
40 #include <linux/elf.h>
41 #endif
42 #endif
43
44 #include "../gdb_proc_service.h"
45
46 typedef struct ps_prochandle *gdb_ps_prochandle_t;
47 typedef void *gdb_ps_read_buf_t;
48 typedef const void *gdb_ps_write_buf_t;
49 typedef size_t gdb_ps_size_t;
50
51 #ifdef HAVE_LINUX_REGSETS
52 #define HAVE_REGSETS
53 #endif
54
55 #ifdef HAVE_REGSETS
56 static struct regset_info *
57 gregset_info(void)
58 {
59 int i = 0;
60
61 while (target_regsets[i].size != -1)
62 {
63 if (target_regsets[i].type == GENERAL_REGS)
64 break;
65 i++;
66 }
67
68 return &target_regsets[i];
69 }
70 #endif
71
72 /* Search for the symbol named NAME within the object named OBJ within
73 the target process PH. If the symbol is found the address of the
74 symbol is stored in SYM_ADDR. */
75
76 ps_err_e
77 ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
78 const char *name, paddr_t *sym_addr)
79 {
80 CORE_ADDR addr;
81
82 if (look_up_one_symbol (name, &addr) == 0)
83 return PS_NOSYM;
84
85 *sym_addr = (paddr_t) (unsigned long) addr;
86 return PS_OK;
87 }
88
89 /* Read SIZE bytes from the target process PH at address ADDR and copy
90 them into BUF. */
91
92 ps_err_e
93 ps_pdread (gdb_ps_prochandle_t ph, paddr_t addr,
94 gdb_ps_read_buf_t buf, gdb_ps_size_t size)
95 {
96 read_inferior_memory (addr, buf, size);
97 return PS_OK;
98 }
99
100 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
101
102 ps_err_e
103 ps_pdwrite (gdb_ps_prochandle_t ph, paddr_t addr,
104 gdb_ps_write_buf_t buf, gdb_ps_size_t size)
105 {
106 return write_inferior_memory (addr, buf, size);
107 }
108
109 /* Get the general registers of LWP LWPID within the target process PH
110 and store them in GREGSET. */
111
112 ps_err_e
113 ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
114 {
115 #ifdef HAVE_REGSETS
116 struct process_info *process;
117 struct thread_info *reg_inferior, *save_inferior;
118
119 process = (struct process_info *) find_inferior_id (&all_processes,
120 lwpid);
121 if (process == NULL)
122 return PS_ERR;
123
124 reg_inferior = get_process_thread (process);
125 save_inferior = current_inferior;
126 current_inferior = reg_inferior;
127
128 the_target->fetch_registers (0);
129 gregset_info()->fill_function (gregset);
130
131 current_inferior = save_inferior;
132 return PS_OK;
133 #else
134 return PS_ERR;
135 #endif
136 }
137
138 /* Set the general registers of LWP LWPID within the target process PH
139 from GREGSET. */
140
141 ps_err_e
142 ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
143 {
144 /* Unneeded. */
145 return PS_ERR;
146 }
147
148 /* Get the floating-point registers of LWP LWPID within the target
149 process PH and store them in FPREGSET. */
150
151 ps_err_e
152 ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
153 gdb_prfpregset_t *fpregset)
154 {
155 /* Unneeded. */
156 return PS_ERR;
157 }
158
159 /* Set the floating-point registers of LWP LWPID within the target
160 process PH from FPREGSET. */
161
162 ps_err_e
163 ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
164 const gdb_prfpregset_t *fpregset)
165 {
166 /* Unneeded. */
167 return PS_ERR;
168 }
169
170 /* Return overall process id of the target PH. Special for GNU/Linux
171 -- not used on Solaris. */
172
173 pid_t
174 ps_getpid (gdb_ps_prochandle_t ph)
175 {
176 return ph->pid;
177 }
178
179