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-2018 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
31 typedef struct ps_prochandle *gdb_ps_prochandle_t;
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
63 ps_err_e
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
79 ps_err_e
80 ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr,
81 gdb_ps_read_buf_t buf, gdb_ps_size_t size)
82 {
83 if (read_inferior_memory ((uintptr_t) addr, (gdb_byte *) buf, size) != 0)
84 return PS_ERR;
85 return PS_OK;
86 }
87
88 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
89
90 ps_err_e
91 ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
92 gdb_ps_write_buf_t buf, gdb_ps_size_t size)
93 {
94 if (write_inferior_memory ((uintptr_t) addr, (const gdb_byte *) buf, size)
95 != 0)
96 return PS_ERR;
97 return PS_OK;
98 }
99
100 /* Get the general registers of LWP LWPID within the target process PH
101 and store them in GREGSET. */
102
103 ps_err_e
104 ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
105 {
106 #ifdef HAVE_REGSETS
107 struct lwp_info *lwp;
108 struct thread_info *reg_thread, *saved_thread;
109 struct regcache *regcache;
110
111 lwp = find_lwp_pid (pid_to_ptid (lwpid));
112 if (lwp == NULL)
113 return PS_ERR;
114
115 reg_thread = get_lwp_thread (lwp);
116 saved_thread = current_thread;
117 current_thread = reg_thread;
118 regcache = get_thread_regcache (current_thread, 1);
119 gregset_info ()->fill_function (regcache, gregset);
120
121 current_thread = saved_thread;
122 return PS_OK;
123 #else
124 return PS_ERR;
125 #endif
126 }
127
128 /* Set the general registers of LWP LWPID within the target process PH
129 from GREGSET. */
130
131 ps_err_e
132 ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
133 {
134 /* Unneeded. */
135 return PS_ERR;
136 }
137
138 /* Get the floating-point registers of LWP LWPID within the target
139 process PH and store them in FPREGSET. */
140
141 ps_err_e
142 ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
143 {
144 /* Unneeded. */
145 return PS_ERR;
146 }
147
148 /* Set the floating-point registers of LWP LWPID within the target
149 process PH from FPREGSET. */
150
151 ps_err_e
152 ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
153 {
154 /* Unneeded. */
155 return PS_ERR;
156 }
157
158 /* Return overall process id of the target PH. Special for GNU/Linux
159 -- not used on Solaris. */
160
161 pid_t
162 ps_getpid (gdb_ps_prochandle_t ph)
163 {
164 return pid_of (current_thread);
165 }
lwpid_t
unsigned int lwpid_t
Definition: gdb_proc_service.h:63
ps_lsetfpregs
ps_err_e ps_lsetfpregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
Definition: proc-service.c:152
gdb_ps_prochandle_t
struct ps_prochandle * gdb_ps_prochandle_t
Definition: proc-service.c:31
current_thread
struct thread_info * current_thread
Definition: inferiors.c:28
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
ps_pglobal_lookup
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
lwp_info
Definition: linux-low.h:276
find_lwp_pid
struct lwp_info * find_lwp_pid(ptid_t ptid)
Definition: linux-low.c:1812
ps_lsetregs
ps_err_e ps_lsetregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
Definition: proc-service.c:132
ps_prochandle
Definition: gdb_proc_service.h:150
ps_lgetregs
ps_err_e ps_lgetregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
Definition: proc-service.c:104
ps_err_e
ps_err_e
Definition: gdb_proc_service.h:51
name
const char * name
Definition: tracepoint.c:180
linux_target_ops::regs_info
const struct regs_info *(* regs_info)(void)
Definition: linux-low.h:133
gdb_ps_write_buf_t
const void * gdb_ps_write_buf_t
Definition: proc-service.c:33
the_low_target
struct linux_target_ops the_low_target
Definition: linux-aarch64-low.c:2955
pid_of
static int pid_of(const thread_info *thread)
Definition: gdbthread.h:214
regcache
Definition: regcache.h:31
gdb_proc_service.h
ps_pdwrite
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:91
ps_lgetfpregs
ps_err_e ps_lgetfpregs(gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
Definition: proc-service.c:142
thread_info
Definition: gdbthread.h:30
linux-low.h
regs_info
Definition: linux-low.h:94
ps_getpid
pid_t ps_getpid(gdb_ps_prochandle_t ph)
Definition: proc-service.c:162
read_inferior_memory
int read_inferior_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
Definition: target.c:120
pid_to_ptid
ptid_t pid_to_ptid(int pid)
Definition: ptid.c:39
get_lwp_thread
#define get_lwp_thread(lwp)
Definition: linux-low.h:264
server.h
psaddr_t
void * psaddr_t
Definition: gdb_proc_service.h:67
gdb_ps_size_t
size_t gdb_ps_size_t
Definition: proc-service.c:34
PS_ERR
Definition: gdb_proc_service.h:54
PS_NOSYM
Definition: gdb_proc_service.h:58
write_inferior_memory
int write_inferior_memory(CORE_ADDR memaddr, const unsigned char *myaddr, int len)
Definition: target.c:145
ps_pdread
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
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
prfpregset_t
elf_fpregset_t prfpregset_t
Definition: gdb_proc_service.h:75
thread_db_look_up_one_symbol
int thread_db_look_up_one_symbol(const char *name, CORE_ADDR *addrp)
Definition: thread-db.c:370
get_thread_regcache
struct regcache * get_thread_regcache(struct thread_info *thread, int fetch)
Definition: regcache.c:27
PS_OK
Definition: gdb_proc_service.h:53
prgregset_t
elf_gregset_t prgregset_t
Definition: gdb_proc_service.h:71
gdb_ps_read_buf_t
void * gdb_ps_read_buf_t
Definition: proc-service.c:32