GDBserver
proc-service.c
Go to the documentation of this file.
1 /* libthread_db helper functions for the remote server for GDB.
2  Copyright (C) 2002-2015 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
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 
29 #include "gdb_proc_service.h"
30 
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 
36 #ifdef HAVE_LINUX_REGSETS
37 #define HAVE_REGSETS
38 #endif
39 
40 #ifdef HAVE_REGSETS
41 static struct regset_info *
42 gregset_info (void)
43 {
44  int i = 0;
45  const struct regs_info *regs_info = (*the_low_target.regs_info) ();
46  struct regsets_info *regsets_info = regs_info->regsets_info;
47 
48  while (regsets_info->regsets[i].size != -1)
49  {
50  if (regsets_info->regsets[i].type == GENERAL_REGS)
51  break;
52  i++;
53  }
54 
55  return &regsets_info->regsets[i];
56 }
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 
64 ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
65  const char *name, psaddr_t *sym_addr)
66 {
67  CORE_ADDR addr;
68 
69  if (thread_db_look_up_one_symbol (name, &addr) == 0)
70  return PS_NOSYM;
71 
72  *sym_addr = (psaddr_t) (unsigned long) addr;
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 
80 ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr,
82 {
83  read_inferior_memory ((unsigned long) addr, buf, size);
84  return PS_OK;
85 }
86 
87 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
88 
90 ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
92 {
93  return write_inferior_memory ((unsigned long) addr, buf, size);
94 }
95 
96 /* Get the general registers of LWP LWPID within the target process PH
97  and store them in GREGSET. */
98 
100 ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
101 {
102 #ifdef HAVE_REGSETS
103  struct lwp_info *lwp;
104  struct thread_info *reg_thread, *saved_thread;
105  struct regcache *regcache;
106 
107  lwp = find_lwp_pid (pid_to_ptid (lwpid));
108  if (lwp == NULL)
109  return PS_ERR;
110 
111  reg_thread = get_lwp_thread (lwp);
112  saved_thread = current_thread;
113  current_thread = reg_thread;
114  regcache = get_thread_regcache (current_thread, 1);
115  gregset_info ()->fill_function (regcache, gregset);
116 
117  current_thread = saved_thread;
118  return PS_OK;
119 #else
120  return PS_ERR;
121 #endif
122 }
123 
124 /* Set the general registers of LWP LWPID within the target process PH
125  from GREGSET. */
126 
127 ps_err_e
128 ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
129 {
130  /* Unneeded. */
131  return PS_ERR;
132 }
133 
134 /* Get the floating-point registers of LWP LWPID within the target
135  process PH and store them in FPREGSET. */
136 
137 ps_err_e
138 ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
139 {
140  /* Unneeded. */
141  return PS_ERR;
142 }
143 
144 /* Set the floating-point registers of LWP LWPID within the target
145  process PH from FPREGSET. */
146 
147 ps_err_e
148 ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
149 {
150  /* Unneeded. */
151  return PS_ERR;
152 }
153 
154 /* Return overall process id of the target PH. Special for GNU/Linux
155  -- not used on Solaris. */
156 
157 pid_t
158 ps_getpid (gdb_ps_prochandle_t ph)
159 {
160  return pid_of (current_thread);
161 }
unsigned int lwpid_t
ps_err_e ps_lsetfpregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
Definition: proc-service.c:148
struct ps_prochandle * gdb_ps_prochandle_t
Definition: proc-service.c:31
struct thread_info * current_thread
Definition: inferiors.c:28
bfd_vma CORE_ADDR
Definition: common-types.h:41
ps_err_e ps_pglobal_lookup(gdb_ps_prochandle_t ph, const char *obj, const char *name, psaddr_t *sym_addr)
Definition: proc-service.c:64
struct lwp_info * find_lwp_pid(ptid_t ptid)
Definition: linux-low.c:1531
ps_err_e ps_lsetregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
Definition: proc-service.c:128
ps_err_e ps_lgetregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
Definition: proc-service.c:100
ps_err_e
const char * name
Definition: tracepoint.c:178
const struct regs_info *(* regs_info)(void)
Definition: linux-low.h:132
const void * gdb_ps_write_buf_t
Definition: proc-service.c:33
struct linux_target_ops the_low_target
ps_err_e ps_pdwrite(gdb_ps_prochandle_t ph, psaddr_t addr, gdb_ps_write_buf_t buf, gdb_ps_size_t size)
Definition: proc-service.c:90
ps_err_e ps_lgetfpregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
Definition: proc-service.c:138
pid_t ps_getpid(gdb_ps_prochandle_t ph)
Definition: proc-service.c:158
int read_inferior_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
Definition: target.c:43
ptid_t pid_to_ptid(int pid)
Definition: ptid.c:44
#define get_lwp_thread(lwp)
Definition: linux-low.h:236
void * psaddr_t
size_t gdb_ps_size_t
Definition: proc-service.c:34
int write_inferior_memory(CORE_ADDR memaddr, const unsigned char *myaddr, int len)
Definition: target.c:68
ps_err_e ps_pdread(gdb_ps_prochandle_t ph, psaddr_t addr, gdb_ps_read_buf_t buf, gdb_ps_size_t size)
Definition: proc-service.c:80
elf_fpregset_t prfpregset_t
int thread_db_look_up_one_symbol(const char *name, CORE_ADDR *addrp)
Definition: thread-db.c:490
#define pid_of(inf)
Definition: inferiors.h:76
struct regcache * get_thread_regcache(struct thread_info *thread, int fetch)
Definition: regcache.c:27
elf_gregset_t prgregset_t
void * gdb_ps_read_buf_t
Definition: proc-service.c:32