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. */
29 #include "symfile.h" /* for struct complaint */
35 #include <sys/types.h>
37 #include <sys/socket.h>
38 #define malloc bogon_malloc /* Sun claims "char *malloc()" not void * */
39 #define free bogon_free /* Sun claims "int free()" not void */
43 #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
45 #include "vx-share/ptrace.h"
46 #include "vx-share/xdr_ptrace.h"
47 #include "vx-share/xdr_ld.h"
48 #include "vx-share/xdr_rdb.h"
49 #include "vx-share/dbgRpcLib.h"
50 #include "vx-share/reg.h"
54 extern void symbol_file_command ();
55 extern int stop_soon_quietly
; /* for wait_for_inferior */
56 extern void host_convert_to_virtual ();
57 extern void host_convert_from_virtual ();
59 static int net_ptrace_clnt_call (); /* Forward decl */
60 static enum clnt_stat
net_clnt_call (); /* Forward decl */
61 extern struct target_ops vx_ops
, vx_run_ops
; /* Forward declaration */
63 /* Saved name of target host and called function for "info files".
67 static char *vx_running
; /* Called function */
69 /* Nonzero means target that is being debugged remotely has a floating
72 static int target_has_fp
;
74 /* Default error message when the network is forking up. */
76 static const char rpcerr
[] = "network target debugging: rpc error";
78 CLIENT
*pClient
; /* client used in net debugging */
79 static int ptraceSock
= RPC_ANYSOCK
;
81 enum clnt_stat
net_clnt_call();
82 static void parse_args ();
84 static struct timeval rpcTimeout
= { 10, 0 };
86 static char *skip_white_space ();
87 static char *find_white_space ();
89 /* Tell the VxWorks target system to download a file.
90 The load addresses of the text, data, and bss segments are
91 stored in *pTextAddr, *pDataAddr, and *pBssAddr (respectively).
92 Returns 0 for success, -1 for failure. */
95 net_load (filename
, pTextAddr
, pDataAddr
, pBssAddr
)
101 enum clnt_stat status
;
102 struct ldfile ldstruct
;
103 struct timeval load_timeout
;
105 bzero ((char *) &ldstruct
, sizeof (ldstruct
));
107 /* We invoke clnt_call () here directly, instead of through
108 net_clnt_call (), because we need to set a large timeout value.
109 The load on the target side can take quite a while, easily
110 more than 10 seconds. The user can kill this call by typing
111 CTRL-C if there really is a problem with the load.
113 Do not change the tv_sec value without checking -- select() imposes
114 a limit of 10**8 on it for no good reason that I can see... */
116 load_timeout
.tv_sec
= 99999999; /* A large number, effectively inf. */
117 load_timeout
.tv_usec
= 0;
119 status
= clnt_call (pClient
, VX_LOAD
, xdr_wrapstring
, &filename
, xdr_ldfile
,
120 &ldstruct
, load_timeout
);
122 if (status
== RPC_SUCCESS
)
124 if (*ldstruct
.name
== 0) /* load failed on VxWorks side */
126 *pTextAddr
= ldstruct
.txt_addr
;
127 *pDataAddr
= ldstruct
.data_addr
;
128 *pBssAddr
= ldstruct
.bss_addr
;
135 /* returns 0 if successful, errno if RPC failed or VxWorks complains. */
138 net_break (addr
, procnum
)
142 enum clnt_stat status
;
144 Rptrace ptrace_in
; /* XXX This is stupid. It doesn't need to be a ptrace
145 structure. How about something smaller? */
147 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
150 ptrace_in
.addr
= addr
;
151 ptrace_in
.pid
= inferior_pid
;
153 status
= net_clnt_call (procnum
, xdr_rptrace
, &ptrace_in
, xdr_int
,
156 if (status
!= RPC_SUCCESS
)
159 if (break_status
== -1)
161 return break_status
; /* probably (FIXME) zero */
164 /* returns 0 if successful, errno otherwise */
167 vx_insert_breakpoint (addr
)
170 return net_break (addr
, VX_BREAK_ADD
);
173 /* returns 0 if successful, errno otherwise */
176 vx_remove_breakpoint (addr
)
179 return net_break (addr
, VX_BREAK_DELETE
);
182 /* Start an inferior process and sets inferior_pid to its pid.
183 EXEC_FILE is the file to run.
184 ALLARGS is a string containing the arguments to the program.
185 ENV is the environment vector to pass.
186 Returns process id. Errors reported with error().
187 On VxWorks, we ignore exec_file. */
190 vx_create_inferior (exec_file
, args
, env
)
195 enum clnt_stat status
;
197 TASK_START taskStart
;
199 bzero ((char *) &passArgs
, sizeof (passArgs
));
200 bzero ((char *) &taskStart
, sizeof (taskStart
));
202 /* parse arguments, put them in passArgs */
204 parse_args (args
, &passArgs
);
206 if (passArgs
.arg_array_len
== 0)
207 error ("You must specify a function name to run, and arguments if any");
209 status
= net_clnt_call (PROCESS_START
, xdr_arg_array
, &passArgs
,
210 xdr_TASK_START
, &taskStart
);
212 if ((status
!= RPC_SUCCESS
) || (taskStart
.status
== -1))
213 error ("Can't create process on remote target machine");
215 /* Save the name of the running function */
216 vx_running
= savestring (passArgs
.arg_array_val
[0],
217 strlen (passArgs
.arg_array_val
[0]));
219 #ifdef CREATE_INFERIOR_HOOK
220 CREATE_INFERIOR_HOOK (pid
);
223 push_target (&vx_run_ops
);
224 inferior_pid
= taskStart
.pid
;
226 /* We will get a trace trap after one instruction.
227 Insert breakpoints and continue. */
229 init_wait_for_inferior ();
231 /* Set up the "saved terminal modes" of the inferior
232 based on what modes we are starting it with. */
233 target_terminal_init ();
235 /* Install inferior's terminal modes. */
236 target_terminal_inferior ();
238 stop_soon_quietly
= 1;
239 wait_for_inferior (); /* Get the task spawn event */
240 stop_soon_quietly
= 0;
242 /* insert_step_breakpoint (); FIXME, do we need this? */
246 /* Fill ARGSTRUCT in argc/argv form with the arguments from the
247 argument string ARGSTRING. */
250 parse_args (arg_string
, arg_struct
)
251 register char *arg_string
;
252 arg_array
*arg_struct
;
254 register int arg_count
= 0; /* number of arguments */
255 register int arg_index
= 0;
258 bzero ((char *) arg_struct
, sizeof (arg_array
));
260 /* first count how many arguments there are */
265 if (*(p0
= skip_white_space (p0
)) == '\0')
267 p0
= find_white_space (p0
);
271 arg_struct
->arg_array_len
= arg_count
;
272 arg_struct
->arg_array_val
= (char **) xmalloc ((arg_count
+ 1)
275 /* now copy argument strings into arg_struct. */
277 while (*(arg_string
= skip_white_space (arg_string
)))
279 p0
= find_white_space (arg_string
);
280 arg_struct
->arg_array_val
[arg_index
++] = savestring (arg_string
,
285 arg_struct
->arg_array_val
[arg_count
] = NULL
;
288 /* Advance a string pointer across whitespace and return a pointer
289 to the first non-white character. */
295 while (*p
== ' ' || *p
== '\t')
300 /* Search for the first unquoted whitespace character in a string.
301 Returns a pointer to the character, or to the null terminator
302 if no whitespace is found. */
310 while ((c
= *p
) != ' ' && c
!= '\t' && c
)
312 if (c
== '\'' || c
== '"')
314 while (*++p
!= c
&& *p
)
327 /* Poll the VxWorks target system for an event related
328 to the debugged task.
329 Returns -1 if remote wait failed, task status otherwise. */
336 enum clnt_stat status
;
338 bzero ((char *) pEvent
, sizeof (RDB_EVENT
));
341 status
= net_clnt_call (PROCESS_WAIT
, xdr_int
, &pid
, xdr_RDB_EVENT
, pEvent
);
343 return (status
== RPC_SUCCESS
)? pEvent
->status
: -1;
346 /* Suspend the remote task.
347 Returns -1 if suspend fails on target system, 0 otherwise. */
354 enum clnt_stat status
;
358 /* don't let rdbTask suspend itself by passing a pid of 0 */
360 if ((pid
= inferior_pid
) == 0)
363 status
= net_clnt_call (VX_TASK_SUSPEND
, xdr_int
, &pid
, xdr_int
,
366 return (status
== RPC_SUCCESS
)? quit_status
: -1;
369 /* Read a register or registers from the remote system. */
372 vx_read_register (regno
)
377 Ptrace_return ptrace_out
;
380 extern char registers
[];
382 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
383 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
385 /* FIXME, eventually only get the ones we need. */
386 registers_fetched ();
388 ptrace_in
.pid
= inferior_pid
;
389 ptrace_out
.info
.more_data
= (caddr_t
) &out_data
;
391 out_data
.len
= 18 * REGISTER_RAW_SIZE (0); /* FIXME 68k hack */
393 out_data
.len
= (16 + 16 + 3) * REGISTER_RAW_SIZE (0);
395 out_data
.bytes
= (caddr_t
) registers
;
397 status
= net_ptrace_clnt_call (PTRACE_GETREGS
, &ptrace_in
, &ptrace_out
);
400 if (ptrace_out
.status
== -1)
402 errno
= ptrace_out
.errno
;
403 perror_with_name ("net_ptrace_clnt_call(PTRACE_GETREGS)");
409 /* If the target has floating point registers, fetch them.
410 Otherwise, zero the floating point register values in
411 registers[] for good measure, even though we might not
413 /* @@ Can't use this -- the rdb library for the 960 target
414 doesn't support setting or retrieving FP regs. KR */
416 struct fp_status inferior_fp_registers
;
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
,
423 &ptrace_in
, &ptrace_out
);
426 if (ptrace_out
.status
== -1)
428 errno
= ptrace_out
.errno
;
429 perror_with_name ("net_ptrace_clnt_call(PTRACE_GETFPREGS)");
432 bcopy (&inferior_fp_registers
, ®isters
[REGISTER_BYTE (FP0_REGNUM
)],
433 REGISTER_RAW_SIZE (FP0_REGNUM
) * 4);
437 bzero ((char *) ®isters
[REGISTER_BYTE (FP0_REGNUM
)],
438 REGISTER_RAW_SIZE (FP0_REGNUM
) * 4);
442 #else /* not 960, thus must be 68000: FIXME! */
446 ptrace_in
.pid
= inferior_pid
;
447 ptrace_out
.info
.more_data
= (caddr_t
) &out_data
;
448 out_data
.len
= 8 * REGISTER_RAW_SIZE (FP0_REGNUM
) /* FIXME */
449 + (3 * sizeof (REGISTER_TYPE
));
450 out_data
.bytes
= (caddr_t
) ®isters
[REGISTER_BYTE (FP0_REGNUM
)];
452 status
= net_ptrace_clnt_call (PTRACE_GETFPREGS
, &ptrace_in
, &ptrace_out
);
455 if (ptrace_out
.status
== -1)
457 errno
= ptrace_out
.errno
;
458 perror_with_name ("net_ptrace_clnt_call(PTRACE_GETFPREGS)");
463 bzero (®isters
[REGISTER_BYTE (FP0_REGNUM
)],
464 8 * REGISTER_RAW_SIZE (FP0_REGNUM
));
465 bzero (®isters
[REGISTER_BYTE (FPC_REGNUM
)],
466 3 * sizeof (REGISTER_TYPE
));
468 #endif /* various architectures */
471 /* Prepare to store registers. Since we will store all of them,
472 read out their current values now. */
475 vx_prepare_to_store ()
477 vx_read_register (-1);
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 */
487 vx_write_register (regno
)
492 extern char registers
[];
495 Ptrace_return ptrace_out
;
497 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
498 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
500 ptrace_in
.pid
= inferior_pid
;
501 ptrace_in
.info
.ttype
= DATA
;
502 ptrace_in
.info
.more_data
= (caddr_t
) &in_data
;
504 in_data
.bytes
= registers
;
508 in_data
.len
= (16 + 16 + 3) * sizeof (REGISTER_TYPE
);
510 #else /* not 960 -- assume 68k -- FIXME */
512 in_data
.len
= 18 * sizeof (REGISTER_TYPE
);
514 #endif /* Different register sets */
516 /* XXX change second param to be a proc number */
517 status
= net_ptrace_clnt_call (PTRACE_SETREGS
, &ptrace_in
, &ptrace_out
);
520 if (ptrace_out
.status
== -1)
522 errno
= ptrace_out
.errno
;
523 perror_with_name ("net_ptrace_clnt_call(PTRACE_SETREGS)");
526 /* Store floating point registers if the target has them. */
530 ptrace_in
.pid
= inferior_pid
;
531 ptrace_in
.info
.ttype
= DATA
;
532 ptrace_in
.info
.more_data
= (caddr_t
) &in_data
;
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
);
540 #else /* not 960 -- assume 68k -- FIXME */
542 in_data
.bytes
= ®isters
[REGISTER_BYTE (FP0_REGNUM
)];
543 in_data
.len
= (8 * REGISTER_RAW_SIZE (FP0_REGNUM
)
544 + (3 * sizeof (REGISTER_TYPE
)));
546 #endif /* Different register sets */
548 status
= net_ptrace_clnt_call (PTRACE_SETFPREGS
, &ptrace_in
, &ptrace_out
);
551 if (ptrace_out
.status
== -1)
553 errno
= ptrace_out
.errno
;
554 perror_with_name ("net_ptrace_clnt_call(PTRACE_SETFPREGS)");
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
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. */
568 vx_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
573 struct target_ops
*target
; /* ignored */
577 Ptrace_return ptrace_out
;
580 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
581 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
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 */
589 ptrace_in
.info
.ttype
= DATA
;
590 ptrace_in
.info
.more_data
= (caddr_t
) &data
;
592 data
.bytes
= (caddr_t
) myaddr
; /* Where from */
593 data
.len
= len
; /* How many bytes (again, for XDR) */
595 /* XXX change second param to be a proc number */
596 status
= net_ptrace_clnt_call (PTRACE_WRITEDATA
, &ptrace_in
, &ptrace_out
);
600 ptrace_out
.info
.more_data
= (caddr_t
) &data
;
601 data
.bytes
= myaddr
; /* Where to */
602 data
.len
= len
; /* How many (again, for XDR) */
604 /* XXX change second param to be a proc number */
605 status
= net_ptrace_clnt_call (PTRACE_READDATA
, &ptrace_in
, &ptrace_out
);
610 if (ptrace_out
.status
== -1)
612 return 0; /* No bytes moved */
614 return len
; /* Moved *all* the bytes */
620 printf ("\tAttached to host `%s'", vx_host
);
621 printf (", which has %sfloating point", target_has_fp
? "": "no ");
628 printf ("\tRunning %s VxWorks process %s",
629 vx_running
? "child": "attached",
630 local_hex_string(inferior_pid
));
632 printf (", function `%s'", vx_running
);
637 vx_resume (step
, siggnal
)
643 Ptrace_return ptrace_out
;
645 if (siggnal
!= 0 && siggnal
!= stop_signal
)
646 error ("Cannot send signals to VxWorks processes");
648 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
649 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
651 ptrace_in
.pid
= inferior_pid
;
652 ptrace_in
.addr
= 1; /* Target side insists on this, or it panics. */
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
);
659 if (ptrace_out
.status
== -1)
661 errno
= ptrace_out
.errno
;
662 perror_with_name ("Resuming remote process");
669 pop_target (); /* Pop back to no-child state */
670 generic_mourn_inferior ();
674 /* This function allows the addition of incrementally linked object files. */
677 vx_load_command (arg_string
, from_tty
)
686 error ("The load command takes a file name");
688 arg_string
= tilde_expand (arg_string
);
689 make_cleanup (free
, arg_string
);
695 if (net_load (arg_string
, &text_addr
, &data_addr
, &bss_addr
) == -1)
696 error ("Load failed on target machine");
699 /* FIXME, for now we ignore data_addr and bss_addr. */
700 symbol_file_add (arg_string
, from_tty
, text_addr
, 0, 0, 0);
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. */
711 enum clnt_stat status
;
713 SOURCE_STEP source_step
;
715 source_step
.taskId
= inferior_pid
;
719 source_step
.startAddr
= step_range_start
;
720 source_step
.endAddr
= step_range_end
;
724 source_step
.startAddr
= 0;
725 source_step
.endAddr
= 0;
728 status
= net_clnt_call (VX_SOURCE_STEP
, xdr_SOURCE_STEP
, &source_step
,
729 xdr_int
, &step_status
);
731 if (status
== RPC_SUCCESS
)
738 /* Emulate ptrace using RPC calls to the VxWorks target system.
739 Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */
742 net_ptrace_clnt_call (request
, pPtraceIn
, pPtraceOut
)
743 enum ptracereq request
;
745 Ptrace_return
*pPtraceOut
;
747 enum clnt_stat status
;
749 status
= net_clnt_call (request
, xdr_rptrace
, pPtraceIn
, xdr_ptrace_return
,
752 if (status
!= RPC_SUCCESS
)
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. */
765 net_get_boot_file (pBootFile
)
768 enum clnt_stat status
;
770 status
= net_clnt_call (VX_BOOT_FILE_INQ
, xdr_void
, (char *) 0,
771 xdr_wrapstring
, pBootFile
);
772 return (status
== RPC_SUCCESS
) ? 0 : -1;
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. */
781 net_get_symbols (pLoadTable
)
782 ldtabl
*pLoadTable
; /* return pointer to ldtabl here */
784 enum clnt_stat status
;
786 bzero ((char *) pLoadTable
, sizeof (struct ldtabl
));
788 status
= net_clnt_call (VX_STATE_INQ
, xdr_void
, 0, xdr_ldtabl
, pLoadTable
);
789 return (status
== RPC_SUCCESS
) ? 0 : -1;
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. */
796 struct complaint cant_contact_target
=
797 {"Lost contact with VxWorks target", 0, 0};
800 vx_lookup_symbol (name
, pAddr
)
801 char *name
; /* symbol name */
804 enum clnt_stat status
;
805 SYMBOL_ADDR symbolAddr
;
808 bzero ((char *) &symbolAddr
, sizeof (symbolAddr
));
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);
817 *pAddr
= symbolAddr
.addr
;
818 return symbolAddr
.status
;
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. */
828 enum clnt_stat status
;
829 bool_t fp
= 0; /* true if fp processor is present on target board */
831 status
= net_clnt_call (VX_FP_INQUIRE
, xdr_void
, 0, xdr_bool
, &fp
);
832 if (status
!= RPC_SUCCESS
)
838 /* Establish an RPC connection with the VxWorks target system.
839 Calls error () if unable to establish connection. */
845 struct sockaddr_in destAddr
;
846 struct hostent
*destHost
;
848 /* get the internet address for the given host */
850 if ((destHost
= (struct hostent
*) gethostbyname (host
)) == NULL
)
851 error ("Invalid hostname. Couldn't find remote host address.");
853 bzero (&destAddr
, sizeof (destAddr
));
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. */
860 /* Create a tcp client transport on which to issue
861 calls to the remote ptrace server. */
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 */
869 clnt_pcreateerror ("\tnet_connect");
870 error ("Couldn't connect to remote target.");
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.
884 struct timeval select_timeout
;
887 select_timeout
.tv_sec
= 0;
888 select_timeout
.tv_usec
= ms
* 1000;
890 status
= select (0, (fd_set
*) 0, (fd_set
*) 0, (fd_set
*) 0, &select_timeout
);
892 if (status
< 0 && errno
!= EINTR
)
893 perror_with_name ("select");
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. */
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.
919 /* If CTRL-C is hit during this loop,
920 suspend the inferior process. */
925 quit_failed
= (net_quit () == -1);
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. */
935 if (quit_failed
|| net_wait (&rdbEvent
) == -1)
938 if (query ("Can't %s. Disconnect from target system? ",
939 (quit_failed
) ? "suspend remote task"
940 : "get status of remote task"))
942 target_mourn_inferior();
943 error ("Use the \"target\" command to reconnect.");
947 terminal_inferior ();
952 pid
= rdbEvent
.taskId
;
955 sleep_ms (200); /* FIXME Don't kill the network too badly */
957 else if (pid
!= inferior_pid
)
958 fatal ("Bad pid for debugged task: %s\n", local_hex_string(pid
));
961 /* FIXME, eventually do more then SIGTRAP on everything... */
962 switch (rdbEvent
.eventType
)
966 /* FIXME is it possible to distinguish between a
967 XXX normal vs abnormal exit in VxWorks? */
970 case EVENT_START
: /* Task was just started. */
971 WSETSTOP (w
, SIGTRAP
);
975 WSETSTOP (w
, SIGTRAP
);
976 /* XXX was it stopped by a signal? act accordingly */
979 case EVENT_BREAK
: /* Breakpoint was hit. */
980 WSETSTOP (w
, SIGTRAP
);
983 case EVENT_SUSPEND
: /* Task was suspended, probably by ^C. */
984 WSETSTOP (w
, SIGINT
);
987 case EVENT_BUS_ERR
: /* Task made evil nasty reference. */
988 WSETSTOP (w
, SIGBUS
);
991 case EVENT_ZERO_DIV
: /* Division by zero */
992 WSETSTOP (w
, SIGFPE
); /* Like Unix, call it a float exception. */
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
);
1005 *status
= *(int *)&w
; /* Grumble union wait crap Grumble */
1013 symbol_file_command (arg
, 0);
1018 add_symbol_stub (arg
)
1021 struct ldfile
*pLoadFile
= (struct ldfile
*)arg
;
1023 printf("\t%s: ", pLoadFile
->name
);
1024 symbol_file_add (pLoadFile
->name
, 0, pLoadFile
->txt_addr
, 0, 0, 0);
1028 /* Target command for VxWorks target systems.
1030 Used in vxgdb. Takes the name of a remote target machine
1031 running vxWorks and connects to it to initialize remote network
1035 vx_open (args
, from_tty
)
1039 extern int close ();
1041 extern char *source_path
;
1042 struct ldtabl loadTable
;
1043 struct ldfile
*pLoadFile
;
1045 extern CLIENT
*pClient
;
1048 error_no_arg ("target machine name");
1050 target_preopen (from_tty
);
1052 unpush_target (&vx_ops
);
1053 printf ("Attaching remote machine across net...\n");
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. */
1064 target_has_fp
= net_check_for_fp ();
1065 printf_filtered ("Connected to %s.\n", args
);
1069 push_target (&vx_ops
);
1071 /* Save a copy of the target host's name. */
1072 vx_host
= savestring (args
, strlen (args
));
1074 /* Find out the name of the file from which the target was booted
1075 and load its symbol table. */
1077 printf_filtered ("Looking in Unix path for all loaded modules:\n");
1079 if (!net_get_boot_file (&bootFile
))
1082 printf_filtered ("\t%s: ", bootFile
);
1083 if (catch_errors (symbol_stub
, bootFile
,
1084 "Error while reading symbols from boot file:\n"))
1085 puts_filtered ("ok\n");
1086 } else if (from_tty
)
1087 printf ("VxWorks kernel symbols not loaded.\n");
1090 error ("Can't retrieve boot file name from target machine.");
1092 clnt_freeres (pClient
, xdr_wrapstring
, &bootFile
);
1094 if (net_get_symbols (&loadTable
) != 0)
1095 error ("Can't read loaded modules from target machine");
1098 while (++i
< loadTable
.tbl_size
)
1100 QUIT
; /* FIXME, avoids clnt_freeres below: mem leak */
1101 pLoadFile
= &loadTable
.tbl_ent
[i
];
1105 struct cleanup
*old_chain
;
1106 char *fullname
= NULL
;
1108 desc
= openp (source_path
, 0, pLoadFile
->name
, O_RDONLY
, 0, &fullname
);
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
);
1118 (1) Searches the PATH, not the source path.
1119 (2) data and bss are assumed to be at the usual offsets from text. */
1120 catch_errors (add_symbol_stub
, (char *)pLoadFile
, (char *)0);
1123 printf_filtered ("Done.\n");
1125 clnt_freeres (pClient
, xdr_ldtabl
, &loadTable
);
1128 /* attach_command --
1129 takes a task started up outside of gdb and ``attaches'' to it.
1130 This stops it cold in its tracks and allows us to start tracing it. */
1133 vx_attach (args
, from_tty
)
1140 Ptrace_return ptrace_out
;
1146 error_no_arg ("process-id to attach");
1148 pid
= strtol (args
, &cptr
, 0);
1149 if ((cptr
== args
) || (*cptr
!= '\0'))
1150 error ("Invalid process-id -- give a single number in decimal or 0xhex");
1153 printf ("Attaching pid %s.\n", local_hex_string(pid
));
1155 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1156 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1157 ptrace_in
.pid
= pid
;
1159 status
= net_ptrace_clnt_call (PTRACE_ATTACH
, &ptrace_in
, &ptrace_out
);
1162 if (ptrace_out
.status
== -1)
1164 errno
= ptrace_out
.errno
;
1165 perror_with_name ("Attaching remote process");
1169 push_target (&vx_run_ops
);
1173 mark_breakpoints_out ();
1175 /* Set up the "saved terminal modes" of the inferior
1176 based on what modes we are starting it with. */
1177 target_terminal_init ();
1179 /* Install inferior's terminal modes. */
1180 target_terminal_inferior ();
1182 /* We will get a task spawn event immediately. */
1183 init_wait_for_inferior ();
1184 clear_proceed_status ();
1185 stop_soon_quietly
= 1;
1186 wait_for_inferior ();
1187 stop_soon_quietly
= 0;
1192 /* detach_command --
1193 takes a program previously attached to and detaches it.
1194 The program resumes execution and will no longer stop
1195 on signals, etc. We better not have left any breakpoints
1196 in the program or it'll die when it hits one. For this
1197 to work, it may be necessary for the process to have been
1198 previously attached. It *might* work if the program was
1199 started via the normal ptrace (PTRACE_TRACEME). */
1202 vx_detach (args
, from_tty
)
1207 Ptrace_return ptrace_out
;
1212 error ("Argument given to VxWorks \"detach\".");
1215 printf ("Detaching pid %s.\n", local_hex_string(inferior_pid
));
1217 if (args
) /* FIXME, should be possible to leave suspended */
1218 signal
= atoi (args
);
1220 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1221 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1222 ptrace_in
.pid
= inferior_pid
;
1224 status
= net_ptrace_clnt_call (PTRACE_DETACH
, &ptrace_in
, &ptrace_out
);
1227 if (ptrace_out
.status
== -1)
1229 errno
= ptrace_out
.errno
;
1230 perror_with_name ("Detaching VxWorks process");
1234 pop_target (); /* go back to non-executing VxWorks connection */
1237 /* vx_kill -- takes a running task and wipes it out. */
1243 Ptrace_return ptrace_out
;
1246 printf ("Killing pid %s.\n", local_hex_string(inferior_pid
));
1248 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1249 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1250 ptrace_in
.pid
= inferior_pid
;
1252 status
= net_ptrace_clnt_call (PTRACE_KILL
, &ptrace_in
, &ptrace_out
);
1255 if (ptrace_out
.status
== -1)
1257 errno
= ptrace_out
.errno
;
1258 perror_with_name ("Killing VxWorks process");
1261 /* If it gives good status, the process is *gone*, no events remain. */
1263 pop_target (); /* go back to non-executing VxWorks connection */
1266 /* Clean up from the VxWorks process target as it goes away. */
1269 vx_proc_close (quitting
)
1272 inferior_pid
= 0; /* No longer have a process. */
1278 /* Make an RPC call to the VxWorks target.
1279 Returns RPC status. */
1281 static enum clnt_stat
1282 net_clnt_call (procNum
, inProc
, in
, outProc
, out
)
1283 enum ptracereq procNum
;
1289 enum clnt_stat status
;
1291 status
= clnt_call (pClient
, procNum
, inProc
, in
, outProc
, out
, rpcTimeout
);
1293 if (status
!= RPC_SUCCESS
)
1294 clnt_perrno (status
);
1299 /* Clean up before losing control. */
1306 clnt_destroy (pClient
); /* The net connection */
1310 free (vx_host
); /* The hostname */
1314 /* A vxprocess target should be started via "run" not "target". */
1317 vx_proc_open (name
, from_tty
)
1321 error ("Use the \"run\" command to start a VxWorks process.");
1324 /* Target ops structure for accessing memory and such over the net */
1326 struct target_ops vx_ops
= {
1327 "vxworks", "VxWorks target memory via RPC over TCP/IP",
1328 "Use VxWorks target memory. \n\
1329 Specify the name of the machine to connect to.",
1330 vx_open
, vx_close
, vx_attach
, 0, /* vx_detach, */
1331 0, 0, /* resume, wait */
1332 0, 0, /* read_reg, write_reg */
1333 0, host_convert_to_virtual
, host_convert_from_virtual
, /* prep_to_store, */
1334 vx_xfer_memory
, vx_files_info
,
1335 0, 0, /* insert_breakpoint, remove_breakpoint */
1336 0, 0, 0, 0, 0, /* terminal stuff */
1340 vx_create_inferior
, 0, /* mourn_inferior */
1341 core_stratum
, 0, /* next */
1342 1, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */
1343 0, 0, /* Section pointers */
1344 OPS_MAGIC
, /* Always the last thing */
1347 /* Target ops structure for accessing VxWorks child processes over the net */
1349 struct target_ops vx_run_ops
= {
1350 "vxprocess", "VxWorks process",
1351 "VxWorks process, started by the \"run\" command.",
1352 vx_proc_open
, vx_proc_close
, 0, vx_detach
, /* vx_attach */
1354 vx_read_register
, vx_write_register
,
1355 vx_prepare_to_store
, host_convert_to_virtual
, host_convert_from_virtual
,
1356 vx_xfer_memory
, vx_run_files_info
,
1357 vx_insert_breakpoint
, vx_remove_breakpoint
,
1358 0, 0, 0, 0, 0, /* terminal stuff */
1362 0, vx_mourn_inferior
,
1363 process_stratum
, 0, /* next */
1364 0, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1365 /* all_mem is off to avoid spurious msg in "i files" */
1366 0, 0, /* Section pointers */
1367 OPS_MAGIC
, /* Always the last thing */
1369 /* ==> Remember when reading at end of file, there are two "ops" structs here. */
1374 add_target (&vx_ops
);
1375 add_target (&vx_run_ops
);