* linux-i386-low.c (ps_get_thread_area): New.
[deliverable/binutils-gdb.git] / gdb / gdbserver / proc-service.c
CommitLineData
0d62e5e8 1/* libthread_db helper functions for the remote server for GDB.
fd500816 2 Copyright 2002, 2004
0d62e5e8
DJ
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
46typedef struct ps_prochandle *gdb_ps_prochandle_t;
47typedef void *gdb_ps_read_buf_t;
48typedef const void *gdb_ps_write_buf_t;
49typedef size_t gdb_ps_size_t;
50
fd500816
DJ
51#ifdef HAVE_LINUX_REGSETS
52#define HAVE_REGSETS
53#endif
54
55#ifdef HAVE_REGSETS
0d62e5e8
DJ
56static struct regset_info *
57gregset_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}
0d62e5e8
DJ
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
76ps_err_e
77ps_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
92ps_err_e
93ps_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
102ps_err_e
103ps_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
112ps_err_e
113ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
114{
fd500816 115#ifdef HAVE_REGSETS
0d62e5e8 116 struct thread_info *reg_inferior, *save_inferior;
0d62e5e8
DJ
117
118 reg_inferior = (struct thread_info *) find_inferior_id (&all_threads,
119 lwpid);
120 if (reg_inferior == NULL)
121 return PS_ERR;
122
123 save_inferior = current_inferior;
124 current_inferior = reg_inferior;
125
fd500816
DJ
126 the_target->fetch_registers (0);
127 gregset_info()->fill_function (gregset);
0d62e5e8
DJ
128
129 current_inferior = save_inferior;
130 return PS_OK;
fd500816 131#else
0d62e5e8 132 return PS_ERR;
fd500816 133#endif
0d62e5e8
DJ
134}
135
136/* Set the general registers of LWP LWPID within the target process PH
137 from GREGSET. */
138
139ps_err_e
140ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
141{
fd500816 142 /* Unneeded. */
0d62e5e8
DJ
143 return PS_ERR;
144}
145
146/* Get the floating-point registers of LWP LWPID within the target
147 process PH and store them in FPREGSET. */
148
149ps_err_e
150ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
151 gdb_prfpregset_t *fpregset)
152{
fd500816 153 /* Unneeded. */
0d62e5e8
DJ
154 return PS_ERR;
155}
156
157/* Set the floating-point registers of LWP LWPID within the target
158 process PH from FPREGSET. */
159
160ps_err_e
161ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
162 const gdb_prfpregset_t *fpregset)
163{
fd500816 164 /* Unneeded. */
0d62e5e8
DJ
165 return PS_ERR;
166}
167
168/* Return overall process id of the target PH. Special for GNU/Linux
169 -- not used on Solaris. */
170
171pid_t
172ps_getpid (gdb_ps_prochandle_t ph)
173{
174 return ph->pid;
175}
176
177
This page took 0.250598 seconds and 4 git commands to generate.