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