1 /* Memory-access and commands for remote VxWorks processes, for GDB.
3 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999,
4 2000, 2001, 2002 Free Software Foundation, Inc.
6 Contributed by Wind River Systems and Cygnus Support.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
32 #include "complaints.h"
34 #include "bfd.h" /* Required by objfiles.h. */
37 #include "gdb-stabs.h"
40 #include "gdb_string.h"
44 #include <sys/types.h>
45 #include <sys/socket.h>
46 #define malloc bogon_malloc /* Sun claims "char *malloc()" not void * */
47 #define free bogon_free /* Sun claims "int free()" not void */
48 #define realloc bogon_realloc /* Sun claims "char *realloc()", not void * */
53 #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
55 #include "vx-share/ptrace.h"
56 #include "vx-share/xdr_ptrace.h"
57 #include "vx-share/xdr_ld.h"
58 #include "vx-share/xdr_rdb.h"
59 #include "vx-share/dbgRpcLib.h"
63 /* Maximum number of bytes to transfer in a single
64 PTRACE_{READ,WRITE}DATA request. */
65 #define VX_MEMXFER_MAX 4096
67 extern void vx_read_register ();
68 extern void vx_write_register ();
69 extern void symbol_file_command ();
70 extern enum stop_kind stop_soon; /* for wait_for_inferior */
72 static int net_step ();
73 static int net_ptrace_clnt_call (); /* Forward decl */
74 static enum clnt_stat net_clnt_call (); /* Forward decl */
76 /* Target ops structure for accessing memory and such over the net */
78 static struct target_ops vx_ops;
80 /* Target ops structure for accessing VxWorks child processes over the net */
82 static struct target_ops vx_run_ops;
84 /* Saved name of target host and called function for "info files".
88 static char *vx_running; /* Called function */
90 /* Nonzero means target that is being debugged remotely has a floating
95 /* Default error message when the network is forking up. */
97 static const char rpcerr[] = "network target debugging: rpc error";
99 CLIENT *pClient; /* client used in net debugging */
100 static int ptraceSock = RPC_ANYSOCK;
102 enum clnt_stat net_clnt_call ();
103 static void parse_args ();
105 static struct timeval rpcTimeout =
108 static char *skip_white_space ();
109 static char *find_white_space ();
111 /* Tell the VxWorks target system to download a file.
112 The load addresses of the text, data, and bss segments are
113 stored in *pTextAddr, *pDataAddr, and *pBssAddr (respectively).
114 Returns 0 for success, -1 for failure. */
117 net_load (char *filename, CORE_ADDR *pTextAddr, CORE_ADDR *pDataAddr,
120 enum clnt_stat status;
121 struct ldfile ldstruct;
122 struct timeval load_timeout;
124 memset ((char *) &ldstruct, '\0', sizeof (ldstruct));
126 /* We invoke clnt_call () here directly, instead of through
127 net_clnt_call (), because we need to set a large timeout value.
128 The load on the target side can take quite a while, easily
129 more than 10 seconds. The user can kill this call by typing
130 CTRL-C if there really is a problem with the load.
132 Do not change the tv_sec value without checking -- select() imposes
133 a limit of 10**8 on it for no good reason that I can see... */
135 load_timeout.tv_sec = 99999999; /* A large number, effectively inf. */
136 load_timeout.tv_usec = 0;
138 status = clnt_call (pClient, VX_LOAD, xdr_wrapstring, &filename, xdr_ldfile,
139 &ldstruct, load_timeout);
141 if (status == RPC_SUCCESS)
143 if (*ldstruct.name == 0) /* load failed on VxWorks side */
145 *pTextAddr = ldstruct.txt_addr;
146 *pDataAddr = ldstruct.data_addr;
147 *pBssAddr = ldstruct.bss_addr;
154 /* returns 0 if successful, errno if RPC failed or VxWorks complains. */
157 net_break (int addr, u_long procnum)
159 enum clnt_stat status;
161 Rptrace ptrace_in; /* XXX This is stupid. It doesn't need to be a ptrace
162 structure. How about something smaller? */
164 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
167 ptrace_in.addr = addr;
168 ptrace_in.pid = PIDGET (inferior_ptid);
170 status = net_clnt_call (procnum, xdr_rptrace, &ptrace_in, xdr_int,
173 if (status != RPC_SUCCESS)
176 if (break_status == -1)
178 return break_status; /* probably (FIXME) zero */
181 /* returns 0 if successful, errno otherwise */
184 vx_insert_breakpoint (int addr)
186 return net_break (addr, VX_BREAK_ADD);
189 /* returns 0 if successful, errno otherwise */
192 vx_remove_breakpoint (int addr)
194 return net_break (addr, VX_BREAK_DELETE);
197 /* Start an inferior process and sets inferior_ptid to its pid.
198 EXEC_FILE is the file to run.
199 ALLARGS is a string containing the arguments to the program.
200 ENV is the environment vector to pass.
201 Returns process id. Errors reported with error().
202 On VxWorks, we ignore exec_file. */
205 vx_create_inferior (char *exec_file, char *args, char **env)
207 enum clnt_stat status;
209 TASK_START taskStart;
211 memset ((char *) &passArgs, '\0', sizeof (passArgs));
212 memset ((char *) &taskStart, '\0', sizeof (taskStart));
214 /* parse arguments, put them in passArgs */
216 parse_args (args, &passArgs);
218 if (passArgs.arg_array_len == 0)
219 error ("You must specify a function name to run, and arguments if any");
221 status = net_clnt_call (PROCESS_START, xdr_arg_array, &passArgs,
222 xdr_TASK_START, &taskStart);
224 if ((status != RPC_SUCCESS) || (taskStart.status == -1))
225 error ("Can't create process on remote target machine");
227 /* Save the name of the running function */
228 vx_running = savestring (passArgs.arg_array_val[0],
229 strlen (passArgs.arg_array_val[0]));
231 push_target (&vx_run_ops);
232 inferior_ptid = pid_to_ptid (taskStart.pid);
234 /* We will get a trace trap after one instruction.
235 Insert breakpoints and continue. */
237 init_wait_for_inferior ();
239 /* Set up the "saved terminal modes" of the inferior
240 based on what modes we are starting it with. */
241 target_terminal_init ();
243 /* Install inferior's terminal modes. */
244 target_terminal_inferior ();
246 stop_soon = STOP_QUIETLY;
247 wait_for_inferior (); /* Get the task spawn event */
248 stop_soon = NO_STOP_QUIETLY;
250 /* insert_step_breakpoint (); FIXME, do we need this? */
251 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
254 /* Fill ARGSTRUCT in argc/argv form with the arguments from the
255 argument string ARGSTRING. */
258 parse_args (char *arg_string, arg_array *arg_struct)
260 int arg_count = 0; /* number of arguments */
264 memset ((char *) arg_struct, '\0', sizeof (arg_array));
266 /* first count how many arguments there are */
271 if (*(p0 = skip_white_space (p0)) == '\0')
273 p0 = find_white_space (p0);
277 arg_struct->arg_array_len = arg_count;
278 arg_struct->arg_array_val = (char **) xmalloc ((arg_count + 1)
281 /* now copy argument strings into arg_struct. */
283 while (*(arg_string = skip_white_space (arg_string)))
285 p0 = find_white_space (arg_string);
286 arg_struct->arg_array_val[arg_index++] = savestring (arg_string,
291 arg_struct->arg_array_val[arg_count] = NULL;
294 /* Advance a string pointer across whitespace and return a pointer
295 to the first non-white character. */
298 skip_white_space (char *p)
300 while (*p == ' ' || *p == '\t')
305 /* Search for the first unquoted whitespace character in a string.
306 Returns a pointer to the character, or to the null terminator
307 if no whitespace is found. */
310 find_white_space (char *p)
314 while ((c = *p) != ' ' && c != '\t' && c)
316 if (c == '\'' || c == '"')
318 while (*++p != c && *p)
331 /* Poll the VxWorks target system for an event related
332 to the debugged task.
333 Returns -1 if remote wait failed, task status otherwise. */
336 net_wait (RDB_EVENT *pEvent)
339 enum clnt_stat status;
341 memset ((char *) pEvent, '\0', sizeof (RDB_EVENT));
343 pid = PIDGET (inferior_ptid);
344 status = net_clnt_call (PROCESS_WAIT, xdr_int, &pid, xdr_RDB_EVENT,
347 /* return (status == RPC_SUCCESS)? pEvent->status: -1; */
348 if (status == RPC_SUCCESS)
349 return ((pEvent->status) ? 1 : 0);
350 else if (status == RPC_TIMEDOUT)
356 /* Suspend the remote task.
357 Returns -1 if suspend fails on target system, 0 otherwise. */
364 enum clnt_stat status;
368 /* don't let rdbTask suspend itself by passing a pid of 0 */
370 if ((pid = PIDGET (inferior_ptid)) == 0)
373 status = net_clnt_call (VX_TASK_SUSPEND, xdr_int, &pid, xdr_int,
376 return (status == RPC_SUCCESS) ? quit_status : -1;
379 /* Read a register or registers from the remote system. */
382 net_read_registers (char *reg_buf, int len, u_long procnum)
386 Ptrace_return ptrace_out;
390 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
391 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
393 /* Initialize RPC input argument structure. */
395 ptrace_in.pid = PIDGET (inferior_ptid);
396 ptrace_in.info.ttype = NOINFO;
398 /* Initialize RPC return value structure. */
400 out_data.bytes = reg_buf;
402 ptrace_out.info.more_data = (caddr_t) & out_data;
404 /* Call RPC; take an error exit if appropriate. */
406 status = net_ptrace_clnt_call (procnum, &ptrace_in, &ptrace_out);
409 if (ptrace_out.status == -1)
411 errno = ptrace_out.errno_num;
412 sprintf (message, "reading %s registers", (procnum == PTRACE_GETREGS)
415 perror_with_name (message);
419 /* Write register values to a VxWorks target. REG_BUF points to a buffer
420 containing the raw register values, LEN is the length of REG_BUF in
421 bytes, and PROCNUM is the RPC procedure number (PTRACE_SETREGS or
422 PTRACE_SETFPREGS). An error exit is taken if the RPC call fails or
423 if an error status is returned by the remote debug server. This is
424 a utility routine used by vx_write_register (). */
427 net_write_registers (char *reg_buf, int len, u_long procnum)
431 Ptrace_return ptrace_out;
435 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
436 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
438 /* Initialize RPC input argument structure. */
440 in_data.bytes = reg_buf;
443 ptrace_in.pid = PIDGET (inferior_ptid);
444 ptrace_in.info.ttype = DATA;
445 ptrace_in.info.more_data = (caddr_t) & in_data;
447 /* Call RPC; take an error exit if appropriate. */
449 status = net_ptrace_clnt_call (procnum, &ptrace_in, &ptrace_out);
452 if (ptrace_out.status == -1)
454 errno = ptrace_out.errno_num;
455 sprintf (message, "writing %s registers", (procnum == PTRACE_SETREGS)
458 perror_with_name (message);
462 /* Prepare to store registers. Since we will store all of them,
463 read out their current values now. */
466 vx_prepare_to_store (void)
468 /* Fetch all registers, if any of them are not yet fetched. */
469 deprecated_read_register_bytes (0, NULL, DEPRECATED_REGISTER_BYTES);
472 /* Copy LEN bytes to or from remote inferior's memory starting at MEMADDR
473 to debugger memory starting at MYADDR. WRITE is true if writing to the
474 inferior. TARGET is unused.
475 Result is the number of bytes written or read (zero if error). The
476 protocol allows us to return a negative count, indicating that we can't
477 handle the current address but can handle one N bytes further, but
478 vxworks doesn't give us that information. */
481 vx_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
482 struct mem_attrib *attrib, struct target_ops *target)
486 Ptrace_return ptrace_out;
488 enum ptracereq request;
491 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
492 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
494 ptrace_in.pid = PIDGET (inferior_ptid); /* XXX pid unnecessary for READDATA */
495 ptrace_in.addr = (int) memaddr; /* Where from */
496 ptrace_in.data = len; /* How many bytes */
500 ptrace_in.info.ttype = DATA;
501 ptrace_in.info.more_data = (caddr_t) & data;
503 data.bytes = (caddr_t) myaddr; /* Where from */
504 data.len = len; /* How many bytes (again, for XDR) */
505 request = PTRACE_WRITEDATA;
509 ptrace_out.info.more_data = (caddr_t) & data;
510 request = PTRACE_READDATA;
512 /* Loop until the entire request has been satisfied, transferring
513 at most VX_MEMXFER_MAX bytes per iteration. Break from the loop
514 if an error status is returned by the remote debug server. */
519 while (nleft > 0 && status == 0)
521 nxfer = min (nleft, VX_MEMXFER_MAX);
523 ptrace_in.addr = (int) memaddr;
524 ptrace_in.data = nxfer;
525 data.bytes = (caddr_t) myaddr;
528 /* Request a block from the remote debug server; if RPC fails,
529 report an error and return to debugger command level. */
531 if (net_ptrace_clnt_call (request, &ptrace_in, &ptrace_out))
534 status = ptrace_out.status;
543 /* A target-side error has ocurred. Set errno to the error
544 code chosen by the target so that a later perror () will
545 say something meaningful. */
547 errno = ptrace_out.errno_num;
551 /* Return the number of bytes transferred. */
553 return (len - nleft);
559 printf_unfiltered ("\tAttached to host `%s'", vx_host);
560 printf_unfiltered (", which has %sfloating point", target_has_fp ? "" : "no ");
561 printf_unfiltered (".\n");
565 vx_run_files_info (void)
567 printf_unfiltered ("\tRunning %s VxWorks process %s",
568 vx_running ? "child" : "attached",
569 local_hex_string (PIDGET (inferior_ptid)));
571 printf_unfiltered (", function `%s'", vx_running);
572 printf_unfiltered (".\n");
576 vx_resume (ptid_t ptid, int step, enum target_signal siggnal)
580 Ptrace_return ptrace_out;
583 if (ptid_equal (ptid, minus_one_ptid))
584 ptid = inferior_ptid;
586 if (siggnal != 0 && siggnal != stop_signal)
587 error ("Cannot send signals to VxWorks processes");
589 /* Set CONT_ADDR to the address at which we are continuing,
590 or to 1 if we are continuing from where the program stopped.
591 This conforms to traditional ptrace () usage, but at the same
592 time has special meaning for the VxWorks remote debug server.
593 If the address is not 1, the server knows that the target
594 program is jumping to a new address, which requires special
595 handling if there is a breakpoint at the new address. */
597 cont_addr = read_register (PC_REGNUM);
598 if (cont_addr == stop_pc)
601 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
602 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
604 ptrace_in.pid = PIDGET (ptid);
605 ptrace_in.addr = cont_addr; /* Target side insists on this, or it panics. */
608 status = net_step ();
610 status = net_ptrace_clnt_call (PTRACE_CONT, &ptrace_in, &ptrace_out);
614 if (ptrace_out.status == -1)
616 errno = ptrace_out.errno_num;
617 perror_with_name ("Resuming remote process");
622 vx_mourn_inferior (void)
624 pop_target (); /* Pop back to no-child state */
625 generic_mourn_inferior ();
629 static void vx_add_symbols (char *, int, CORE_ADDR, CORE_ADDR, CORE_ADDR);
631 struct find_sect_args
633 CORE_ADDR text_start;
634 CORE_ADDR data_start;
638 static void find_sect (bfd *, asection *, void *);
641 find_sect (bfd *abfd, asection *sect, void *obj)
643 struct find_sect_args *args = (struct find_sect_args *) obj;
645 if (bfd_get_section_flags (abfd, sect) & (SEC_CODE & SEC_READONLY))
646 args->text_start = bfd_get_section_vma (abfd, sect);
647 else if (bfd_get_section_flags (abfd, sect) & SEC_ALLOC)
649 if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
651 /* Exclude .ctor and .dtor sections which have SEC_CODE set but not
653 if (bfd_get_section_flags (abfd, sect) & SEC_DATA)
654 args->data_start = bfd_get_section_vma (abfd, sect);
657 args->bss_start = bfd_get_section_vma (abfd, sect);
662 vx_add_symbols (char *name, int from_tty, CORE_ADDR text_addr,
663 CORE_ADDR data_addr, CORE_ADDR bss_addr)
665 struct section_offsets *offs;
666 struct objfile *objfile;
667 struct find_sect_args ss;
669 /* It might be nice to suppress the breakpoint_re_set which happens here
670 because we are going to do one again after the objfile_relocate. */
671 objfile = symbol_file_add (name, from_tty, NULL, 0, 0);
673 /* This is a (slightly cheesy) way of superceding the old symbols. A less
674 cheesy way would be to find the objfile with the same name and
676 objfile_to_front (objfile);
679 (struct section_offsets *)
680 alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
681 memcpy (offs, objfile->section_offsets,
682 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
687 bfd_map_over_sections (objfile->obfd, find_sect, &ss);
689 /* Both COFF and b.out frontends use these SECT_OFF_* values. */
690 offs->offsets[SECT_OFF_TEXT (objfile)] = text_addr - ss.text_start;
691 offs->offsets[SECT_OFF_DATA (objfile)] = data_addr - ss.data_start;
692 offs->offsets[SECT_OFF_BSS (objfile)] = bss_addr - ss.bss_start;
693 objfile_relocate (objfile, offs);
696 /* This function allows the addition of incrementally linked object files. */
699 vx_load_command (char *arg_string, int from_tty)
706 error ("The load command takes a file name");
708 arg_string = tilde_expand (arg_string);
709 make_cleanup (xfree, arg_string);
713 /* Refuse to load the module if a debugged task is running. Doing so
714 can have a number of unpleasant consequences to the running task. */
716 if (PIDGET (inferior_ptid) != 0 && target_has_execution)
718 if (query ("You may not load a module while the target task is running.\n\
719 Kill the target task? "))
722 error ("Load canceled.");
727 if (net_load (arg_string, &text_addr, &data_addr, &bss_addr) == -1)
728 error ("Load failed on target machine");
731 vx_add_symbols (arg_string, from_tty, text_addr, data_addr, bss_addr);
733 /* Getting new symbols may change our opinion about what is
735 reinit_frame_cache ();
738 /* Single step the target program at the source or machine level.
739 Takes an error exit if rpc fails.
740 Returns -1 if remote single-step operation fails, else 0. */
745 enum clnt_stat status;
747 SOURCE_STEP source_step;
749 source_step.taskId = PIDGET (inferior_ptid);
753 source_step.startAddr = step_range_start;
754 source_step.endAddr = step_range_end;
758 source_step.startAddr = 0;
759 source_step.endAddr = 0;
762 status = net_clnt_call (VX_SOURCE_STEP, xdr_SOURCE_STEP, &source_step,
763 xdr_int, &step_status);
765 if (status == RPC_SUCCESS)
771 /* Emulate ptrace using RPC calls to the VxWorks target system.
772 Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */
775 net_ptrace_clnt_call (enum ptracereq request, Rptrace *pPtraceIn,
776 Ptrace_return *pPtraceOut)
778 enum clnt_stat status;
780 status = net_clnt_call (request, xdr_rptrace, pPtraceIn, xdr_ptrace_return,
783 if (status != RPC_SUCCESS)
789 /* Query the target for the name of the file from which VxWorks was
790 booted. pBootFile is the address of a pointer to the buffer to
791 receive the file name; if the pointer pointed to by pBootFile is
792 NULL, memory for the buffer will be allocated by XDR.
793 Returns -1 if rpc failed, 0 otherwise. */
796 net_get_boot_file (char **pBootFile)
798 enum clnt_stat status;
800 status = net_clnt_call (VX_BOOT_FILE_INQ, xdr_void, (char *) 0,
801 xdr_wrapstring, pBootFile);
802 return (status == RPC_SUCCESS) ? 0 : -1;
805 /* Fetch a list of loaded object modules from the VxWorks target
806 and store in PLOADTABLE.
807 Returns -1 if rpc failed, 0 otherwise
808 There's no way to check if the returned loadTable is correct.
809 VxWorks doesn't check it. */
812 net_get_symbols (ldtabl *pLoadTable)
814 enum clnt_stat status;
816 memset ((char *) pLoadTable, '\0', sizeof (struct ldtabl));
818 status = net_clnt_call (VX_STATE_INQ, xdr_void, 0, xdr_ldtabl, pLoadTable);
819 return (status == RPC_SUCCESS) ? 0 : -1;
822 /* Look up a symbol in the VxWorks target's symbol table.
823 Returns status of symbol read on target side (0=success, -1=fail)
824 Returns -1 and complain()s if rpc fails. */
827 vx_lookup_symbol (char *name, /* symbol name */
830 enum clnt_stat status;
831 SYMBOL_ADDR symbolAddr;
834 memset ((char *) &symbolAddr, '\0', sizeof (symbolAddr));
836 status = net_clnt_call (VX_SYMBOL_INQ, xdr_wrapstring, &name,
837 xdr_SYMBOL_ADDR, &symbolAddr);
838 if (status != RPC_SUCCESS)
840 complaint (&symfile_complaints, "Lost contact with VxWorks target");
844 *pAddr = symbolAddr.addr;
845 return symbolAddr.status;
848 /* Check to see if the VxWorks target has a floating point coprocessor.
849 Returns 1 if target has floating point processor, 0 otherwise.
850 Calls error() if rpc fails. */
853 net_check_for_fp (void)
855 enum clnt_stat status;
856 bool_t fp = 0; /* true if fp processor is present on target board */
858 status = net_clnt_call (VX_FP_INQUIRE, xdr_void, 0, xdr_bool, &fp);
859 if (status != RPC_SUCCESS)
865 /* Establish an RPC connection with the VxWorks target system.
866 Calls error () if unable to establish connection. */
869 net_connect (char *host)
871 struct sockaddr_in destAddr;
872 struct hostent *destHost;
875 /* Get the internet address for the given host. Allow a numeric
876 IP address or a hostname. */
878 addr = inet_addr (host);
881 destHost = (struct hostent *) gethostbyname (host);
882 if (destHost == NULL)
883 /* FIXME: Probably should include hostname here in quotes.
884 For example if the user types "target vxworks vx960 " it should
885 say "Invalid host `vx960 '." not just "Invalid hostname". */
886 error ("Invalid hostname. Couldn't find remote host address.");
887 addr = *(unsigned long *) destHost->h_addr;
890 memset (&destAddr, '\0', sizeof (destAddr));
892 destAddr.sin_addr.s_addr = addr;
893 destAddr.sin_family = AF_INET;
894 destAddr.sin_port = 0; /* set to actual port that remote
895 ptrace is listening on. */
897 /* Create a tcp client transport on which to issue
898 calls to the remote ptrace server. */
900 ptraceSock = RPC_ANYSOCK;
901 pClient = clnttcp_create (&destAddr, RDBPROG, RDBVERS, &ptraceSock, 0, 0);
902 /* FIXME, here is where we deal with different version numbers of the
907 clnt_pcreateerror ("\tnet_connect");
908 error ("Couldn't connect to remote target.");
912 /* Sleep for the specified number of milliseconds
913 * (assumed to be less than 1000).
914 * If select () is interrupted, returns immediately;
915 * takes an error exit if select () fails for some other reason.
921 struct timeval select_timeout;
924 select_timeout.tv_sec = 0;
925 select_timeout.tv_usec = ms * 1000;
927 status = select (0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0,
930 if (status < 0 && errno != EINTR)
931 perror_with_name ("select");
935 vx_wait (ptid_t ptid_to_wait_for, struct target_waitstatus *status)
943 /* If CTRL-C is hit during this loop,
944 suspend the inferior process. */
949 quit_failed = (net_quit () == -1);
953 /* If a net_quit () or net_wait () call has failed,
954 allow the user to break the connection with the target.
955 We can't simply error () out of this loop, since the
956 data structures representing the state of the inferior
957 are in an inconsistent state. */
959 if (quit_failed || net_wait (&rdbEvent) == -1)
962 if (query ("Can't %s. Disconnect from target system? ",
963 (quit_failed) ? "suspend remote task"
964 : "get status of remote task"))
966 target_mourn_inferior ();
967 error ("Use the \"target\" command to reconnect.");
971 terminal_inferior ();
976 pid = rdbEvent.taskId;
979 sleep_ms (200); /* FIXME Don't kill the network too badly */
981 else if (pid != PIDGET (inferior_ptid))
982 internal_error (__FILE__, __LINE__,
983 "Bad pid for debugged task: %s\n",
984 local_hex_string ((unsigned long) pid));
988 /* The mostly likely kind. */
989 status->kind = TARGET_WAITKIND_STOPPED;
991 switch (rdbEvent.eventType)
994 status->kind = TARGET_WAITKIND_EXITED;
995 /* FIXME is it possible to distinguish between a
996 normal vs abnormal exit in VxWorks? */
997 status->value.integer = 0;
1001 /* Task was just started. */
1002 status->value.sig = TARGET_SIGNAL_TRAP;
1006 status->value.sig = TARGET_SIGNAL_TRAP;
1007 /* XXX was it stopped by a signal? act accordingly */
1010 case EVENT_BREAK: /* Breakpoint was hit. */
1011 status->value.sig = TARGET_SIGNAL_TRAP;
1014 case EVENT_SUSPEND: /* Task was suspended, probably by ^C. */
1015 status->value.sig = TARGET_SIGNAL_INT;
1018 case EVENT_BUS_ERR: /* Task made evil nasty reference. */
1019 status->value.sig = TARGET_SIGNAL_BUS;
1022 case EVENT_ZERO_DIV: /* Division by zero */
1023 status->value.sig = TARGET_SIGNAL_FPE;
1028 status->value.sig = i960_fault_to_signal (rdbEvent.sigType);
1030 /* Back in the old days, before enum target_signal, this code used
1031 to add NSIG to the signal number and claim that PRINT_RANDOM_SIGNAL
1032 would take care of it. But PRINT_RANDOM_SIGNAL has never been
1033 defined except on the i960, so I don't really know what we are
1034 supposed to do on other architectures. */
1035 status->value.sig = TARGET_SIGNAL_UNKNOWN;
1039 return pid_to_ptid (pid);
1043 symbol_stub (char *arg)
1045 symbol_file_add_main (arg, 0);
1050 add_symbol_stub (char *arg)
1052 struct ldfile *pLoadFile = (struct ldfile *) arg;
1054 printf_unfiltered ("\t%s: ", pLoadFile->name);
1055 vx_add_symbols (pLoadFile->name, 0, pLoadFile->txt_addr,
1056 pLoadFile->data_addr, pLoadFile->bss_addr);
1057 printf_unfiltered ("ok\n");
1060 /* Target command for VxWorks target systems.
1062 Used in vxgdb. Takes the name of a remote target machine
1063 running vxWorks and connects to it to initialize remote network
1067 vx_open (char *args, int from_tty)
1069 extern int close ();
1071 extern char *source_path;
1072 struct ldtabl loadTable;
1073 struct ldfile *pLoadFile;
1075 extern CLIENT *pClient;
1076 int symbols_added = 0;
1079 error_no_arg ("target machine name");
1081 target_preopen (from_tty);
1083 unpush_target (&vx_ops);
1084 printf_unfiltered ("Attaching remote machine across net...\n");
1085 gdb_flush (gdb_stdout);
1087 /* Allow the user to kill the connect attempt by typing ^C.
1088 Wait until the call to target_has_fp () completes before
1089 disallowing an immediate quit, since even if net_connect ()
1090 is successful, the remote debug server might be hung. */
1095 target_has_fp = net_check_for_fp ();
1096 printf_filtered ("Connected to %s.\n", args);
1100 push_target (&vx_ops);
1102 /* Save a copy of the target host's name. */
1103 vx_host = savestring (args, strlen (args));
1105 /* Find out the name of the file from which the target was booted
1106 and load its symbol table. */
1108 printf_filtered ("Looking in Unix path for all loaded modules:\n");
1110 if (!net_get_boot_file (&bootFile))
1114 printf_filtered ("\t%s: ", bootFile);
1115 /* This assumes that the kernel is never relocated. Hope that is an
1116 accurate assumption. */
1120 "Error while reading symbols from boot file:\n",
1122 puts_filtered ("ok\n");
1125 printf_unfiltered ("VxWorks kernel symbols not loaded.\n");
1128 error ("Can't retrieve boot file name from target machine.");
1130 clnt_freeres (pClient, xdr_wrapstring, &bootFile);
1132 if (net_get_symbols (&loadTable) != 0)
1133 error ("Can't read loaded modules from target machine");
1136 while (++i < loadTable.tbl_size)
1138 QUIT; /* FIXME, avoids clnt_freeres below: mem leak */
1139 pLoadFile = &loadTable.tbl_ent[i];
1143 struct cleanup *old_chain;
1144 char *fullname = NULL;
1146 desc = openp (source_path, 0, pLoadFile->name, O_RDONLY, 0, &fullname);
1148 perror_with_name (pLoadFile->name);
1149 old_chain = make_cleanup (close, desc);
1150 add_file_at_addr (fullname, desc, pLoadFile->txt_addr, pLoadFile->data_addr,
1151 pLoadFile->bss_addr);
1152 do_cleanups (old_chain);
1155 /* FIXME: Is there something better to search than the PATH? (probably
1156 not the source path, since source might be in different directories
1159 if (catch_errors (add_symbol_stub, (char *) pLoadFile, (char *) 0,
1164 printf_filtered ("Done.\n");
1166 clnt_freeres (pClient, xdr_ldtabl, &loadTable);
1168 /* Getting new symbols may change our opinion about what is
1171 reinit_frame_cache ();
1174 /* Takes a task started up outside of gdb and ``attaches'' to it.
1175 This stops it cold in its tracks and allows us to start tracing it. */
1178 vx_attach (char *args, int from_tty)
1183 Ptrace_return ptrace_out;
1187 error_no_arg ("process-id to attach");
1189 pid = strtoul (args, &cptr, 0);
1190 if ((cptr == args) || (*cptr != '\0'))
1191 error ("Invalid process-id -- give a single number in decimal or 0xhex");
1194 printf_unfiltered ("Attaching pid %s.\n",
1195 local_hex_string ((unsigned long) pid));
1197 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
1198 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
1199 ptrace_in.pid = pid;
1201 status = net_ptrace_clnt_call (PTRACE_ATTACH, &ptrace_in, &ptrace_out);
1204 if (ptrace_out.status == -1)
1206 errno = ptrace_out.errno_num;
1207 perror_with_name ("Attaching remote process");
1212 inferior_ptid = pid_to_ptid (pid);
1213 push_target (&vx_run_ops);
1220 /* detach_command --
1221 takes a program previously attached to and detaches it.
1222 The program resumes execution and will no longer stop
1223 on signals, etc. We better not have left any breakpoints
1224 in the program or it'll die when it hits one. For this
1225 to work, it may be necessary for the process to have been
1226 previously attached. It *might* work if the program was
1227 started via the normal ptrace (PTRACE_TRACEME). */
1230 vx_detach (char *args, int from_tty)
1233 Ptrace_return ptrace_out;
1238 error ("Argument given to VxWorks \"detach\".");
1241 printf_unfiltered ("Detaching pid %s.\n",
1243 (unsigned long) PIDGET (inferior_ptid)));
1245 if (args) /* FIXME, should be possible to leave suspended */
1246 signal = atoi (args);
1248 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
1249 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
1250 ptrace_in.pid = PIDGET (inferior_ptid);
1252 status = net_ptrace_clnt_call (PTRACE_DETACH, &ptrace_in, &ptrace_out);
1255 if (ptrace_out.status == -1)
1257 errno = ptrace_out.errno_num;
1258 perror_with_name ("Detaching VxWorks process");
1261 inferior_ptid = null_ptid;
1262 pop_target (); /* go back to non-executing VxWorks connection */
1265 /* vx_kill -- takes a running task and wipes it out. */
1271 Ptrace_return ptrace_out;
1274 printf_unfiltered ("Killing pid %s.\n", local_hex_string ((unsigned long) PIDGET (inferior_ptid)));
1276 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
1277 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
1278 ptrace_in.pid = PIDGET (inferior_ptid);
1280 status = net_ptrace_clnt_call (PTRACE_KILL, &ptrace_in, &ptrace_out);
1283 else if (ptrace_out.status == -1)
1285 errno = ptrace_out.errno_num;
1286 perror_with_name ("Killing VxWorks process");
1289 /* If it gives good status, the process is *gone*, no events remain.
1290 If the kill failed, assume the process is gone anyhow. */
1291 inferior_ptid = null_ptid;
1292 pop_target (); /* go back to non-executing VxWorks connection */
1295 /* Clean up from the VxWorks process target as it goes away. */
1298 vx_proc_close (int quitting)
1300 inferior_ptid = null_ptid; /* No longer have a process. */
1306 /* Make an RPC call to the VxWorks target.
1307 Returns RPC status. */
1309 static enum clnt_stat
1310 net_clnt_call (enum ptracereq procNum, xdrproc_t inProc, char *in,
1311 xdrproc_t outProc, char *out)
1313 enum clnt_stat status;
1315 status = clnt_call (pClient, procNum, inProc, in, outProc, out, rpcTimeout);
1317 if (status != RPC_SUCCESS)
1318 clnt_perrno (status);
1323 /* Clean up before losing control. */
1326 vx_close (int quitting)
1329 clnt_destroy (pClient); /* The net connection */
1333 xfree (vx_host); /* The hostname */
1337 /* A vxprocess target should be started via "run" not "target". */
1339 vx_proc_open (char *name, int from_tty)
1341 error ("Use the \"run\" command to start a VxWorks process.");
1347 vx_ops.to_shortname = "vxworks";
1348 vx_ops.to_longname = "VxWorks target memory via RPC over TCP/IP";
1349 vx_ops.to_doc = "Use VxWorks target memory. \n\
1350 Specify the name of the machine to connect to.";
1351 vx_ops.to_open = vx_open;
1352 vx_ops.to_close = vx_close;
1353 vx_ops.to_attach = vx_attach;
1354 vx_ops.to_xfer_memory = vx_xfer_memory;
1355 vx_ops.to_files_info = vx_files_info;
1356 vx_ops.to_load = vx_load_command;
1357 vx_ops.to_lookup_symbol = vx_lookup_symbol;
1358 vx_ops.to_create_inferior = vx_create_inferior;
1359 vx_ops.to_stratum = core_stratum;
1360 vx_ops.to_has_all_memory = 1;
1361 vx_ops.to_has_memory = 1;
1362 vx_ops.to_magic = OPS_MAGIC; /* Always the last thing */
1366 init_vx_run_ops (void)
1368 vx_run_ops.to_shortname = "vxprocess";
1369 vx_run_ops.to_longname = "VxWorks process";
1370 vx_run_ops.to_doc = "VxWorks process; started by the \"run\" command.";
1371 vx_run_ops.to_open = vx_proc_open;
1372 vx_run_ops.to_close = vx_proc_close;
1373 vx_run_ops.to_detach = vx_detach;
1374 vx_run_ops.to_resume = vx_resume;
1375 vx_run_ops.to_wait = vx_wait;
1376 vx_run_ops.to_fetch_registers = vx_read_register;
1377 vx_run_ops.to_store_registers = vx_write_register;
1378 vx_run_ops.to_prepare_to_store = vx_prepare_to_store;
1379 vx_run_ops.to_xfer_memory = vx_xfer_memory;
1380 vx_run_ops.to_files_info = vx_run_files_info;
1381 vx_run_ops.to_insert_breakpoint = vx_insert_breakpoint;
1382 vx_run_ops.to_remove_breakpoint = vx_remove_breakpoint;
1383 vx_run_ops.to_kill = vx_kill;
1384 vx_run_ops.to_load = vx_load_command;
1385 vx_run_ops.to_lookup_symbol = vx_lookup_symbol;
1386 vx_run_ops.to_mourn_inferior = vx_mourn_inferior;
1387 vx_run_ops.to_stratum = process_stratum;
1388 vx_run_ops.to_has_memory = 1;
1389 vx_run_ops.to_has_stack = 1;
1390 vx_run_ops.to_has_registers = 1;
1391 vx_run_ops.to_has_execution = 1;
1392 vx_run_ops.to_magic = OPS_MAGIC;
1396 _initialize_vx (void)
1399 add_target (&vx_ops);
1401 add_target (&vx_run_ops);
1404 (add_set_cmd ("vxworks-timeout", class_support, var_uinteger,
1405 (char *) &rpcTimeout.tv_sec,
1406 "Set seconds to wait for rpc calls to return.\n\
1407 Set the number of seconds to wait for rpc calls to return.", &setlist),