]>
Commit | Line | Data |
---|---|---|
dd3b648e | 1 | /* Memory-access and commands for remote VxWorks processes, for GDB. |
e17960fb | 2 | Copyright 1990, 1991, 1992 Free Software Foundation, Inc. |
dd3b648e RP |
3 | Contributed by Wind River Systems and Cygnus Support. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
99a7de40 | 7 | This program is free software; you can redistribute it and/or modify |
dd3b648e | 8 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
dd3b648e | 11 | |
99a7de40 | 12 | This program is distributed in the hope that it will be useful, |
dd3b648e RP |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e RP |
20 | |
21 | #include "defs.h" | |
dd3b648e RP |
22 | #include "frame.h" |
23 | #include "inferior.h" | |
24 | #include "wait.h" | |
25 | #include "target.h" | |
26 | #include "gdbcore.h" | |
27 | #include "command.h" | |
28 | #include "symtab.h" | |
5998e362 | 29 | #include "complaints.h" |
56894788 | 30 | #include "gdbcmd.h" |
dd3b648e | 31 | |
dd3b648e RP |
32 | #include <string.h> |
33 | #include <errno.h> | |
34 | #include <signal.h> | |
35 | #include <fcntl.h> | |
36 | #include <sys/types.h> | |
dd3b648e | 37 | #include <sys/socket.h> |
0d6d92c7 | 38 | #define malloc bogon_malloc /* Sun claims "char *malloc()" not void * */ |
dd3b648e | 39 | #define free bogon_free /* Sun claims "int free()" not void */ |
b67903ac | 40 | #define realloc bogon_realloc /* Sun claims "char *realloc()", not void * */ |
dd3b648e | 41 | #include <rpc/rpc.h> |
0d6d92c7 | 42 | #undef malloc |
dd3b648e | 43 | #undef free |
b67903ac | 44 | #undef realloc |
dd3b648e RP |
45 | #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */ |
46 | #include <netdb.h> | |
aa942355 SG |
47 | #include "vx-share/ptrace.h" |
48 | #include "vx-share/xdr_ptrace.h" | |
49 | #include "vx-share/xdr_ld.h" | |
50 | #include "vx-share/xdr_rdb.h" | |
51 | #include "vx-share/dbgRpcLib.h" | |
dd3b648e | 52 | |
dd3b648e | 53 | #include <symtab.h> |
1ab3bf1b | 54 | |
dd3b648e | 55 | extern void symbol_file_command (); |
dd3b648e RP |
56 | extern int stop_soon_quietly; /* for wait_for_inferior */ |
57 | ||
58 | static int net_ptrace_clnt_call (); /* Forward decl */ | |
59 | static enum clnt_stat net_clnt_call (); /* Forward decl */ | |
60 | extern struct target_ops vx_ops, vx_run_ops; /* Forward declaration */ | |
61 | ||
62 | /* Saved name of target host and called function for "info files". | |
63 | Both malloc'd. */ | |
64 | ||
65 | static char *vx_host; | |
66 | static char *vx_running; /* Called function */ | |
67 | ||
68 | /* Nonzero means target that is being debugged remotely has a floating | |
69 | point processor. */ | |
70 | ||
71 | static int target_has_fp; | |
72 | ||
73 | /* Default error message when the network is forking up. */ | |
74 | ||
75 | static const char rpcerr[] = "network target debugging: rpc error"; | |
76 | ||
77 | CLIENT *pClient; /* client used in net debugging */ | |
78 | static int ptraceSock = RPC_ANYSOCK; | |
79 | ||
80 | enum clnt_stat net_clnt_call(); | |
81 | static void parse_args (); | |
82 | ||
83 | static struct timeval rpcTimeout = { 10, 0 }; | |
84 | ||
85 | static char *skip_white_space (); | |
86 | static char *find_white_space (); | |
87 | ||
88 | /* Tell the VxWorks target system to download a file. | |
89 | The load addresses of the text, data, and bss segments are | |
afc5505f | 90 | stored in *pTextAddr, *pDataAddr, and *pBssAddr (respectively). |
dd3b648e RP |
91 | Returns 0 for success, -1 for failure. */ |
92 | ||
93 | static int | |
94 | net_load (filename, pTextAddr, pDataAddr, pBssAddr) | |
95 | char *filename; | |
96 | CORE_ADDR *pTextAddr; | |
97 | CORE_ADDR *pDataAddr; | |
98 | CORE_ADDR *pBssAddr; | |
99 | { | |
100 | enum clnt_stat status; | |
101 | struct ldfile ldstruct; | |
102 | struct timeval load_timeout; | |
103 | ||
4ed97c9a | 104 | memset ((char *) &ldstruct, '\0', sizeof (ldstruct)); |
dd3b648e RP |
105 | |
106 | /* We invoke clnt_call () here directly, instead of through | |
107 | net_clnt_call (), because we need to set a large timeout value. | |
108 | The load on the target side can take quite a while, easily | |
109 | more than 10 seconds. The user can kill this call by typing | |
110 | CTRL-C if there really is a problem with the load. | |
afc5505f | 111 | |
dd3b648e RP |
112 | Do not change the tv_sec value without checking -- select() imposes |
113 | a limit of 10**8 on it for no good reason that I can see... */ | |
114 | ||
115 | load_timeout.tv_sec = 99999999; /* A large number, effectively inf. */ | |
116 | load_timeout.tv_usec = 0; | |
117 | ||
118 | status = clnt_call (pClient, VX_LOAD, xdr_wrapstring, &filename, xdr_ldfile, | |
119 | &ldstruct, load_timeout); | |
120 | ||
121 | if (status == RPC_SUCCESS) | |
122 | { | |
afc5505f | 123 | if (*ldstruct.name == 0) /* load failed on VxWorks side */ |
dd3b648e RP |
124 | return -1; |
125 | *pTextAddr = ldstruct.txt_addr; | |
126 | *pDataAddr = ldstruct.data_addr; | |
127 | *pBssAddr = ldstruct.bss_addr; | |
128 | return 0; | |
129 | } | |
130 | else | |
131 | return -1; | |
132 | } | |
133 | ||
134 | /* returns 0 if successful, errno if RPC failed or VxWorks complains. */ | |
135 | ||
136 | static int | |
137 | net_break (addr, procnum) | |
138 | int addr; | |
139 | u_long procnum; | |
140 | { | |
141 | enum clnt_stat status; | |
142 | int break_status; | |
143 | Rptrace ptrace_in; /* XXX This is stupid. It doesn't need to be a ptrace | |
144 | structure. How about something smaller? */ | |
145 | ||
4ed97c9a | 146 | memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in)); |
dd3b648e RP |
147 | break_status = 0; |
148 | ||
149 | ptrace_in.addr = addr; | |
150 | ptrace_in.pid = inferior_pid; | |
151 | ||
152 | status = net_clnt_call (procnum, xdr_rptrace, &ptrace_in, xdr_int, | |
153 | &break_status); | |
154 | ||
155 | if (status != RPC_SUCCESS) | |
156 | return errno; | |
157 | ||
158 | if (break_status == -1) | |
159 | return ENOMEM; | |
160 | return break_status; /* probably (FIXME) zero */ | |
161 | } | |
162 | ||
163 | /* returns 0 if successful, errno otherwise */ | |
164 | ||
8616205a | 165 | static int |
dd3b648e RP |
166 | vx_insert_breakpoint (addr) |
167 | int addr; | |
168 | { | |
169 | return net_break (addr, VX_BREAK_ADD); | |
170 | } | |
171 | ||
172 | /* returns 0 if successful, errno otherwise */ | |
173 | ||
8616205a | 174 | static int |
dd3b648e RP |
175 | vx_remove_breakpoint (addr) |
176 | int addr; | |
177 | { | |
178 | return net_break (addr, VX_BREAK_DELETE); | |
179 | } | |
180 | ||
dd3b648e RP |
181 | /* Start an inferior process and sets inferior_pid to its pid. |
182 | EXEC_FILE is the file to run. | |
183 | ALLARGS is a string containing the arguments to the program. | |
184 | ENV is the environment vector to pass. | |
185 | Returns process id. Errors reported with error(). | |
186 | On VxWorks, we ignore exec_file. */ | |
187 | ||
8616205a | 188 | static void |
dd3b648e RP |
189 | vx_create_inferior (exec_file, args, env) |
190 | char *exec_file; | |
191 | char *args; | |
192 | char **env; | |
193 | { | |
194 | enum clnt_stat status; | |
195 | arg_array passArgs; | |
196 | TASK_START taskStart; | |
197 | ||
4ed97c9a RP |
198 | memset ((char *) &passArgs, '\0', sizeof (passArgs)); |
199 | memset ((char *) &taskStart, '\0', sizeof (taskStart)); | |
dd3b648e RP |
200 | |
201 | /* parse arguments, put them in passArgs */ | |
202 | ||
203 | parse_args (args, &passArgs); | |
204 | ||
205 | if (passArgs.arg_array_len == 0) | |
206 | error ("You must specify a function name to run, and arguments if any"); | |
207 | ||
208 | status = net_clnt_call (PROCESS_START, xdr_arg_array, &passArgs, | |
209 | xdr_TASK_START, &taskStart); | |
210 | ||
211 | if ((status != RPC_SUCCESS) || (taskStart.status == -1)) | |
212 | error ("Can't create process on remote target machine"); | |
213 | ||
214 | /* Save the name of the running function */ | |
215 | vx_running = savestring (passArgs.arg_array_val[0], | |
216 | strlen (passArgs.arg_array_val[0])); | |
217 | ||
dd3b648e RP |
218 | push_target (&vx_run_ops); |
219 | inferior_pid = taskStart.pid; | |
220 | ||
dd3b648e RP |
221 | /* We will get a trace trap after one instruction. |
222 | Insert breakpoints and continue. */ | |
223 | ||
224 | init_wait_for_inferior (); | |
225 | ||
226 | /* Set up the "saved terminal modes" of the inferior | |
227 | based on what modes we are starting it with. */ | |
228 | target_terminal_init (); | |
229 | ||
230 | /* Install inferior's terminal modes. */ | |
231 | target_terminal_inferior (); | |
232 | ||
dd3b648e RP |
233 | stop_soon_quietly = 1; |
234 | wait_for_inferior (); /* Get the task spawn event */ | |
235 | stop_soon_quietly = 0; | |
236 | ||
237 | /* insert_step_breakpoint (); FIXME, do we need this? */ | |
45dc9be3 | 238 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
dd3b648e RP |
239 | } |
240 | ||
241 | /* Fill ARGSTRUCT in argc/argv form with the arguments from the | |
242 | argument string ARGSTRING. */ | |
243 | ||
244 | static void | |
245 | parse_args (arg_string, arg_struct) | |
246 | register char *arg_string; | |
247 | arg_array *arg_struct; | |
248 | { | |
249 | register int arg_count = 0; /* number of arguments */ | |
250 | register int arg_index = 0; | |
251 | register char *p0; | |
252 | ||
4ed97c9a | 253 | memset ((char *) arg_struct, '\0', sizeof (arg_array)); |
dd3b648e RP |
254 | |
255 | /* first count how many arguments there are */ | |
256 | ||
257 | p0 = arg_string; | |
258 | while (*p0 != '\0') | |
259 | { | |
260 | if (*(p0 = skip_white_space (p0)) == '\0') | |
261 | break; | |
262 | p0 = find_white_space (p0); | |
263 | arg_count++; | |
264 | } | |
265 | ||
266 | arg_struct->arg_array_len = arg_count; | |
267 | arg_struct->arg_array_val = (char **) xmalloc ((arg_count + 1) | |
268 | * sizeof (char *)); | |
269 | ||
270 | /* now copy argument strings into arg_struct. */ | |
271 | ||
272 | while (*(arg_string = skip_white_space (arg_string))) | |
273 | { | |
274 | p0 = find_white_space (arg_string); | |
275 | arg_struct->arg_array_val[arg_index++] = savestring (arg_string, | |
276 | p0 - arg_string); | |
277 | arg_string = p0; | |
278 | } | |
279 | ||
280 | arg_struct->arg_array_val[arg_count] = NULL; | |
281 | } | |
282 | ||
283 | /* Advance a string pointer across whitespace and return a pointer | |
284 | to the first non-white character. */ | |
285 | ||
286 | static char * | |
287 | skip_white_space (p) | |
288 | register char *p; | |
289 | { | |
290 | while (*p == ' ' || *p == '\t') | |
291 | p++; | |
292 | return p; | |
293 | } | |
294 | ||
295 | /* Search for the first unquoted whitespace character in a string. | |
296 | Returns a pointer to the character, or to the null terminator | |
297 | if no whitespace is found. */ | |
298 | ||
299 | static char * | |
300 | find_white_space (p) | |
301 | register char *p; | |
302 | { | |
303 | register int c; | |
304 | ||
305 | while ((c = *p) != ' ' && c != '\t' && c) | |
306 | { | |
307 | if (c == '\'' || c == '"') | |
308 | { | |
309 | while (*++p != c && *p) | |
310 | { | |
311 | if (*p == '\\') | |
312 | p++; | |
313 | } | |
314 | if (!*p) | |
315 | break; | |
316 | } | |
317 | p++; | |
318 | } | |
319 | return p; | |
320 | } | |
321 | ||
322 | /* Poll the VxWorks target system for an event related | |
323 | to the debugged task. | |
324 | Returns -1 if remote wait failed, task status otherwise. */ | |
325 | ||
8616205a | 326 | static int |
dd3b648e RP |
327 | net_wait (pEvent) |
328 | RDB_EVENT *pEvent; | |
329 | { | |
330 | int pid; | |
331 | enum clnt_stat status; | |
332 | ||
4ed97c9a | 333 | memset ((char *) pEvent, '\0', sizeof (RDB_EVENT)); |
dd3b648e RP |
334 | |
335 | pid = inferior_pid; | |
336 | status = net_clnt_call (PROCESS_WAIT, xdr_int, &pid, xdr_RDB_EVENT, pEvent); | |
337 | ||
338 | return (status == RPC_SUCCESS)? pEvent->status: -1; | |
339 | } | |
340 | ||
341 | /* Suspend the remote task. | |
342 | Returns -1 if suspend fails on target system, 0 otherwise. */ | |
343 | ||
8616205a | 344 | static int |
dd3b648e RP |
345 | net_quit () |
346 | { | |
347 | int pid; | |
348 | int quit_status; | |
349 | enum clnt_stat status; | |
350 | ||
351 | quit_status = 0; | |
352 | ||
353 | /* don't let rdbTask suspend itself by passing a pid of 0 */ | |
354 | ||
355 | if ((pid = inferior_pid) == 0) | |
356 | return -1; | |
357 | ||
358 | status = net_clnt_call (VX_TASK_SUSPEND, xdr_int, &pid, xdr_int, | |
359 | &quit_status); | |
360 | ||
361 | return (status == RPC_SUCCESS)? quit_status: -1; | |
362 | } | |
363 | ||
364 | /* Read a register or registers from the remote system. */ | |
365 | ||
8616205a | 366 | static void |
dd3b648e RP |
367 | vx_read_register (regno) |
368 | int regno; | |
369 | { | |
370 | int status; | |
371 | Rptrace ptrace_in; | |
372 | Ptrace_return ptrace_out; | |
8616205a SG |
373 | C_bytes in_data; |
374 | C_bytes out_data; | |
dd3b648e RP |
375 | extern char registers[]; |
376 | ||
4ed97c9a RP |
377 | memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in)); |
378 | memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out)); | |
dd3b648e RP |
379 | |
380 | /* FIXME, eventually only get the ones we need. */ | |
381 | registers_fetched (); | |
382 | ||
383 | ptrace_in.pid = inferior_pid; | |
8616205a | 384 | ptrace_out.info.more_data = (caddr_t) &out_data; |
35799202 | 385 | out_data.len = VX_NUM_REGS * REGISTER_RAW_SIZE (0); |
8616205a SG |
386 | out_data.bytes = (caddr_t) registers; |
387 | ||
dd3b648e RP |
388 | status = net_ptrace_clnt_call (PTRACE_GETREGS, &ptrace_in, &ptrace_out); |
389 | if (status) | |
390 | error (rpcerr); | |
391 | if (ptrace_out.status == -1) | |
392 | { | |
393 | errno = ptrace_out.errno; | |
8616205a | 394 | perror_with_name ("net_ptrace_clnt_call(PTRACE_GETREGS)"); |
dd3b648e RP |
395 | } |
396 | ||
35799202 | 397 | #ifdef VX_SIZE_FPREGS |
afc5505f KR |
398 | /* If the target has floating point registers, fetch them. |
399 | Otherwise, zero the floating point register values in | |
400 | registers[] for good measure, even though we might not | |
401 | need to. */ | |
dd3b648e | 402 | |
dd3b648e RP |
403 | if (target_has_fp) |
404 | { | |
405 | ptrace_in.pid = inferior_pid; | |
8616205a | 406 | ptrace_out.info.more_data = (caddr_t) &out_data; |
35799202 | 407 | out_data.len = VX_SIZE_FPREGS; |
8616205a SG |
408 | out_data.bytes = (caddr_t) ®isters[REGISTER_BYTE (FP0_REGNUM)]; |
409 | ||
dd3b648e RP |
410 | status = net_ptrace_clnt_call (PTRACE_GETFPREGS, &ptrace_in, &ptrace_out); |
411 | if (status) | |
412 | error (rpcerr); | |
413 | if (ptrace_out.status == -1) | |
414 | { | |
415 | errno = ptrace_out.errno; | |
8616205a | 416 | perror_with_name ("net_ptrace_clnt_call(PTRACE_GETFPREGS)"); |
dd3b648e | 417 | } |
dd3b648e RP |
418 | } |
419 | else | |
420 | { | |
4ed97c9a | 421 | memset (®isters[REGISTER_BYTE (FP0_REGNUM)], '\0', VX_SIZE_FPREGS); |
dd3b648e | 422 | } |
35799202 | 423 | #endif /* VX_SIZE_FPREGS */ |
dd3b648e RP |
424 | } |
425 | ||
426 | /* Prepare to store registers. Since we will store all of them, | |
427 | read out their current values now. */ | |
428 | ||
8616205a | 429 | static void |
dd3b648e RP |
430 | vx_prepare_to_store () |
431 | { | |
4ddd278f JG |
432 | /* Fetch all registers, if any of them are not yet fetched. */ |
433 | read_register_bytes (0, NULL, REGISTER_BYTES); | |
dd3b648e RP |
434 | } |
435 | ||
436 | ||
437 | /* Store our register values back into the inferior. | |
438 | If REGNO is -1, do this for all registers. | |
439 | Otherwise, REGNO specifies which register (so we can save time). */ | |
440 | /* FIXME, look at REGNO to save time here */ | |
441 | ||
8616205a | 442 | static void |
dd3b648e RP |
443 | vx_write_register (regno) |
444 | int regno; | |
445 | { | |
8616205a SG |
446 | C_bytes in_data; |
447 | C_bytes out_data; | |
dd3b648e RP |
448 | extern char registers[]; |
449 | int status; | |
450 | Rptrace ptrace_in; | |
451 | Ptrace_return ptrace_out; | |
452 | ||
4ed97c9a RP |
453 | memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in)); |
454 | memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out)); | |
dd3b648e | 455 | |
8616205a SG |
456 | ptrace_in.pid = inferior_pid; |
457 | ptrace_in.info.ttype = DATA; | |
458 | ptrace_in.info.more_data = (caddr_t) &in_data; | |
459 | ||
460 | in_data.bytes = registers; | |
461 | ||
f4f0d174 | 462 | in_data.len = VX_NUM_REGS * REGISTER_SIZE; |
dd3b648e | 463 | |
dd3b648e RP |
464 | /* XXX change second param to be a proc number */ |
465 | status = net_ptrace_clnt_call (PTRACE_SETREGS, &ptrace_in, &ptrace_out); | |
466 | if (status) | |
467 | error (rpcerr); | |
468 | if (ptrace_out.status == -1) | |
469 | { | |
470 | errno = ptrace_out.errno; | |
8616205a | 471 | perror_with_name ("net_ptrace_clnt_call(PTRACE_SETREGS)"); |
dd3b648e RP |
472 | } |
473 | ||
35799202 | 474 | #ifdef VX_SIZE_FPREGS |
dd3b648e RP |
475 | /* Store floating point registers if the target has them. */ |
476 | ||
477 | if (target_has_fp) | |
478 | { | |
8616205a SG |
479 | ptrace_in.pid = inferior_pid; |
480 | ptrace_in.info.ttype = DATA; | |
481 | ptrace_in.info.more_data = (caddr_t) &in_data; | |
482 | ||
483 | ||
afc5505f | 484 | in_data.bytes = ®isters[REGISTER_BYTE (FP0_REGNUM)]; |
35799202 | 485 | in_data.len = VX_SIZE_FPREGS; |
dd3b648e | 486 | |
dd3b648e RP |
487 | status = net_ptrace_clnt_call (PTRACE_SETFPREGS, &ptrace_in, &ptrace_out); |
488 | if (status) | |
489 | error (rpcerr); | |
490 | if (ptrace_out.status == -1) | |
491 | { | |
492 | errno = ptrace_out.errno; | |
8616205a | 493 | perror_with_name ("net_ptrace_clnt_call(PTRACE_SETFPREGS)"); |
dd3b648e RP |
494 | } |
495 | } | |
35799202 | 496 | #endif /* VX_SIZE_FPREGS */ |
dd3b648e RP |
497 | } |
498 | ||
499 | /* Copy LEN bytes to or from remote inferior's memory starting at MEMADDR | |
500 | to debugger memory starting at MYADDR. WRITE is true if writing to the | |
501 | inferior. | |
502 | Result is the number of bytes written or read (zero if error). The | |
503 | protocol allows us to return a negative count, indicating that we can't | |
504 | handle the current address but can handle one N bytes further, but | |
505 | vxworks doesn't give us that information. */ | |
506 | ||
8616205a | 507 | static int |
8f1f2a72 | 508 | vx_xfer_memory (memaddr, myaddr, len, write, target) |
dd3b648e RP |
509 | CORE_ADDR memaddr; |
510 | char *myaddr; | |
511 | int len; | |
8f1f2a72 JG |
512 | int write; |
513 | struct target_ops *target; /* ignored */ | |
dd3b648e RP |
514 | { |
515 | int status; | |
516 | Rptrace ptrace_in; | |
517 | Ptrace_return ptrace_out; | |
518 | C_bytes data; | |
519 | ||
4ed97c9a RP |
520 | memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in)); |
521 | memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out)); | |
dd3b648e RP |
522 | |
523 | ptrace_in.pid = inferior_pid; /* XXX pid unnecessary for READDATA */ | |
524 | ptrace_in.addr = (int) memaddr; /* Where from */ | |
525 | ptrace_in.data = len; /* How many bytes */ | |
526 | ||
527 | if (write) | |
528 | { | |
529 | ptrace_in.info.ttype = DATA; | |
530 | ptrace_in.info.more_data = (caddr_t) &data; | |
531 | ||
532 | data.bytes = (caddr_t) myaddr; /* Where from */ | |
533 | data.len = len; /* How many bytes (again, for XDR) */ | |
534 | ||
535 | /* XXX change second param to be a proc number */ | |
536 | status = net_ptrace_clnt_call (PTRACE_WRITEDATA, &ptrace_in, &ptrace_out); | |
537 | } | |
538 | else | |
539 | { | |
540 | ptrace_out.info.more_data = (caddr_t) &data; | |
541 | data.bytes = myaddr; /* Where to */ | |
542 | data.len = len; /* How many (again, for XDR) */ | |
543 | ||
544 | /* XXX change second param to be a proc number */ | |
545 | status = net_ptrace_clnt_call (PTRACE_READDATA, &ptrace_in, &ptrace_out); | |
546 | } | |
547 | ||
548 | if (status) | |
549 | error (rpcerr); | |
550 | if (ptrace_out.status == -1) | |
551 | { | |
552 | return 0; /* No bytes moved */ | |
553 | } | |
554 | return len; /* Moved *all* the bytes */ | |
555 | } | |
556 | ||
8616205a | 557 | static void |
dd3b648e RP |
558 | vx_files_info () |
559 | { | |
199b2450 TL |
560 | printf_unfiltered ("\tAttached to host `%s'", vx_host); |
561 | printf_unfiltered (", which has %sfloating point", target_has_fp? "": "no "); | |
562 | printf_unfiltered (".\n"); | |
dd3b648e RP |
563 | } |
564 | ||
8616205a | 565 | static void |
dd3b648e RP |
566 | vx_run_files_info () |
567 | { | |
199b2450 | 568 | printf_unfiltered ("\tRunning %s VxWorks process %s", |
833e0d94 JK |
569 | vx_running ? "child" : "attached", |
570 | local_hex_string (inferior_pid)); | |
dd3b648e | 571 | if (vx_running) |
199b2450 TL |
572 | printf_unfiltered (", function `%s'", vx_running); |
573 | printf_unfiltered(".\n"); | |
dd3b648e RP |
574 | } |
575 | ||
8616205a | 576 | static void |
25286543 SG |
577 | vx_resume (pid, step, siggnal) |
578 | int pid; | |
dd3b648e | 579 | int step; |
67ac9759 | 580 | enum target_signal siggnal; |
dd3b648e RP |
581 | { |
582 | int status; | |
583 | Rptrace ptrace_in; | |
584 | Ptrace_return ptrace_out; | |
585 | ||
de43d7d0 SG |
586 | if (pid == -1) |
587 | pid = inferior_pid; | |
588 | ||
dd3b648e RP |
589 | if (siggnal != 0 && siggnal != stop_signal) |
590 | error ("Cannot send signals to VxWorks processes"); | |
591 | ||
4ed97c9a RP |
592 | memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in)); |
593 | memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out)); | |
dd3b648e | 594 | |
25286543 | 595 | ptrace_in.pid = pid; |
dd3b648e RP |
596 | ptrace_in.addr = 1; /* Target side insists on this, or it panics. */ |
597 | ||
598 | /* XXX change second param to be a proc number */ | |
599 | status = net_ptrace_clnt_call (step? PTRACE_SINGLESTEP: PTRACE_CONT, | |
600 | &ptrace_in, &ptrace_out); | |
601 | if (status) | |
602 | error (rpcerr); | |
603 | if (ptrace_out.status == -1) | |
604 | { | |
605 | errno = ptrace_out.errno; | |
606 | perror_with_name ("Resuming remote process"); | |
607 | } | |
608 | } | |
609 | ||
8616205a | 610 | static void |
dd3b648e RP |
611 | vx_mourn_inferior () |
612 | { | |
613 | pop_target (); /* Pop back to no-child state */ | |
614 | generic_mourn_inferior (); | |
615 | } | |
616 | ||
617 | \f | |
618 | /* This function allows the addition of incrementally linked object files. */ | |
619 | ||
8616205a | 620 | static void |
dd3b648e RP |
621 | vx_load_command (arg_string, from_tty) |
622 | char* arg_string; | |
623 | int from_tty; | |
624 | { | |
625 | CORE_ADDR text_addr; | |
626 | CORE_ADDR data_addr; | |
627 | CORE_ADDR bss_addr; | |
628 | ||
629 | if (arg_string == 0) | |
630 | error ("The load command takes a file name"); | |
631 | ||
632 | arg_string = tilde_expand (arg_string); | |
633 | make_cleanup (free, arg_string); | |
634 | ||
635 | dont_repeat (); | |
636 | ||
637 | QUIT; | |
638 | immediate_quit++; | |
639 | if (net_load (arg_string, &text_addr, &data_addr, &bss_addr) == -1) | |
640 | error ("Load failed on target machine"); | |
641 | immediate_quit--; | |
642 | ||
643 | /* FIXME, for now we ignore data_addr and bss_addr. */ | |
4ed3a9ea | 644 | symbol_file_add (arg_string, from_tty, text_addr, 0, 0, 0); |
46d185d3 PS |
645 | |
646 | /* Getting new symbols may change our opinion about what is | |
647 | frameless. */ | |
648 | reinit_frame_cache (); | |
dd3b648e RP |
649 | } |
650 | ||
651 | #ifdef FIXME /* Not ready for prime time */ | |
652 | /* Single step the target program at the source or machine level. | |
653 | Takes an error exit if rpc fails. | |
654 | Returns -1 if remote single-step operation fails, else 0. */ | |
655 | ||
656 | static int | |
657 | net_step () | |
658 | { | |
659 | enum clnt_stat status; | |
660 | int step_status; | |
661 | SOURCE_STEP source_step; | |
662 | ||
663 | source_step.taskId = inferior_pid; | |
664 | ||
665 | if (step_range_end) | |
666 | { | |
667 | source_step.startAddr = step_range_start; | |
668 | source_step.endAddr = step_range_end; | |
669 | } | |
670 | else | |
671 | { | |
672 | source_step.startAddr = 0; | |
673 | source_step.endAddr = 0; | |
674 | } | |
675 | ||
676 | status = net_clnt_call (VX_SOURCE_STEP, xdr_SOURCE_STEP, &source_step, | |
677 | xdr_int, &step_status); | |
678 | ||
679 | if (status == RPC_SUCCESS) | |
680 | return step_status; | |
681 | else | |
682 | error (rpcerr); | |
683 | } | |
684 | #endif | |
685 | ||
686 | /* Emulate ptrace using RPC calls to the VxWorks target system. | |
687 | Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */ | |
688 | ||
689 | static int | |
690 | net_ptrace_clnt_call (request, pPtraceIn, pPtraceOut) | |
691 | enum ptracereq request; | |
692 | Rptrace *pPtraceIn; | |
693 | Ptrace_return *pPtraceOut; | |
694 | { | |
695 | enum clnt_stat status; | |
696 | ||
697 | status = net_clnt_call (request, xdr_rptrace, pPtraceIn, xdr_ptrace_return, | |
698 | pPtraceOut); | |
699 | ||
700 | if (status != RPC_SUCCESS) | |
701 | return -1; | |
702 | ||
703 | return 0; | |
704 | } | |
705 | ||
706 | /* Query the target for the name of the file from which VxWorks was | |
707 | booted. pBootFile is the address of a pointer to the buffer to | |
708 | receive the file name; if the pointer pointed to by pBootFile is | |
709 | NULL, memory for the buffer will be allocated by XDR. | |
710 | Returns -1 if rpc failed, 0 otherwise. */ | |
711 | ||
8616205a | 712 | static int |
dd3b648e RP |
713 | net_get_boot_file (pBootFile) |
714 | char **pBootFile; | |
715 | { | |
716 | enum clnt_stat status; | |
717 | ||
718 | status = net_clnt_call (VX_BOOT_FILE_INQ, xdr_void, (char *) 0, | |
719 | xdr_wrapstring, pBootFile); | |
720 | return (status == RPC_SUCCESS) ? 0 : -1; | |
721 | } | |
722 | ||
723 | /* Fetch a list of loaded object modules from the VxWorks target. | |
724 | Returns -1 if rpc failed, 0 otherwise | |
725 | There's no way to check if the returned loadTable is correct. | |
726 | VxWorks doesn't check it. */ | |
727 | ||
8616205a | 728 | static int |
dd3b648e RP |
729 | net_get_symbols (pLoadTable) |
730 | ldtabl *pLoadTable; /* return pointer to ldtabl here */ | |
731 | { | |
732 | enum clnt_stat status; | |
733 | ||
4ed97c9a | 734 | memset ((char *) pLoadTable, '\0', sizeof (struct ldtabl)); |
dd3b648e RP |
735 | |
736 | status = net_clnt_call (VX_STATE_INQ, xdr_void, 0, xdr_ldtabl, pLoadTable); | |
737 | return (status == RPC_SUCCESS) ? 0 : -1; | |
738 | } | |
739 | ||
740 | /* Look up a symbol in the VxWorks target's symbol table. | |
741 | Returns status of symbol read on target side (0=success, -1=fail) | |
742 | Returns -1 and complain()s if rpc fails. */ | |
743 | ||
744 | struct complaint cant_contact_target = | |
745 | {"Lost contact with VxWorks target", 0, 0}; | |
746 | ||
8616205a | 747 | static int |
dd3b648e RP |
748 | vx_lookup_symbol (name, pAddr) |
749 | char *name; /* symbol name */ | |
750 | CORE_ADDR *pAddr; | |
751 | { | |
752 | enum clnt_stat status; | |
753 | SYMBOL_ADDR symbolAddr; | |
754 | ||
755 | *pAddr = 0; | |
4ed97c9a | 756 | memset ((char *) &symbolAddr, '\0', sizeof (symbolAddr)); |
dd3b648e RP |
757 | |
758 | status = net_clnt_call (VX_SYMBOL_INQ, xdr_wrapstring, &name, | |
759 | xdr_SYMBOL_ADDR, &symbolAddr); | |
760 | if (status != RPC_SUCCESS) { | |
51b80b00 | 761 | complain (&cant_contact_target); |
dd3b648e RP |
762 | return -1; |
763 | } | |
764 | ||
765 | *pAddr = symbolAddr.addr; | |
766 | return symbolAddr.status; | |
767 | } | |
768 | ||
769 | /* Check to see if the VxWorks target has a floating point coprocessor. | |
770 | Returns 1 if target has floating point processor, 0 otherwise. | |
771 | Calls error() if rpc fails. */ | |
772 | ||
8616205a | 773 | static int |
dd3b648e RP |
774 | net_check_for_fp () |
775 | { | |
776 | enum clnt_stat status; | |
777 | bool_t fp = 0; /* true if fp processor is present on target board */ | |
778 | ||
779 | status = net_clnt_call (VX_FP_INQUIRE, xdr_void, 0, xdr_bool, &fp); | |
780 | if (status != RPC_SUCCESS) | |
781 | error (rpcerr); | |
782 | ||
783 | return (int) fp; | |
784 | } | |
785 | ||
786 | /* Establish an RPC connection with the VxWorks target system. | |
787 | Calls error () if unable to establish connection. */ | |
788 | ||
8616205a | 789 | static void |
dd3b648e RP |
790 | net_connect (host) |
791 | char *host; | |
792 | { | |
793 | struct sockaddr_in destAddr; | |
794 | struct hostent *destHost; | |
ebe8362f JK |
795 | unsigned long addr; |
796 | ||
797 | /* Get the internet address for the given host. Allow a numeric | |
798 | IP address or a hostname. */ | |
dd3b648e | 799 | |
ebe8362f JK |
800 | addr = inet_addr (host); |
801 | if (addr == -1) | |
802 | { | |
803 | destHost = (struct hostent *) gethostbyname (host); | |
804 | if (destHost == NULL) | |
805 | error ("Invalid hostname. Couldn't find remote host address."); | |
806 | addr = * (unsigned long *) destHost->h_addr; | |
807 | } | |
dd3b648e | 808 | |
4ed97c9a | 809 | memset (&destAddr, '\0', sizeof (destAddr)); |
dd3b648e | 810 | |
ebe8362f | 811 | destAddr.sin_addr.s_addr = addr; |
dd3b648e RP |
812 | destAddr.sin_family = AF_INET; |
813 | destAddr.sin_port = 0; /* set to actual port that remote | |
814 | ptrace is listening on. */ | |
815 | ||
816 | /* Create a tcp client transport on which to issue | |
817 | calls to the remote ptrace server. */ | |
818 | ||
819 | ptraceSock = RPC_ANYSOCK; | |
820 | pClient = clnttcp_create (&destAddr, RDBPROG, RDBVERS, &ptraceSock, 0, 0); | |
821 | /* FIXME, here is where we deal with different version numbers of the proto */ | |
822 | ||
823 | if (pClient == NULL) | |
824 | { | |
825 | clnt_pcreateerror ("\tnet_connect"); | |
826 | error ("Couldn't connect to remote target."); | |
827 | } | |
828 | } | |
829 | \f | |
830 | /* Sleep for the specified number of milliseconds | |
831 | * (assumed to be less than 1000). | |
832 | * If select () is interrupted, returns immediately; | |
833 | * takes an error exit if select () fails for some other reason. | |
834 | */ | |
835 | ||
836 | static void | |
837 | sleep_ms (ms) | |
838 | long ms; | |
839 | { | |
840 | struct timeval select_timeout; | |
841 | int status; | |
842 | ||
843 | select_timeout.tv_sec = 0; | |
844 | select_timeout.tv_usec = ms * 1000; | |
845 | ||
846 | status = select (0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &select_timeout); | |
847 | ||
848 | if (status < 0 && errno != EINTR) | |
849 | perror_with_name ("select"); | |
850 | } | |
851 | ||
852 | /* Wait for control to return from inferior to debugger. | |
853 | If inferior gets a signal, we may decide to start it up again | |
854 | instead of returning. That is why there is a loop in this function. | |
855 | When this function actually returns it means the inferior | |
856 | should be left stopped and GDB should read more commands. */ | |
857 | ||
858 | /* For network debugging with VxWorks. | |
859 | * VxWorks knows when tasks hit breakpoints, receive signals, exit, etc, | |
860 | * so vx_wait() receives this information directly from | |
861 | * VxWorks instead of trying to figure out what happenned via a wait() call. | |
862 | */ | |
863 | ||
864 | static int | |
c3cabecb JK |
865 | vx_wait (pid_to_wait_for, status) |
866 | int pid_to_wait_for; | |
67ac9759 | 867 | struct target_waitstatus *status; |
dd3b648e RP |
868 | { |
869 | register int pid; | |
dd3b648e RP |
870 | RDB_EVENT rdbEvent; |
871 | int quit_failed; | |
872 | ||
873 | do | |
874 | { | |
875 | /* If CTRL-C is hit during this loop, | |
876 | suspend the inferior process. */ | |
877 | ||
878 | quit_failed = 0; | |
879 | if (quit_flag) | |
880 | { | |
881 | quit_failed = (net_quit () == -1); | |
882 | quit_flag = 0; | |
883 | } | |
884 | ||
885 | /* If a net_quit () or net_wait () call has failed, | |
886 | allow the user to break the connection with the target. | |
887 | We can't simply error () out of this loop, since the | |
888 | data structures representing the state of the inferior | |
889 | are in an inconsistent state. */ | |
890 | ||
891 | if (quit_failed || net_wait (&rdbEvent) == -1) | |
892 | { | |
893 | terminal_ours (); | |
894 | if (query ("Can't %s. Disconnect from target system? ", | |
895 | (quit_failed) ? "suspend remote task" | |
896 | : "get status of remote task")) | |
897 | { | |
898 | target_mourn_inferior(); | |
899 | error ("Use the \"target\" command to reconnect."); | |
900 | } | |
901 | else | |
902 | { | |
903 | terminal_inferior (); | |
904 | continue; | |
905 | } | |
906 | } | |
907 | ||
908 | pid = rdbEvent.taskId; | |
909 | if (pid == 0) | |
910 | { | |
911 | sleep_ms (200); /* FIXME Don't kill the network too badly */ | |
912 | } | |
913 | else if (pid != inferior_pid) | |
5573d7d4 JK |
914 | fatal ("Bad pid for debugged task: %s\n", |
915 | local_hex_string((unsigned long) pid)); | |
dd3b648e RP |
916 | } while (pid == 0); |
917 | ||
67ac9759 JK |
918 | /* The mostly likely kind. */ |
919 | status->kind = TARGET_WAITKIND_STOPPED; | |
920 | ||
dd3b648e RP |
921 | switch (rdbEvent.eventType) |
922 | { | |
923 | case EVENT_EXIT: | |
67ac9759 | 924 | status->kind = TARGET_WAITKIND_EXITED; |
dd3b648e | 925 | /* FIXME is it possible to distinguish between a |
67ac9759 JK |
926 | normal vs abnormal exit in VxWorks? */ |
927 | status->value.integer = 0; | |
dd3b648e RP |
928 | break; |
929 | ||
67ac9759 JK |
930 | case EVENT_START: |
931 | /* Task was just started. */ | |
932 | status->value.sig = TARGET_SIGNAL_TRAP; | |
dd3b648e RP |
933 | break; |
934 | ||
935 | case EVENT_STOP: | |
67ac9759 | 936 | status->value.sig = TARGET_SIGNAL_TRAP; |
dd3b648e RP |
937 | /* XXX was it stopped by a signal? act accordingly */ |
938 | break; | |
939 | ||
940 | case EVENT_BREAK: /* Breakpoint was hit. */ | |
67ac9759 | 941 | status->value.sig = TARGET_SIGNAL_TRAP; |
dd3b648e RP |
942 | break; |
943 | ||
944 | case EVENT_SUSPEND: /* Task was suspended, probably by ^C. */ | |
67ac9759 | 945 | status->value.sig = TARGET_SIGNAL_INT; |
dd3b648e RP |
946 | break; |
947 | ||
948 | case EVENT_BUS_ERR: /* Task made evil nasty reference. */ | |
67ac9759 | 949 | status->value.sig = TARGET_SIGNAL_BUS; |
dd3b648e RP |
950 | break; |
951 | ||
952 | case EVENT_ZERO_DIV: /* Division by zero */ | |
67ac9759 | 953 | status->value.sig = TARGET_SIGNAL_FPE; |
021959e2 | 954 | break; |
dd3b648e RP |
955 | |
956 | case EVENT_SIGNAL: | |
d0acb092 | 957 | #ifdef I80960 |
67ac9759 | 958 | status->value.sig = i960_fault_to_signal (rdbEvent.sigType); |
d0acb092 JK |
959 | #else |
960 | /* Back in the old days, before enum target_signal, this code used | |
961 | to add NSIG to the signal number and claim that PRINT_RANDOM_SIGNAL | |
962 | would take care of it. But PRINT_RANDOM_SIGNAL has never been | |
963 | defined except on the i960, so I don't really know what we are | |
964 | supposed to do on other architectures. */ | |
965 | status->value.sig = TARGET_SIGNAL_UNKNOWN; | |
966 | #endif | |
dd3b648e RP |
967 | break; |
968 | } /* switch */ | |
dd3b648e RP |
969 | return pid; |
970 | } | |
971 | \f | |
972 | static int | |
973 | symbol_stub (arg) | |
bdbd5f50 | 974 | char *arg; |
dd3b648e | 975 | { |
bdbd5f50 | 976 | symbol_file_command (arg, 0); |
dd3b648e RP |
977 | return 1; |
978 | } | |
979 | ||
980 | static int | |
981 | add_symbol_stub (arg) | |
bdbd5f50 | 982 | char *arg; |
dd3b648e RP |
983 | { |
984 | struct ldfile *pLoadFile = (struct ldfile *)arg; | |
985 | ||
199b2450 | 986 | printf_unfiltered("\t%s: ", pLoadFile->name); |
4ed3a9ea | 987 | symbol_file_add (pLoadFile->name, 0, pLoadFile->txt_addr, 0, 0, 0); |
199b2450 | 988 | printf_unfiltered ("ok\n"); |
dd3b648e RP |
989 | return 1; |
990 | } | |
991 | /* Target command for VxWorks target systems. | |
992 | ||
993 | Used in vxgdb. Takes the name of a remote target machine | |
994 | running vxWorks and connects to it to initialize remote network | |
995 | debugging. */ | |
996 | ||
997 | static void | |
998 | vx_open (args, from_tty) | |
999 | char *args; | |
1000 | int from_tty; | |
1001 | { | |
1002 | extern int close (); | |
1003 | char *bootFile; | |
1004 | extern char *source_path; | |
1005 | struct ldtabl loadTable; | |
1006 | struct ldfile *pLoadFile; | |
1007 | int i; | |
1008 | extern CLIENT *pClient; | |
46d185d3 | 1009 | int symbols_added = 0; |
dd3b648e RP |
1010 | |
1011 | if (!args) | |
1012 | error_no_arg ("target machine name"); | |
1013 | ||
70dcc196 JK |
1014 | target_preopen (from_tty); |
1015 | ||
dd3b648e | 1016 | unpush_target (&vx_ops); |
199b2450 TL |
1017 | printf_unfiltered ("Attaching remote machine across net...\n"); |
1018 | gdb_flush (gdb_stdout); | |
dd3b648e RP |
1019 | |
1020 | /* Allow the user to kill the connect attempt by typing ^C. | |
1021 | Wait until the call to target_has_fp () completes before | |
1022 | disallowing an immediate quit, since even if net_connect () | |
1023 | is successful, the remote debug server might be hung. */ | |
1024 | ||
1025 | immediate_quit++; | |
1026 | ||
1027 | net_connect (args); | |
1028 | target_has_fp = net_check_for_fp (); | |
1029 | printf_filtered ("Connected to %s.\n", args); | |
1030 | ||
1031 | immediate_quit--; | |
1032 | ||
1033 | push_target (&vx_ops); | |
1034 | ||
1035 | /* Save a copy of the target host's name. */ | |
1036 | vx_host = savestring (args, strlen (args)); | |
1037 | ||
1038 | /* Find out the name of the file from which the target was booted | |
1039 | and load its symbol table. */ | |
1040 | ||
1041 | printf_filtered ("Looking in Unix path for all loaded modules:\n"); | |
1042 | bootFile = NULL; | |
1043 | if (!net_get_boot_file (&bootFile)) | |
1044 | { | |
1045 | if (*bootFile) { | |
1046 | printf_filtered ("\t%s: ", bootFile); | |
9748446f JK |
1047 | if (catch_errors |
1048 | (symbol_stub, bootFile, | |
1049 | "Error while reading symbols from boot file:\n", RETURN_MASK_ALL)) | |
dd3b648e RP |
1050 | puts_filtered ("ok\n"); |
1051 | } else if (from_tty) | |
199b2450 | 1052 | printf_unfiltered ("VxWorks kernel symbols not loaded.\n"); |
dd3b648e RP |
1053 | } |
1054 | else | |
1055 | error ("Can't retrieve boot file name from target machine."); | |
1056 | ||
1057 | clnt_freeres (pClient, xdr_wrapstring, &bootFile); | |
1058 | ||
1059 | if (net_get_symbols (&loadTable) != 0) | |
1060 | error ("Can't read loaded modules from target machine"); | |
1061 | ||
1062 | i = 0-1; | |
1063 | while (++i < loadTable.tbl_size) | |
1064 | { | |
1065 | QUIT; /* FIXME, avoids clnt_freeres below: mem leak */ | |
1066 | pLoadFile = &loadTable.tbl_ent [i]; | |
1067 | #ifdef WRS_ORIG | |
1068 | { | |
1069 | register int desc; | |
1070 | struct cleanup *old_chain; | |
1071 | char *fullname = NULL; | |
1072 | ||
1073 | desc = openp (source_path, 0, pLoadFile->name, O_RDONLY, 0, &fullname); | |
1074 | if (desc < 0) | |
1075 | perror_with_name (pLoadFile->name); | |
1076 | old_chain = make_cleanup (close, desc); | |
1077 | add_file_at_addr (fullname, desc, pLoadFile->txt_addr, pLoadFile->data_addr, | |
1078 | pLoadFile->bss_addr); | |
1079 | do_cleanups (old_chain); | |
1080 | } | |
1081 | #else | |
1082 | /* Botches, FIXME: | |
1083 | (1) Searches the PATH, not the source path. | |
1084 | (2) data and bss are assumed to be at the usual offsets from text. */ | |
46d185d3 PS |
1085 | if (catch_errors (add_symbol_stub, (char *)pLoadFile, (char *)0, |
1086 | RETURN_MASK_ALL)) | |
1087 | symbols_added = 1; | |
dd3b648e RP |
1088 | #endif |
1089 | } | |
1090 | printf_filtered ("Done.\n"); | |
1091 | ||
1092 | clnt_freeres (pClient, xdr_ldtabl, &loadTable); | |
46d185d3 PS |
1093 | |
1094 | /* Getting new symbols may change our opinion about what is | |
1095 | frameless. */ | |
1096 | if (symbols_added) | |
1097 | reinit_frame_cache (); | |
dd3b648e RP |
1098 | } |
1099 | \f | |
836e343b | 1100 | /* Takes a task started up outside of gdb and ``attaches'' to it. |
dd3b648e RP |
1101 | This stops it cold in its tracks and allows us to start tracing it. */ |
1102 | ||
1103 | static void | |
1104 | vx_attach (args, from_tty) | |
1105 | char *args; | |
1106 | int from_tty; | |
1107 | { | |
3d19ff2b | 1108 | unsigned long pid; |
dd3b648e RP |
1109 | char *cptr = 0; |
1110 | Rptrace ptrace_in; | |
1111 | Ptrace_return ptrace_out; | |
1112 | int status; | |
1113 | ||
dd3b648e RP |
1114 | if (!args) |
1115 | error_no_arg ("process-id to attach"); | |
1116 | ||
3d19ff2b | 1117 | pid = strtoul (args, &cptr, 0); |
dd3b648e RP |
1118 | if ((cptr == args) || (*cptr != '\0')) |
1119 | error ("Invalid process-id -- give a single number in decimal or 0xhex"); | |
1120 | ||
1121 | if (from_tty) | |
3d19ff2b SS |
1122 | printf_unfiltered ("Attaching pid %s.\n", |
1123 | local_hex_string((unsigned long) pid)); | |
dd3b648e | 1124 | |
4ed97c9a RP |
1125 | memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in)); |
1126 | memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out)); | |
dd3b648e RP |
1127 | ptrace_in.pid = pid; |
1128 | ||
1129 | status = net_ptrace_clnt_call (PTRACE_ATTACH, &ptrace_in, &ptrace_out); | |
1130 | if (status == -1) | |
1131 | error (rpcerr); | |
1132 | if (ptrace_out.status == -1) | |
1133 | { | |
1134 | errno = ptrace_out.errno; | |
1135 | perror_with_name ("Attaching remote process"); | |
1136 | } | |
1137 | ||
1138 | /* It worked... */ | |
1139 | push_target (&vx_run_ops); | |
3d19ff2b SS |
1140 | /* The unsigned long pid will get turned into a signed int here, |
1141 | but it doesn't seem to matter. inferior_pid must be signed | |
1142 | in order for other parts of GDB to work correctly. */ | |
dd3b648e RP |
1143 | inferior_pid = pid; |
1144 | vx_running = 0; | |
dd3b648e RP |
1145 | } |
1146 | ||
1147 | ||
1148 | /* detach_command -- | |
1149 | takes a program previously attached to and detaches it. | |
1150 | The program resumes execution and will no longer stop | |
1151 | on signals, etc. We better not have left any breakpoints | |
1152 | in the program or it'll die when it hits one. For this | |
1153 | to work, it may be necessary for the process to have been | |
1154 | previously attached. It *might* work if the program was | |
1155 | started via the normal ptrace (PTRACE_TRACEME). */ | |
1156 | ||
1157 | static void | |
1158 | vx_detach (args, from_tty) | |
1159 | char *args; | |
1160 | int from_tty; | |
1161 | { | |
1162 | Rptrace ptrace_in; | |
1163 | Ptrace_return ptrace_out; | |
1164 | int signal = 0; | |
1165 | int status; | |
1166 | ||
1167 | if (args) | |
1168 | error ("Argument given to VxWorks \"detach\"."); | |
1169 | ||
1170 | if (from_tty) | |
199b2450 | 1171 | printf_unfiltered ("Detaching pid %s.\n", |
5573d7d4 | 1172 | local_hex_string((unsigned long) inferior_pid)); |
dd3b648e RP |
1173 | |
1174 | if (args) /* FIXME, should be possible to leave suspended */ | |
1175 | signal = atoi (args); | |
1176 | ||
4ed97c9a RP |
1177 | memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in)); |
1178 | memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out)); | |
dd3b648e RP |
1179 | ptrace_in.pid = inferior_pid; |
1180 | ||
1181 | status = net_ptrace_clnt_call (PTRACE_DETACH, &ptrace_in, &ptrace_out); | |
1182 | if (status == -1) | |
1183 | error (rpcerr); | |
1184 | if (ptrace_out.status == -1) | |
1185 | { | |
1186 | errno = ptrace_out.errno; | |
1187 | perror_with_name ("Detaching VxWorks process"); | |
1188 | } | |
1189 | ||
1190 | inferior_pid = 0; | |
1191 | pop_target (); /* go back to non-executing VxWorks connection */ | |
1192 | } | |
1193 | ||
1194 | /* vx_kill -- takes a running task and wipes it out. */ | |
1195 | ||
1196 | static void | |
afc5505f | 1197 | vx_kill () |
dd3b648e RP |
1198 | { |
1199 | Rptrace ptrace_in; | |
1200 | Ptrace_return ptrace_out; | |
1201 | int status; | |
1202 | ||
199b2450 | 1203 | printf_unfiltered ("Killing pid %s.\n", local_hex_string((unsigned long) inferior_pid)); |
dd3b648e | 1204 | |
4ed97c9a RP |
1205 | memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in)); |
1206 | memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out)); | |
dd3b648e RP |
1207 | ptrace_in.pid = inferior_pid; |
1208 | ||
1209 | status = net_ptrace_clnt_call (PTRACE_KILL, &ptrace_in, &ptrace_out); | |
1210 | if (status == -1) | |
195b44d9 ILT |
1211 | warning (rpcerr); |
1212 | else if (ptrace_out.status == -1) | |
dd3b648e RP |
1213 | { |
1214 | errno = ptrace_out.errno; | |
1215 | perror_with_name ("Killing VxWorks process"); | |
1216 | } | |
1217 | ||
195b44d9 ILT |
1218 | /* If it gives good status, the process is *gone*, no events remain. |
1219 | If the kill failed, assume the process is gone anyhow. */ | |
dd3b648e RP |
1220 | inferior_pid = 0; |
1221 | pop_target (); /* go back to non-executing VxWorks connection */ | |
1222 | } | |
1223 | ||
1224 | /* Clean up from the VxWorks process target as it goes away. */ | |
1225 | ||
8616205a | 1226 | static void |
dd3b648e RP |
1227 | vx_proc_close (quitting) |
1228 | int quitting; | |
1229 | { | |
1230 | inferior_pid = 0; /* No longer have a process. */ | |
1231 | if (vx_running) | |
1232 | free (vx_running); | |
1233 | vx_running = 0; | |
1234 | } | |
1235 | \f | |
dd3b648e RP |
1236 | /* Make an RPC call to the VxWorks target. |
1237 | Returns RPC status. */ | |
1238 | ||
1239 | static enum clnt_stat | |
1240 | net_clnt_call (procNum, inProc, in, outProc, out) | |
1241 | enum ptracereq procNum; | |
1242 | xdrproc_t inProc; | |
1243 | char *in; | |
1244 | xdrproc_t outProc; | |
1245 | char *out; | |
1246 | { | |
1247 | enum clnt_stat status; | |
1248 | ||
1249 | status = clnt_call (pClient, procNum, inProc, in, outProc, out, rpcTimeout); | |
1250 | ||
1251 | if (status != RPC_SUCCESS) | |
1252 | clnt_perrno (status); | |
1253 | ||
1254 | return status; | |
1255 | } | |
1256 | ||
1257 | /* Clean up before losing control. */ | |
1258 | ||
8616205a | 1259 | static void |
dd3b648e RP |
1260 | vx_close (quitting) |
1261 | int quitting; | |
1262 | { | |
1263 | if (pClient) | |
1264 | clnt_destroy (pClient); /* The net connection */ | |
1265 | pClient = 0; | |
1266 | ||
1267 | if (vx_host) | |
1268 | free (vx_host); /* The hostname */ | |
1269 | vx_host = 0; | |
1270 | } | |
1271 | ||
70dcc196 JK |
1272 | /* A vxprocess target should be started via "run" not "target". */ |
1273 | /*ARGSUSED*/ | |
1274 | static void | |
1275 | vx_proc_open (name, from_tty) | |
1276 | char *name; | |
1277 | int from_tty; | |
1278 | { | |
1279 | error ("Use the \"run\" command to start a VxWorks process."); | |
1280 | } | |
dd3b648e RP |
1281 | |
1282 | /* Target ops structure for accessing memory and such over the net */ | |
1283 | ||
1284 | struct target_ops vx_ops = { | |
1285 | "vxworks", "VxWorks target memory via RPC over TCP/IP", | |
70dcc196 JK |
1286 | "Use VxWorks target memory. \n\ |
1287 | Specify the name of the machine to connect to.", | |
dd3b648e RP |
1288 | vx_open, vx_close, vx_attach, 0, /* vx_detach, */ |
1289 | 0, 0, /* resume, wait */ | |
1290 | 0, 0, /* read_reg, write_reg */ | |
a03d4f8e | 1291 | 0, /* prep_to_store, */ |
dd3b648e RP |
1292 | vx_xfer_memory, vx_files_info, |
1293 | 0, 0, /* insert_breakpoint, remove_breakpoint */ | |
1294 | 0, 0, 0, 0, 0, /* terminal stuff */ | |
1295 | 0, /* vx_kill, */ | |
8f1f2a72 | 1296 | vx_load_command, |
dd3b648e RP |
1297 | vx_lookup_symbol, |
1298 | vx_create_inferior, 0, /* mourn_inferior */ | |
5ee4e16c | 1299 | 0, /* can_run */ |
3950a34e | 1300 | 0, /* notice_signals */ |
dd3b648e RP |
1301 | core_stratum, 0, /* next */ |
1302 | 1, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */ | |
8f1f2a72 | 1303 | 0, 0, /* Section pointers */ |
dd3b648e RP |
1304 | OPS_MAGIC, /* Always the last thing */ |
1305 | }; | |
1306 | ||
1307 | /* Target ops structure for accessing VxWorks child processes over the net */ | |
1308 | ||
1309 | struct target_ops vx_run_ops = { | |
1310 | "vxprocess", "VxWorks process", | |
70dcc196 JK |
1311 | "VxWorks process, started by the \"run\" command.", |
1312 | vx_proc_open, vx_proc_close, 0, vx_detach, /* vx_attach */ | |
dd3b648e RP |
1313 | vx_resume, vx_wait, |
1314 | vx_read_register, vx_write_register, | |
a03d4f8e | 1315 | vx_prepare_to_store, |
dd3b648e RP |
1316 | vx_xfer_memory, vx_run_files_info, |
1317 | vx_insert_breakpoint, vx_remove_breakpoint, | |
1318 | 0, 0, 0, 0, 0, /* terminal stuff */ | |
1319 | vx_kill, | |
8f1f2a72 | 1320 | vx_load_command, |
dd3b648e RP |
1321 | vx_lookup_symbol, |
1322 | 0, vx_mourn_inferior, | |
5ee4e16c | 1323 | 0, /* can_run */ |
3950a34e | 1324 | 0, /* notice_signals */ |
dd3b648e RP |
1325 | process_stratum, 0, /* next */ |
1326 | 0, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */ | |
1327 | /* all_mem is off to avoid spurious msg in "i files" */ | |
8f1f2a72 | 1328 | 0, 0, /* Section pointers */ |
dd3b648e RP |
1329 | OPS_MAGIC, /* Always the last thing */ |
1330 | }; | |
1331 | /* ==> Remember when reading at end of file, there are two "ops" structs here. */ | |
1332 | \f | |
1333 | void | |
1334 | _initialize_vx () | |
1335 | { | |
56894788 RP |
1336 | |
1337 | add_show_from_set | |
1c5d6049 | 1338 | (add_set_cmd ("vxworks-timeout", class_support, var_uinteger, |
56894788 RP |
1339 | (char *) &rpcTimeout.tv_sec, |
1340 | "Set seconds to wait for rpc calls to return.\n\ | |
1341 | Set the number of seconds to wait for rpc calls to return.", &setlist), | |
1342 | &showlist); | |
1343 | ||
1344 | add_target (&vx_ops); | |
dd3b648e RP |
1345 | add_target (&vx_run_ops); |
1346 | } |