1 /* Memory-access and commands for remote VxWorks processes, for GDB.
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Wind River Systems and Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
30 #include "symfile.h" /* for struct complaint */
36 #include <sys/types.h>
38 #include <sys/socket.h>
39 #define free bogon_free /* Sun claims "int free()" not void */
42 #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
45 #include "xdr_ptrace.h"
48 #include "dbgRpcLib.h"
52 extern void symbol_file_command ();
53 extern int stop_soon_quietly
; /* for wait_for_inferior */
55 static int net_ptrace_clnt_call (); /* Forward decl */
56 static enum clnt_stat
net_clnt_call (); /* Forward decl */
57 extern struct target_ops vx_ops
, vx_run_ops
; /* Forward declaration */
59 /* Saved name of target host and called function for "info files".
63 static char *vx_running
; /* Called function */
65 /* Nonzero means target that is being debugged remotely has a floating
68 static int target_has_fp
;
70 /* Default error message when the network is forking up. */
72 static const char rpcerr
[] = "network target debugging: rpc error";
74 CLIENT
*pClient
; /* client used in net debugging */
75 static int ptraceSock
= RPC_ANYSOCK
;
77 enum clnt_stat
net_clnt_call();
78 static void parse_args ();
80 static struct timeval rpcTimeout
= { 10, 0 };
82 static char *skip_white_space ();
83 static char *find_white_space ();
85 /* Tell the VxWorks target system to download a file.
86 The load addresses of the text, data, and bss segments are
87 stored in pTextAddr, pDataAddr, and *pBssAddr (respectively).
88 Returns 0 for success, -1 for failure. */
91 net_load (filename
, pTextAddr
, pDataAddr
, pBssAddr
)
97 enum clnt_stat status
;
98 struct ldfile ldstruct
;
99 struct timeval load_timeout
;
101 bzero ((char *) &ldstruct
, sizeof (ldstruct
));
103 /* We invoke clnt_call () here directly, instead of through
104 net_clnt_call (), because we need to set a large timeout value.
105 The load on the target side can take quite a while, easily
106 more than 10 seconds. The user can kill this call by typing
107 CTRL-C if there really is a problem with the load.
109 Do not change the tv_sec value without checking -- select() imposes
110 a limit of 10**8 on it for no good reason that I can see... */
112 load_timeout
.tv_sec
= 99999999; /* A large number, effectively inf. */
113 load_timeout
.tv_usec
= 0;
115 status
= clnt_call (pClient
, VX_LOAD
, xdr_wrapstring
, &filename
, xdr_ldfile
,
116 &ldstruct
, load_timeout
);
118 if (status
== RPC_SUCCESS
)
120 if (*ldstruct
.name
== NULL
) /* load failed on VxWorks side */
122 *pTextAddr
= ldstruct
.txt_addr
;
123 *pDataAddr
= ldstruct
.data_addr
;
124 *pBssAddr
= ldstruct
.bss_addr
;
131 /* returns 0 if successful, errno if RPC failed or VxWorks complains. */
134 net_break (addr
, procnum
)
138 enum clnt_stat status
;
140 Rptrace ptrace_in
; /* XXX This is stupid. It doesn't need to be a ptrace
141 structure. How about something smaller? */
143 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
146 ptrace_in
.addr
= addr
;
147 ptrace_in
.pid
= inferior_pid
;
149 status
= net_clnt_call (procnum
, xdr_rptrace
, &ptrace_in
, xdr_int
,
152 if (status
!= RPC_SUCCESS
)
155 if (break_status
== -1)
157 return break_status
; /* probably (FIXME) zero */
160 /* returns 0 if successful, errno otherwise */
163 vx_insert_breakpoint (addr
)
166 return net_break (addr
, VX_BREAK_ADD
);
169 /* returns 0 if successful, errno otherwise */
172 vx_remove_breakpoint (addr
)
175 return net_break (addr
, VX_BREAK_DELETE
);
178 /* Start an inferior process and sets inferior_pid to its pid.
179 EXEC_FILE is the file to run.
180 ALLARGS is a string containing the arguments to the program.
181 ENV is the environment vector to pass.
182 Returns process id. Errors reported with error().
183 On VxWorks, we ignore exec_file. */
186 vx_create_inferior (exec_file
, args
, env
)
191 enum clnt_stat status
;
193 TASK_START taskStart
;
195 bzero ((char *) &passArgs
, sizeof (passArgs
));
196 bzero ((char *) &taskStart
, sizeof (taskStart
));
198 /* parse arguments, put them in passArgs */
200 parse_args (args
, &passArgs
);
202 if (passArgs
.arg_array_len
== 0)
203 error ("You must specify a function name to run, and arguments if any");
205 status
= net_clnt_call (PROCESS_START
, xdr_arg_array
, &passArgs
,
206 xdr_TASK_START
, &taskStart
);
208 if ((status
!= RPC_SUCCESS
) || (taskStart
.status
== -1))
209 error ("Can't create process on remote target machine");
211 /* Save the name of the running function */
212 vx_running
= savestring (passArgs
.arg_array_val
[0],
213 strlen (passArgs
.arg_array_val
[0]));
215 #ifdef CREATE_INFERIOR_HOOK
216 CREATE_INFERIOR_HOOK (pid
);
219 push_target (&vx_run_ops
);
220 inferior_pid
= taskStart
.pid
;
222 /* We will get a trace trap after one instruction.
223 Insert breakpoints and continue. */
225 init_wait_for_inferior ();
227 /* Set up the "saved terminal modes" of the inferior
228 based on what modes we are starting it with. */
229 target_terminal_init ();
231 /* Install inferior's terminal modes. */
232 target_terminal_inferior ();
234 stop_soon_quietly
= 1;
235 wait_for_inferior (); /* Get the task spawn event */
236 stop_soon_quietly
= 0;
238 /* insert_step_breakpoint (); FIXME, do we need this? */
242 /* Fill ARGSTRUCT in argc/argv form with the arguments from the
243 argument string ARGSTRING. */
246 parse_args (arg_string
, arg_struct
)
247 register char *arg_string
;
248 arg_array
*arg_struct
;
250 register int arg_count
= 0; /* number of arguments */
251 register int arg_index
= 0;
254 bzero ((char *) arg_struct
, sizeof (arg_array
));
256 /* first count how many arguments there are */
261 if (*(p0
= skip_white_space (p0
)) == '\0')
263 p0
= find_white_space (p0
);
267 arg_struct
->arg_array_len
= arg_count
;
268 arg_struct
->arg_array_val
= (char **) xmalloc ((arg_count
+ 1)
271 /* now copy argument strings into arg_struct. */
273 while (*(arg_string
= skip_white_space (arg_string
)))
275 p0
= find_white_space (arg_string
);
276 arg_struct
->arg_array_val
[arg_index
++] = savestring (arg_string
,
281 arg_struct
->arg_array_val
[arg_count
] = NULL
;
284 /* Advance a string pointer across whitespace and return a pointer
285 to the first non-white character. */
291 while (*p
== ' ' || *p
== '\t')
296 /* Search for the first unquoted whitespace character in a string.
297 Returns a pointer to the character, or to the null terminator
298 if no whitespace is found. */
306 while ((c
= *p
) != ' ' && c
!= '\t' && c
)
308 if (c
== '\'' || c
== '"')
310 while (*++p
!= c
&& *p
)
323 /* Poll the VxWorks target system for an event related
324 to the debugged task.
325 Returns -1 if remote wait failed, task status otherwise. */
332 enum clnt_stat status
;
334 bzero ((char *) pEvent
, sizeof (RDB_EVENT
));
337 status
= net_clnt_call (PROCESS_WAIT
, xdr_int
, &pid
, xdr_RDB_EVENT
, pEvent
);
339 return (status
== RPC_SUCCESS
)? pEvent
->status
: -1;
342 /* Suspend the remote task.
343 Returns -1 if suspend fails on target system, 0 otherwise. */
350 enum clnt_stat status
;
354 /* don't let rdbTask suspend itself by passing a pid of 0 */
356 if ((pid
= inferior_pid
) == 0)
359 status
= net_clnt_call (VX_TASK_SUSPEND
, xdr_int
, &pid
, xdr_int
,
362 return (status
== RPC_SUCCESS
)? quit_status
: -1;
365 /* Read a register or registers from the remote system. */
368 vx_read_register (regno
)
373 Ptrace_return ptrace_out
;
374 struct regs inferior_registers
;
375 struct fp_status inferior_fp_registers
;
376 extern char registers
[];
378 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
379 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
381 /* FIXME, eventually only get the ones we need. */
382 registers_fetched ();
384 ptrace_in
.pid
= inferior_pid
;
385 ptrace_out
.info
.more_data
= (caddr_t
) &inferior_registers
;
386 status
= net_ptrace_clnt_call (PTRACE_GETREGS
, &ptrace_in
, &ptrace_out
);
389 if (ptrace_out
.status
== -1)
391 errno
= ptrace_out
.errno
;
397 bcopy ((char *) inferior_registers
.r_lreg
,
398 ®isters
[REGISTER_BYTE (R0_REGNUM
)], 16 * sizeof (int));
399 bcopy ((char *) inferior_registers
.r_greg
,
400 ®isters
[REGISTER_BYTE (G0_REGNUM
)], 16 * sizeof (int));
402 /* Don't assume that a location in registers[] is properly aligned. */
404 bcopy ((char *) &inferior_registers
.r_pcw
,
405 ®isters
[REGISTER_BYTE (PCW_REGNUM
)], sizeof (int));
406 bcopy ((char *) &inferior_registers
.r_acw
,
407 ®isters
[REGISTER_BYTE (ACW_REGNUM
)], sizeof (int));
408 bcopy ((char *) &inferior_registers
.r_lreg
[2], /* r2 (RIP) -> IP */
409 ®isters
[REGISTER_BYTE (IP_REGNUM
)], sizeof (int));
410 bcopy ((char *) &inferior_registers
.r_tcw
,
411 ®isters
[REGISTER_BYTE (TCW_REGNUM
)], sizeof (int));
413 /* If the target has floating point registers, fetch them.
414 Otherwise, zero the floating point register values in
415 registers[] for good measure, even though we might not
420 ptrace_in
.pid
= inferior_pid
;
421 ptrace_out
.info
.more_data
= (caddr_t
) &inferior_fp_registers
;
422 status
= net_ptrace_clnt_call (PTRACE_GETFPREGS
, &ptrace_in
, &ptrace_out
);
425 if (ptrace_out
.status
== -1)
427 errno
= ptrace_out
.errno
;
431 bcopy (&inferior_fp_registers
, ®isters
[REGISTER_BYTE (FP0_REGNUM
)],
432 REGISTER_RAW_SIZE (FP0_REGNUM
) * 4);
436 bzero ((char *) ®isters
[REGISTER_BYTE (FP0_REGNUM
)],
437 REGISTER_RAW_SIZE (FP0_REGNUM
) * 4);
440 #else /* not 960, thus must be 68000: FIXME! */
442 bcopy (&inferior_registers
, registers
, 16 * 4);
443 *(int *)®isters
[REGISTER_BYTE (PS_REGNUM
)] = inferior_registers
.r_ps
;
444 *(int *)®isters
[REGISTER_BYTE (PC_REGNUM
)] = inferior_registers
.r_pc
;
448 ptrace_in
.pid
= inferior_pid
;
449 ptrace_out
.info
.more_data
= (caddr_t
) &inferior_fp_registers
;
450 status
= net_ptrace_clnt_call (PTRACE_GETFPREGS
, &ptrace_in
, &ptrace_out
);
453 if (ptrace_out
.status
== -1)
455 errno
= ptrace_out
.errno
;
459 bcopy (&inferior_fp_registers
, ®isters
[REGISTER_BYTE (FP0_REGNUM
)],
460 sizeof inferior_fp_registers
.fps_regs
);
461 bcopy (&inferior_fp_registers
.fps_control
,
462 ®isters
[REGISTER_BYTE (FPC_REGNUM
)],
463 sizeof inferior_fp_registers
- sizeof inferior_fp_registers
.fps_regs
);
467 bzero (®isters
[REGISTER_BYTE (FP0_REGNUM
)],
468 sizeof inferior_fp_registers
.fps_regs
);
469 bzero (®isters
[REGISTER_BYTE (FPC_REGNUM
)],
470 sizeof inferior_fp_registers
- sizeof inferior_fp_registers
.fps_regs
);
472 #endif /* various architectures */
477 /* Prepare to store registers. Since we will store all of them,
478 read out their current values now. */
481 vx_prepare_to_store ()
483 vx_read_register (-1);
487 /* Store our register values back into the inferior.
488 If REGNO is -1, do this for all registers.
489 Otherwise, REGNO specifies which register (so we can save time). */
490 /* FIXME, look at REGNO to save time here */
492 vx_write_register (regno
)
495 struct regs inferior_registers
;
496 struct fp_status inferior_fp_registers
;
497 extern char registers
[];
500 Ptrace_return ptrace_out
;
502 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
503 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
507 bcopy (®isters
[REGISTER_BYTE (R0_REGNUM
)],
508 (char *) inferior_registers
.r_lreg
, 16 * sizeof (int));
509 bcopy (®isters
[REGISTER_BYTE (G0_REGNUM
)],
510 (char *) inferior_registers
.r_greg
, 16 * sizeof (int));
512 /* Don't assume that a location in registers[] is properly aligned. */
514 bcopy (®isters
[REGISTER_BYTE (PCW_REGNUM
)],
515 (char *) &inferior_registers
.r_pcw
, sizeof (int));
516 bcopy (®isters
[REGISTER_BYTE (ACW_REGNUM
)],
517 (char *) &inferior_registers
.r_acw
, sizeof (int));
518 bcopy (®isters
[REGISTER_BYTE (TCW_REGNUM
)],
519 (char *) &inferior_registers
.r_tcw
, sizeof (int));
521 #else /* not 960 -- assume 68k -- FIXME */
523 bcopy (registers
, &inferior_registers
, 16 * 4);
524 inferior_registers
.r_ps
= *(int *)®isters
[REGISTER_BYTE (PS_REGNUM
)];
525 inferior_registers
.r_pc
= *(int *)®isters
[REGISTER_BYTE (PC_REGNUM
)];
527 #endif /* Different register sets */
529 ptrace_in
.pid
= inferior_pid
;
530 ptrace_in
.info
.ttype
= REGS
;
531 ptrace_in
.info
.more_data
= (caddr_t
) &inferior_registers
;
533 /* XXX change second param to be a proc number */
534 status
= net_ptrace_clnt_call (PTRACE_SETREGS
, &ptrace_in
, &ptrace_out
);
537 if (ptrace_out
.status
== -1)
539 errno
= ptrace_out
.errno
;
543 /* Store floating point registers if the target has them. */
549 bcopy (®isters
[REGISTER_BYTE (FP0_REGNUM
)], &inferior_fp_registers
,
550 sizeof inferior_fp_registers
.fps_regs
);
552 #else /* not 960 -- assume 68k -- FIXME */
554 bcopy (®isters
[REGISTER_BYTE (FP0_REGNUM
)], &inferior_fp_registers
,
555 sizeof inferior_fp_registers
.fps_regs
);
556 bcopy (®isters
[REGISTER_BYTE (FPC_REGNUM
)],
557 &inferior_fp_registers
.fps_control
,
558 sizeof inferior_fp_registers
- sizeof inferior_fp_registers
.fps_regs
);
560 #endif /* Different register sets */
562 ptrace_in
.pid
= inferior_pid
;
563 ptrace_in
.info
.ttype
= FPREGS
;
564 ptrace_in
.info
.more_data
= (caddr_t
) &inferior_fp_registers
;
566 status
= net_ptrace_clnt_call (PTRACE_SETFPREGS
, &ptrace_in
, &ptrace_out
);
569 if (ptrace_out
.status
== -1)
571 errno
= ptrace_out
.errno
;
578 /* Copy LEN bytes to or from remote inferior's memory starting at MEMADDR
579 to debugger memory starting at MYADDR. WRITE is true if writing to the
581 Result is the number of bytes written or read (zero if error). The
582 protocol allows us to return a negative count, indicating that we can't
583 handle the current address but can handle one N bytes further, but
584 vxworks doesn't give us that information. */
587 vx_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
592 struct target_ops
*target
; /* ignored */
596 Ptrace_return ptrace_out
;
599 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
600 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
602 ptrace_in
.pid
= inferior_pid
; /* XXX pid unnecessary for READDATA */
603 ptrace_in
.addr
= (int) memaddr
; /* Where from */
604 ptrace_in
.data
= len
; /* How many bytes */
608 ptrace_in
.info
.ttype
= DATA
;
609 ptrace_in
.info
.more_data
= (caddr_t
) &data
;
611 data
.bytes
= (caddr_t
) myaddr
; /* Where from */
612 data
.len
= len
; /* How many bytes (again, for XDR) */
614 /* XXX change second param to be a proc number */
615 status
= net_ptrace_clnt_call (PTRACE_WRITEDATA
, &ptrace_in
, &ptrace_out
);
619 ptrace_out
.info
.more_data
= (caddr_t
) &data
;
620 data
.bytes
= myaddr
; /* Where to */
621 data
.len
= len
; /* How many (again, for XDR) */
623 /* XXX change second param to be a proc number */
624 status
= net_ptrace_clnt_call (PTRACE_READDATA
, &ptrace_in
, &ptrace_out
);
629 if (ptrace_out
.status
== -1)
631 return 0; /* No bytes moved */
633 return len
; /* Moved *all* the bytes */
639 printf ("\tAttached to host `%s'", vx_host
);
640 printf (", which has %sfloating point", target_has_fp
? "": "no ");
647 printf ("\tRunning %s VxWorks process %s",
648 vx_running
? "child": "attached",
649 local_hex_string(inferior_pid
));
651 printf (", function `%s'", vx_running
);
656 vx_resume (step
, siggnal
)
662 Ptrace_return ptrace_out
;
664 if (siggnal
!= 0 && siggnal
!= stop_signal
)
665 error ("Cannot send signals to VxWorks processes");
667 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
668 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
670 ptrace_in
.pid
= inferior_pid
;
671 ptrace_in
.addr
= 1; /* Target side insists on this, or it panics. */
673 /* XXX change second param to be a proc number */
674 status
= net_ptrace_clnt_call (step
? PTRACE_SINGLESTEP
: PTRACE_CONT
,
675 &ptrace_in
, &ptrace_out
);
678 if (ptrace_out
.status
== -1)
680 errno
= ptrace_out
.errno
;
681 perror_with_name ("Resuming remote process");
688 pop_target (); /* Pop back to no-child state */
689 generic_mourn_inferior ();
693 /* This function allows the addition of incrementally linked object files. */
696 vx_load_command (arg_string
, from_tty
)
705 error ("The load command takes a file name");
707 arg_string
= tilde_expand (arg_string
);
708 make_cleanup (free
, arg_string
);
714 if (net_load (arg_string
, &text_addr
, &data_addr
, &bss_addr
) == -1)
715 error ("Load failed on target machine");
718 /* FIXME, for now we ignore data_addr and bss_addr. */
719 (void) symbol_file_add (arg_string
, from_tty
, text_addr
, 0);
722 #ifdef FIXME /* Not ready for prime time */
723 /* Single step the target program at the source or machine level.
724 Takes an error exit if rpc fails.
725 Returns -1 if remote single-step operation fails, else 0. */
730 enum clnt_stat status
;
732 SOURCE_STEP source_step
;
734 source_step
.taskId
= inferior_pid
;
738 source_step
.startAddr
= step_range_start
;
739 source_step
.endAddr
= step_range_end
;
743 source_step
.startAddr
= 0;
744 source_step
.endAddr
= 0;
747 status
= net_clnt_call (VX_SOURCE_STEP
, xdr_SOURCE_STEP
, &source_step
,
748 xdr_int
, &step_status
);
750 if (status
== RPC_SUCCESS
)
757 /* Emulate ptrace using RPC calls to the VxWorks target system.
758 Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */
761 net_ptrace_clnt_call (request
, pPtraceIn
, pPtraceOut
)
762 enum ptracereq request
;
764 Ptrace_return
*pPtraceOut
;
766 enum clnt_stat status
;
768 status
= net_clnt_call (request
, xdr_rptrace
, pPtraceIn
, xdr_ptrace_return
,
771 if (status
!= RPC_SUCCESS
)
777 /* Query the target for the name of the file from which VxWorks was
778 booted. pBootFile is the address of a pointer to the buffer to
779 receive the file name; if the pointer pointed to by pBootFile is
780 NULL, memory for the buffer will be allocated by XDR.
781 Returns -1 if rpc failed, 0 otherwise. */
784 net_get_boot_file (pBootFile
)
787 enum clnt_stat status
;
789 status
= net_clnt_call (VX_BOOT_FILE_INQ
, xdr_void
, (char *) 0,
790 xdr_wrapstring
, pBootFile
);
791 return (status
== RPC_SUCCESS
) ? 0 : -1;
794 /* Fetch a list of loaded object modules from the VxWorks target.
795 Returns -1 if rpc failed, 0 otherwise
796 There's no way to check if the returned loadTable is correct.
797 VxWorks doesn't check it. */
800 net_get_symbols (pLoadTable
)
801 ldtabl
*pLoadTable
; /* return pointer to ldtabl here */
803 enum clnt_stat status
;
805 bzero ((char *) pLoadTable
, sizeof (struct ldtabl
));
807 status
= net_clnt_call (VX_STATE_INQ
, xdr_void
, 0, xdr_ldtabl
, pLoadTable
);
808 return (status
== RPC_SUCCESS
) ? 0 : -1;
811 /* Look up a symbol in the VxWorks target's symbol table.
812 Returns status of symbol read on target side (0=success, -1=fail)
813 Returns -1 and complain()s if rpc fails. */
815 struct complaint cant_contact_target
=
816 {"Lost contact with VxWorks target", 0, 0};
819 vx_lookup_symbol (name
, pAddr
)
820 char *name
; /* symbol name */
823 enum clnt_stat status
;
824 SYMBOL_ADDR symbolAddr
;
827 bzero ((char *) &symbolAddr
, sizeof (symbolAddr
));
829 status
= net_clnt_call (VX_SYMBOL_INQ
, xdr_wrapstring
, &name
,
830 xdr_SYMBOL_ADDR
, &symbolAddr
);
831 if (status
!= RPC_SUCCESS
) {
832 complain (&cant_contact_target
, 0);
836 *pAddr
= symbolAddr
.addr
;
837 return symbolAddr
.status
;
840 /* Check to see if the VxWorks target has a floating point coprocessor.
841 Returns 1 if target has floating point processor, 0 otherwise.
842 Calls error() if rpc fails. */
847 enum clnt_stat status
;
848 bool_t fp
= 0; /* true if fp processor is present on target board */
850 status
= net_clnt_call (VX_FP_INQUIRE
, xdr_void
, 0, xdr_bool
, &fp
);
851 if (status
!= RPC_SUCCESS
)
857 /* Establish an RPC connection with the VxWorks target system.
858 Calls error () if unable to establish connection. */
864 struct sockaddr_in destAddr
;
865 struct hostent
*destHost
;
867 /* get the internet address for the given host */
869 if ((destHost
= (struct hostent
*) gethostbyname (host
)) == NULL
)
870 error ("Invalid hostname. Couldn't find remote host address.");
872 bzero (&destAddr
, sizeof (destAddr
));
874 destAddr
.sin_addr
.s_addr
= * (u_long
*) destHost
->h_addr
;
875 destAddr
.sin_family
= AF_INET
;
876 destAddr
.sin_port
= 0; /* set to actual port that remote
877 ptrace is listening on. */
879 /* Create a tcp client transport on which to issue
880 calls to the remote ptrace server. */
882 ptraceSock
= RPC_ANYSOCK
;
883 pClient
= clnttcp_create (&destAddr
, RDBPROG
, RDBVERS
, &ptraceSock
, 0, 0);
884 /* FIXME, here is where we deal with different version numbers of the proto */
888 clnt_pcreateerror ("\tnet_connect");
889 error ("Couldn't connect to remote target.");
893 /* Sleep for the specified number of milliseconds
894 * (assumed to be less than 1000).
895 * If select () is interrupted, returns immediately;
896 * takes an error exit if select () fails for some other reason.
903 struct timeval select_timeout
;
906 select_timeout
.tv_sec
= 0;
907 select_timeout
.tv_usec
= ms
* 1000;
909 status
= select (0, (fd_set
*) 0, (fd_set
*) 0, (fd_set
*) 0, &select_timeout
);
911 if (status
< 0 && errno
!= EINTR
)
912 perror_with_name ("select");
915 /* Wait for control to return from inferior to debugger.
916 If inferior gets a signal, we may decide to start it up again
917 instead of returning. That is why there is a loop in this function.
918 When this function actually returns it means the inferior
919 should be left stopped and GDB should read more commands. */
921 /* For network debugging with VxWorks.
922 * VxWorks knows when tasks hit breakpoints, receive signals, exit, etc,
923 * so vx_wait() receives this information directly from
924 * VxWorks instead of trying to figure out what happenned via a wait() call.
938 /* If CTRL-C is hit during this loop,
939 suspend the inferior process. */
944 quit_failed
= (net_quit () == -1);
948 /* If a net_quit () or net_wait () call has failed,
949 allow the user to break the connection with the target.
950 We can't simply error () out of this loop, since the
951 data structures representing the state of the inferior
952 are in an inconsistent state. */
954 if (quit_failed
|| net_wait (&rdbEvent
) == -1)
957 if (query ("Can't %s. Disconnect from target system? ",
958 (quit_failed
) ? "suspend remote task"
959 : "get status of remote task"))
961 target_mourn_inferior();
962 error ("Use the \"target\" command to reconnect.");
966 terminal_inferior ();
971 pid
= rdbEvent
.taskId
;
974 sleep_ms (200); /* FIXME Don't kill the network too badly */
976 else if (pid
!= inferior_pid
)
977 fatal ("Bad pid for debugged task: %s\n", local_hex_string(pid
));
980 /* FIXME, eventually do more then SIGTRAP on everything... */
981 switch (rdbEvent
.eventType
)
985 /* FIXME is it possible to distinguish between a
986 XXX normal vs abnormal exit in VxWorks? */
989 case EVENT_START
: /* Task was just started. */
990 WSETSTOP (w
, SIGTRAP
);
994 WSETSTOP (w
, SIGTRAP
);
995 /* XXX was it stopped by a signal? act accordingly */
998 case EVENT_BREAK
: /* Breakpoint was hit. */
999 WSETSTOP (w
, SIGTRAP
);
1002 case EVENT_SUSPEND
: /* Task was suspended, probably by ^C. */
1003 WSETSTOP (w
, SIGINT
);
1006 case EVENT_BUS_ERR
: /* Task made evil nasty reference. */
1007 WSETSTOP (w
, SIGBUS
);
1010 case EVENT_ZERO_DIV
: /* Division by zero */
1011 WSETSTOP (w
, SIGFPE
); /* Like Unix, call it a float exception. */
1015 /* The target is not running Unix, and its
1016 faults/traces do not map nicely into Unix signals.
1017 Make sure they do not get confused with Unix signals
1018 by numbering them with values higher than the highest
1019 legal Unix signal. code in the arch-dependent PRINT_RANDOM_SIGNAL
1020 routine will interpret the value for wait_for_inferior. */
1021 WSETSTOP (w
, rdbEvent
.sigType
+ NSIG
);
1024 *status
= *(int *)&w
; /* Grumble union wait crap Grumble */
1032 symbol_file_command (arg
, 0);
1037 add_symbol_stub (arg
)
1040 struct ldfile
*pLoadFile
= (struct ldfile
*)arg
;
1042 printf("\t%s: ", pLoadFile
->name
);
1043 (void) symbol_file_add (pLoadFile
->name
, 0, pLoadFile
->txt_addr
, 0);
1047 /* Target command for VxWorks target systems.
1049 Used in vxgdb. Takes the name of a remote target machine
1050 running vxWorks and connects to it to initialize remote network
1054 vx_open (args
, from_tty
)
1058 extern int close ();
1060 extern char *source_path
;
1061 struct ldtabl loadTable
;
1062 struct ldfile
*pLoadFile
;
1064 extern CLIENT
*pClient
;
1067 error_no_arg ("target machine name");
1069 target_preopen (from_tty
);
1071 unpush_target (&vx_ops
);
1072 printf ("Attaching remote machine across net...\n");
1075 /* Allow the user to kill the connect attempt by typing ^C.
1076 Wait until the call to target_has_fp () completes before
1077 disallowing an immediate quit, since even if net_connect ()
1078 is successful, the remote debug server might be hung. */
1083 target_has_fp
= net_check_for_fp ();
1084 printf_filtered ("Connected to %s.\n", args
);
1088 push_target (&vx_ops
);
1090 /* Save a copy of the target host's name. */
1091 vx_host
= savestring (args
, strlen (args
));
1093 /* Find out the name of the file from which the target was booted
1094 and load its symbol table. */
1096 printf_filtered ("Looking in Unix path for all loaded modules:\n");
1098 if (!net_get_boot_file (&bootFile
))
1101 printf_filtered ("\t%s: ", bootFile
);
1102 if (catch_errors (symbol_stub
, bootFile
,
1103 "Error while reading symbols from boot file:\n"))
1104 puts_filtered ("ok\n");
1105 } else if (from_tty
)
1106 printf ("VxWorks kernel symbols not loaded.\n");
1109 error ("Can't retrieve boot file name from target machine.");
1111 clnt_freeres (pClient
, xdr_wrapstring
, &bootFile
);
1113 if (net_get_symbols (&loadTable
) != 0)
1114 error ("Can't read loaded modules from target machine");
1117 while (++i
< loadTable
.tbl_size
)
1119 QUIT
; /* FIXME, avoids clnt_freeres below: mem leak */
1120 pLoadFile
= &loadTable
.tbl_ent
[i
];
1124 struct cleanup
*old_chain
;
1125 char *fullname
= NULL
;
1127 desc
= openp (source_path
, 0, pLoadFile
->name
, O_RDONLY
, 0, &fullname
);
1129 perror_with_name (pLoadFile
->name
);
1130 old_chain
= make_cleanup (close
, desc
);
1131 add_file_at_addr (fullname
, desc
, pLoadFile
->txt_addr
, pLoadFile
->data_addr
,
1132 pLoadFile
->bss_addr
);
1133 do_cleanups (old_chain
);
1137 (1) Searches the PATH, not the source path.
1138 (2) data and bss are assumed to be at the usual offsets from text. */
1139 catch_errors (add_symbol_stub
, (char *)pLoadFile
, (char *)0);
1142 printf_filtered ("Done.\n");
1144 clnt_freeres (pClient
, xdr_ldtabl
, &loadTable
);
1147 /* attach_command --
1148 takes a task started up outside of gdb and ``attaches'' to it.
1149 This stops it cold in its tracks and allows us to start tracing it. */
1152 vx_attach (args
, from_tty
)
1159 Ptrace_return ptrace_out
;
1165 error_no_arg ("process-id to attach");
1167 pid
= strtol (args
, &cptr
, 0);
1168 if ((cptr
== args
) || (*cptr
!= '\0'))
1169 error ("Invalid process-id -- give a single number in decimal or 0xhex");
1172 printf ("Attaching pid %s.\n", local_hex_string(pid
));
1174 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1175 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1176 ptrace_in
.pid
= pid
;
1178 status
= net_ptrace_clnt_call (PTRACE_ATTACH
, &ptrace_in
, &ptrace_out
);
1181 if (ptrace_out
.status
== -1)
1183 errno
= ptrace_out
.errno
;
1184 perror_with_name ("Attaching remote process");
1188 push_target (&vx_run_ops
);
1192 mark_breakpoints_out ();
1194 /* Set up the "saved terminal modes" of the inferior
1195 based on what modes we are starting it with. */
1196 target_terminal_init ();
1198 /* Install inferior's terminal modes. */
1199 target_terminal_inferior ();
1201 /* We will get a task spawn event immediately. */
1202 init_wait_for_inferior ();
1203 clear_proceed_status ();
1204 stop_soon_quietly
= 1;
1205 wait_for_inferior ();
1206 stop_soon_quietly
= 0;
1211 /* detach_command --
1212 takes a program previously attached to and detaches it.
1213 The program resumes execution and will no longer stop
1214 on signals, etc. We better not have left any breakpoints
1215 in the program or it'll die when it hits one. For this
1216 to work, it may be necessary for the process to have been
1217 previously attached. It *might* work if the program was
1218 started via the normal ptrace (PTRACE_TRACEME). */
1221 vx_detach (args
, from_tty
)
1226 Ptrace_return ptrace_out
;
1231 error ("Argument given to VxWorks \"detach\".");
1234 printf ("Detaching pid %s.\n", local_hex_string(inferior_pid
));
1236 if (args
) /* FIXME, should be possible to leave suspended */
1237 signal
= atoi (args
);
1239 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1240 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1241 ptrace_in
.pid
= inferior_pid
;
1243 status
= net_ptrace_clnt_call (PTRACE_DETACH
, &ptrace_in
, &ptrace_out
);
1246 if (ptrace_out
.status
== -1)
1248 errno
= ptrace_out
.errno
;
1249 perror_with_name ("Detaching VxWorks process");
1253 pop_target (); /* go back to non-executing VxWorks connection */
1256 /* vx_kill -- takes a running task and wipes it out. */
1259 vx_kill (args
, from_tty
)
1264 Ptrace_return ptrace_out
;
1268 error ("Argument given to VxWorks \"kill\".");
1271 printf ("Killing pid %s.\n", local_hex_string(inferior_pid
));
1273 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1274 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1275 ptrace_in
.pid
= inferior_pid
;
1277 status
= net_ptrace_clnt_call (PTRACE_KILL
, &ptrace_in
, &ptrace_out
);
1280 if (ptrace_out
.status
== -1)
1282 errno
= ptrace_out
.errno
;
1283 perror_with_name ("Killing VxWorks process");
1286 /* If it gives good status, the process is *gone*, no events remain. */
1288 pop_target (); /* go back to non-executing VxWorks connection */
1291 /* Clean up from the VxWorks process target as it goes away. */
1294 vx_proc_close (quitting
)
1297 inferior_pid
= 0; /* No longer have a process. */
1303 /* Cross-net conversion of floats to and from extended form.
1304 (This is needed because different target machines have different
1305 extended floating point formats.) */
1307 /* Convert from an extended float to a double.
1309 The extended float is stored as raw data pointed to by FROM.
1310 Return the converted value as raw data in the double pointed to by TO.
1314 vx_convert_to_virtual (regno
, from
, to
)
1319 enum clnt_stat status
;
1321 if (REGISTER_CONVERTIBLE (regno
))
1323 if (!target_has_fp
) {
1324 *(double *)to
= 0.0; /* Skip the trouble if no float anyway */
1328 status
= net_clnt_call (VX_CONV_FROM_68881
, xdr_ext_fp
, from
,
1331 if (status
== RPC_SUCCESS
)
1337 bcopy (from
, to
, REGISTER_VIRTUAL_SIZE (regno
));
1341 /* The converse: convert from a double to an extended float.
1343 The double is stored as raw data pointed to by FROM.
1344 Return the converted value as raw data in the extended
1345 float pointed to by TO.
1349 vx_convert_from_virtual (regno
, from
, to
)
1354 enum clnt_stat status
;
1356 if (REGISTER_CONVERTIBLE (regno
))
1358 if (!target_has_fp
) {
1359 bzero (to
, REGISTER_RAW_SIZE (FP0_REGNUM
)); /* Shrug */
1363 status
= net_clnt_call (VX_CONV_TO_68881
, xdr_double
, from
,
1365 if (status
== RPC_SUCCESS
)
1371 bcopy (from
, to
, REGISTER_VIRTUAL_SIZE (regno
));
1374 /* Make an RPC call to the VxWorks target.
1375 Returns RPC status. */
1377 static enum clnt_stat
1378 net_clnt_call (procNum
, inProc
, in
, outProc
, out
)
1379 enum ptracereq procNum
;
1385 enum clnt_stat status
;
1387 status
= clnt_call (pClient
, procNum
, inProc
, in
, outProc
, out
, rpcTimeout
);
1389 if (status
!= RPC_SUCCESS
)
1390 clnt_perrno (status
);
1395 /* Clean up before losing control. */
1402 clnt_destroy (pClient
); /* The net connection */
1406 free (vx_host
); /* The hostname */
1410 /* A vxprocess target should be started via "run" not "target". */
1413 vx_proc_open (name
, from_tty
)
1417 error ("Use the \"run\" command to start a VxWorks process.");
1420 /* Target ops structure for accessing memory and such over the net */
1422 struct target_ops vx_ops
= {
1423 "vxworks", "VxWorks target memory via RPC over TCP/IP",
1424 "Use VxWorks target memory. \n\
1425 Specify the name of the machine to connect to.",
1426 vx_open
, vx_close
, vx_attach
, 0, /* vx_detach, */
1427 0, 0, /* resume, wait */
1428 0, 0, /* read_reg, write_reg */
1429 0, vx_convert_to_virtual
, vx_convert_from_virtual
, /* prep_to_store, */
1430 vx_xfer_memory
, vx_files_info
,
1431 0, 0, /* insert_breakpoint, remove_breakpoint */
1432 0, 0, 0, 0, 0, /* terminal stuff */
1436 vx_create_inferior
, 0, /* mourn_inferior */
1437 core_stratum
, 0, /* next */
1438 1, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */
1439 0, 0, /* Section pointers */
1440 OPS_MAGIC
, /* Always the last thing */
1443 /* Target ops structure for accessing VxWorks child processes over the net */
1445 struct target_ops vx_run_ops
= {
1446 "vxprocess", "VxWorks process",
1447 "VxWorks process, started by the \"run\" command.",
1448 vx_proc_open
, vx_proc_close
, 0, vx_detach
, /* vx_attach */
1450 vx_read_register
, vx_write_register
,
1451 vx_prepare_to_store
, vx_convert_to_virtual
, vx_convert_from_virtual
,
1452 vx_xfer_memory
, vx_run_files_info
,
1453 vx_insert_breakpoint
, vx_remove_breakpoint
,
1454 0, 0, 0, 0, 0, /* terminal stuff */
1458 0, vx_mourn_inferior
,
1459 process_stratum
, 0, /* next */
1460 0, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1461 /* all_mem is off to avoid spurious msg in "i files" */
1462 0, 0, /* Section pointers */
1463 OPS_MAGIC
, /* Always the last thing */
1465 /* ==> Remember when reading at end of file, there are two "ops" structs here. */
1470 add_target (&vx_ops
);
1471 add_target (&vx_run_ops
);