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 "complaints.h"
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #define malloc bogon_malloc /* Sun claims "char *malloc()" not void * */
38 #define free bogon_free /* Sun claims "int free()" not void */
39 #define realloc bogon_realloc /* Sun claims "char *realloc()", not void * */
44 #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
46 #include "vx-share/ptrace.h"
47 #include "vx-share/xdr_ptrace.h"
48 #include "vx-share/xdr_ld.h"
49 #include "vx-share/xdr_rdb.h"
50 #include "vx-share/dbgRpcLib.h"
54 extern void symbol_file_command ();
55 extern int stop_soon_quietly
; /* for wait_for_inferior */
57 static int net_ptrace_clnt_call (); /* Forward decl */
58 static enum clnt_stat
net_clnt_call (); /* Forward decl */
59 extern struct target_ops vx_ops
, vx_run_ops
; /* Forward declaration */
61 /* Saved name of target host and called function for "info files".
65 static char *vx_running
; /* Called function */
67 /* Nonzero means target that is being debugged remotely has a floating
70 static int target_has_fp
;
72 /* Default error message when the network is forking up. */
74 static const char rpcerr
[] = "network target debugging: rpc error";
76 CLIENT
*pClient
; /* client used in net debugging */
77 static int ptraceSock
= RPC_ANYSOCK
;
79 enum clnt_stat
net_clnt_call();
80 static void parse_args ();
82 static struct timeval rpcTimeout
= { 10, 0 };
84 static char *skip_white_space ();
85 static char *find_white_space ();
87 /* Tell the VxWorks target system to download a file.
88 The load addresses of the text, data, and bss segments are
89 stored in *pTextAddr, *pDataAddr, and *pBssAddr (respectively).
90 Returns 0 for success, -1 for failure. */
93 net_load (filename
, pTextAddr
, pDataAddr
, pBssAddr
)
99 enum clnt_stat status
;
100 struct ldfile ldstruct
;
101 struct timeval load_timeout
;
103 bzero ((char *) &ldstruct
, sizeof (ldstruct
));
105 /* We invoke clnt_call () here directly, instead of through
106 net_clnt_call (), because we need to set a large timeout value.
107 The load on the target side can take quite a while, easily
108 more than 10 seconds. The user can kill this call by typing
109 CTRL-C if there really is a problem with the load.
111 Do not change the tv_sec value without checking -- select() imposes
112 a limit of 10**8 on it for no good reason that I can see... */
114 load_timeout
.tv_sec
= 99999999; /* A large number, effectively inf. */
115 load_timeout
.tv_usec
= 0;
117 status
= clnt_call (pClient
, VX_LOAD
, xdr_wrapstring
, &filename
, xdr_ldfile
,
118 &ldstruct
, load_timeout
);
120 if (status
== RPC_SUCCESS
)
122 if (*ldstruct
.name
== 0) /* load failed on VxWorks side */
124 *pTextAddr
= ldstruct
.txt_addr
;
125 *pDataAddr
= ldstruct
.data_addr
;
126 *pBssAddr
= ldstruct
.bss_addr
;
133 /* returns 0 if successful, errno if RPC failed or VxWorks complains. */
136 net_break (addr
, procnum
)
140 enum clnt_stat status
;
142 Rptrace ptrace_in
; /* XXX This is stupid. It doesn't need to be a ptrace
143 structure. How about something smaller? */
145 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
148 ptrace_in
.addr
= addr
;
149 ptrace_in
.pid
= inferior_pid
;
151 status
= net_clnt_call (procnum
, xdr_rptrace
, &ptrace_in
, xdr_int
,
154 if (status
!= RPC_SUCCESS
)
157 if (break_status
== -1)
159 return break_status
; /* probably (FIXME) zero */
162 /* returns 0 if successful, errno otherwise */
165 vx_insert_breakpoint (addr
)
168 return net_break (addr
, VX_BREAK_ADD
);
171 /* returns 0 if successful, errno otherwise */
174 vx_remove_breakpoint (addr
)
177 return net_break (addr
, VX_BREAK_DELETE
);
180 /* Start an inferior process and sets inferior_pid to its pid.
181 EXEC_FILE is the file to run.
182 ALLARGS is a string containing the arguments to the program.
183 ENV is the environment vector to pass.
184 Returns process id. Errors reported with error().
185 On VxWorks, we ignore exec_file. */
188 vx_create_inferior (exec_file
, args
, env
)
193 enum clnt_stat status
;
195 TASK_START taskStart
;
197 bzero ((char *) &passArgs
, sizeof (passArgs
));
198 bzero ((char *) &taskStart
, sizeof (taskStart
));
200 /* parse arguments, put them in passArgs */
202 parse_args (args
, &passArgs
);
204 if (passArgs
.arg_array_len
== 0)
205 error ("You must specify a function name to run, and arguments if any");
207 status
= net_clnt_call (PROCESS_START
, xdr_arg_array
, &passArgs
,
208 xdr_TASK_START
, &taskStart
);
210 if ((status
!= RPC_SUCCESS
) || (taskStart
.status
== -1))
211 error ("Can't create process on remote target machine");
213 /* Save the name of the running function */
214 vx_running
= savestring (passArgs
.arg_array_val
[0],
215 strlen (passArgs
.arg_array_val
[0]));
217 #ifdef CREATE_INFERIOR_HOOK
218 CREATE_INFERIOR_HOOK (pid
);
221 push_target (&vx_run_ops
);
222 inferior_pid
= taskStart
.pid
;
224 /* We will get a trace trap after one instruction.
225 Insert breakpoints and continue. */
227 init_wait_for_inferior ();
229 /* Set up the "saved terminal modes" of the inferior
230 based on what modes we are starting it with. */
231 target_terminal_init ();
233 /* Install inferior's terminal modes. */
234 target_terminal_inferior ();
236 stop_soon_quietly
= 1;
237 wait_for_inferior (); /* Get the task spawn event */
238 stop_soon_quietly
= 0;
240 /* insert_step_breakpoint (); FIXME, do we need this? */
244 /* Fill ARGSTRUCT in argc/argv form with the arguments from the
245 argument string ARGSTRING. */
248 parse_args (arg_string
, arg_struct
)
249 register char *arg_string
;
250 arg_array
*arg_struct
;
252 register int arg_count
= 0; /* number of arguments */
253 register int arg_index
= 0;
256 bzero ((char *) arg_struct
, sizeof (arg_array
));
258 /* first count how many arguments there are */
263 if (*(p0
= skip_white_space (p0
)) == '\0')
265 p0
= find_white_space (p0
);
269 arg_struct
->arg_array_len
= arg_count
;
270 arg_struct
->arg_array_val
= (char **) xmalloc ((arg_count
+ 1)
273 /* now copy argument strings into arg_struct. */
275 while (*(arg_string
= skip_white_space (arg_string
)))
277 p0
= find_white_space (arg_string
);
278 arg_struct
->arg_array_val
[arg_index
++] = savestring (arg_string
,
283 arg_struct
->arg_array_val
[arg_count
] = NULL
;
286 /* Advance a string pointer across whitespace and return a pointer
287 to the first non-white character. */
293 while (*p
== ' ' || *p
== '\t')
298 /* Search for the first unquoted whitespace character in a string.
299 Returns a pointer to the character, or to the null terminator
300 if no whitespace is found. */
308 while ((c
= *p
) != ' ' && c
!= '\t' && c
)
310 if (c
== '\'' || c
== '"')
312 while (*++p
!= c
&& *p
)
325 /* Poll the VxWorks target system for an event related
326 to the debugged task.
327 Returns -1 if remote wait failed, task status otherwise. */
334 enum clnt_stat status
;
336 bzero ((char *) pEvent
, sizeof (RDB_EVENT
));
339 status
= net_clnt_call (PROCESS_WAIT
, xdr_int
, &pid
, xdr_RDB_EVENT
, pEvent
);
341 return (status
== RPC_SUCCESS
)? pEvent
->status
: -1;
344 /* Suspend the remote task.
345 Returns -1 if suspend fails on target system, 0 otherwise. */
352 enum clnt_stat status
;
356 /* don't let rdbTask suspend itself by passing a pid of 0 */
358 if ((pid
= inferior_pid
) == 0)
361 status
= net_clnt_call (VX_TASK_SUSPEND
, xdr_int
, &pid
, xdr_int
,
364 return (status
== RPC_SUCCESS
)? quit_status
: -1;
367 /* Read a register or registers from the remote system. */
370 vx_read_register (regno
)
375 Ptrace_return ptrace_out
;
378 extern char registers
[];
380 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
381 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
383 /* FIXME, eventually only get the ones we need. */
384 registers_fetched ();
386 ptrace_in
.pid
= inferior_pid
;
387 ptrace_out
.info
.more_data
= (caddr_t
) &out_data
;
388 out_data
.len
= VX_NUM_REGS
* REGISTER_RAW_SIZE (0);
389 out_data
.bytes
= (caddr_t
) registers
;
391 status
= net_ptrace_clnt_call (PTRACE_GETREGS
, &ptrace_in
, &ptrace_out
);
394 if (ptrace_out
.status
== -1)
396 errno
= ptrace_out
.errno
;
397 perror_with_name ("net_ptrace_clnt_call(PTRACE_GETREGS)");
400 #ifdef VX_SIZE_FPREGS
401 /* If the target has floating point registers, fetch them.
402 Otherwise, zero the floating point register values in
403 registers[] for good measure, even though we might not
408 ptrace_in
.pid
= inferior_pid
;
409 ptrace_out
.info
.more_data
= (caddr_t
) &out_data
;
410 out_data
.len
= VX_SIZE_FPREGS
;
411 out_data
.bytes
= (caddr_t
) ®isters
[REGISTER_BYTE (FP0_REGNUM
)];
413 status
= net_ptrace_clnt_call (PTRACE_GETFPREGS
, &ptrace_in
, &ptrace_out
);
416 if (ptrace_out
.status
== -1)
418 errno
= ptrace_out
.errno
;
419 perror_with_name ("net_ptrace_clnt_call(PTRACE_GETFPREGS)");
424 bzero (®isters
[REGISTER_BYTE (FP0_REGNUM
)], VX_SIZE_FPREGS
);
426 #endif /* VX_SIZE_FPREGS */
429 /* Prepare to store registers. Since we will store all of them,
430 read out their current values now. */
433 vx_prepare_to_store ()
435 /* Fetch all registers, if any of them are not yet fetched. */
436 read_register_bytes (0, NULL
, REGISTER_BYTES
);
440 /* Store our register values back into the inferior.
441 If REGNO is -1, do this for all registers.
442 Otherwise, REGNO specifies which register (so we can save time). */
443 /* FIXME, look at REGNO to save time here */
446 vx_write_register (regno
)
451 extern char registers
[];
454 Ptrace_return ptrace_out
;
456 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
457 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
459 ptrace_in
.pid
= inferior_pid
;
460 ptrace_in
.info
.ttype
= DATA
;
461 ptrace_in
.info
.more_data
= (caddr_t
) &in_data
;
463 in_data
.bytes
= registers
;
465 in_data
.len
= VX_NUM_REGS
* sizeof (REGISTER_TYPE
);
467 /* XXX change second param to be a proc number */
468 status
= net_ptrace_clnt_call (PTRACE_SETREGS
, &ptrace_in
, &ptrace_out
);
471 if (ptrace_out
.status
== -1)
473 errno
= ptrace_out
.errno
;
474 perror_with_name ("net_ptrace_clnt_call(PTRACE_SETREGS)");
477 #ifdef VX_SIZE_FPREGS
478 /* Store floating point registers if the target has them. */
482 ptrace_in
.pid
= inferior_pid
;
483 ptrace_in
.info
.ttype
= DATA
;
484 ptrace_in
.info
.more_data
= (caddr_t
) &in_data
;
487 in_data
.bytes
= ®isters
[REGISTER_BYTE (FP0_REGNUM
)];
488 in_data
.len
= VX_SIZE_FPREGS
;
490 status
= net_ptrace_clnt_call (PTRACE_SETFPREGS
, &ptrace_in
, &ptrace_out
);
493 if (ptrace_out
.status
== -1)
495 errno
= ptrace_out
.errno
;
496 perror_with_name ("net_ptrace_clnt_call(PTRACE_SETFPREGS)");
499 #endif /* VX_SIZE_FPREGS */
502 /* Copy LEN bytes to or from remote inferior's memory starting at MEMADDR
503 to debugger memory starting at MYADDR. WRITE is true if writing to the
505 Result is the number of bytes written or read (zero if error). The
506 protocol allows us to return a negative count, indicating that we can't
507 handle the current address but can handle one N bytes further, but
508 vxworks doesn't give us that information. */
511 vx_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
516 struct target_ops
*target
; /* ignored */
520 Ptrace_return ptrace_out
;
523 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
524 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
526 ptrace_in
.pid
= inferior_pid
; /* XXX pid unnecessary for READDATA */
527 ptrace_in
.addr
= (int) memaddr
; /* Where from */
528 ptrace_in
.data
= len
; /* How many bytes */
532 ptrace_in
.info
.ttype
= DATA
;
533 ptrace_in
.info
.more_data
= (caddr_t
) &data
;
535 data
.bytes
= (caddr_t
) myaddr
; /* Where from */
536 data
.len
= len
; /* How many bytes (again, for XDR) */
538 /* XXX change second param to be a proc number */
539 status
= net_ptrace_clnt_call (PTRACE_WRITEDATA
, &ptrace_in
, &ptrace_out
);
543 ptrace_out
.info
.more_data
= (caddr_t
) &data
;
544 data
.bytes
= myaddr
; /* Where to */
545 data
.len
= len
; /* How many (again, for XDR) */
547 /* XXX change second param to be a proc number */
548 status
= net_ptrace_clnt_call (PTRACE_READDATA
, &ptrace_in
, &ptrace_out
);
553 if (ptrace_out
.status
== -1)
555 return 0; /* No bytes moved */
557 return len
; /* Moved *all* the bytes */
563 printf ("\tAttached to host `%s'", vx_host
);
564 printf (", which has %sfloating point", target_has_fp
? "": "no ");
571 printf ("\tRunning %s VxWorks process %s",
572 vx_running
? "child": "attached",
573 local_hex_string(inferior_pid
));
575 printf (", function `%s'", vx_running
);
580 vx_resume (step
, siggnal
)
586 Ptrace_return ptrace_out
;
588 if (siggnal
!= 0 && siggnal
!= stop_signal
)
589 error ("Cannot send signals to VxWorks processes");
591 bzero ((char *) &ptrace_in
, sizeof (ptrace_in
));
592 bzero ((char *) &ptrace_out
, sizeof (ptrace_out
));
594 ptrace_in
.pid
= inferior_pid
;
595 ptrace_in
.addr
= 1; /* Target side insists on this, or it panics. */
597 /* XXX change second param to be a proc number */
598 status
= net_ptrace_clnt_call (step
? PTRACE_SINGLESTEP
: PTRACE_CONT
,
599 &ptrace_in
, &ptrace_out
);
602 if (ptrace_out
.status
== -1)
604 errno
= ptrace_out
.errno
;
605 perror_with_name ("Resuming remote process");
612 pop_target (); /* Pop back to no-child state */
613 generic_mourn_inferior ();
617 /* This function allows the addition of incrementally linked object files. */
620 vx_load_command (arg_string
, from_tty
)
629 error ("The load command takes a file name");
631 arg_string
= tilde_expand (arg_string
);
632 make_cleanup (free
, arg_string
);
638 if (net_load (arg_string
, &text_addr
, &data_addr
, &bss_addr
) == -1)
639 error ("Load failed on target machine");
642 /* FIXME, for now we ignore data_addr and bss_addr. */
643 symbol_file_add (arg_string
, from_tty
, text_addr
, 0, 0, 0);
646 #ifdef FIXME /* Not ready for prime time */
647 /* Single step the target program at the source or machine level.
648 Takes an error exit if rpc fails.
649 Returns -1 if remote single-step operation fails, else 0. */
654 enum clnt_stat status
;
656 SOURCE_STEP source_step
;
658 source_step
.taskId
= inferior_pid
;
662 source_step
.startAddr
= step_range_start
;
663 source_step
.endAddr
= step_range_end
;
667 source_step
.startAddr
= 0;
668 source_step
.endAddr
= 0;
671 status
= net_clnt_call (VX_SOURCE_STEP
, xdr_SOURCE_STEP
, &source_step
,
672 xdr_int
, &step_status
);
674 if (status
== RPC_SUCCESS
)
681 /* Emulate ptrace using RPC calls to the VxWorks target system.
682 Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */
685 net_ptrace_clnt_call (request
, pPtraceIn
, pPtraceOut
)
686 enum ptracereq request
;
688 Ptrace_return
*pPtraceOut
;
690 enum clnt_stat status
;
692 status
= net_clnt_call (request
, xdr_rptrace
, pPtraceIn
, xdr_ptrace_return
,
695 if (status
!= RPC_SUCCESS
)
701 /* Query the target for the name of the file from which VxWorks was
702 booted. pBootFile is the address of a pointer to the buffer to
703 receive the file name; if the pointer pointed to by pBootFile is
704 NULL, memory for the buffer will be allocated by XDR.
705 Returns -1 if rpc failed, 0 otherwise. */
708 net_get_boot_file (pBootFile
)
711 enum clnt_stat status
;
713 status
= net_clnt_call (VX_BOOT_FILE_INQ
, xdr_void
, (char *) 0,
714 xdr_wrapstring
, pBootFile
);
715 return (status
== RPC_SUCCESS
) ? 0 : -1;
718 /* Fetch a list of loaded object modules from the VxWorks target.
719 Returns -1 if rpc failed, 0 otherwise
720 There's no way to check if the returned loadTable is correct.
721 VxWorks doesn't check it. */
724 net_get_symbols (pLoadTable
)
725 ldtabl
*pLoadTable
; /* return pointer to ldtabl here */
727 enum clnt_stat status
;
729 bzero ((char *) pLoadTable
, sizeof (struct ldtabl
));
731 status
= net_clnt_call (VX_STATE_INQ
, xdr_void
, 0, xdr_ldtabl
, pLoadTable
);
732 return (status
== RPC_SUCCESS
) ? 0 : -1;
735 /* Look up a symbol in the VxWorks target's symbol table.
736 Returns status of symbol read on target side (0=success, -1=fail)
737 Returns -1 and complain()s if rpc fails. */
739 struct complaint cant_contact_target
=
740 {"Lost contact with VxWorks target", 0, 0};
743 vx_lookup_symbol (name
, pAddr
)
744 char *name
; /* symbol name */
747 enum clnt_stat status
;
748 SYMBOL_ADDR symbolAddr
;
751 bzero ((char *) &symbolAddr
, sizeof (symbolAddr
));
753 status
= net_clnt_call (VX_SYMBOL_INQ
, xdr_wrapstring
, &name
,
754 xdr_SYMBOL_ADDR
, &symbolAddr
);
755 if (status
!= RPC_SUCCESS
) {
756 complain (&cant_contact_target
);
760 *pAddr
= symbolAddr
.addr
;
761 return symbolAddr
.status
;
764 /* Check to see if the VxWorks target has a floating point coprocessor.
765 Returns 1 if target has floating point processor, 0 otherwise.
766 Calls error() if rpc fails. */
771 enum clnt_stat status
;
772 bool_t fp
= 0; /* true if fp processor is present on target board */
774 status
= net_clnt_call (VX_FP_INQUIRE
, xdr_void
, 0, xdr_bool
, &fp
);
775 if (status
!= RPC_SUCCESS
)
781 /* Establish an RPC connection with the VxWorks target system.
782 Calls error () if unable to establish connection. */
788 struct sockaddr_in destAddr
;
789 struct hostent
*destHost
;
792 /* Get the internet address for the given host. Allow a numeric
793 IP address or a hostname. */
795 addr
= inet_addr (host
);
798 destHost
= (struct hostent
*) gethostbyname (host
);
799 if (destHost
== NULL
)
800 error ("Invalid hostname. Couldn't find remote host address.");
801 addr
= * (unsigned long *) destHost
->h_addr
;
804 bzero (&destAddr
, sizeof (destAddr
));
806 destAddr
.sin_addr
.s_addr
= addr
;
807 destAddr
.sin_family
= AF_INET
;
808 destAddr
.sin_port
= 0; /* set to actual port that remote
809 ptrace is listening on. */
811 /* Create a tcp client transport on which to issue
812 calls to the remote ptrace server. */
814 ptraceSock
= RPC_ANYSOCK
;
815 pClient
= clnttcp_create (&destAddr
, RDBPROG
, RDBVERS
, &ptraceSock
, 0, 0);
816 /* FIXME, here is where we deal with different version numbers of the proto */
820 clnt_pcreateerror ("\tnet_connect");
821 error ("Couldn't connect to remote target.");
825 /* Sleep for the specified number of milliseconds
826 * (assumed to be less than 1000).
827 * If select () is interrupted, returns immediately;
828 * takes an error exit if select () fails for some other reason.
835 struct timeval select_timeout
;
838 select_timeout
.tv_sec
= 0;
839 select_timeout
.tv_usec
= ms
* 1000;
841 status
= select (0, (fd_set
*) 0, (fd_set
*) 0, (fd_set
*) 0, &select_timeout
);
843 if (status
< 0 && errno
!= EINTR
)
844 perror_with_name ("select");
847 /* Wait for control to return from inferior to debugger.
848 If inferior gets a signal, we may decide to start it up again
849 instead of returning. That is why there is a loop in this function.
850 When this function actually returns it means the inferior
851 should be left stopped and GDB should read more commands. */
853 /* For network debugging with VxWorks.
854 * VxWorks knows when tasks hit breakpoints, receive signals, exit, etc,
855 * so vx_wait() receives this information directly from
856 * VxWorks instead of trying to figure out what happenned via a wait() call.
870 /* If CTRL-C is hit during this loop,
871 suspend the inferior process. */
876 quit_failed
= (net_quit () == -1);
880 /* If a net_quit () or net_wait () call has failed,
881 allow the user to break the connection with the target.
882 We can't simply error () out of this loop, since the
883 data structures representing the state of the inferior
884 are in an inconsistent state. */
886 if (quit_failed
|| net_wait (&rdbEvent
) == -1)
889 if (query ("Can't %s. Disconnect from target system? ",
890 (quit_failed
) ? "suspend remote task"
891 : "get status of remote task"))
893 target_mourn_inferior();
894 error ("Use the \"target\" command to reconnect.");
898 terminal_inferior ();
903 pid
= rdbEvent
.taskId
;
906 sleep_ms (200); /* FIXME Don't kill the network too badly */
908 else if (pid
!= inferior_pid
)
909 fatal ("Bad pid for debugged task: %s\n", local_hex_string(pid
));
912 /* FIXME, eventually do more then SIGTRAP on everything... */
913 switch (rdbEvent
.eventType
)
917 /* FIXME is it possible to distinguish between a
918 XXX normal vs abnormal exit in VxWorks? */
921 case EVENT_START
: /* Task was just started. */
922 WSETSTOP (w
, SIGTRAP
);
926 WSETSTOP (w
, SIGTRAP
);
927 /* XXX was it stopped by a signal? act accordingly */
930 case EVENT_BREAK
: /* Breakpoint was hit. */
931 WSETSTOP (w
, SIGTRAP
);
934 case EVENT_SUSPEND
: /* Task was suspended, probably by ^C. */
935 WSETSTOP (w
, SIGINT
);
938 case EVENT_BUS_ERR
: /* Task made evil nasty reference. */
939 WSETSTOP (w
, SIGBUS
);
942 case EVENT_ZERO_DIV
: /* Division by zero */
943 WSETSTOP (w
, SIGFPE
); /* Like Unix, call it a float exception. */
947 /* The target is not running Unix, and its
948 faults/traces do not map nicely into Unix signals.
949 Make sure they do not get confused with Unix signals
950 by numbering them with values higher than the highest
951 legal Unix signal. code in the arch-dependent PRINT_RANDOM_SIGNAL
952 routine will interpret the value for wait_for_inferior. */
953 WSETSTOP (w
, rdbEvent
.sigType
+ NSIG
);
956 *status
= *(int *)&w
; /* Grumble union wait crap Grumble */
964 symbol_file_command (arg
, 0);
969 add_symbol_stub (arg
)
972 struct ldfile
*pLoadFile
= (struct ldfile
*)arg
;
974 printf("\t%s: ", pLoadFile
->name
);
975 symbol_file_add (pLoadFile
->name
, 0, pLoadFile
->txt_addr
, 0, 0, 0);
979 /* Target command for VxWorks target systems.
981 Used in vxgdb. Takes the name of a remote target machine
982 running vxWorks and connects to it to initialize remote network
986 vx_open (args
, from_tty
)
992 extern char *source_path
;
993 struct ldtabl loadTable
;
994 struct ldfile
*pLoadFile
;
996 extern CLIENT
*pClient
;
999 error_no_arg ("target machine name");
1001 target_preopen (from_tty
);
1003 unpush_target (&vx_ops
);
1004 printf ("Attaching remote machine across net...\n");
1007 /* Allow the user to kill the connect attempt by typing ^C.
1008 Wait until the call to target_has_fp () completes before
1009 disallowing an immediate quit, since even if net_connect ()
1010 is successful, the remote debug server might be hung. */
1015 target_has_fp
= net_check_for_fp ();
1016 printf_filtered ("Connected to %s.\n", args
);
1020 push_target (&vx_ops
);
1022 /* Save a copy of the target host's name. */
1023 vx_host
= savestring (args
, strlen (args
));
1025 /* Find out the name of the file from which the target was booted
1026 and load its symbol table. */
1028 printf_filtered ("Looking in Unix path for all loaded modules:\n");
1030 if (!net_get_boot_file (&bootFile
))
1033 printf_filtered ("\t%s: ", bootFile
);
1034 if (catch_errors (symbol_stub
, bootFile
,
1035 "Error while reading symbols from boot file:\n"))
1036 puts_filtered ("ok\n");
1037 } else if (from_tty
)
1038 printf ("VxWorks kernel symbols not loaded.\n");
1041 error ("Can't retrieve boot file name from target machine.");
1043 clnt_freeres (pClient
, xdr_wrapstring
, &bootFile
);
1045 if (net_get_symbols (&loadTable
) != 0)
1046 error ("Can't read loaded modules from target machine");
1049 while (++i
< loadTable
.tbl_size
)
1051 QUIT
; /* FIXME, avoids clnt_freeres below: mem leak */
1052 pLoadFile
= &loadTable
.tbl_ent
[i
];
1056 struct cleanup
*old_chain
;
1057 char *fullname
= NULL
;
1059 desc
= openp (source_path
, 0, pLoadFile
->name
, O_RDONLY
, 0, &fullname
);
1061 perror_with_name (pLoadFile
->name
);
1062 old_chain
= make_cleanup (close
, desc
);
1063 add_file_at_addr (fullname
, desc
, pLoadFile
->txt_addr
, pLoadFile
->data_addr
,
1064 pLoadFile
->bss_addr
);
1065 do_cleanups (old_chain
);
1069 (1) Searches the PATH, not the source path.
1070 (2) data and bss are assumed to be at the usual offsets from text. */
1071 catch_errors (add_symbol_stub
, (char *)pLoadFile
, (char *)0);
1074 printf_filtered ("Done.\n");
1076 clnt_freeres (pClient
, xdr_ldtabl
, &loadTable
);
1079 /* Takes a task started up outside of gdb and ``attaches'' to it.
1080 This stops it cold in its tracks and allows us to start tracing it. */
1083 vx_attach (args
, from_tty
)
1090 Ptrace_return ptrace_out
;
1094 error_no_arg ("process-id to attach");
1096 pid
= strtol (args
, &cptr
, 0);
1097 if ((cptr
== args
) || (*cptr
!= '\0'))
1098 error ("Invalid process-id -- give a single number in decimal or 0xhex");
1101 printf ("Attaching pid %s.\n", local_hex_string(pid
));
1103 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1104 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1105 ptrace_in
.pid
= pid
;
1107 status
= net_ptrace_clnt_call (PTRACE_ATTACH
, &ptrace_in
, &ptrace_out
);
1110 if (ptrace_out
.status
== -1)
1112 errno
= ptrace_out
.errno
;
1113 perror_with_name ("Attaching remote process");
1117 push_target (&vx_run_ops
);
1123 /* detach_command --
1124 takes a program previously attached to and detaches it.
1125 The program resumes execution and will no longer stop
1126 on signals, etc. We better not have left any breakpoints
1127 in the program or it'll die when it hits one. For this
1128 to work, it may be necessary for the process to have been
1129 previously attached. It *might* work if the program was
1130 started via the normal ptrace (PTRACE_TRACEME). */
1133 vx_detach (args
, from_tty
)
1138 Ptrace_return ptrace_out
;
1143 error ("Argument given to VxWorks \"detach\".");
1146 printf ("Detaching pid %s.\n", local_hex_string(inferior_pid
));
1148 if (args
) /* FIXME, should be possible to leave suspended */
1149 signal
= atoi (args
);
1151 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1152 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1153 ptrace_in
.pid
= inferior_pid
;
1155 status
= net_ptrace_clnt_call (PTRACE_DETACH
, &ptrace_in
, &ptrace_out
);
1158 if (ptrace_out
.status
== -1)
1160 errno
= ptrace_out
.errno
;
1161 perror_with_name ("Detaching VxWorks process");
1165 pop_target (); /* go back to non-executing VxWorks connection */
1168 /* vx_kill -- takes a running task and wipes it out. */
1174 Ptrace_return ptrace_out
;
1177 printf ("Killing pid %s.\n", local_hex_string(inferior_pid
));
1179 bzero ((char *)&ptrace_in
, sizeof (ptrace_in
));
1180 bzero ((char *)&ptrace_out
, sizeof (ptrace_out
));
1181 ptrace_in
.pid
= inferior_pid
;
1183 status
= net_ptrace_clnt_call (PTRACE_KILL
, &ptrace_in
, &ptrace_out
);
1186 else if (ptrace_out
.status
== -1)
1188 errno
= ptrace_out
.errno
;
1189 perror_with_name ("Killing VxWorks process");
1192 /* If it gives good status, the process is *gone*, no events remain.
1193 If the kill failed, assume the process is gone anyhow. */
1195 pop_target (); /* go back to non-executing VxWorks connection */
1198 /* Clean up from the VxWorks process target as it goes away. */
1201 vx_proc_close (quitting
)
1204 inferior_pid
= 0; /* No longer have a process. */
1210 /* Make an RPC call to the VxWorks target.
1211 Returns RPC status. */
1213 static enum clnt_stat
1214 net_clnt_call (procNum
, inProc
, in
, outProc
, out
)
1215 enum ptracereq procNum
;
1221 enum clnt_stat status
;
1223 status
= clnt_call (pClient
, procNum
, inProc
, in
, outProc
, out
, rpcTimeout
);
1225 if (status
!= RPC_SUCCESS
)
1226 clnt_perrno (status
);
1231 /* Clean up before losing control. */
1238 clnt_destroy (pClient
); /* The net connection */
1242 free (vx_host
); /* The hostname */
1246 /* A vxprocess target should be started via "run" not "target". */
1249 vx_proc_open (name
, from_tty
)
1253 error ("Use the \"run\" command to start a VxWorks process.");
1256 /* Target ops structure for accessing memory and such over the net */
1258 struct target_ops vx_ops
= {
1259 "vxworks", "VxWorks target memory via RPC over TCP/IP",
1260 "Use VxWorks target memory. \n\
1261 Specify the name of the machine to connect to.",
1262 vx_open
, vx_close
, vx_attach
, 0, /* vx_detach, */
1263 0, 0, /* resume, wait */
1264 0, 0, /* read_reg, write_reg */
1265 0, /* prep_to_store, */
1266 vx_xfer_memory
, vx_files_info
,
1267 0, 0, /* insert_breakpoint, remove_breakpoint */
1268 0, 0, 0, 0, 0, /* terminal stuff */
1272 vx_create_inferior
, 0, /* mourn_inferior */
1274 0, /* notice_signals */
1275 core_stratum
, 0, /* next */
1276 1, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */
1277 0, 0, /* Section pointers */
1278 OPS_MAGIC
, /* Always the last thing */
1281 /* Target ops structure for accessing VxWorks child processes over the net */
1283 struct target_ops vx_run_ops
= {
1284 "vxprocess", "VxWorks process",
1285 "VxWorks process, started by the \"run\" command.",
1286 vx_proc_open
, vx_proc_close
, 0, vx_detach
, /* vx_attach */
1288 vx_read_register
, vx_write_register
,
1289 vx_prepare_to_store
,
1290 vx_xfer_memory
, vx_run_files_info
,
1291 vx_insert_breakpoint
, vx_remove_breakpoint
,
1292 0, 0, 0, 0, 0, /* terminal stuff */
1296 0, vx_mourn_inferior
,
1298 0, /* notice_signals */
1299 process_stratum
, 0, /* next */
1300 0, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1301 /* all_mem is off to avoid spurious msg in "i files" */
1302 0, 0, /* Section pointers */
1303 OPS_MAGIC
, /* Always the last thing */
1305 /* ==> Remember when reading at end of file, there are two "ops" structs here. */
1310 add_target (&vx_ops
);
1311 add_target (&vx_run_ops
);