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"
36 #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 */
40 #define realloc bogon_realloc /* Sun claims "char *realloc()", not void * */
45 #include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
47 #include "vx-share/ptrace.h"
48 #include "vx-share/xdr_ptrace.h"
49 #include "vx-share/xdr_ld.h"
50 #include "vx-share/xdr_rdb.h"
51 #include "vx-share/dbgRpcLib.h"
55 extern void symbol_file_command ();
56 extern int stop_soon_quietly; /* for wait_for_inferior */
58 static int net_ptrace_clnt_call (); /* Forward decl */
59 static enum clnt_stat net_clnt_call (); /* Forward decl */
60 extern struct target_ops vx_ops, vx_run_ops; /* Forward declaration */
62 /* Saved name of target host and called function for "info files".
66 static char *vx_running; /* Called function */
68 /* Nonzero means target that is being debugged remotely has a floating
71 static int target_has_fp;
73 /* Default error message when the network is forking up. */
75 static const char rpcerr[] = "network target debugging: rpc error";
77 CLIENT *pClient; /* client used in net debugging */
78 static int ptraceSock = RPC_ANYSOCK;
80 enum clnt_stat net_clnt_call();
81 static void parse_args ();
83 static struct timeval rpcTimeout = { 10, 0 };
85 static char *skip_white_space ();
86 static char *find_white_space ();
88 /* Tell the VxWorks target system to download a file.
89 The load addresses of the text, data, and bss segments are
90 stored in *pTextAddr, *pDataAddr, and *pBssAddr (respectively).
91 Returns 0 for success, -1 for failure. */
94 net_load (filename, pTextAddr, pDataAddr, pBssAddr)
100 enum clnt_stat status;
101 struct ldfile ldstruct;
102 struct timeval load_timeout;
104 memset ((char *) &ldstruct, '\0', sizeof (ldstruct));
106 /* We invoke clnt_call () here directly, instead of through
107 net_clnt_call (), because we need to set a large timeout value.
108 The load on the target side can take quite a while, easily
109 more than 10 seconds. The user can kill this call by typing
110 CTRL-C if there really is a problem with the load.
112 Do not change the tv_sec value without checking -- select() imposes
113 a limit of 10**8 on it for no good reason that I can see... */
115 load_timeout.tv_sec = 99999999; /* A large number, effectively inf. */
116 load_timeout.tv_usec = 0;
118 status = clnt_call (pClient, VX_LOAD, xdr_wrapstring, &filename, xdr_ldfile,
119 &ldstruct, load_timeout);
121 if (status == RPC_SUCCESS)
123 if (*ldstruct.name == 0) /* load failed on VxWorks side */
125 *pTextAddr = ldstruct.txt_addr;
126 *pDataAddr = ldstruct.data_addr;
127 *pBssAddr = ldstruct.bss_addr;
134 /* returns 0 if successful, errno if RPC failed or VxWorks complains. */
137 net_break (addr, procnum)
141 enum clnt_stat status;
143 Rptrace ptrace_in; /* XXX This is stupid. It doesn't need to be a ptrace
144 structure. How about something smaller? */
146 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
149 ptrace_in.addr = addr;
150 ptrace_in.pid = inferior_pid;
152 status = net_clnt_call (procnum, xdr_rptrace, &ptrace_in, xdr_int,
155 if (status != RPC_SUCCESS)
158 if (break_status == -1)
160 return break_status; /* probably (FIXME) zero */
163 /* returns 0 if successful, errno otherwise */
166 vx_insert_breakpoint (addr)
169 return net_break (addr, VX_BREAK_ADD);
172 /* returns 0 if successful, errno otherwise */
175 vx_remove_breakpoint (addr)
178 return net_break (addr, VX_BREAK_DELETE);
181 /* Start an inferior process and sets inferior_pid to its pid.
182 EXEC_FILE is the file to run.
183 ALLARGS is a string containing the arguments to the program.
184 ENV is the environment vector to pass.
185 Returns process id. Errors reported with error().
186 On VxWorks, we ignore exec_file. */
189 vx_create_inferior (exec_file, args, env)
194 enum clnt_stat status;
196 TASK_START taskStart;
198 memset ((char *) &passArgs, '\0', sizeof (passArgs));
199 memset ((char *) &taskStart, '\0', sizeof (taskStart));
201 /* parse arguments, put them in passArgs */
203 parse_args (args, &passArgs);
205 if (passArgs.arg_array_len == 0)
206 error ("You must specify a function name to run, and arguments if any");
208 status = net_clnt_call (PROCESS_START, xdr_arg_array, &passArgs,
209 xdr_TASK_START, &taskStart);
211 if ((status != RPC_SUCCESS) || (taskStart.status == -1))
212 error ("Can't create process on remote target machine");
214 /* Save the name of the running function */
215 vx_running = savestring (passArgs.arg_array_val[0],
216 strlen (passArgs.arg_array_val[0]));
218 push_target (&vx_run_ops);
219 inferior_pid = taskStart.pid;
221 /* We will get a trace trap after one instruction.
222 Insert breakpoints and continue. */
224 init_wait_for_inferior ();
226 /* Set up the "saved terminal modes" of the inferior
227 based on what modes we are starting it with. */
228 target_terminal_init ();
230 /* Install inferior's terminal modes. */
231 target_terminal_inferior ();
233 stop_soon_quietly = 1;
234 wait_for_inferior (); /* Get the task spawn event */
235 stop_soon_quietly = 0;
237 /* insert_step_breakpoint (); FIXME, do we need this? */
238 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
241 /* Fill ARGSTRUCT in argc/argv form with the arguments from the
242 argument string ARGSTRING. */
245 parse_args (arg_string, arg_struct)
246 register char *arg_string;
247 arg_array *arg_struct;
249 register int arg_count = 0; /* number of arguments */
250 register int arg_index = 0;
253 memset ((char *) arg_struct, '\0', sizeof (arg_array));
255 /* first count how many arguments there are */
260 if (*(p0 = skip_white_space (p0)) == '\0')
262 p0 = find_white_space (p0);
266 arg_struct->arg_array_len = arg_count;
267 arg_struct->arg_array_val = (char **) xmalloc ((arg_count + 1)
270 /* now copy argument strings into arg_struct. */
272 while (*(arg_string = skip_white_space (arg_string)))
274 p0 = find_white_space (arg_string);
275 arg_struct->arg_array_val[arg_index++] = savestring (arg_string,
280 arg_struct->arg_array_val[arg_count] = NULL;
283 /* Advance a string pointer across whitespace and return a pointer
284 to the first non-white character. */
290 while (*p == ' ' || *p == '\t')
295 /* Search for the first unquoted whitespace character in a string.
296 Returns a pointer to the character, or to the null terminator
297 if no whitespace is found. */
305 while ((c = *p) != ' ' && c != '\t' && c)
307 if (c == '\'' || c == '"')
309 while (*++p != c && *p)
322 /* Poll the VxWorks target system for an event related
323 to the debugged task.
324 Returns -1 if remote wait failed, task status otherwise. */
331 enum clnt_stat status;
333 memset ((char *) pEvent, '\0', sizeof (RDB_EVENT));
336 status = net_clnt_call (PROCESS_WAIT, xdr_int, &pid, xdr_RDB_EVENT, pEvent);
338 return (status == RPC_SUCCESS)? pEvent->status: -1;
341 /* Suspend the remote task.
342 Returns -1 if suspend fails on target system, 0 otherwise. */
349 enum clnt_stat status;
353 /* don't let rdbTask suspend itself by passing a pid of 0 */
355 if ((pid = inferior_pid) == 0)
358 status = net_clnt_call (VX_TASK_SUSPEND, xdr_int, &pid, xdr_int,
361 return (status == RPC_SUCCESS)? quit_status: -1;
364 /* Read a register or registers from the remote system. */
367 vx_read_register (regno)
372 Ptrace_return ptrace_out;
375 extern char registers[];
377 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
378 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
380 /* FIXME, eventually only get the ones we need. */
381 registers_fetched ();
383 ptrace_in.pid = inferior_pid;
384 ptrace_out.info.more_data = (caddr_t) &out_data;
385 out_data.len = VX_NUM_REGS * REGISTER_RAW_SIZE (0);
386 out_data.bytes = (caddr_t) registers;
388 status = net_ptrace_clnt_call (PTRACE_GETREGS, &ptrace_in, &ptrace_out);
391 if (ptrace_out.status == -1)
393 errno = ptrace_out.errno;
394 perror_with_name ("net_ptrace_clnt_call(PTRACE_GETREGS)");
397 #ifdef VX_SIZE_FPREGS
398 /* If the target has floating point registers, fetch them.
399 Otherwise, zero the floating point register values in
400 registers[] for good measure, even though we might not
405 ptrace_in.pid = inferior_pid;
406 ptrace_out.info.more_data = (caddr_t) &out_data;
407 out_data.len = VX_SIZE_FPREGS;
408 out_data.bytes = (caddr_t) ®isters[REGISTER_BYTE (FP0_REGNUM)];
410 status = net_ptrace_clnt_call (PTRACE_GETFPREGS, &ptrace_in, &ptrace_out);
413 if (ptrace_out.status == -1)
415 errno = ptrace_out.errno;
416 perror_with_name ("net_ptrace_clnt_call(PTRACE_GETFPREGS)");
421 memset (®isters[REGISTER_BYTE (FP0_REGNUM)], '\0', VX_SIZE_FPREGS);
423 #endif /* VX_SIZE_FPREGS */
426 /* Prepare to store registers. Since we will store all of them,
427 read out their current values now. */
430 vx_prepare_to_store ()
432 /* Fetch all registers, if any of them are not yet fetched. */
433 read_register_bytes (0, NULL, REGISTER_BYTES);
437 /* Store our register values back into the inferior.
438 If REGNO is -1, do this for all registers.
439 Otherwise, REGNO specifies which register (so we can save time). */
440 /* FIXME, look at REGNO to save time here */
443 vx_write_register (regno)
448 extern char registers[];
451 Ptrace_return ptrace_out;
453 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
454 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
456 ptrace_in.pid = inferior_pid;
457 ptrace_in.info.ttype = DATA;
458 ptrace_in.info.more_data = (caddr_t) &in_data;
460 in_data.bytes = registers;
462 in_data.len = VX_NUM_REGS * REGISTER_SIZE;
464 /* XXX change second param to be a proc number */
465 status = net_ptrace_clnt_call (PTRACE_SETREGS, &ptrace_in, &ptrace_out);
468 if (ptrace_out.status == -1)
470 errno = ptrace_out.errno;
471 perror_with_name ("net_ptrace_clnt_call(PTRACE_SETREGS)");
474 #ifdef VX_SIZE_FPREGS
475 /* Store floating point registers if the target has them. */
479 ptrace_in.pid = inferior_pid;
480 ptrace_in.info.ttype = DATA;
481 ptrace_in.info.more_data = (caddr_t) &in_data;
484 in_data.bytes = ®isters[REGISTER_BYTE (FP0_REGNUM)];
485 in_data.len = VX_SIZE_FPREGS;
487 status = net_ptrace_clnt_call (PTRACE_SETFPREGS, &ptrace_in, &ptrace_out);
490 if (ptrace_out.status == -1)
492 errno = ptrace_out.errno;
493 perror_with_name ("net_ptrace_clnt_call(PTRACE_SETFPREGS)");
496 #endif /* VX_SIZE_FPREGS */
499 /* Copy LEN bytes to or from remote inferior's memory starting at MEMADDR
500 to debugger memory starting at MYADDR. WRITE is true if writing to the
502 Result is the number of bytes written or read (zero if error). The
503 protocol allows us to return a negative count, indicating that we can't
504 handle the current address but can handle one N bytes further, but
505 vxworks doesn't give us that information. */
508 vx_xfer_memory (memaddr, myaddr, len, write, target)
513 struct target_ops *target; /* ignored */
517 Ptrace_return ptrace_out;
520 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
521 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
523 ptrace_in.pid = inferior_pid; /* XXX pid unnecessary for READDATA */
524 ptrace_in.addr = (int) memaddr; /* Where from */
525 ptrace_in.data = len; /* How many bytes */
529 ptrace_in.info.ttype = DATA;
530 ptrace_in.info.more_data = (caddr_t) &data;
532 data.bytes = (caddr_t) myaddr; /* Where from */
533 data.len = len; /* How many bytes (again, for XDR) */
535 /* XXX change second param to be a proc number */
536 status = net_ptrace_clnt_call (PTRACE_WRITEDATA, &ptrace_in, &ptrace_out);
540 ptrace_out.info.more_data = (caddr_t) &data;
541 data.bytes = myaddr; /* Where to */
542 data.len = len; /* How many (again, for XDR) */
544 /* XXX change second param to be a proc number */
545 status = net_ptrace_clnt_call (PTRACE_READDATA, &ptrace_in, &ptrace_out);
550 if (ptrace_out.status == -1)
552 return 0; /* No bytes moved */
554 return len; /* Moved *all* the bytes */
560 printf_unfiltered ("\tAttached to host `%s'", vx_host);
561 printf_unfiltered (", which has %sfloating point", target_has_fp? "": "no ");
562 printf_unfiltered (".\n");
568 printf_unfiltered ("\tRunning %s VxWorks process %s",
569 vx_running? "child": "attached",
570 local_hex_string((unsigned long) inferior_pid));
572 printf_unfiltered (", function `%s'", vx_running);
573 printf_unfiltered(".\n");
577 vx_resume (pid, step, siggnal)
580 enum target_signal siggnal;
584 Ptrace_return ptrace_out;
589 if (siggnal != 0 && siggnal != stop_signal)
590 error ("Cannot send signals to VxWorks processes");
592 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
593 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
596 ptrace_in.addr = 1; /* Target side insists on this, or it panics. */
598 /* XXX change second param to be a proc number */
599 status = net_ptrace_clnt_call (step? PTRACE_SINGLESTEP: PTRACE_CONT,
600 &ptrace_in, &ptrace_out);
603 if (ptrace_out.status == -1)
605 errno = ptrace_out.errno;
606 perror_with_name ("Resuming remote process");
613 pop_target (); /* Pop back to no-child state */
614 generic_mourn_inferior ();
618 /* This function allows the addition of incrementally linked object files. */
621 vx_load_command (arg_string, from_tty)
630 error ("The load command takes a file name");
632 arg_string = tilde_expand (arg_string);
633 make_cleanup (free, arg_string);
639 if (net_load (arg_string, &text_addr, &data_addr, &bss_addr) == -1)
640 error ("Load failed on target machine");
643 /* FIXME, for now we ignore data_addr and bss_addr. */
644 symbol_file_add (arg_string, from_tty, text_addr, 0, 0, 0);
647 #ifdef FIXME /* Not ready for prime time */
648 /* Single step the target program at the source or machine level.
649 Takes an error exit if rpc fails.
650 Returns -1 if remote single-step operation fails, else 0. */
655 enum clnt_stat status;
657 SOURCE_STEP source_step;
659 source_step.taskId = inferior_pid;
663 source_step.startAddr = step_range_start;
664 source_step.endAddr = step_range_end;
668 source_step.startAddr = 0;
669 source_step.endAddr = 0;
672 status = net_clnt_call (VX_SOURCE_STEP, xdr_SOURCE_STEP, &source_step,
673 xdr_int, &step_status);
675 if (status == RPC_SUCCESS)
682 /* Emulate ptrace using RPC calls to the VxWorks target system.
683 Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */
686 net_ptrace_clnt_call (request, pPtraceIn, pPtraceOut)
687 enum ptracereq request;
689 Ptrace_return *pPtraceOut;
691 enum clnt_stat status;
693 status = net_clnt_call (request, xdr_rptrace, pPtraceIn, xdr_ptrace_return,
696 if (status != RPC_SUCCESS)
702 /* Query the target for the name of the file from which VxWorks was
703 booted. pBootFile is the address of a pointer to the buffer to
704 receive the file name; if the pointer pointed to by pBootFile is
705 NULL, memory for the buffer will be allocated by XDR.
706 Returns -1 if rpc failed, 0 otherwise. */
709 net_get_boot_file (pBootFile)
712 enum clnt_stat status;
714 status = net_clnt_call (VX_BOOT_FILE_INQ, xdr_void, (char *) 0,
715 xdr_wrapstring, pBootFile);
716 return (status == RPC_SUCCESS) ? 0 : -1;
719 /* Fetch a list of loaded object modules from the VxWorks target.
720 Returns -1 if rpc failed, 0 otherwise
721 There's no way to check if the returned loadTable is correct.
722 VxWorks doesn't check it. */
725 net_get_symbols (pLoadTable)
726 ldtabl *pLoadTable; /* return pointer to ldtabl here */
728 enum clnt_stat status;
730 memset ((char *) pLoadTable, '\0', sizeof (struct ldtabl));
732 status = net_clnt_call (VX_STATE_INQ, xdr_void, 0, xdr_ldtabl, pLoadTable);
733 return (status == RPC_SUCCESS) ? 0 : -1;
736 /* Look up a symbol in the VxWorks target's symbol table.
737 Returns status of symbol read on target side (0=success, -1=fail)
738 Returns -1 and complain()s if rpc fails. */
740 struct complaint cant_contact_target =
741 {"Lost contact with VxWorks target", 0, 0};
744 vx_lookup_symbol (name, pAddr)
745 char *name; /* symbol name */
748 enum clnt_stat status;
749 SYMBOL_ADDR symbolAddr;
752 memset ((char *) &symbolAddr, '\0', sizeof (symbolAddr));
754 status = net_clnt_call (VX_SYMBOL_INQ, xdr_wrapstring, &name,
755 xdr_SYMBOL_ADDR, &symbolAddr);
756 if (status != RPC_SUCCESS) {
757 complain (&cant_contact_target);
761 *pAddr = symbolAddr.addr;
762 return symbolAddr.status;
765 /* Check to see if the VxWorks target has a floating point coprocessor.
766 Returns 1 if target has floating point processor, 0 otherwise.
767 Calls error() if rpc fails. */
772 enum clnt_stat status;
773 bool_t fp = 0; /* true if fp processor is present on target board */
775 status = net_clnt_call (VX_FP_INQUIRE, xdr_void, 0, xdr_bool, &fp);
776 if (status != RPC_SUCCESS)
782 /* Establish an RPC connection with the VxWorks target system.
783 Calls error () if unable to establish connection. */
789 struct sockaddr_in destAddr;
790 struct hostent *destHost;
793 /* Get the internet address for the given host. Allow a numeric
794 IP address or a hostname. */
796 addr = inet_addr (host);
799 destHost = (struct hostent *) gethostbyname (host);
800 if (destHost == NULL)
801 error ("Invalid hostname. Couldn't find remote host address.");
802 addr = * (unsigned long *) destHost->h_addr;
805 memset (&destAddr, '\0', sizeof (destAddr));
807 destAddr.sin_addr.s_addr = addr;
808 destAddr.sin_family = AF_INET;
809 destAddr.sin_port = 0; /* set to actual port that remote
810 ptrace is listening on. */
812 /* Create a tcp client transport on which to issue
813 calls to the remote ptrace server. */
815 ptraceSock = RPC_ANYSOCK;
816 pClient = clnttcp_create (&destAddr, RDBPROG, RDBVERS, &ptraceSock, 0, 0);
817 /* FIXME, here is where we deal with different version numbers of the proto */
821 clnt_pcreateerror ("\tnet_connect");
822 error ("Couldn't connect to remote target.");
826 /* Sleep for the specified number of milliseconds
827 * (assumed to be less than 1000).
828 * If select () is interrupted, returns immediately;
829 * takes an error exit if select () fails for some other reason.
836 struct timeval select_timeout;
839 select_timeout.tv_sec = 0;
840 select_timeout.tv_usec = ms * 1000;
842 status = select (0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &select_timeout);
844 if (status < 0 && errno != EINTR)
845 perror_with_name ("select");
848 /* Wait for control to return from inferior to debugger.
849 If inferior gets a signal, we may decide to start it up again
850 instead of returning. That is why there is a loop in this function.
851 When this function actually returns it means the inferior
852 should be left stopped and GDB should read more commands. */
854 /* For network debugging with VxWorks.
855 * VxWorks knows when tasks hit breakpoints, receive signals, exit, etc,
856 * so vx_wait() receives this information directly from
857 * VxWorks instead of trying to figure out what happenned via a wait() call.
861 vx_wait (pid_to_wait_for, status)
863 struct target_waitstatus *status;
871 /* If CTRL-C is hit during this loop,
872 suspend the inferior process. */
877 quit_failed = (net_quit () == -1);
881 /* If a net_quit () or net_wait () call has failed,
882 allow the user to break the connection with the target.
883 We can't simply error () out of this loop, since the
884 data structures representing the state of the inferior
885 are in an inconsistent state. */
887 if (quit_failed || net_wait (&rdbEvent) == -1)
890 if (query ("Can't %s. Disconnect from target system? ",
891 (quit_failed) ? "suspend remote task"
892 : "get status of remote task"))
894 target_mourn_inferior();
895 error ("Use the \"target\" command to reconnect.");
899 terminal_inferior ();
904 pid = rdbEvent.taskId;
907 sleep_ms (200); /* FIXME Don't kill the network too badly */
909 else if (pid != inferior_pid)
910 fatal ("Bad pid for debugged task: %s\n",
911 local_hex_string((unsigned long) pid));
914 /* The mostly likely kind. */
915 status->kind = TARGET_WAITKIND_STOPPED;
917 switch (rdbEvent.eventType)
920 status->kind = TARGET_WAITKIND_EXITED;
921 /* FIXME is it possible to distinguish between a
922 normal vs abnormal exit in VxWorks? */
923 status->value.integer = 0;
927 /* Task was just started. */
928 status->value.sig = TARGET_SIGNAL_TRAP;
932 status->value.sig = TARGET_SIGNAL_TRAP;
933 /* XXX was it stopped by a signal? act accordingly */
936 case EVENT_BREAK: /* Breakpoint was hit. */
937 status->value.sig = TARGET_SIGNAL_TRAP;
940 case EVENT_SUSPEND: /* Task was suspended, probably by ^C. */
941 status->value.sig = TARGET_SIGNAL_INT;
944 case EVENT_BUS_ERR: /* Task made evil nasty reference. */
945 status->value.sig = TARGET_SIGNAL_BUS;
948 case EVENT_ZERO_DIV: /* Division by zero */
949 status->value.sig = TARGET_SIGNAL_FPE;
953 status->value.sig = i960_fault_to_signal (rdbEvent.sigType);
963 symbol_file_command (arg, 0);
968 add_symbol_stub (arg)
971 struct ldfile *pLoadFile = (struct ldfile *)arg;
973 printf_unfiltered("\t%s: ", pLoadFile->name);
974 symbol_file_add (pLoadFile->name, 0, pLoadFile->txt_addr, 0, 0, 0);
975 printf_unfiltered ("ok\n");
978 /* Target command for VxWorks target systems.
980 Used in vxgdb. Takes the name of a remote target machine
981 running vxWorks and connects to it to initialize remote network
985 vx_open (args, from_tty)
991 extern char *source_path;
992 struct ldtabl loadTable;
993 struct ldfile *pLoadFile;
995 extern CLIENT *pClient;
998 error_no_arg ("target machine name");
1000 target_preopen (from_tty);
1002 unpush_target (&vx_ops);
1003 printf_unfiltered ("Attaching remote machine across net...\n");
1004 gdb_flush (gdb_stdout);
1006 /* Allow the user to kill the connect attempt by typing ^C.
1007 Wait until the call to target_has_fp () completes before
1008 disallowing an immediate quit, since even if net_connect ()
1009 is successful, the remote debug server might be hung. */
1014 target_has_fp = net_check_for_fp ();
1015 printf_filtered ("Connected to %s.\n", args);
1019 push_target (&vx_ops);
1021 /* Save a copy of the target host's name. */
1022 vx_host = savestring (args, strlen (args));
1024 /* Find out the name of the file from which the target was booted
1025 and load its symbol table. */
1027 printf_filtered ("Looking in Unix path for all loaded modules:\n");
1029 if (!net_get_boot_file (&bootFile))
1032 printf_filtered ("\t%s: ", bootFile);
1034 (symbol_stub, bootFile,
1035 "Error while reading symbols from boot file:\n", RETURN_MASK_ALL))
1036 puts_filtered ("ok\n");
1037 } else if (from_tty)
1038 printf_unfiltered ("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,
1075 printf_filtered ("Done.\n");
1077 clnt_freeres (pClient, xdr_ldtabl, &loadTable);
1080 /* Takes a task started up outside of gdb and ``attaches'' to it.
1081 This stops it cold in its tracks and allows us to start tracing it. */
1084 vx_attach (args, from_tty)
1091 Ptrace_return ptrace_out;
1095 error_no_arg ("process-id to attach");
1097 pid = strtol (args, &cptr, 0);
1098 if ((cptr == args) || (*cptr != '\0'))
1099 error ("Invalid process-id -- give a single number in decimal or 0xhex");
1102 printf_unfiltered ("Attaching pid %s.\n",
1103 local_hex_string((unsigned long) pid));
1105 memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in));
1106 memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out));
1107 ptrace_in.pid = pid;
1109 status = net_ptrace_clnt_call (PTRACE_ATTACH, &ptrace_in, &ptrace_out);
1112 if (ptrace_out.status == -1)
1114 errno = ptrace_out.errno;
1115 perror_with_name ("Attaching remote process");
1119 push_target (&vx_run_ops);
1125 /* detach_command --
1126 takes a program previously attached to and detaches it.
1127 The program resumes execution and will no longer stop
1128 on signals, etc. We better not have left any breakpoints
1129 in the program or it'll die when it hits one. For this
1130 to work, it may be necessary for the process to have been
1131 previously attached. It *might* work if the program was
1132 started via the normal ptrace (PTRACE_TRACEME). */
1135 vx_detach (args, from_tty)
1140 Ptrace_return ptrace_out;
1145 error ("Argument given to VxWorks \"detach\".");
1148 printf_unfiltered ("Detaching pid %s.\n",
1149 local_hex_string((unsigned long) inferior_pid));
1151 if (args) /* FIXME, should be possible to leave suspended */
1152 signal = atoi (args);
1154 memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in));
1155 memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out));
1156 ptrace_in.pid = inferior_pid;
1158 status = net_ptrace_clnt_call (PTRACE_DETACH, &ptrace_in, &ptrace_out);
1161 if (ptrace_out.status == -1)
1163 errno = ptrace_out.errno;
1164 perror_with_name ("Detaching VxWorks process");
1168 pop_target (); /* go back to non-executing VxWorks connection */
1171 /* vx_kill -- takes a running task and wipes it out. */
1177 Ptrace_return ptrace_out;
1180 printf_unfiltered ("Killing pid %s.\n", local_hex_string((unsigned long) inferior_pid));
1182 memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in));
1183 memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out));
1184 ptrace_in.pid = inferior_pid;
1186 status = net_ptrace_clnt_call (PTRACE_KILL, &ptrace_in, &ptrace_out);
1189 else if (ptrace_out.status == -1)
1191 errno = ptrace_out.errno;
1192 perror_with_name ("Killing VxWorks process");
1195 /* If it gives good status, the process is *gone*, no events remain.
1196 If the kill failed, assume the process is gone anyhow. */
1198 pop_target (); /* go back to non-executing VxWorks connection */
1201 /* Clean up from the VxWorks process target as it goes away. */
1204 vx_proc_close (quitting)
1207 inferior_pid = 0; /* No longer have a process. */
1213 /* Make an RPC call to the VxWorks target.
1214 Returns RPC status. */
1216 static enum clnt_stat
1217 net_clnt_call (procNum, inProc, in, outProc, out)
1218 enum ptracereq procNum;
1224 enum clnt_stat status;
1226 status = clnt_call (pClient, procNum, inProc, in, outProc, out, rpcTimeout);
1228 if (status != RPC_SUCCESS)
1229 clnt_perrno (status);
1234 /* Clean up before losing control. */
1241 clnt_destroy (pClient); /* The net connection */
1245 free (vx_host); /* The hostname */
1249 /* A vxprocess target should be started via "run" not "target". */
1252 vx_proc_open (name, from_tty)
1256 error ("Use the \"run\" command to start a VxWorks process.");
1259 /* Target ops structure for accessing memory and such over the net */
1261 struct target_ops vx_ops = {
1262 "vxworks", "VxWorks target memory via RPC over TCP/IP",
1263 "Use VxWorks target memory. \n\
1264 Specify the name of the machine to connect to.",
1265 vx_open, vx_close, vx_attach, 0, /* vx_detach, */
1266 0, 0, /* resume, wait */
1267 0, 0, /* read_reg, write_reg */
1268 0, /* prep_to_store, */
1269 vx_xfer_memory, vx_files_info,
1270 0, 0, /* insert_breakpoint, remove_breakpoint */
1271 0, 0, 0, 0, 0, /* terminal stuff */
1275 vx_create_inferior, 0, /* mourn_inferior */
1277 0, /* notice_signals */
1278 core_stratum, 0, /* next */
1279 1, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */
1280 0, 0, /* Section pointers */
1281 OPS_MAGIC, /* Always the last thing */
1284 /* Target ops structure for accessing VxWorks child processes over the net */
1286 struct target_ops vx_run_ops = {
1287 "vxprocess", "VxWorks process",
1288 "VxWorks process, started by the \"run\" command.",
1289 vx_proc_open, vx_proc_close, 0, vx_detach, /* vx_attach */
1291 vx_read_register, vx_write_register,
1292 vx_prepare_to_store,
1293 vx_xfer_memory, vx_run_files_info,
1294 vx_insert_breakpoint, vx_remove_breakpoint,
1295 0, 0, 0, 0, 0, /* terminal stuff */
1299 0, vx_mourn_inferior,
1301 0, /* notice_signals */
1302 process_stratum, 0, /* next */
1303 0, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1304 /* all_mem is off to avoid spurious msg in "i files" */
1305 0, 0, /* Section pointers */
1306 OPS_MAGIC, /* Always the last thing */
1308 /* ==> Remember when reading at end of file, there are two "ops" structs here. */
1315 (add_set_cmd ("vxworks-timeout", class_support, var_uinteger,
1316 (char *) &rpcTimeout.tv_sec,
1317 "Set seconds to wait for rpc calls to return.\n\
1318 Set the number of seconds to wait for rpc calls to return.", &setlist),
1321 add_target (&vx_ops);
1322 add_target (&vx_run_ops);