OLD | NEW |
1 /* Shared utility routines for GDB to interact with agent. | 1 /* Shared utility routines for GDB to interact with agent. |
2 | 2 |
3 Copyright (C) 2009-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2009-2013 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #ifdef GDBSERVER | 20 #ifdef GDBSERVER |
21 #include "server.h" | 21 #include "server.h" |
22 #else | 22 #else |
23 #include "defs.h" | 23 #include "defs.h" |
24 #include "target.h" | 24 #include "target.h" |
25 #include "inferior.h" /* for non_stop */ | 25 #include "inferior.h" /* for non_stop */ |
26 #endif | 26 #endif |
27 | 27 |
28 #include <string.h> | 28 #include <string.h> |
29 #include <unistd.h> | 29 #include <unistd.h> |
30 #include "agent.h" | 30 #include "agent.h" |
| 31 #include "filestuff.h" |
31 | 32 |
32 int debug_agent = 0; | 33 int debug_agent = 0; |
33 | 34 |
34 #ifdef GDBSERVER | 35 #ifdef GDBSERVER |
35 #define DEBUG_AGENT(fmt, args...) \ | 36 #define DEBUG_AGENT(fmt, args...) \ |
36 if (debug_agent) \ | 37 if (debug_agent) \ |
37 fprintf (stderr, fmt, ##args); | 38 fprintf (stderr, fmt, ##args); |
38 #else | 39 #else |
39 #define DEBUG_AGENT(fmt, args...) \ | 40 #define DEBUG_AGENT(fmt, args...) \ |
40 if (debug_agent) \ | 41 if (debug_agent) \ |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 static unsigned int | 119 static unsigned int |
119 agent_get_helper_thread_id (void) | 120 agent_get_helper_thread_id (void) |
120 { | 121 { |
121 if (helper_thread_id == 0) | 122 if (helper_thread_id == 0) |
122 { | 123 { |
123 #ifdef GDBSERVER | 124 #ifdef GDBSERVER |
124 if (read_inferior_memory (ipa_sym_addrs.addr_helper_thread_id, | 125 if (read_inferior_memory (ipa_sym_addrs.addr_helper_thread_id, |
125 (unsigned char *) &helper_thread_id, | 126 (unsigned char *) &helper_thread_id, |
126 sizeof helper_thread_id)) | 127 sizeof helper_thread_id)) |
127 #else | 128 #else |
128 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); | 129 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ()); |
129 gdb_byte buf[4]; | 130 gdb_byte buf[4]; |
130 | 131 |
131 if (target_read_memory (ipa_sym_addrs.addr_helper_thread_id, | 132 if (target_read_memory (ipa_sym_addrs.addr_helper_thread_id, |
132 buf, sizeof buf) == 0) | 133 buf, sizeof buf) == 0) |
133 helper_thread_id = extract_unsigned_integer (buf, sizeof buf, | 134 helper_thread_id = extract_unsigned_integer (buf, sizeof buf, |
134 byte_order); | 135 byte_order); |
135 else | 136 else |
136 #endif | 137 #endif |
137 { | 138 { |
138 warning (_("Error reading helper thread's id in lib")); | 139 warning (_("Error reading helper thread's id in lib")); |
(...skipping 22 matching lines...) Expand all Loading... |
161 { | 162 { |
162 #ifdef HAVE_SYS_UN_H | 163 #ifdef HAVE_SYS_UN_H |
163 struct sockaddr_un addr; | 164 struct sockaddr_un addr; |
164 int res, fd; | 165 int res, fd; |
165 char path[UNIX_PATH_MAX]; | 166 char path[UNIX_PATH_MAX]; |
166 | 167 |
167 res = xsnprintf (path, UNIX_PATH_MAX, "%s/gdb_ust%d", P_tmpdir, pid); | 168 res = xsnprintf (path, UNIX_PATH_MAX, "%s/gdb_ust%d", P_tmpdir, pid); |
168 if (res >= UNIX_PATH_MAX) | 169 if (res >= UNIX_PATH_MAX) |
169 return -1; | 170 return -1; |
170 | 171 |
171 res = fd = socket (PF_UNIX, SOCK_STREAM, 0); | 172 res = fd = gdb_socket_cloexec (PF_UNIX, SOCK_STREAM, 0); |
172 if (res == -1) | 173 if (res == -1) |
173 { | 174 { |
174 warning (_("error opening sync socket: %s"), strerror (errno)); | 175 warning (_("error opening sync socket: %s"), strerror (errno)); |
175 return -1; | 176 return -1; |
176 } | 177 } |
177 | 178 |
178 addr.sun_family = AF_UNIX; | 179 addr.sun_family = AF_UNIX; |
179 | 180 |
180 res = xsnprintf (addr.sun_path, UNIX_PATH_MAX, "%s", path); | 181 res = xsnprintf (addr.sun_path, UNIX_PATH_MAX, "%s", path); |
181 if (res >= UNIX_PATH_MAX) | 182 if (res >= UNIX_PATH_MAX) |
(...skipping 29 matching lines...) Expand all Loading... |
211 agent_run_command (int pid, const char *cmd, int len) | 212 agent_run_command (int pid, const char *cmd, int len) |
212 { | 213 { |
213 int fd; | 214 int fd; |
214 int tid = agent_get_helper_thread_id (); | 215 int tid = agent_get_helper_thread_id (); |
215 ptid_t ptid = ptid_build (pid, tid, 0); | 216 ptid_t ptid = ptid_build (pid, tid, 0); |
216 | 217 |
217 #ifdef GDBSERVER | 218 #ifdef GDBSERVER |
218 int ret = write_inferior_memory (ipa_sym_addrs.addr_cmd_buf, | 219 int ret = write_inferior_memory (ipa_sym_addrs.addr_cmd_buf, |
219 (const unsigned char *) cmd, len); | 220 (const unsigned char *) cmd, len); |
220 #else | 221 #else |
221 int ret = target_write_memory (ipa_sym_addrs.addr_cmd_buf, cmd, len); | 222 int ret = target_write_memory (ipa_sym_addrs.addr_cmd_buf, |
| 223 » » » » (gdb_byte *) cmd, len); |
222 #endif | 224 #endif |
223 | 225 |
224 if (ret != 0) | 226 if (ret != 0) |
225 { | 227 { |
226 warning (_("unable to write")); | 228 warning (_("unable to write")); |
227 return -1; | 229 return -1; |
228 } | 230 } |
229 | 231 |
230 DEBUG_AGENT ("agent: resumed helper thread\n"); | 232 DEBUG_AGENT ("agent: resumed helper thread\n"); |
231 | 233 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 int | 327 int |
326 agent_capability_check (enum agent_capa agent_capa) | 328 agent_capability_check (enum agent_capa agent_capa) |
327 { | 329 { |
328 if (agent_capability == 0) | 330 if (agent_capability == 0) |
329 { | 331 { |
330 #ifdef GDBSERVER | 332 #ifdef GDBSERVER |
331 if (read_inferior_memory (ipa_sym_addrs.addr_capability, | 333 if (read_inferior_memory (ipa_sym_addrs.addr_capability, |
332 (unsigned char *) &agent_capability, | 334 (unsigned char *) &agent_capability, |
333 sizeof agent_capability)) | 335 sizeof agent_capability)) |
334 #else | 336 #else |
335 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); | 337 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ()); |
336 gdb_byte buf[4]; | 338 gdb_byte buf[4]; |
337 | 339 |
338 if (target_read_memory (ipa_sym_addrs.addr_capability, | 340 if (target_read_memory (ipa_sym_addrs.addr_capability, |
339 buf, sizeof buf) == 0) | 341 buf, sizeof buf) == 0) |
340 agent_capability = extract_unsigned_integer (buf, sizeof buf, | 342 agent_capability = extract_unsigned_integer (buf, sizeof buf, |
341 byte_order); | 343 byte_order); |
342 else | 344 else |
343 #endif | 345 #endif |
344 warning (_("Error reading capability of agent")); | 346 warning (_("Error reading capability of agent")); |
345 } | 347 } |
346 return agent_capability & agent_capa; | 348 return agent_capability & agent_capa; |
347 } | 349 } |
348 | 350 |
349 /* Invalidate the cache of agent capability, so we'll read it from inferior | 351 /* Invalidate the cache of agent capability, so we'll read it from inferior |
350 again. Call it when launches a new program or reconnect to remote stub. */ | 352 again. Call it when launches a new program or reconnect to remote stub. */ |
351 | 353 |
352 void | 354 void |
353 agent_capability_invalidate (void) | 355 agent_capability_invalidate (void) |
354 { | 356 { |
355 agent_capability = 0; | 357 agent_capability = 0; |
356 } | 358 } |
OLD | NEW |