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> | |
36 | #include <sys/time.h> | |
37 | #include <sys/socket.h> | |
38 | #define free bogon_free /* Sun claims "int free()" not void */ | |
39 | #include <rpc/rpc.h> | |
40 | #undef free | |
41 | #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */ | |
42 | #include <netdb.h> | |
43 | #include <ptrace.h> | |
44 | #include "xdr_ptrace.h" | |
45 | #include "xdr_ld.h" | |
46 | #include "xdr_rdb.h" | |
47 | #include "dbgRpcLib.h" | |
48 | ||
dd3b648e | 49 | #include <symtab.h> |
1ab3bf1b | 50 | |
dd3b648e | 51 | extern void symbol_file_command (); |
dd3b648e RP |
52 | extern int stop_soon_quietly; /* for wait_for_inferior */ |
53 | ||
54 | static int net_ptrace_clnt_call (); /* Forward decl */ | |
55 | static enum clnt_stat net_clnt_call (); /* Forward decl */ | |
56 | extern struct target_ops vx_ops, vx_run_ops; /* Forward declaration */ | |
57 | ||
58 | /* Saved name of target host and called function for "info files". | |
59 | Both malloc'd. */ | |
60 | ||
61 | static char *vx_host; | |
62 | static char *vx_running; /* Called function */ | |
63 | ||
64 | /* Nonzero means target that is being debugged remotely has a floating | |
65 | point processor. */ | |
66 | ||
67 | static int target_has_fp; | |
68 | ||
69 | /* Default error message when the network is forking up. */ | |
70 | ||
71 | static const char rpcerr[] = "network target debugging: rpc error"; | |
72 | ||
73 | CLIENT *pClient; /* client used in net debugging */ | |
74 | static int ptraceSock = RPC_ANYSOCK; | |
75 | ||
76 | enum clnt_stat net_clnt_call(); | |
77 | static void parse_args (); | |
78 | ||
79 | static struct timeval rpcTimeout = { 10, 0 }; | |
80 | ||
81 | static char *skip_white_space (); | |
82 | static char *find_white_space (); | |
83 | ||
84 | /* Tell the VxWorks target system to download a file. | |
85 | The load addresses of the text, data, and bss segments are | |
86 | stored in pTextAddr, pDataAddr, and *pBssAddr (respectively). | |
87 | Returns 0 for success, -1 for failure. */ | |
88 | ||
89 | static int | |
90 | net_load (filename, pTextAddr, pDataAddr, pBssAddr) | |
91 | char *filename; | |
92 | CORE_ADDR *pTextAddr; | |
93 | CORE_ADDR *pDataAddr; | |
94 | CORE_ADDR *pBssAddr; | |
95 | { | |
96 | enum clnt_stat status; | |
97 | struct ldfile ldstruct; | |
98 | struct timeval load_timeout; | |
99 | ||
100 | bzero ((char *) &ldstruct, sizeof (ldstruct)); | |
101 | ||
102 | /* We invoke clnt_call () here directly, instead of through | |
103 | net_clnt_call (), because we need to set a large timeout value. | |
104 | The load on the target side can take quite a while, easily | |
105 | more than 10 seconds. The user can kill this call by typing | |
106 | CTRL-C if there really is a problem with the load. | |
107 | ||
108 | Do not change the tv_sec value without checking -- select() imposes | |
109 | a limit of 10**8 on it for no good reason that I can see... */ | |
110 | ||
111 | load_timeout.tv_sec = 99999999; /* A large number, effectively inf. */ | |
112 | load_timeout.tv_usec = 0; | |
113 | ||
114 | status = clnt_call (pClient, VX_LOAD, xdr_wrapstring, &filename, xdr_ldfile, | |
115 | &ldstruct, load_timeout); | |
116 | ||
117 | if (status == RPC_SUCCESS) | |
118 | { | |
119 | if (*ldstruct.name == NULL) /* load failed on VxWorks side */ | |
120 | return -1; | |
121 | *pTextAddr = ldstruct.txt_addr; | |
122 | *pDataAddr = ldstruct.data_addr; | |
123 | *pBssAddr = ldstruct.bss_addr; | |
124 | return 0; | |
125 | } | |
126 | else | |
127 | return -1; | |
128 | } | |
129 | ||
130 | /* returns 0 if successful, errno if RPC failed or VxWorks complains. */ | |
131 | ||
132 | static int | |
133 | net_break (addr, procnum) | |
134 | int addr; | |
135 | u_long procnum; | |
136 | { | |
137 | enum clnt_stat status; | |
138 | int break_status; | |
139 | Rptrace ptrace_in; /* XXX This is stupid. It doesn't need to be a ptrace | |
140 | structure. How about something smaller? */ | |
141 | ||
142 | bzero ((char *) &ptrace_in, sizeof (ptrace_in)); | |
143 | break_status = 0; | |
144 | ||
145 | ptrace_in.addr = addr; | |
146 | ptrace_in.pid = inferior_pid; | |
147 | ||
148 | status = net_clnt_call (procnum, xdr_rptrace, &ptrace_in, xdr_int, | |
149 | &break_status); | |
150 | ||
151 | if (status != RPC_SUCCESS) | |
152 | return errno; | |
153 | ||
154 | if (break_status == -1) | |
155 | return ENOMEM; | |
156 | return break_status; /* probably (FIXME) zero */ | |
157 | } | |
158 | ||
159 | /* returns 0 if successful, errno otherwise */ | |
160 | ||
161 | int | |
162 | vx_insert_breakpoint (addr) | |
163 | int addr; | |
164 | { | |
165 | return net_break (addr, VX_BREAK_ADD); | |
166 | } | |
167 | ||
168 | /* returns 0 if successful, errno otherwise */ | |
169 | ||
170 | int | |
171 | vx_remove_breakpoint (addr) | |
172 | int addr; | |
173 | { | |
174 | return net_break (addr, VX_BREAK_DELETE); | |
175 | } | |
176 | ||
dd3b648e RP |
177 | /* Start an inferior process and sets inferior_pid to its pid. |
178 | EXEC_FILE is the file to run. | |
179 | ALLARGS is a string containing the arguments to the program. | |
180 | ENV is the environment vector to pass. | |
181 | Returns process id. Errors reported with error(). | |
182 | On VxWorks, we ignore exec_file. */ | |
183 | ||
184 | void | |
185 | vx_create_inferior (exec_file, args, env) | |
186 | char *exec_file; | |
187 | char *args; | |
188 | char **env; | |
189 | { | |
190 | enum clnt_stat status; | |
191 | arg_array passArgs; | |
192 | TASK_START taskStart; | |
193 | ||
194 | bzero ((char *) &passArgs, sizeof (passArgs)); | |
195 | bzero ((char *) &taskStart, sizeof (taskStart)); | |
196 | ||
197 | /* parse arguments, put them in passArgs */ | |
198 | ||
199 | parse_args (args, &passArgs); | |
200 | ||
201 | if (passArgs.arg_array_len == 0) | |
202 | error ("You must specify a function name to run, and arguments if any"); | |
203 | ||
204 | status = net_clnt_call (PROCESS_START, xdr_arg_array, &passArgs, | |
205 | xdr_TASK_START, &taskStart); | |
206 | ||
207 | if ((status != RPC_SUCCESS) || (taskStart.status == -1)) | |
208 | error ("Can't create process on remote target machine"); | |
209 | ||
210 | /* Save the name of the running function */ | |
211 | vx_running = savestring (passArgs.arg_array_val[0], | |
212 | strlen (passArgs.arg_array_val[0])); | |
213 | ||
214 | #ifdef CREATE_INFERIOR_HOOK | |
215 | CREATE_INFERIOR_HOOK (pid); | |
216 | #endif | |
217 | ||
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? */ | |
238 | proceed(-1, -1, 0); | |
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 | ||
253 | bzero ((char *) arg_struct, sizeof (arg_array)); | |
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 | ||
326 | int | |
327 | net_wait (pEvent) | |
328 | RDB_EVENT *pEvent; | |
329 | { | |
330 | int pid; | |
331 | enum clnt_stat status; | |
332 | ||
333 | bzero ((char *) pEvent, sizeof (RDB_EVENT)); | |
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 | ||
344 | int | |
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 | ||
366 | int | |
367 | vx_read_register (regno) | |
368 | int regno; | |
369 | { | |
370 | int status; | |
371 | Rptrace ptrace_in; | |
372 | Ptrace_return ptrace_out; | |
373 | struct regs inferior_registers; | |
374 | struct fp_status inferior_fp_registers; | |
375 | extern char registers[]; | |
376 | ||
377 | bzero ((char *) &ptrace_in, sizeof (ptrace_in)); | |
378 | bzero ((char *) &ptrace_out, sizeof (ptrace_out)); | |
379 | ||
380 | /* FIXME, eventually only get the ones we need. */ | |
381 | registers_fetched (); | |
382 | ||
383 | ptrace_in.pid = inferior_pid; | |
384 | ptrace_out.info.more_data = (caddr_t) &inferior_registers; | |
385 | status = net_ptrace_clnt_call (PTRACE_GETREGS, &ptrace_in, &ptrace_out); | |
386 | if (status) | |
387 | error (rpcerr); | |
388 | if (ptrace_out.status == -1) | |
389 | { | |
390 | errno = ptrace_out.errno; | |
391 | return -1; | |
392 | } | |
393 | ||
394 | #ifdef I80960 | |
395 | ||
396 | bcopy ((char *) inferior_registers.r_lreg, | |
397 | ®isters[REGISTER_BYTE (R0_REGNUM)], 16 * sizeof (int)); | |
398 | bcopy ((char *) inferior_registers.r_greg, | |
399 | ®isters[REGISTER_BYTE (G0_REGNUM)], 16 * sizeof (int)); | |
400 | ||
401 | /* Don't assume that a location in registers[] is properly aligned. */ | |
402 | ||
403 | bcopy ((char *) &inferior_registers.r_pcw, | |
404 | ®isters[REGISTER_BYTE (PCW_REGNUM)], sizeof (int)); | |
405 | bcopy ((char *) &inferior_registers.r_acw, | |
406 | ®isters[REGISTER_BYTE (ACW_REGNUM)], sizeof (int)); | |
407 | bcopy ((char *) &inferior_registers.r_lreg[2], /* r2 (RIP) -> IP */ | |
408 | ®isters[REGISTER_BYTE (IP_REGNUM)], sizeof (int)); | |
409 | bcopy ((char *) &inferior_registers.r_tcw, | |
410 | ®isters[REGISTER_BYTE (TCW_REGNUM)], sizeof (int)); | |
411 | ||
412 | /* If the target has floating point registers, fetch them. | |
413 | Otherwise, zero the floating point register values in | |
414 | registers[] for good measure, even though we might not | |
415 | need to. */ | |
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, &ptrace_in, &ptrace_out); | |
422 | if (status) | |
423 | error (rpcerr); | |
424 | if (ptrace_out.status == -1) | |
425 | { | |
426 | errno = ptrace_out.errno; | |
427 | return -1; | |
428 | } | |
429 | ||
430 | bcopy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)], | |
431 | REGISTER_RAW_SIZE (FP0_REGNUM) * 4); | |
432 | } | |
433 | else | |
434 | { | |
435 | bzero ((char *) ®isters[REGISTER_BYTE (FP0_REGNUM)], | |
436 | REGISTER_RAW_SIZE (FP0_REGNUM) * 4); | |
437 | } | |
438 | ||
439 | #else /* not 960, thus must be 68000: FIXME! */ | |
440 | ||
441 | bcopy (&inferior_registers, registers, 16 * 4); | |
442 | *(int *)®isters[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps; | |
443 | *(int *)®isters[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc; | |
444 | ||
445 | if (target_has_fp) | |
446 | { | |
447 | ptrace_in.pid = inferior_pid; | |
448 | ptrace_out.info.more_data = (caddr_t) &inferior_fp_registers; | |
449 | status = net_ptrace_clnt_call (PTRACE_GETFPREGS, &ptrace_in, &ptrace_out); | |
450 | if (status) | |
451 | error (rpcerr); | |
452 | if (ptrace_out.status == -1) | |
453 | { | |
454 | errno = ptrace_out.errno; | |
455 | return -1; | |
456 | } | |
457 | ||
458 | bcopy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)], | |
459 | sizeof inferior_fp_registers.fps_regs); | |
460 | bcopy (&inferior_fp_registers.fps_control, | |
461 | ®isters[REGISTER_BYTE (FPC_REGNUM)], | |
462 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs); | |
463 | } | |
464 | else | |
465 | { | |
466 | bzero (®isters[REGISTER_BYTE (FP0_REGNUM)], | |
467 | sizeof inferior_fp_registers.fps_regs); | |
468 | bzero (®isters[REGISTER_BYTE (FPC_REGNUM)], | |
469 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs); | |
470 | } | |
471 | #endif /* various architectures */ | |
472 | ||
473 | return 0; | |
474 | } | |
475 | ||
476 | /* Prepare to store registers. Since we will store all of them, | |
477 | read out their current values now. */ | |
478 | ||
479 | void | |
480 | vx_prepare_to_store () | |
481 | { | |
482 | vx_read_register (-1); | |
483 | } | |
484 | ||
485 | ||
486 | /* Store our register values back into the inferior. | |
487 | If REGNO is -1, do this for all registers. | |
488 | Otherwise, REGNO specifies which register (so we can save time). */ | |
489 | /* FIXME, look at REGNO to save time here */ | |
490 | ||
491 | vx_write_register (regno) | |
492 | int regno; | |
493 | { | |
494 | struct regs inferior_registers; | |
495 | struct fp_status inferior_fp_registers; | |
496 | extern char registers[]; | |
497 | int status; | |
498 | Rptrace ptrace_in; | |
499 | Ptrace_return ptrace_out; | |
500 | ||
501 | bzero ((char *) &ptrace_in, sizeof (ptrace_in)); | |
502 | bzero ((char *) &ptrace_out, sizeof (ptrace_out)); | |
503 | ||
504 | #ifdef I80960 | |
505 | ||
506 | bcopy (®isters[REGISTER_BYTE (R0_REGNUM)], | |
507 | (char *) inferior_registers.r_lreg, 16 * sizeof (int)); | |
508 | bcopy (®isters[REGISTER_BYTE (G0_REGNUM)], | |
509 | (char *) inferior_registers.r_greg, 16 * sizeof (int)); | |
510 | ||
511 | /* Don't assume that a location in registers[] is properly aligned. */ | |
512 | ||
513 | bcopy (®isters[REGISTER_BYTE (PCW_REGNUM)], | |
514 | (char *) &inferior_registers.r_pcw, sizeof (int)); | |
515 | bcopy (®isters[REGISTER_BYTE (ACW_REGNUM)], | |
516 | (char *) &inferior_registers.r_acw, sizeof (int)); | |
517 | bcopy (®isters[REGISTER_BYTE (TCW_REGNUM)], | |
518 | (char *) &inferior_registers.r_tcw, sizeof (int)); | |
519 | ||
520 | #else /* not 960 -- assume 68k -- FIXME */ | |
521 | ||
522 | bcopy (registers, &inferior_registers, 16 * 4); | |
523 | inferior_registers.r_ps = *(int *)®isters[REGISTER_BYTE (PS_REGNUM)]; | |
524 | inferior_registers.r_pc = *(int *)®isters[REGISTER_BYTE (PC_REGNUM)]; | |
525 | ||
526 | #endif /* Different register sets */ | |
527 | ||
528 | ptrace_in.pid = inferior_pid; | |
529 | ptrace_in.info.ttype = REGS; | |
530 | ptrace_in.info.more_data = (caddr_t) &inferior_registers; | |
531 | ||
532 | /* XXX change second param to be a proc number */ | |
533 | status = net_ptrace_clnt_call (PTRACE_SETREGS, &ptrace_in, &ptrace_out); | |
534 | if (status) | |
535 | error (rpcerr); | |
536 | if (ptrace_out.status == -1) | |
537 | { | |
538 | errno = ptrace_out.errno; | |
539 | return -1; | |
540 | } | |
541 | ||
542 | /* Store floating point registers if the target has them. */ | |
543 | ||
544 | if (target_has_fp) | |
545 | { | |
546 | #ifdef I80960 | |
547 | ||
548 | bcopy (®isters[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers, | |
549 | sizeof inferior_fp_registers.fps_regs); | |
550 | ||
551 | #else /* not 960 -- assume 68k -- FIXME */ | |
552 | ||
553 | bcopy (®isters[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers, | |
554 | sizeof inferior_fp_registers.fps_regs); | |
555 | bcopy (®isters[REGISTER_BYTE (FPC_REGNUM)], | |
556 | &inferior_fp_registers.fps_control, | |
557 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs); | |
558 | ||
559 | #endif /* Different register sets */ | |
560 | ||
561 | ptrace_in.pid = inferior_pid; | |
562 | ptrace_in.info.ttype = FPREGS; | |
563 | ptrace_in.info.more_data = (caddr_t) &inferior_fp_registers; | |
564 | ||
565 | status = net_ptrace_clnt_call (PTRACE_SETFPREGS, &ptrace_in, &ptrace_out); | |
566 | if (status) | |
567 | error (rpcerr); | |
568 | if (ptrace_out.status == -1) | |
569 | { | |
570 | errno = ptrace_out.errno; | |
571 | return -1; | |
572 | } | |
573 | } | |
574 | return 0; | |
575 | } | |
576 | ||
577 | /* Copy LEN bytes to or from remote inferior's memory starting at MEMADDR | |
578 | to debugger memory starting at MYADDR. WRITE is true if writing to the | |
579 | inferior. | |
580 | Result is the number of bytes written or read (zero if error). The | |
581 | protocol allows us to return a negative count, indicating that we can't | |
582 | handle the current address but can handle one N bytes further, but | |
583 | vxworks doesn't give us that information. */ | |
584 | ||
585 | int | |
8f1f2a72 | 586 | vx_xfer_memory (memaddr, myaddr, len, write, target) |
dd3b648e RP |
587 | CORE_ADDR memaddr; |
588 | char *myaddr; | |
589 | int len; | |
8f1f2a72 JG |
590 | int write; |
591 | struct target_ops *target; /* ignored */ | |
dd3b648e RP |
592 | { |
593 | int status; | |
594 | Rptrace ptrace_in; | |
595 | Ptrace_return ptrace_out; | |
596 | C_bytes data; | |
597 | ||
598 | bzero ((char *) &ptrace_in, sizeof (ptrace_in)); | |
599 | bzero ((char *) &ptrace_out, sizeof (ptrace_out)); | |
600 | ||
601 | ptrace_in.pid = inferior_pid; /* XXX pid unnecessary for READDATA */ | |
602 | ptrace_in.addr = (int) memaddr; /* Where from */ | |
603 | ptrace_in.data = len; /* How many bytes */ | |
604 | ||
605 | if (write) | |
606 | { | |
607 | ptrace_in.info.ttype = DATA; | |
608 | ptrace_in.info.more_data = (caddr_t) &data; | |
609 | ||
610 | data.bytes = (caddr_t) myaddr; /* Where from */ | |
611 | data.len = len; /* How many bytes (again, for XDR) */ | |
612 | ||
613 | /* XXX change second param to be a proc number */ | |
614 | status = net_ptrace_clnt_call (PTRACE_WRITEDATA, &ptrace_in, &ptrace_out); | |
615 | } | |
616 | else | |
617 | { | |
618 | ptrace_out.info.more_data = (caddr_t) &data; | |
619 | data.bytes = myaddr; /* Where to */ | |
620 | data.len = len; /* How many (again, for XDR) */ | |
621 | ||
622 | /* XXX change second param to be a proc number */ | |
623 | status = net_ptrace_clnt_call (PTRACE_READDATA, &ptrace_in, &ptrace_out); | |
624 | } | |
625 | ||
626 | if (status) | |
627 | error (rpcerr); | |
628 | if (ptrace_out.status == -1) | |
629 | { | |
630 | return 0; /* No bytes moved */ | |
631 | } | |
632 | return len; /* Moved *all* the bytes */ | |
633 | } | |
634 | ||
635 | void | |
636 | vx_files_info () | |
637 | { | |
638 | printf ("\tAttached to host `%s'", vx_host); | |
639 | printf (", which has %sfloating point", target_has_fp? "": "no "); | |
640 | printf (".\n"); | |
641 | } | |
642 | ||
643 | void | |
644 | vx_run_files_info () | |
645 | { | |
e3af0493 | 646 | printf ("\tRunning %s VxWorks process %s", |
dd3b648e | 647 | vx_running? "child": "attached", |
e3af0493 | 648 | local_hex_string(inferior_pid)); |
dd3b648e RP |
649 | if (vx_running) |
650 | printf (", function `%s'", vx_running); | |
651 | printf(".\n"); | |
652 | } | |
653 | ||
654 | void | |
655 | vx_resume (step, siggnal) | |
656 | int step; | |
657 | int siggnal; | |
658 | { | |
659 | int status; | |
660 | Rptrace ptrace_in; | |
661 | Ptrace_return ptrace_out; | |
662 | ||
663 | if (siggnal != 0 && siggnal != stop_signal) | |
664 | error ("Cannot send signals to VxWorks processes"); | |
665 | ||
666 | bzero ((char *) &ptrace_in, sizeof (ptrace_in)); | |
667 | bzero ((char *) &ptrace_out, sizeof (ptrace_out)); | |
668 | ||
669 | ptrace_in.pid = inferior_pid; | |
670 | ptrace_in.addr = 1; /* Target side insists on this, or it panics. */ | |
671 | ||
672 | /* XXX change second param to be a proc number */ | |
673 | status = net_ptrace_clnt_call (step? PTRACE_SINGLESTEP: PTRACE_CONT, | |
674 | &ptrace_in, &ptrace_out); | |
675 | if (status) | |
676 | error (rpcerr); | |
677 | if (ptrace_out.status == -1) | |
678 | { | |
679 | errno = ptrace_out.errno; | |
680 | perror_with_name ("Resuming remote process"); | |
681 | } | |
682 | } | |
683 | ||
684 | void | |
685 | vx_mourn_inferior () | |
686 | { | |
687 | pop_target (); /* Pop back to no-child state */ | |
688 | generic_mourn_inferior (); | |
689 | } | |
690 | ||
691 | \f | |
692 | /* This function allows the addition of incrementally linked object files. */ | |
693 | ||
694 | void | |
695 | vx_load_command (arg_string, from_tty) | |
696 | char* arg_string; | |
697 | int from_tty; | |
698 | { | |
699 | CORE_ADDR text_addr; | |
700 | CORE_ADDR data_addr; | |
701 | CORE_ADDR bss_addr; | |
702 | ||
703 | if (arg_string == 0) | |
704 | error ("The load command takes a file name"); | |
705 | ||
706 | arg_string = tilde_expand (arg_string); | |
707 | make_cleanup (free, arg_string); | |
708 | ||
709 | dont_repeat (); | |
710 | ||
711 | QUIT; | |
712 | immediate_quit++; | |
713 | if (net_load (arg_string, &text_addr, &data_addr, &bss_addr) == -1) | |
714 | error ("Load failed on target machine"); | |
715 | immediate_quit--; | |
716 | ||
717 | /* FIXME, for now we ignore data_addr and bss_addr. */ | |
1ab3bf1b | 718 | (void) symbol_file_add (arg_string, from_tty, text_addr, 0); |
dd3b648e RP |
719 | } |
720 | ||
721 | #ifdef FIXME /* Not ready for prime time */ | |
722 | /* Single step the target program at the source or machine level. | |
723 | Takes an error exit if rpc fails. | |
724 | Returns -1 if remote single-step operation fails, else 0. */ | |
725 | ||
726 | static int | |
727 | net_step () | |
728 | { | |
729 | enum clnt_stat status; | |
730 | int step_status; | |
731 | SOURCE_STEP source_step; | |
732 | ||
733 | source_step.taskId = inferior_pid; | |
734 | ||
735 | if (step_range_end) | |
736 | { | |
737 | source_step.startAddr = step_range_start; | |
738 | source_step.endAddr = step_range_end; | |
739 | } | |
740 | else | |
741 | { | |
742 | source_step.startAddr = 0; | |
743 | source_step.endAddr = 0; | |
744 | } | |
745 | ||
746 | status = net_clnt_call (VX_SOURCE_STEP, xdr_SOURCE_STEP, &source_step, | |
747 | xdr_int, &step_status); | |
748 | ||
749 | if (status == RPC_SUCCESS) | |
750 | return step_status; | |
751 | else | |
752 | error (rpcerr); | |
753 | } | |
754 | #endif | |
755 | ||
756 | /* Emulate ptrace using RPC calls to the VxWorks target system. | |
757 | Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */ | |
758 | ||
759 | static int | |
760 | net_ptrace_clnt_call (request, pPtraceIn, pPtraceOut) | |
761 | enum ptracereq request; | |
762 | Rptrace *pPtraceIn; | |
763 | Ptrace_return *pPtraceOut; | |
764 | { | |
765 | enum clnt_stat status; | |
766 | ||
767 | status = net_clnt_call (request, xdr_rptrace, pPtraceIn, xdr_ptrace_return, | |
768 | pPtraceOut); | |
769 | ||
770 | if (status != RPC_SUCCESS) | |
771 | return -1; | |
772 | ||
773 | return 0; | |
774 | } | |
775 | ||
776 | /* Query the target for the name of the file from which VxWorks was | |
777 | booted. pBootFile is the address of a pointer to the buffer to | |
778 | receive the file name; if the pointer pointed to by pBootFile is | |
779 | NULL, memory for the buffer will be allocated by XDR. | |
780 | Returns -1 if rpc failed, 0 otherwise. */ | |
781 | ||
782 | int | |
783 | net_get_boot_file (pBootFile) | |
784 | char **pBootFile; | |
785 | { | |
786 | enum clnt_stat status; | |
787 | ||
788 | status = net_clnt_call (VX_BOOT_FILE_INQ, xdr_void, (char *) 0, | |
789 | xdr_wrapstring, pBootFile); | |
790 | return (status == RPC_SUCCESS) ? 0 : -1; | |
791 | } | |
792 | ||
793 | /* Fetch a list of loaded object modules from the VxWorks target. | |
794 | Returns -1 if rpc failed, 0 otherwise | |
795 | There's no way to check if the returned loadTable is correct. | |
796 | VxWorks doesn't check it. */ | |
797 | ||
798 | int | |
799 | net_get_symbols (pLoadTable) | |
800 | ldtabl *pLoadTable; /* return pointer to ldtabl here */ | |
801 | { | |
802 | enum clnt_stat status; | |
803 | ||
804 | bzero ((char *) pLoadTable, sizeof (struct ldtabl)); | |
805 | ||
806 | status = net_clnt_call (VX_STATE_INQ, xdr_void, 0, xdr_ldtabl, pLoadTable); | |
807 | return (status == RPC_SUCCESS) ? 0 : -1; | |
808 | } | |
809 | ||
810 | /* Look up a symbol in the VxWorks target's symbol table. | |
811 | Returns status of symbol read on target side (0=success, -1=fail) | |
812 | Returns -1 and complain()s if rpc fails. */ | |
813 | ||
814 | struct complaint cant_contact_target = | |
815 | {"Lost contact with VxWorks target", 0, 0}; | |
816 | ||
817 | int | |
818 | vx_lookup_symbol (name, pAddr) | |
819 | char *name; /* symbol name */ | |
820 | CORE_ADDR *pAddr; | |
821 | { | |
822 | enum clnt_stat status; | |
823 | SYMBOL_ADDR symbolAddr; | |
824 | ||
825 | *pAddr = 0; | |
826 | bzero ((char *) &symbolAddr, sizeof (symbolAddr)); | |
827 | ||
828 | status = net_clnt_call (VX_SYMBOL_INQ, xdr_wrapstring, &name, | |
829 | xdr_SYMBOL_ADDR, &symbolAddr); | |
830 | if (status != RPC_SUCCESS) { | |
831 | complain (&cant_contact_target, 0); | |
832 | return -1; | |
833 | } | |
834 | ||
835 | *pAddr = symbolAddr.addr; | |
836 | return symbolAddr.status; | |
837 | } | |
838 | ||
839 | /* Check to see if the VxWorks target has a floating point coprocessor. | |
840 | Returns 1 if target has floating point processor, 0 otherwise. | |
841 | Calls error() if rpc fails. */ | |
842 | ||
843 | int | |
844 | net_check_for_fp () | |
845 | { | |
846 | enum clnt_stat status; | |
847 | bool_t fp = 0; /* true if fp processor is present on target board */ | |
848 | ||
849 | status = net_clnt_call (VX_FP_INQUIRE, xdr_void, 0, xdr_bool, &fp); | |
850 | if (status != RPC_SUCCESS) | |
851 | error (rpcerr); | |
852 | ||
853 | return (int) fp; | |
854 | } | |
855 | ||
856 | /* Establish an RPC connection with the VxWorks target system. | |
857 | Calls error () if unable to establish connection. */ | |
858 | ||
859 | void | |
860 | net_connect (host) | |
861 | char *host; | |
862 | { | |
863 | struct sockaddr_in destAddr; | |
864 | struct hostent *destHost; | |
865 | ||
866 | /* get the internet address for the given host */ | |
867 | ||
868 | if ((destHost = (struct hostent *) gethostbyname (host)) == NULL) | |
869 | error ("Invalid hostname. Couldn't find remote host address."); | |
870 | ||
871 | bzero (&destAddr, sizeof (destAddr)); | |
872 | ||
873 | destAddr.sin_addr.s_addr = * (u_long *) destHost->h_addr; | |
874 | destAddr.sin_family = AF_INET; | |
875 | destAddr.sin_port = 0; /* set to actual port that remote | |
876 | ptrace is listening on. */ | |
877 | ||
878 | /* Create a tcp client transport on which to issue | |
879 | calls to the remote ptrace server. */ | |
880 | ||
881 | ptraceSock = RPC_ANYSOCK; | |
882 | pClient = clnttcp_create (&destAddr, RDBPROG, RDBVERS, &ptraceSock, 0, 0); | |
883 | /* FIXME, here is where we deal with different version numbers of the proto */ | |
884 | ||
885 | if (pClient == NULL) | |
886 | { | |
887 | clnt_pcreateerror ("\tnet_connect"); | |
888 | error ("Couldn't connect to remote target."); | |
889 | } | |
890 | } | |
891 | \f | |
892 | /* Sleep for the specified number of milliseconds | |
893 | * (assumed to be less than 1000). | |
894 | * If select () is interrupted, returns immediately; | |
895 | * takes an error exit if select () fails for some other reason. | |
896 | */ | |
897 | ||
898 | static void | |
899 | sleep_ms (ms) | |
900 | long ms; | |
901 | { | |
902 | struct timeval select_timeout; | |
903 | int status; | |
904 | ||
905 | select_timeout.tv_sec = 0; | |
906 | select_timeout.tv_usec = ms * 1000; | |
907 | ||
908 | status = select (0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &select_timeout); | |
909 | ||
910 | if (status < 0 && errno != EINTR) | |
911 | perror_with_name ("select"); | |
912 | } | |
913 | ||
914 | /* Wait for control to return from inferior to debugger. | |
915 | If inferior gets a signal, we may decide to start it up again | |
916 | instead of returning. That is why there is a loop in this function. | |
917 | When this function actually returns it means the inferior | |
918 | should be left stopped and GDB should read more commands. */ | |
919 | ||
920 | /* For network debugging with VxWorks. | |
921 | * VxWorks knows when tasks hit breakpoints, receive signals, exit, etc, | |
922 | * so vx_wait() receives this information directly from | |
923 | * VxWorks instead of trying to figure out what happenned via a wait() call. | |
924 | */ | |
925 | ||
926 | static int | |
927 | vx_wait (status) | |
928 | int *status; | |
929 | { | |
930 | register int pid; | |
931 | WAITTYPE w; | |
932 | RDB_EVENT rdbEvent; | |
933 | int quit_failed; | |
934 | ||
935 | do | |
936 | { | |
937 | /* If CTRL-C is hit during this loop, | |
938 | suspend the inferior process. */ | |
939 | ||
940 | quit_failed = 0; | |
941 | if (quit_flag) | |
942 | { | |
943 | quit_failed = (net_quit () == -1); | |
944 | quit_flag = 0; | |
945 | } | |
946 | ||
947 | /* If a net_quit () or net_wait () call has failed, | |
948 | allow the user to break the connection with the target. | |
949 | We can't simply error () out of this loop, since the | |
950 | data structures representing the state of the inferior | |
951 | are in an inconsistent state. */ | |
952 | ||
953 | if (quit_failed || net_wait (&rdbEvent) == -1) | |
954 | { | |
955 | terminal_ours (); | |
956 | if (query ("Can't %s. Disconnect from target system? ", | |
957 | (quit_failed) ? "suspend remote task" | |
958 | : "get status of remote task")) | |
959 | { | |
960 | target_mourn_inferior(); | |
961 | error ("Use the \"target\" command to reconnect."); | |
962 | } | |
963 | else | |
964 | { | |
965 | terminal_inferior (); | |
966 | continue; | |
967 | } | |
968 | } | |
969 | ||
970 | pid = rdbEvent.taskId; | |
971 | if (pid == 0) | |
972 | { | |
973 | sleep_ms (200); /* FIXME Don't kill the network too badly */ | |
974 | } | |
975 | else if (pid != inferior_pid) | |
e3af0493 | 976 | fatal ("Bad pid for debugged task: %s\n", local_hex_string(pid)); |
dd3b648e RP |
977 | } while (pid == 0); |
978 | ||
979 | /* FIXME, eventually do more then SIGTRAP on everything... */ | |
980 | switch (rdbEvent.eventType) | |
981 | { | |
982 | case EVENT_EXIT: | |
983 | WSETEXIT (w, 0); | |
984 | /* FIXME is it possible to distinguish between a | |
985 | XXX normal vs abnormal exit in VxWorks? */ | |
986 | break; | |
987 | ||
988 | case EVENT_START: /* Task was just started. */ | |
989 | WSETSTOP (w, SIGTRAP); | |
990 | break; | |
991 | ||
992 | case EVENT_STOP: | |
993 | WSETSTOP (w, SIGTRAP); | |
994 | /* XXX was it stopped by a signal? act accordingly */ | |
995 | break; | |
996 | ||
997 | case EVENT_BREAK: /* Breakpoint was hit. */ | |
998 | WSETSTOP (w, SIGTRAP); | |
999 | break; | |
1000 | ||
1001 | case EVENT_SUSPEND: /* Task was suspended, probably by ^C. */ | |
1002 | WSETSTOP (w, SIGINT); | |
1003 | break; | |
1004 | ||
1005 | case EVENT_BUS_ERR: /* Task made evil nasty reference. */ | |
1006 | WSETSTOP (w, SIGBUS); | |
1007 | break; | |
1008 | ||
1009 | case EVENT_ZERO_DIV: /* Division by zero */ | |
1010 | WSETSTOP (w, SIGFPE); /* Like Unix, call it a float exception. */ | |
021959e2 | 1011 | break; |
dd3b648e RP |
1012 | |
1013 | case EVENT_SIGNAL: | |
1014 | /* The target is not running Unix, and its | |
1015 | faults/traces do not map nicely into Unix signals. | |
1016 | Make sure they do not get confused with Unix signals | |
1017 | by numbering them with values higher than the highest | |
1018 | legal Unix signal. code in the arch-dependent PRINT_RANDOM_SIGNAL | |
1019 | routine will interpret the value for wait_for_inferior. */ | |
1020 | WSETSTOP (w, rdbEvent.sigType + NSIG); | |
1021 | break; | |
1022 | } /* switch */ | |
1023 | *status = *(int *)&w; /* Grumble union wait crap Grumble */ | |
1024 | return pid; | |
1025 | } | |
1026 | \f | |
1027 | static int | |
1028 | symbol_stub (arg) | |
bdbd5f50 | 1029 | char *arg; |
dd3b648e | 1030 | { |
bdbd5f50 | 1031 | symbol_file_command (arg, 0); |
dd3b648e RP |
1032 | return 1; |
1033 | } | |
1034 | ||
1035 | static int | |
1036 | add_symbol_stub (arg) | |
bdbd5f50 | 1037 | char *arg; |
dd3b648e RP |
1038 | { |
1039 | struct ldfile *pLoadFile = (struct ldfile *)arg; | |
1040 | ||
1041 | printf("\t%s: ", pLoadFile->name); | |
1ab3bf1b | 1042 | (void) symbol_file_add (pLoadFile->name, 0, pLoadFile->txt_addr, 0); |
dd3b648e RP |
1043 | printf ("ok\n"); |
1044 | return 1; | |
1045 | } | |
1046 | /* Target command for VxWorks target systems. | |
1047 | ||
1048 | Used in vxgdb. Takes the name of a remote target machine | |
1049 | running vxWorks and connects to it to initialize remote network | |
1050 | debugging. */ | |
1051 | ||
1052 | static void | |
1053 | vx_open (args, from_tty) | |
1054 | char *args; | |
1055 | int from_tty; | |
1056 | { | |
1057 | extern int close (); | |
1058 | char *bootFile; | |
1059 | extern char *source_path; | |
1060 | struct ldtabl loadTable; | |
1061 | struct ldfile *pLoadFile; | |
1062 | int i; | |
1063 | extern CLIENT *pClient; | |
1064 | ||
1065 | if (!args) | |
1066 | error_no_arg ("target machine name"); | |
1067 | ||
70dcc196 JK |
1068 | target_preopen (from_tty); |
1069 | ||
dd3b648e RP |
1070 | unpush_target (&vx_ops); |
1071 | printf ("Attaching remote machine across net...\n"); | |
1072 | fflush (stdout); | |
1073 | ||
1074 | /* Allow the user to kill the connect attempt by typing ^C. | |
1075 | Wait until the call to target_has_fp () completes before | |
1076 | disallowing an immediate quit, since even if net_connect () | |
1077 | is successful, the remote debug server might be hung. */ | |
1078 | ||
1079 | immediate_quit++; | |
1080 | ||
1081 | net_connect (args); | |
1082 | target_has_fp = net_check_for_fp (); | |
1083 | printf_filtered ("Connected to %s.\n", args); | |
1084 | ||
1085 | immediate_quit--; | |
1086 | ||
1087 | push_target (&vx_ops); | |
1088 | ||
1089 | /* Save a copy of the target host's name. */ | |
1090 | vx_host = savestring (args, strlen (args)); | |
1091 | ||
1092 | /* Find out the name of the file from which the target was booted | |
1093 | and load its symbol table. */ | |
1094 | ||
1095 | printf_filtered ("Looking in Unix path for all loaded modules:\n"); | |
1096 | bootFile = NULL; | |
1097 | if (!net_get_boot_file (&bootFile)) | |
1098 | { | |
1099 | if (*bootFile) { | |
1100 | printf_filtered ("\t%s: ", bootFile); | |
bdbd5f50 | 1101 | if (catch_errors (symbol_stub, bootFile, |
06b6c733 | 1102 | "Error while reading symbols from boot file:\n")) |
dd3b648e RP |
1103 | puts_filtered ("ok\n"); |
1104 | } else if (from_tty) | |
1105 | printf ("VxWorks kernel symbols not loaded.\n"); | |
1106 | } | |
1107 | else | |
1108 | error ("Can't retrieve boot file name from target machine."); | |
1109 | ||
1110 | clnt_freeres (pClient, xdr_wrapstring, &bootFile); | |
1111 | ||
1112 | if (net_get_symbols (&loadTable) != 0) | |
1113 | error ("Can't read loaded modules from target machine"); | |
1114 | ||
1115 | i = 0-1; | |
1116 | while (++i < loadTable.tbl_size) | |
1117 | { | |
1118 | QUIT; /* FIXME, avoids clnt_freeres below: mem leak */ | |
1119 | pLoadFile = &loadTable.tbl_ent [i]; | |
1120 | #ifdef WRS_ORIG | |
1121 | { | |
1122 | register int desc; | |
1123 | struct cleanup *old_chain; | |
1124 | char *fullname = NULL; | |
1125 | ||
1126 | desc = openp (source_path, 0, pLoadFile->name, O_RDONLY, 0, &fullname); | |
1127 | if (desc < 0) | |
1128 | perror_with_name (pLoadFile->name); | |
1129 | old_chain = make_cleanup (close, desc); | |
1130 | add_file_at_addr (fullname, desc, pLoadFile->txt_addr, pLoadFile->data_addr, | |
1131 | pLoadFile->bss_addr); | |
1132 | do_cleanups (old_chain); | |
1133 | } | |
1134 | #else | |
1135 | /* Botches, FIXME: | |
1136 | (1) Searches the PATH, not the source path. | |
1137 | (2) data and bss are assumed to be at the usual offsets from text. */ | |
bdbd5f50 | 1138 | catch_errors (add_symbol_stub, (char *)pLoadFile, (char *)0); |
dd3b648e RP |
1139 | #endif |
1140 | } | |
1141 | printf_filtered ("Done.\n"); | |
1142 | ||
1143 | clnt_freeres (pClient, xdr_ldtabl, &loadTable); | |
1144 | } | |
1145 | \f | |
1146 | /* attach_command -- | |
1147 | takes a task started up outside of gdb and ``attaches'' to it. | |
1148 | This stops it cold in its tracks and allows us to start tracing it. */ | |
1149 | ||
1150 | static void | |
1151 | vx_attach (args, from_tty) | |
1152 | char *args; | |
1153 | int from_tty; | |
1154 | { | |
1155 | int pid; | |
1156 | char *cptr = 0; | |
1157 | Rptrace ptrace_in; | |
1158 | Ptrace_return ptrace_out; | |
1159 | int status; | |
1160 | ||
1161 | dont_repeat(); | |
1162 | ||
1163 | if (!args) | |
1164 | error_no_arg ("process-id to attach"); | |
1165 | ||
1166 | pid = strtol (args, &cptr, 0); | |
1167 | if ((cptr == args) || (*cptr != '\0')) | |
1168 | error ("Invalid process-id -- give a single number in decimal or 0xhex"); | |
1169 | ||
1170 | if (from_tty) | |
e3af0493 | 1171 | printf ("Attaching pid %s.\n", local_hex_string(pid)); |
dd3b648e RP |
1172 | |
1173 | bzero ((char *)&ptrace_in, sizeof (ptrace_in)); | |
1174 | bzero ((char *)&ptrace_out, sizeof (ptrace_out)); | |
1175 | ptrace_in.pid = pid; | |
1176 | ||
1177 | status = net_ptrace_clnt_call (PTRACE_ATTACH, &ptrace_in, &ptrace_out); | |
1178 | if (status == -1) | |
1179 | error (rpcerr); | |
1180 | if (ptrace_out.status == -1) | |
1181 | { | |
1182 | errno = ptrace_out.errno; | |
1183 | perror_with_name ("Attaching remote process"); | |
1184 | } | |
1185 | ||
1186 | /* It worked... */ | |
1187 | push_target (&vx_run_ops); | |
1188 | inferior_pid = pid; | |
1189 | vx_running = 0; | |
1190 | ||
dd3b648e RP |
1191 | mark_breakpoints_out (); |
1192 | ||
1193 | /* Set up the "saved terminal modes" of the inferior | |
1194 | based on what modes we are starting it with. */ | |
1195 | target_terminal_init (); | |
1196 | ||
1197 | /* Install inferior's terminal modes. */ | |
1198 | target_terminal_inferior (); | |
1199 | ||
1200 | /* We will get a task spawn event immediately. */ | |
1201 | init_wait_for_inferior (); | |
1202 | clear_proceed_status (); | |
1203 | stop_soon_quietly = 1; | |
1204 | wait_for_inferior (); | |
1205 | stop_soon_quietly = 0; | |
1206 | normal_stop (); | |
1207 | } | |
1208 | ||
1209 | ||
1210 | /* detach_command -- | |
1211 | takes a program previously attached to and detaches it. | |
1212 | The program resumes execution and will no longer stop | |
1213 | on signals, etc. We better not have left any breakpoints | |
1214 | in the program or it'll die when it hits one. For this | |
1215 | to work, it may be necessary for the process to have been | |
1216 | previously attached. It *might* work if the program was | |
1217 | started via the normal ptrace (PTRACE_TRACEME). */ | |
1218 | ||
1219 | static void | |
1220 | vx_detach (args, from_tty) | |
1221 | char *args; | |
1222 | int from_tty; | |
1223 | { | |
1224 | Rptrace ptrace_in; | |
1225 | Ptrace_return ptrace_out; | |
1226 | int signal = 0; | |
1227 | int status; | |
1228 | ||
1229 | if (args) | |
1230 | error ("Argument given to VxWorks \"detach\"."); | |
1231 | ||
1232 | if (from_tty) | |
e3af0493 | 1233 | printf ("Detaching pid %s.\n", local_hex_string(inferior_pid)); |
dd3b648e RP |
1234 | |
1235 | if (args) /* FIXME, should be possible to leave suspended */ | |
1236 | signal = atoi (args); | |
1237 | ||
1238 | bzero ((char *)&ptrace_in, sizeof (ptrace_in)); | |
1239 | bzero ((char *)&ptrace_out, sizeof (ptrace_out)); | |
1240 | ptrace_in.pid = inferior_pid; | |
1241 | ||
1242 | status = net_ptrace_clnt_call (PTRACE_DETACH, &ptrace_in, &ptrace_out); | |
1243 | if (status == -1) | |
1244 | error (rpcerr); | |
1245 | if (ptrace_out.status == -1) | |
1246 | { | |
1247 | errno = ptrace_out.errno; | |
1248 | perror_with_name ("Detaching VxWorks process"); | |
1249 | } | |
1250 | ||
1251 | inferior_pid = 0; | |
1252 | pop_target (); /* go back to non-executing VxWorks connection */ | |
1253 | } | |
1254 | ||
1255 | /* vx_kill -- takes a running task and wipes it out. */ | |
1256 | ||
1257 | static void | |
1258 | vx_kill (args, from_tty) | |
1259 | char *args; | |
1260 | int from_tty; | |
1261 | { | |
1262 | Rptrace ptrace_in; | |
1263 | Ptrace_return ptrace_out; | |
1264 | int status; | |
1265 | ||
1266 | if (args) | |
1267 | error ("Argument given to VxWorks \"kill\"."); | |
1268 | ||
1269 | if (from_tty) | |
e3af0493 | 1270 | printf ("Killing pid %s.\n", local_hex_string(inferior_pid)); |
dd3b648e RP |
1271 | |
1272 | bzero ((char *)&ptrace_in, sizeof (ptrace_in)); | |
1273 | bzero ((char *)&ptrace_out, sizeof (ptrace_out)); | |
1274 | ptrace_in.pid = inferior_pid; | |
1275 | ||
1276 | status = net_ptrace_clnt_call (PTRACE_KILL, &ptrace_in, &ptrace_out); | |
1277 | if (status == -1) | |
1278 | error (rpcerr); | |
1279 | if (ptrace_out.status == -1) | |
1280 | { | |
1281 | errno = ptrace_out.errno; | |
1282 | perror_with_name ("Killing VxWorks process"); | |
1283 | } | |
1284 | ||
1285 | /* If it gives good status, the process is *gone*, no events remain. */ | |
1286 | inferior_pid = 0; | |
1287 | pop_target (); /* go back to non-executing VxWorks connection */ | |
1288 | } | |
1289 | ||
1290 | /* Clean up from the VxWorks process target as it goes away. */ | |
1291 | ||
1292 | void | |
1293 | vx_proc_close (quitting) | |
1294 | int quitting; | |
1295 | { | |
1296 | inferior_pid = 0; /* No longer have a process. */ | |
1297 | if (vx_running) | |
1298 | free (vx_running); | |
1299 | vx_running = 0; | |
1300 | } | |
1301 | \f | |
1302 | /* Cross-net conversion of floats to and from extended form. | |
1303 | (This is needed because different target machines have different | |
1304 | extended floating point formats.) */ | |
1305 | ||
1306 | /* Convert from an extended float to a double. | |
1307 | ||
1308 | The extended float is stored as raw data pointed to by FROM. | |
1309 | Return the converted value as raw data in the double pointed to by TO. | |
1310 | */ | |
1311 | ||
1312 | static void | |
1313 | vx_convert_to_virtual (regno, from, to) | |
1314 | int regno; | |
1315 | char *from; | |
1316 | char *to; | |
1317 | { | |
1318 | enum clnt_stat status; | |
1319 | ||
1320 | if (REGISTER_CONVERTIBLE (regno)) | |
1321 | { | |
1322 | if (!target_has_fp) { | |
1323 | *(double *)to = 0.0; /* Skip the trouble if no float anyway */ | |
1324 | return; | |
1325 | } | |
1326 | ||
1327 | status = net_clnt_call (VX_CONV_FROM_68881, xdr_ext_fp, from, | |
1328 | xdr_double, to); | |
1329 | ||
1330 | if (status == RPC_SUCCESS) | |
1331 | return; | |
1332 | else | |
1333 | error (rpcerr); | |
1334 | } | |
1335 | else | |
1336 | bcopy (from, to, REGISTER_VIRTUAL_SIZE (regno)); | |
1337 | } | |
1338 | ||
1339 | ||
1340 | /* The converse: convert from a double to an extended float. | |
1341 | ||
1342 | The double is stored as raw data pointed to by FROM. | |
1343 | Return the converted value as raw data in the extended | |
1344 | float pointed to by TO. | |
1345 | */ | |
1346 | ||
1347 | static void | |
1348 | vx_convert_from_virtual (regno, from, to) | |
1349 | int regno; | |
1350 | char *from; | |
1351 | char *to; | |
1352 | { | |
1353 | enum clnt_stat status; | |
1354 | ||
1355 | if (REGISTER_CONVERTIBLE (regno)) | |
1356 | { | |
1357 | if (!target_has_fp) { | |
1358 | bzero (to, REGISTER_RAW_SIZE (FP0_REGNUM)); /* Shrug */ | |
1359 | return; | |
1360 | } | |
1361 | ||
1362 | status = net_clnt_call (VX_CONV_TO_68881, xdr_double, from, | |
1363 | xdr_ext_fp, to); | |
1364 | if (status == RPC_SUCCESS) | |
1365 | return; | |
1366 | else | |
1367 | error (rpcerr); | |
1368 | } | |
1369 | else | |
1370 | bcopy (from, to, REGISTER_VIRTUAL_SIZE (regno)); | |
1371 | } | |
1372 | \f | |
1373 | /* Make an RPC call to the VxWorks target. | |
1374 | Returns RPC status. */ | |
1375 | ||
1376 | static enum clnt_stat | |
1377 | net_clnt_call (procNum, inProc, in, outProc, out) | |
1378 | enum ptracereq procNum; | |
1379 | xdrproc_t inProc; | |
1380 | char *in; | |
1381 | xdrproc_t outProc; | |
1382 | char *out; | |
1383 | { | |
1384 | enum clnt_stat status; | |
1385 | ||
1386 | status = clnt_call (pClient, procNum, inProc, in, outProc, out, rpcTimeout); | |
1387 | ||
1388 | if (status != RPC_SUCCESS) | |
1389 | clnt_perrno (status); | |
1390 | ||
1391 | return status; | |
1392 | } | |
1393 | ||
1394 | /* Clean up before losing control. */ | |
1395 | ||
1396 | void | |
1397 | vx_close (quitting) | |
1398 | int quitting; | |
1399 | { | |
1400 | if (pClient) | |
1401 | clnt_destroy (pClient); /* The net connection */ | |
1402 | pClient = 0; | |
1403 | ||
1404 | if (vx_host) | |
1405 | free (vx_host); /* The hostname */ | |
1406 | vx_host = 0; | |
1407 | } | |
1408 | ||
70dcc196 JK |
1409 | /* A vxprocess target should be started via "run" not "target". */ |
1410 | /*ARGSUSED*/ | |
1411 | static void | |
1412 | vx_proc_open (name, from_tty) | |
1413 | char *name; | |
1414 | int from_tty; | |
1415 | { | |
1416 | error ("Use the \"run\" command to start a VxWorks process."); | |
1417 | } | |
dd3b648e RP |
1418 | |
1419 | /* Target ops structure for accessing memory and such over the net */ | |
1420 | ||
1421 | struct target_ops vx_ops = { | |
1422 | "vxworks", "VxWorks target memory via RPC over TCP/IP", | |
70dcc196 JK |
1423 | "Use VxWorks target memory. \n\ |
1424 | Specify the name of the machine to connect to.", | |
dd3b648e RP |
1425 | vx_open, vx_close, vx_attach, 0, /* vx_detach, */ |
1426 | 0, 0, /* resume, wait */ | |
1427 | 0, 0, /* read_reg, write_reg */ | |
1428 | 0, vx_convert_to_virtual, vx_convert_from_virtual, /* prep_to_store, */ | |
1429 | vx_xfer_memory, vx_files_info, | |
1430 | 0, 0, /* insert_breakpoint, remove_breakpoint */ | |
1431 | 0, 0, 0, 0, 0, /* terminal stuff */ | |
1432 | 0, /* vx_kill, */ | |
8f1f2a72 | 1433 | vx_load_command, |
dd3b648e RP |
1434 | vx_lookup_symbol, |
1435 | vx_create_inferior, 0, /* mourn_inferior */ | |
1436 | core_stratum, 0, /* next */ | |
1437 | 1, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */ | |
8f1f2a72 | 1438 | 0, 0, /* Section pointers */ |
dd3b648e RP |
1439 | OPS_MAGIC, /* Always the last thing */ |
1440 | }; | |
1441 | ||
1442 | /* Target ops structure for accessing VxWorks child processes over the net */ | |
1443 | ||
1444 | struct target_ops vx_run_ops = { | |
1445 | "vxprocess", "VxWorks process", | |
70dcc196 JK |
1446 | "VxWorks process, started by the \"run\" command.", |
1447 | vx_proc_open, vx_proc_close, 0, vx_detach, /* vx_attach */ | |
dd3b648e RP |
1448 | vx_resume, vx_wait, |
1449 | vx_read_register, vx_write_register, | |
1450 | vx_prepare_to_store, vx_convert_to_virtual, vx_convert_from_virtual, | |
1451 | vx_xfer_memory, vx_run_files_info, | |
1452 | vx_insert_breakpoint, vx_remove_breakpoint, | |
1453 | 0, 0, 0, 0, 0, /* terminal stuff */ | |
1454 | vx_kill, | |
8f1f2a72 | 1455 | vx_load_command, |
dd3b648e RP |
1456 | vx_lookup_symbol, |
1457 | 0, vx_mourn_inferior, | |
1458 | process_stratum, 0, /* next */ | |
1459 | 0, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */ | |
1460 | /* all_mem is off to avoid spurious msg in "i files" */ | |
8f1f2a72 | 1461 | 0, 0, /* Section pointers */ |
dd3b648e RP |
1462 | OPS_MAGIC, /* Always the last thing */ |
1463 | }; | |
1464 | /* ==> Remember when reading at end of file, there are two "ops" structs here. */ | |
1465 | \f | |
1466 | void | |
1467 | _initialize_vx () | |
1468 | { | |
1469 | add_target (&vx_ops); | |
1470 | add_target (&vx_run_ops); | |
1471 | } |