spelling fix.
[deliverable/binutils-gdb.git] / gdb / remote-vx.c
CommitLineData
dd3b648e 1/* Memory-access and commands for remote VxWorks processes, for GDB.
1de13231 2 Copyright (C) 1990-95, 1997-98, 1999 Free Software Foundation, Inc.
dd3b648e
RP
3 Contributed by Wind River Systems and Cygnus Support.
4
5This file is part of GDB.
6
99a7de40 7This program is free software; you can redistribute it and/or modify
dd3b648e 8it under the terms of the GNU General Public License as published by
99a7de40
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
dd3b648e 11
99a7de40 12This program is distributed in the hope that it will be useful,
dd3b648e
RP
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
99a7de40 18along with this program; if not, write to the Free Software
6c9638b4 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
dd3b648e
RP
20
21#include "defs.h"
dd3b648e
RP
22#include "frame.h"
23#include "inferior.h"
24#include "wait.h"
25#include "target.h"
26#include "gdbcore.h"
27#include "command.h"
28#include "symtab.h"
5998e362 29#include "complaints.h"
56894788 30#include "gdbcmd.h"
e7b5942b
JK
31#include "bfd.h" /* Required by objfiles.h. */
32#include "symfile.h" /* Required by objfiles.h. */
33#include "objfiles.h"
34#include "gdb-stabs.h"
dd3b648e 35
2b576293 36#include "gdb_string.h"
dd3b648e
RP
37#include <errno.h>
38#include <signal.h>
39#include <fcntl.h>
40#include <sys/types.h>
dd3b648e 41#include <sys/socket.h>
0d6d92c7 42#define malloc bogon_malloc /* Sun claims "char *malloc()" not void * */
dd3b648e 43#define free bogon_free /* Sun claims "int free()" not void */
b67903ac 44#define realloc bogon_realloc /* Sun claims "char *realloc()", not void * */
dd3b648e 45#include <rpc/rpc.h>
0d6d92c7 46#undef malloc
dd3b648e 47#undef free
b67903ac 48#undef realloc
dd3b648e
RP
49#include <sys/time.h> /* UTek's <rpc/rpc.h> doesn't #incl this */
50#include <netdb.h>
aa942355
SG
51#include "vx-share/ptrace.h"
52#include "vx-share/xdr_ptrace.h"
53#include "vx-share/xdr_ld.h"
54#include "vx-share/xdr_rdb.h"
55#include "vx-share/dbgRpcLib.h"
dd3b648e 56
dd3b648e 57#include <symtab.h>
1ab3bf1b 58
161520dc
KH
59/* Maximum number of bytes to transfer in a single
60 PTRACE_{READ,WRITE}DATA request. */
61#define VX_MEMXFER_MAX 4096
62
63extern void vx_read_register ();
64extern void vx_write_register ();
dd3b648e 65extern void symbol_file_command ();
dd3b648e
RP
66extern int stop_soon_quietly; /* for wait_for_inferior */
67
161520dc 68static int net_step ();
dd3b648e
RP
69static int net_ptrace_clnt_call (); /* Forward decl */
70static enum clnt_stat net_clnt_call (); /* Forward decl */
64aa82eb
SS
71
72/* Target ops structure for accessing memory and such over the net */
73
74static struct target_ops vx_ops;
75
76/* Target ops structure for accessing VxWorks child processes over the net */
77
78static struct target_ops vx_run_ops;
dd3b648e
RP
79
80/* Saved name of target host and called function for "info files".
81 Both malloc'd. */
82
83static char *vx_host;
84static char *vx_running; /* Called function */
85
86/* Nonzero means target that is being debugged remotely has a floating
87 point processor. */
88
161520dc 89int target_has_fp;
dd3b648e
RP
90
91/* Default error message when the network is forking up. */
92
93static const char rpcerr[] = "network target debugging: rpc error";
94
95CLIENT *pClient; /* client used in net debugging */
96static int ptraceSock = RPC_ANYSOCK;
97
98enum clnt_stat net_clnt_call();
99static void parse_args ();
100
101static struct timeval rpcTimeout = { 10, 0 };
102
103static char *skip_white_space ();
104static char *find_white_space ();
105
106/* Tell the VxWorks target system to download a file.
107 The load addresses of the text, data, and bss segments are
afc5505f 108 stored in *pTextAddr, *pDataAddr, and *pBssAddr (respectively).
dd3b648e
RP
109 Returns 0 for success, -1 for failure. */
110
111static int
112net_load (filename, pTextAddr, pDataAddr, pBssAddr)
e7b5942b
JK
113 char *filename;
114 CORE_ADDR *pTextAddr;
115 CORE_ADDR *pDataAddr;
116 CORE_ADDR *pBssAddr;
117{
118 enum clnt_stat status;
119 struct ldfile ldstruct;
120 struct timeval load_timeout;
dd3b648e 121
e7b5942b 122 memset ((char *) &ldstruct, '\0', sizeof (ldstruct));
afc5505f 123
e7b5942b
JK
124 /* We invoke clnt_call () here directly, instead of through
125 net_clnt_call (), because we need to set a large timeout value.
126 The load on the target side can take quite a while, easily
127 more than 10 seconds. The user can kill this call by typing
128 CTRL-C if there really is a problem with the load.
dd3b648e 129
e7b5942b
JK
130 Do not change the tv_sec value without checking -- select() imposes
131 a limit of 10**8 on it for no good reason that I can see... */
132
133 load_timeout.tv_sec = 99999999; /* A large number, effectively inf. */
134 load_timeout.tv_usec = 0;
dd3b648e 135
e7b5942b
JK
136 status = clnt_call (pClient, VX_LOAD, xdr_wrapstring, &filename, xdr_ldfile,
137 &ldstruct, load_timeout);
138
139 if (status == RPC_SUCCESS)
140 {
141 if (*ldstruct.name == 0) /* load failed on VxWorks side */
142 return -1;
143 *pTextAddr = ldstruct.txt_addr;
144 *pDataAddr = ldstruct.data_addr;
145 *pBssAddr = ldstruct.bss_addr;
146 return 0;
dd3b648e 147 }
e7b5942b
JK
148 else
149 return -1;
150}
151
dd3b648e
RP
152/* returns 0 if successful, errno if RPC failed or VxWorks complains. */
153
154static int
155net_break (addr, procnum)
e7b5942b
JK
156 int addr;
157 u_long procnum;
158{
159 enum clnt_stat status;
160 int break_status;
161 Rptrace ptrace_in; /* XXX This is stupid. It doesn't need to be a ptrace
162 structure. How about something smaller? */
163
164 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
165 break_status = 0;
dd3b648e 166
e7b5942b
JK
167 ptrace_in.addr = addr;
168 ptrace_in.pid = inferior_pid;
dd3b648e 169
e7b5942b
JK
170 status = net_clnt_call (procnum, xdr_rptrace, &ptrace_in, xdr_int,
171 &break_status);
dd3b648e 172
e7b5942b
JK
173 if (status != RPC_SUCCESS)
174 return errno;
dd3b648e 175
e7b5942b
JK
176 if (break_status == -1)
177 return ENOMEM;
178 return break_status; /* probably (FIXME) zero */
179}
dd3b648e 180
dd3b648e
RP
181/* returns 0 if successful, errno otherwise */
182
8616205a 183static int
dd3b648e 184vx_insert_breakpoint (addr)
e7b5942b
JK
185 int addr;
186{
187 return net_break (addr, VX_BREAK_ADD);
188}
dd3b648e
RP
189
190/* returns 0 if successful, errno otherwise */
191
8616205a 192static int
dd3b648e 193vx_remove_breakpoint (addr)
e7b5942b
JK
194 int addr;
195{
196 return net_break (addr, VX_BREAK_DELETE);
197}
dd3b648e 198
dd3b648e
RP
199/* Start an inferior process and sets inferior_pid to its pid.
200 EXEC_FILE is the file to run.
201 ALLARGS is a string containing the arguments to the program.
202 ENV is the environment vector to pass.
203 Returns process id. Errors reported with error().
204 On VxWorks, we ignore exec_file. */
205
8616205a 206static void
dd3b648e
RP
207vx_create_inferior (exec_file, args, env)
208 char *exec_file;
209 char *args;
210 char **env;
211{
212 enum clnt_stat status;
213 arg_array passArgs;
214 TASK_START taskStart;
215
4ed97c9a
RP
216 memset ((char *) &passArgs, '\0', sizeof (passArgs));
217 memset ((char *) &taskStart, '\0', sizeof (taskStart));
dd3b648e
RP
218
219 /* parse arguments, put them in passArgs */
220
221 parse_args (args, &passArgs);
222
223 if (passArgs.arg_array_len == 0)
224 error ("You must specify a function name to run, and arguments if any");
225
226 status = net_clnt_call (PROCESS_START, xdr_arg_array, &passArgs,
227 xdr_TASK_START, &taskStart);
228
229 if ((status != RPC_SUCCESS) || (taskStart.status == -1))
230 error ("Can't create process on remote target machine");
231
232 /* Save the name of the running function */
233 vx_running = savestring (passArgs.arg_array_val[0],
234 strlen (passArgs.arg_array_val[0]));
235
dd3b648e
RP
236 push_target (&vx_run_ops);
237 inferior_pid = taskStart.pid;
238
dd3b648e
RP
239 /* We will get a trace trap after one instruction.
240 Insert breakpoints and continue. */
241
242 init_wait_for_inferior ();
243
244 /* Set up the "saved terminal modes" of the inferior
245 based on what modes we are starting it with. */
246 target_terminal_init ();
247
248 /* Install inferior's terminal modes. */
249 target_terminal_inferior ();
250
dd3b648e
RP
251 stop_soon_quietly = 1;
252 wait_for_inferior (); /* Get the task spawn event */
253 stop_soon_quietly = 0;
254
255 /* insert_step_breakpoint (); FIXME, do we need this? */
45dc9be3 256 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
dd3b648e
RP
257}
258
259/* Fill ARGSTRUCT in argc/argv form with the arguments from the
260 argument string ARGSTRING. */
261
262static void
263parse_args (arg_string, arg_struct)
264 register char *arg_string;
265 arg_array *arg_struct;
266{
267 register int arg_count = 0; /* number of arguments */
268 register int arg_index = 0;
269 register char *p0;
270
4ed97c9a 271 memset ((char *) arg_struct, '\0', sizeof (arg_array));
dd3b648e
RP
272
273 /* first count how many arguments there are */
274
275 p0 = arg_string;
276 while (*p0 != '\0')
277 {
278 if (*(p0 = skip_white_space (p0)) == '\0')
279 break;
280 p0 = find_white_space (p0);
281 arg_count++;
282 }
283
284 arg_struct->arg_array_len = arg_count;
285 arg_struct->arg_array_val = (char **) xmalloc ((arg_count + 1)
286 * sizeof (char *));
287
288 /* now copy argument strings into arg_struct. */
289
290 while (*(arg_string = skip_white_space (arg_string)))
291 {
292 p0 = find_white_space (arg_string);
293 arg_struct->arg_array_val[arg_index++] = savestring (arg_string,
294 p0 - arg_string);
295 arg_string = p0;
296 }
297
298 arg_struct->arg_array_val[arg_count] = NULL;
299}
300
301/* Advance a string pointer across whitespace and return a pointer
302 to the first non-white character. */
303
304static char *
305skip_white_space (p)
306 register char *p;
307{
308 while (*p == ' ' || *p == '\t')
309 p++;
310 return p;
311}
312
313/* Search for the first unquoted whitespace character in a string.
314 Returns a pointer to the character, or to the null terminator
315 if no whitespace is found. */
316
317static char *
318find_white_space (p)
319 register char *p;
320{
321 register int c;
322
323 while ((c = *p) != ' ' && c != '\t' && c)
324 {
325 if (c == '\'' || c == '"')
326 {
327 while (*++p != c && *p)
328 {
329 if (*p == '\\')
330 p++;
331 }
332 if (!*p)
333 break;
334 }
335 p++;
336 }
337 return p;
338}
339
340/* Poll the VxWorks target system for an event related
341 to the debugged task.
342 Returns -1 if remote wait failed, task status otherwise. */
343
8616205a 344static int
dd3b648e
RP
345net_wait (pEvent)
346 RDB_EVENT *pEvent;
347{
348 int pid;
349 enum clnt_stat status;
350
4ed97c9a 351 memset ((char *) pEvent, '\0', sizeof (RDB_EVENT));
dd3b648e
RP
352
353 pid = inferior_pid;
e7b5942b
JK
354 status = net_clnt_call (PROCESS_WAIT, xdr_int, &pid, xdr_RDB_EVENT,
355 pEvent);
dd3b648e 356
161520dc
KH
357 /* return (status == RPC_SUCCESS)? pEvent->status: -1; */
358 if (status == RPC_SUCCESS)
359 return ((pEvent->status) ? 1 : 0);
360 else if (status == RPC_TIMEDOUT)
361 return (1);
362 else
363 return (-1);
dd3b648e
RP
364}
365
366/* Suspend the remote task.
367 Returns -1 if suspend fails on target system, 0 otherwise. */
368
8616205a 369static int
dd3b648e
RP
370net_quit ()
371{
e7b5942b
JK
372 int pid;
373 int quit_status;
374 enum clnt_stat status;
dd3b648e 375
e7b5942b 376 quit_status = 0;
dd3b648e 377
e7b5942b 378 /* don't let rdbTask suspend itself by passing a pid of 0 */
dd3b648e 379
e7b5942b
JK
380 if ((pid = inferior_pid) == 0)
381 return -1;
dd3b648e 382
e7b5942b
JK
383 status = net_clnt_call (VX_TASK_SUSPEND, xdr_int, &pid, xdr_int,
384 &quit_status);
dd3b648e 385
e7b5942b 386 return (status == RPC_SUCCESS)? quit_status: -1;
dd3b648e
RP
387}
388
389/* Read a register or registers from the remote system. */
390
161520dc
KH
391void
392net_read_registers (reg_buf, len, procnum)
393 char *reg_buf;
394 int len;
395 u_long procnum;
dd3b648e
RP
396{
397 int status;
398 Rptrace ptrace_in;
399 Ptrace_return ptrace_out;
8616205a 400 C_bytes out_data;
161520dc 401 char message[100];
dd3b648e 402
bf644f8f
JK
403 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
404 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
dd3b648e 405
161520dc
KH
406 /* Initialize RPC input argument structure. */
407
dd3b648e 408 ptrace_in.pid = inferior_pid;
161520dc
KH
409 ptrace_in.info.ttype = NOINFO;
410
411 /* Initialize RPC return value structure. */
412
413 out_data.bytes = reg_buf;
414 out_data.len = len;
8616205a 415 ptrace_out.info.more_data = (caddr_t) &out_data;
161520dc
KH
416
417 /* Call RPC; take an error exit if appropriate. */
418
419 status = net_ptrace_clnt_call (procnum, &ptrace_in, &ptrace_out);
dd3b648e
RP
420 if (status)
421 error (rpcerr);
422 if (ptrace_out.status == -1)
423 {
e5fddd37 424 errno = ptrace_out.errno_num;
161520dc
KH
425 sprintf (message, "reading %s registers", (procnum == PTRACE_GETREGS)
426 ? "general-purpose"
427 : "floating-point");
428 perror_with_name (message);
bf644f8f 429 }
dd3b648e
RP
430}
431
161520dc
KH
432/* Write register values to a VxWorks target. REG_BUF points to a buffer
433 containing the raw register values, LEN is the length of REG_BUF in
434 bytes, and PROCNUM is the RPC procedure number (PTRACE_SETREGS or
435 PTRACE_SETFPREGS). An error exit is taken if the RPC call fails or
436 if an error status is returned by the remote debug server. This is
437 a utility routine used by vx_write_register (). */
dd3b648e 438
161520dc
KH
439void
440net_write_registers (reg_buf, len, procnum)
441 char *reg_buf;
442 int len;
443 u_long procnum;
dd3b648e 444{
dd3b648e
RP
445 int status;
446 Rptrace ptrace_in;
447 Ptrace_return ptrace_out;
161520dc
KH
448 C_bytes in_data;
449 char message[100];
83d9bb14 450
bf644f8f
JK
451 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
452 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
dd3b648e 453
161520dc
KH
454 /* Initialize RPC input argument structure. */
455
456 in_data.bytes = reg_buf;
457 in_data.len = len;
458
8616205a 459 ptrace_in.pid = inferior_pid;
161520dc 460 ptrace_in.info.ttype = DATA;
8616205a
SG
461 ptrace_in.info.more_data = (caddr_t) &in_data;
462
161520dc 463 /* Call RPC; take an error exit if appropriate. */
dd3b648e 464
161520dc 465 status = net_ptrace_clnt_call (procnum, &ptrace_in, &ptrace_out);
dd3b648e 466 if (status)
e7b5942b 467 error (rpcerr);
dd3b648e
RP
468 if (ptrace_out.status == -1)
469 {
e5fddd37 470 errno = ptrace_out.errno_num;
161520dc
KH
471 sprintf (message, "writing %s registers", (procnum == PTRACE_SETREGS)
472 ? "general-purpose"
473 : "floating-point");
474 perror_with_name (message);
dd3b648e 475 }
161520dc 476}
dd3b648e 477
161520dc
KH
478/* Prepare to store registers. Since we will store all of them,
479 read out their current values now. */
bf644f8f 480
161520dc
KH
481static void
482vx_prepare_to_store ()
483{
484 /* Fetch all registers, if any of them are not yet fetched. */
485 read_register_bytes (0, NULL, REGISTER_BYTES);
dd3b648e
RP
486}
487
488/* Copy LEN bytes to or from remote inferior's memory starting at MEMADDR
489 to debugger memory starting at MYADDR. WRITE is true if writing to the
490 inferior.
491 Result is the number of bytes written or read (zero if error). The
492 protocol allows us to return a negative count, indicating that we can't
493 handle the current address but can handle one N bytes further, but
494 vxworks doesn't give us that information. */
495
8616205a 496static int
8f1f2a72 497vx_xfer_memory (memaddr, myaddr, len, write, target)
dd3b648e
RP
498 CORE_ADDR memaddr;
499 char *myaddr;
500 int len;
8f1f2a72
JG
501 int write;
502 struct target_ops *target; /* ignored */
dd3b648e
RP
503{
504 int status;
505 Rptrace ptrace_in;
506 Ptrace_return ptrace_out;
507 C_bytes data;
161520dc
KH
508 enum ptracereq request;
509 int nleft, nxfer;
dd3b648e 510
4ed97c9a
RP
511 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
512 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
dd3b648e
RP
513
514 ptrace_in.pid = inferior_pid; /* XXX pid unnecessary for READDATA */
515 ptrace_in.addr = (int) memaddr; /* Where from */
516 ptrace_in.data = len; /* How many bytes */
517
518 if (write)
519 {
520 ptrace_in.info.ttype = DATA;
521 ptrace_in.info.more_data = (caddr_t) &data;
522
523 data.bytes = (caddr_t) myaddr; /* Where from */
524 data.len = len; /* How many bytes (again, for XDR) */
161520dc 525 request = PTRACE_WRITEDATA;
dd3b648e
RP
526 }
527 else
528 {
529 ptrace_out.info.more_data = (caddr_t) &data;
161520dc 530 request = PTRACE_READDATA;
bf644f8f 531 }
161520dc
KH
532 /* Loop until the entire request has been satisfied, transferring
533 at most VX_MEMXFER_MAX bytes per iteration. Break from the loop
534 if an error status is returned by the remote debug server. */
83d9bb14 535
161520dc
KH
536 nleft = len;
537 status = 0;
538
539 while (nleft > 0 && status == 0)
dd3b648e 540 {
161520dc
KH
541 nxfer = min (nleft, VX_MEMXFER_MAX);
542
543 ptrace_in.addr = (int) memaddr;
544 ptrace_in.data = nxfer;
545 data.bytes = (caddr_t) myaddr;
546 data.len = nxfer;
547
548 /* Request a block from the remote debug server; if RPC fails,
549 report an error and return to debugger command level. */
550
551 if (net_ptrace_clnt_call (request, &ptrace_in, &ptrace_out))
552 error (rpcerr);
553
554 status = ptrace_out.status;
555 if (status == 0)
556 {
557 memaddr += nxfer;
558 myaddr += nxfer;
559 nleft -= nxfer;
560 }
561 else
562 {
563 /* A target-side error has ocurred. Set errno to the error
564 code chosen by the target so that a later perror () will
565 say something meaningful. */
566
e5fddd37 567 errno = ptrace_out.errno_num;
161520dc 568 }
dd3b648e 569 }
161520dc
KH
570
571 /* Return the number of bytes transferred. */
572
573 return (len - nleft);
dd3b648e
RP
574}
575
8616205a 576static void
dd3b648e
RP
577vx_files_info ()
578{
199b2450
TL
579 printf_unfiltered ("\tAttached to host `%s'", vx_host);
580 printf_unfiltered (", which has %sfloating point", target_has_fp? "": "no ");
581 printf_unfiltered (".\n");
dd3b648e
RP
582}
583
8616205a 584static void
dd3b648e
RP
585vx_run_files_info ()
586{
199b2450 587 printf_unfiltered ("\tRunning %s VxWorks process %s",
833e0d94
JK
588 vx_running ? "child" : "attached",
589 local_hex_string (inferior_pid));
dd3b648e 590 if (vx_running)
199b2450
TL
591 printf_unfiltered (", function `%s'", vx_running);
592 printf_unfiltered(".\n");
dd3b648e
RP
593}
594
8616205a 595static void
25286543
SG
596vx_resume (pid, step, siggnal)
597 int pid;
dd3b648e 598 int step;
67ac9759 599 enum target_signal siggnal;
dd3b648e
RP
600{
601 int status;
602 Rptrace ptrace_in;
603 Ptrace_return ptrace_out;
161520dc 604 CORE_ADDR cont_addr;
dd3b648e 605
de43d7d0
SG
606 if (pid == -1)
607 pid = inferior_pid;
608
dd3b648e
RP
609 if (siggnal != 0 && siggnal != stop_signal)
610 error ("Cannot send signals to VxWorks processes");
611
161520dc
KH
612 /* Set CONT_ADDR to the address at which we are continuing,
613 or to 1 if we are continuing from where the program stopped.
614 This conforms to traditional ptrace () usage, but at the same
615 time has special meaning for the VxWorks remote debug server.
616 If the address is not 1, the server knows that the target
617 program is jumping to a new address, which requires special
618 handling if there is a breakpoint at the new address. */
619
620 cont_addr = read_register (PC_REGNUM);
621 if (cont_addr == stop_pc)
622 cont_addr = 1;
623
4ed97c9a
RP
624 memset ((char *) &ptrace_in, '\0', sizeof (ptrace_in));
625 memset ((char *) &ptrace_out, '\0', sizeof (ptrace_out));
dd3b648e 626
25286543 627 ptrace_in.pid = pid;
161520dc
KH
628 ptrace_in.addr = cont_addr; /* Target side insists on this, or it panics. */
629
630 if (step)
631 status = net_step();
632 else
633 status = net_ptrace_clnt_call (PTRACE_CONT, &ptrace_in, &ptrace_out);
dd3b648e 634
dd3b648e 635 if (status)
e7b5942b 636 error (rpcerr);
dd3b648e
RP
637 if (ptrace_out.status == -1)
638 {
e5fddd37 639 errno = ptrace_out.errno_num;
dd3b648e
RP
640 perror_with_name ("Resuming remote process");
641 }
642}
643
8616205a 644static void
dd3b648e
RP
645vx_mourn_inferior ()
646{
647 pop_target (); /* Pop back to no-child state */
648 generic_mourn_inferior ();
649}
650
651\f
e7b5942b
JK
652static void vx_add_symbols PARAMS ((char *, int, CORE_ADDR, CORE_ADDR,
653 CORE_ADDR));
654
655struct find_sect_args {
656 CORE_ADDR text_start;
657 CORE_ADDR data_start;
658 CORE_ADDR bss_start;
659};
660
661static void find_sect PARAMS ((bfd *, asection *, void *));
662
663static void
664find_sect (abfd, sect, obj)
665 bfd *abfd;
666 asection *sect;
667 PTR obj;
668{
669 struct find_sect_args *args = (struct find_sect_args *)obj;
670
671 if (bfd_get_section_flags (abfd, sect) & (SEC_CODE & SEC_READONLY))
672 args->text_start = bfd_get_section_vma (abfd, sect);
673 else if (bfd_get_section_flags (abfd, sect) & SEC_ALLOC)
674 {
675 if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
676 {
677 /* Exclude .ctor and .dtor sections which have SEC_CODE set but not
678 SEC_DATA. */
679 if (bfd_get_section_flags (abfd, sect) & SEC_DATA)
680 args->data_start = bfd_get_section_vma (abfd, sect);
681 }
682 else
683 args->bss_start = bfd_get_section_vma (abfd, sect);
684 }
685}
686
687static void
688vx_add_symbols (name, from_tty, text_addr, data_addr, bss_addr)
689 char *name;
690 int from_tty;
691 CORE_ADDR text_addr;
692 CORE_ADDR data_addr;
693 CORE_ADDR bss_addr;
694{
695 struct section_offsets *offs;
696 struct objfile *objfile;
697 struct find_sect_args ss;
698
3a470454
JK
699 /* It might be nice to suppress the breakpoint_re_set which happens here
700 because we are going to do one again after the objfile_relocate. */
65b07ddc 701 objfile = symbol_file_add (name, from_tty, 0, 0, 0, 0, 0, 0);
3a470454
JK
702
703 /* This is a (slightly cheesy) way of superceding the old symbols. A less
704 cheesy way would be to find the objfile with the same name and
705 free_objfile it. */
706 objfile_to_front (objfile);
707
e7b5942b
JK
708 offs = (struct section_offsets *)
709 alloca (sizeof (struct section_offsets)
710 + objfile->num_sections * sizeof (offs->offsets));
711 memcpy (offs, objfile->section_offsets,
712 sizeof (struct section_offsets)
713 + objfile->num_sections * sizeof (offs->offsets));
714
715 ss.text_start = 0;
716 ss.data_start = 0;
717 ss.bss_start = 0;
718 bfd_map_over_sections (objfile->obfd, find_sect, &ss);
719
720 /* Both COFF and b.out frontends use these SECT_OFF_* values. */
721 ANOFFSET (offs, SECT_OFF_TEXT) = text_addr - ss.text_start;
722 ANOFFSET (offs, SECT_OFF_DATA) = data_addr - ss.data_start;
723 ANOFFSET (offs, SECT_OFF_BSS) = bss_addr - ss.bss_start;
724 objfile_relocate (objfile, offs);
725}
726
dd3b648e
RP
727/* This function allows the addition of incrementally linked object files. */
728
8616205a 729static void
dd3b648e 730vx_load_command (arg_string, from_tty)
e7b5942b 731 char *arg_string;
dd3b648e
RP
732 int from_tty;
733{
734 CORE_ADDR text_addr;
735 CORE_ADDR data_addr;
736 CORE_ADDR bss_addr;
e7b5942b 737
dd3b648e
RP
738 if (arg_string == 0)
739 error ("The load command takes a file name");
740
741 arg_string = tilde_expand (arg_string);
742 make_cleanup (free, arg_string);
743
744 dont_repeat ();
745
161520dc
KH
746 /* Refuse to load the module if a debugged task is running. Doing so
747 can have a number of unpleasant consequences to the running task. */
748
749 if (inferior_pid != 0 && target_has_execution)
750 {
751 if (query ("You may not load a module while the target task is running.\n\
752Kill the target task? "))
753 target_kill ();
754 else
755 error ("Load cancelled.");
756 }
757
dd3b648e
RP
758 QUIT;
759 immediate_quit++;
760 if (net_load (arg_string, &text_addr, &data_addr, &bss_addr) == -1)
761 error ("Load failed on target machine");
762 immediate_quit--;
763
e7b5942b 764 vx_add_symbols (arg_string, from_tty, text_addr, data_addr, bss_addr);
46d185d3
PS
765
766 /* Getting new symbols may change our opinion about what is
767 frameless. */
768 reinit_frame_cache ();
dd3b648e
RP
769}
770
dd3b648e
RP
771/* Single step the target program at the source or machine level.
772 Takes an error exit if rpc fails.
773 Returns -1 if remote single-step operation fails, else 0. */
774
775static int
776net_step ()
777{
778 enum clnt_stat status;
779 int step_status;
780 SOURCE_STEP source_step;
781
782 source_step.taskId = inferior_pid;
783
784 if (step_range_end)
785 {
786 source_step.startAddr = step_range_start;
787 source_step.endAddr = step_range_end;
788 }
789 else
790 {
791 source_step.startAddr = 0;
792 source_step.endAddr = 0;
793 }
794
795 status = net_clnt_call (VX_SOURCE_STEP, xdr_SOURCE_STEP, &source_step,
796 xdr_int, &step_status);
797
798 if (status == RPC_SUCCESS)
799 return step_status;
800 else
801 error (rpcerr);
802}
dd3b648e
RP
803
804/* Emulate ptrace using RPC calls to the VxWorks target system.
805 Returns nonzero (-1) if RPC status to VxWorks is bad, 0 otherwise. */
806
807static int
808net_ptrace_clnt_call (request, pPtraceIn, pPtraceOut)
809 enum ptracereq request;
810 Rptrace *pPtraceIn;
811 Ptrace_return *pPtraceOut;
812{
813 enum clnt_stat status;
814
815 status = net_clnt_call (request, xdr_rptrace, pPtraceIn, xdr_ptrace_return,
816 pPtraceOut);
817
818 if (status != RPC_SUCCESS)
819 return -1;
820
821 return 0;
822}
823
824/* Query the target for the name of the file from which VxWorks was
825 booted. pBootFile is the address of a pointer to the buffer to
826 receive the file name; if the pointer pointed to by pBootFile is
827 NULL, memory for the buffer will be allocated by XDR.
828 Returns -1 if rpc failed, 0 otherwise. */
829
8616205a 830static int
dd3b648e
RP
831net_get_boot_file (pBootFile)
832 char **pBootFile;
833{
834 enum clnt_stat status;
835
836 status = net_clnt_call (VX_BOOT_FILE_INQ, xdr_void, (char *) 0,
837 xdr_wrapstring, pBootFile);
838 return (status == RPC_SUCCESS) ? 0 : -1;
839}
840
841/* Fetch a list of loaded object modules from the VxWorks target.
842 Returns -1 if rpc failed, 0 otherwise
843 There's no way to check if the returned loadTable is correct.
844 VxWorks doesn't check it. */
845
8616205a 846static int
dd3b648e
RP
847net_get_symbols (pLoadTable)
848 ldtabl *pLoadTable; /* return pointer to ldtabl here */
849{
850 enum clnt_stat status;
851
4ed97c9a 852 memset ((char *) pLoadTable, '\0', sizeof (struct ldtabl));
dd3b648e
RP
853
854 status = net_clnt_call (VX_STATE_INQ, xdr_void, 0, xdr_ldtabl, pLoadTable);
855 return (status == RPC_SUCCESS) ? 0 : -1;
856}
857
858/* Look up a symbol in the VxWorks target's symbol table.
859 Returns status of symbol read on target side (0=success, -1=fail)
860 Returns -1 and complain()s if rpc fails. */
861
862struct complaint cant_contact_target =
863 {"Lost contact with VxWorks target", 0, 0};
864
8616205a 865static int
dd3b648e
RP
866vx_lookup_symbol (name, pAddr)
867 char *name; /* symbol name */
868 CORE_ADDR *pAddr;
869{
870 enum clnt_stat status;
871 SYMBOL_ADDR symbolAddr;
872
873 *pAddr = 0;
4ed97c9a 874 memset ((char *) &symbolAddr, '\0', sizeof (symbolAddr));
dd3b648e
RP
875
876 status = net_clnt_call (VX_SYMBOL_INQ, xdr_wrapstring, &name,
877 xdr_SYMBOL_ADDR, &symbolAddr);
e7b5942b
JK
878 if (status != RPC_SUCCESS)
879 {
51b80b00 880 complain (&cant_contact_target);
dd3b648e 881 return -1;
e7b5942b 882 }
dd3b648e
RP
883
884 *pAddr = symbolAddr.addr;
885 return symbolAddr.status;
886}
887
888/* Check to see if the VxWorks target has a floating point coprocessor.
889 Returns 1 if target has floating point processor, 0 otherwise.
890 Calls error() if rpc fails. */
891
8616205a 892static int
dd3b648e
RP
893net_check_for_fp ()
894{
895 enum clnt_stat status;
896 bool_t fp = 0; /* true if fp processor is present on target board */
897
898 status = net_clnt_call (VX_FP_INQUIRE, xdr_void, 0, xdr_bool, &fp);
899 if (status != RPC_SUCCESS)
e7b5942b 900 error (rpcerr);
dd3b648e
RP
901
902 return (int) fp;
903}
904
905/* Establish an RPC connection with the VxWorks target system.
906 Calls error () if unable to establish connection. */
907
8616205a 908static void
dd3b648e
RP
909net_connect (host)
910 char *host;
911{
912 struct sockaddr_in destAddr;
913 struct hostent *destHost;
ebe8362f 914 unsigned long addr;
e7b5942b 915
ebe8362f
JK
916 /* Get the internet address for the given host. Allow a numeric
917 IP address or a hostname. */
dd3b648e 918
ebe8362f
JK
919 addr = inet_addr (host);
920 if (addr == -1)
921 {
922 destHost = (struct hostent *) gethostbyname (host);
923 if (destHost == NULL)
e7b5942b
JK
924 /* FIXME: Probably should include hostname here in quotes.
925 For example if the user types "target vxworks vx960 " it should
926 say "Invalid host `vx960 '." not just "Invalid hostname". */
ebe8362f
JK
927 error ("Invalid hostname. Couldn't find remote host address.");
928 addr = * (unsigned long *) destHost->h_addr;
929 }
dd3b648e 930
4ed97c9a 931 memset (&destAddr, '\0', sizeof (destAddr));
dd3b648e 932
ebe8362f 933 destAddr.sin_addr.s_addr = addr;
dd3b648e
RP
934 destAddr.sin_family = AF_INET;
935 destAddr.sin_port = 0; /* set to actual port that remote
936 ptrace is listening on. */
937
938 /* Create a tcp client transport on which to issue
939 calls to the remote ptrace server. */
940
941 ptraceSock = RPC_ANYSOCK;
942 pClient = clnttcp_create (&destAddr, RDBPROG, RDBVERS, &ptraceSock, 0, 0);
e7b5942b
JK
943 /* FIXME, here is where we deal with different version numbers of the
944 proto */
945
dd3b648e
RP
946 if (pClient == NULL)
947 {
948 clnt_pcreateerror ("\tnet_connect");
949 error ("Couldn't connect to remote target.");
950 }
951}
952\f
953/* Sleep for the specified number of milliseconds
954 * (assumed to be less than 1000).
955 * If select () is interrupted, returns immediately;
956 * takes an error exit if select () fails for some other reason.
957 */
958
959static void
960sleep_ms (ms)
961 long ms;
962{
963 struct timeval select_timeout;
964 int status;
965
966 select_timeout.tv_sec = 0;
967 select_timeout.tv_usec = ms * 1000;
968
e7b5942b
JK
969 status = select (0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0,
970 &select_timeout);
dd3b648e
RP
971
972 if (status < 0 && errno != EINTR)
973 perror_with_name ("select");
974}
975
dd3b648e 976static int
c3cabecb
JK
977vx_wait (pid_to_wait_for, status)
978 int pid_to_wait_for;
67ac9759 979 struct target_waitstatus *status;
dd3b648e
RP
980{
981 register int pid;
dd3b648e
RP
982 RDB_EVENT rdbEvent;
983 int quit_failed;
984
985 do
986 {
987 /* If CTRL-C is hit during this loop,
988 suspend the inferior process. */
989
990 quit_failed = 0;
991 if (quit_flag)
992 {
993 quit_failed = (net_quit () == -1);
994 quit_flag = 0;
995 }
996
997 /* If a net_quit () or net_wait () call has failed,
998 allow the user to break the connection with the target.
999 We can't simply error () out of this loop, since the
1000 data structures representing the state of the inferior
1001 are in an inconsistent state. */
1002
1003 if (quit_failed || net_wait (&rdbEvent) == -1)
1004 {
1005 terminal_ours ();
1006 if (query ("Can't %s. Disconnect from target system? ",
1007 (quit_failed) ? "suspend remote task"
1008 : "get status of remote task"))
1009 {
1010 target_mourn_inferior();
1011 error ("Use the \"target\" command to reconnect.");
1012 }
1013 else
1014 {
1015 terminal_inferior ();
1016 continue;
1017 }
1018 }
1019
1020 pid = rdbEvent.taskId;
1021 if (pid == 0)
1022 {
1023 sleep_ms (200); /* FIXME Don't kill the network too badly */
1024 }
1025 else if (pid != inferior_pid)
5573d7d4
JK
1026 fatal ("Bad pid for debugged task: %s\n",
1027 local_hex_string((unsigned long) pid));
dd3b648e
RP
1028 } while (pid == 0);
1029
67ac9759
JK
1030 /* The mostly likely kind. */
1031 status->kind = TARGET_WAITKIND_STOPPED;
1032
dd3b648e
RP
1033 switch (rdbEvent.eventType)
1034 {
1035 case EVENT_EXIT:
67ac9759 1036 status->kind = TARGET_WAITKIND_EXITED;
dd3b648e 1037 /* FIXME is it possible to distinguish between a
67ac9759
JK
1038 normal vs abnormal exit in VxWorks? */
1039 status->value.integer = 0;
dd3b648e
RP
1040 break;
1041
67ac9759
JK
1042 case EVENT_START:
1043 /* Task was just started. */
1044 status->value.sig = TARGET_SIGNAL_TRAP;
dd3b648e
RP
1045 break;
1046
1047 case EVENT_STOP:
67ac9759 1048 status->value.sig = TARGET_SIGNAL_TRAP;
dd3b648e
RP
1049 /* XXX was it stopped by a signal? act accordingly */
1050 break;
1051
1052 case EVENT_BREAK: /* Breakpoint was hit. */
67ac9759 1053 status->value.sig = TARGET_SIGNAL_TRAP;
dd3b648e
RP
1054 break;
1055
1056 case EVENT_SUSPEND: /* Task was suspended, probably by ^C. */
67ac9759 1057 status->value.sig = TARGET_SIGNAL_INT;
dd3b648e
RP
1058 break;
1059
1060 case EVENT_BUS_ERR: /* Task made evil nasty reference. */
67ac9759 1061 status->value.sig = TARGET_SIGNAL_BUS;
dd3b648e
RP
1062 break;
1063
1064 case EVENT_ZERO_DIV: /* Division by zero */
67ac9759 1065 status->value.sig = TARGET_SIGNAL_FPE;
021959e2 1066 break;
dd3b648e
RP
1067
1068 case EVENT_SIGNAL:
d0acb092 1069#ifdef I80960
67ac9759 1070 status->value.sig = i960_fault_to_signal (rdbEvent.sigType);
d0acb092
JK
1071#else
1072 /* Back in the old days, before enum target_signal, this code used
1073 to add NSIG to the signal number and claim that PRINT_RANDOM_SIGNAL
1074 would take care of it. But PRINT_RANDOM_SIGNAL has never been
1075 defined except on the i960, so I don't really know what we are
1076 supposed to do on other architectures. */
1077 status->value.sig = TARGET_SIGNAL_UNKNOWN;
1078#endif
dd3b648e
RP
1079 break;
1080 } /* switch */
dd3b648e
RP
1081 return pid;
1082}
1083\f
1084static int
1085symbol_stub (arg)
bdbd5f50 1086 char *arg;
dd3b648e 1087{
bdbd5f50 1088 symbol_file_command (arg, 0);
dd3b648e
RP
1089 return 1;
1090}
1091
1092static int
1093add_symbol_stub (arg)
bdbd5f50 1094 char *arg;
dd3b648e
RP
1095{
1096 struct ldfile *pLoadFile = (struct ldfile *)arg;
1097
199b2450 1098 printf_unfiltered("\t%s: ", pLoadFile->name);
e7b5942b
JK
1099 vx_add_symbols (pLoadFile->name, 0, pLoadFile->txt_addr,
1100 pLoadFile->data_addr, pLoadFile->bss_addr);
199b2450 1101 printf_unfiltered ("ok\n");
dd3b648e
RP
1102 return 1;
1103}
1104/* Target command for VxWorks target systems.
1105
1106 Used in vxgdb. Takes the name of a remote target machine
1107 running vxWorks and connects to it to initialize remote network
1108 debugging. */
1109
1110static void
1111vx_open (args, from_tty)
1112 char *args;
1113 int from_tty;
1114{
1115 extern int close ();
1116 char *bootFile;
1117 extern char *source_path;
1118 struct ldtabl loadTable;
1119 struct ldfile *pLoadFile;
1120 int i;
1121 extern CLIENT *pClient;
46d185d3 1122 int symbols_added = 0;
dd3b648e
RP
1123
1124 if (!args)
1125 error_no_arg ("target machine name");
1126
70dcc196
JK
1127 target_preopen (from_tty);
1128
dd3b648e 1129 unpush_target (&vx_ops);
199b2450
TL
1130 printf_unfiltered ("Attaching remote machine across net...\n");
1131 gdb_flush (gdb_stdout);
dd3b648e
RP
1132
1133 /* Allow the user to kill the connect attempt by typing ^C.
1134 Wait until the call to target_has_fp () completes before
1135 disallowing an immediate quit, since even if net_connect ()
1136 is successful, the remote debug server might be hung. */
1137
1138 immediate_quit++;
1139
1140 net_connect (args);
1141 target_has_fp = net_check_for_fp ();
1142 printf_filtered ("Connected to %s.\n", args);
1143
1144 immediate_quit--;
1145
1146 push_target (&vx_ops);
1147
1148 /* Save a copy of the target host's name. */
1149 vx_host = savestring (args, strlen (args));
1150
1151 /* Find out the name of the file from which the target was booted
1152 and load its symbol table. */
1153
1154 printf_filtered ("Looking in Unix path for all loaded modules:\n");
1155 bootFile = NULL;
1156 if (!net_get_boot_file (&bootFile))
1157 {
e7b5942b
JK
1158 if (*bootFile)
1159 {
1160 printf_filtered ("\t%s: ", bootFile);
1161 /* This assumes that the kernel is never relocated. Hope that is an
1162 accurate assumption. */
1163 if (catch_errors
1164 (symbol_stub,
1165 bootFile,
1166 "Error while reading symbols from boot file:\n",
1167 RETURN_MASK_ALL))
1168 puts_filtered ("ok\n");
1169 }
1170 else if (from_tty)
199b2450 1171 printf_unfiltered ("VxWorks kernel symbols not loaded.\n");
dd3b648e
RP
1172 }
1173 else
1174 error ("Can't retrieve boot file name from target machine.");
1175
1176 clnt_freeres (pClient, xdr_wrapstring, &bootFile);
1177
1178 if (net_get_symbols (&loadTable) != 0)
1179 error ("Can't read loaded modules from target machine");
1180
1181 i = 0-1;
1182 while (++i < loadTable.tbl_size)
1183 {
1184 QUIT; /* FIXME, avoids clnt_freeres below: mem leak */
1185 pLoadFile = &loadTable.tbl_ent [i];
1186#ifdef WRS_ORIG
1187 {
1188 register int desc;
1189 struct cleanup *old_chain;
1190 char *fullname = NULL;
1191
1192 desc = openp (source_path, 0, pLoadFile->name, O_RDONLY, 0, &fullname);
1193 if (desc < 0)
1194 perror_with_name (pLoadFile->name);
1195 old_chain = make_cleanup (close, desc);
1196 add_file_at_addr (fullname, desc, pLoadFile->txt_addr, pLoadFile->data_addr,
1197 pLoadFile->bss_addr);
1198 do_cleanups (old_chain);
1199 }
1200#else
e7b5942b
JK
1201 /* FIXME: Is there something better to search than the PATH? (probably
1202 not the source path, since source might be in different directories
1203 than objects. */
1204
46d185d3
PS
1205 if (catch_errors (add_symbol_stub, (char *)pLoadFile, (char *)0,
1206 RETURN_MASK_ALL))
1207 symbols_added = 1;
dd3b648e
RP
1208#endif
1209 }
1210 printf_filtered ("Done.\n");
1211
1212 clnt_freeres (pClient, xdr_ldtabl, &loadTable);
46d185d3
PS
1213
1214 /* Getting new symbols may change our opinion about what is
1215 frameless. */
1216 if (symbols_added)
1217 reinit_frame_cache ();
dd3b648e
RP
1218}
1219\f
836e343b 1220/* Takes a task started up outside of gdb and ``attaches'' to it.
dd3b648e
RP
1221 This stops it cold in its tracks and allows us to start tracing it. */
1222
1223static void
1224vx_attach (args, from_tty)
1225 char *args;
1226 int from_tty;
1227{
3d19ff2b 1228 unsigned long pid;
dd3b648e
RP
1229 char *cptr = 0;
1230 Rptrace ptrace_in;
1231 Ptrace_return ptrace_out;
1232 int status;
1233
dd3b648e
RP
1234 if (!args)
1235 error_no_arg ("process-id to attach");
1236
3d19ff2b 1237 pid = strtoul (args, &cptr, 0);
dd3b648e
RP
1238 if ((cptr == args) || (*cptr != '\0'))
1239 error ("Invalid process-id -- give a single number in decimal or 0xhex");
1240
1241 if (from_tty)
3d19ff2b
SS
1242 printf_unfiltered ("Attaching pid %s.\n",
1243 local_hex_string((unsigned long) pid));
dd3b648e 1244
4ed97c9a
RP
1245 memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in));
1246 memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out));
dd3b648e
RP
1247 ptrace_in.pid = pid;
1248
1249 status = net_ptrace_clnt_call (PTRACE_ATTACH, &ptrace_in, &ptrace_out);
1250 if (status == -1)
1251 error (rpcerr);
1252 if (ptrace_out.status == -1)
1253 {
e5fddd37 1254 errno = ptrace_out.errno_num;
dd3b648e
RP
1255 perror_with_name ("Attaching remote process");
1256 }
1257
1258 /* It worked... */
161520dc 1259
e1a51cc2
SG
1260 inferior_pid = pid;
1261 push_target (&vx_run_ops);
161520dc 1262
e1a51cc2
SG
1263 if (vx_running)
1264 free (vx_running);
1265 vx_running = 0;
dd3b648e
RP
1266}
1267
dd3b648e
RP
1268/* detach_command --
1269 takes a program previously attached to and detaches it.
1270 The program resumes execution and will no longer stop
1271 on signals, etc. We better not have left any breakpoints
1272 in the program or it'll die when it hits one. For this
1273 to work, it may be necessary for the process to have been
1274 previously attached. It *might* work if the program was
1275 started via the normal ptrace (PTRACE_TRACEME). */
1276
1277static void
1278vx_detach (args, from_tty)
1279 char *args;
1280 int from_tty;
1281{
1282 Rptrace ptrace_in;
1283 Ptrace_return ptrace_out;
1284 int signal = 0;
1285 int status;
1286
1287 if (args)
1288 error ("Argument given to VxWorks \"detach\".");
1289
1290 if (from_tty)
199b2450 1291 printf_unfiltered ("Detaching pid %s.\n",
5573d7d4 1292 local_hex_string((unsigned long) inferior_pid));
dd3b648e
RP
1293
1294 if (args) /* FIXME, should be possible to leave suspended */
1295 signal = atoi (args);
1296
4ed97c9a
RP
1297 memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in));
1298 memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out));
dd3b648e
RP
1299 ptrace_in.pid = inferior_pid;
1300
1301 status = net_ptrace_clnt_call (PTRACE_DETACH, &ptrace_in, &ptrace_out);
1302 if (status == -1)
1303 error (rpcerr);
1304 if (ptrace_out.status == -1)
1305 {
e5fddd37 1306 errno = ptrace_out.errno_num;
dd3b648e
RP
1307 perror_with_name ("Detaching VxWorks process");
1308 }
1309
1310 inferior_pid = 0;
1311 pop_target (); /* go back to non-executing VxWorks connection */
1312}
1313
1314/* vx_kill -- takes a running task and wipes it out. */
1315
1316static void
afc5505f 1317vx_kill ()
dd3b648e
RP
1318{
1319 Rptrace ptrace_in;
1320 Ptrace_return ptrace_out;
1321 int status;
1322
199b2450 1323 printf_unfiltered ("Killing pid %s.\n", local_hex_string((unsigned long) inferior_pid));
dd3b648e 1324
4ed97c9a
RP
1325 memset ((char *)&ptrace_in, '\0', sizeof (ptrace_in));
1326 memset ((char *)&ptrace_out, '\0', sizeof (ptrace_out));
dd3b648e
RP
1327 ptrace_in.pid = inferior_pid;
1328
1329 status = net_ptrace_clnt_call (PTRACE_KILL, &ptrace_in, &ptrace_out);
1330 if (status == -1)
195b44d9
ILT
1331 warning (rpcerr);
1332 else if (ptrace_out.status == -1)
dd3b648e 1333 {
e5fddd37 1334 errno = ptrace_out.errno_num;
dd3b648e
RP
1335 perror_with_name ("Killing VxWorks process");
1336 }
1337
195b44d9
ILT
1338 /* If it gives good status, the process is *gone*, no events remain.
1339 If the kill failed, assume the process is gone anyhow. */
dd3b648e
RP
1340 inferior_pid = 0;
1341 pop_target (); /* go back to non-executing VxWorks connection */
1342}
1343
1344/* Clean up from the VxWorks process target as it goes away. */
1345
8616205a 1346static void
dd3b648e
RP
1347vx_proc_close (quitting)
1348 int quitting;
1349{
1350 inferior_pid = 0; /* No longer have a process. */
1351 if (vx_running)
1352 free (vx_running);
1353 vx_running = 0;
1354}
1355\f
dd3b648e
RP
1356/* Make an RPC call to the VxWorks target.
1357 Returns RPC status. */
1358
1359static enum clnt_stat
1360net_clnt_call (procNum, inProc, in, outProc, out)
1361 enum ptracereq procNum;
1362 xdrproc_t inProc;
1363 char *in;
1364 xdrproc_t outProc;
1365 char *out;
1366{
1367 enum clnt_stat status;
1368
1369 status = clnt_call (pClient, procNum, inProc, in, outProc, out, rpcTimeout);
1370
1371 if (status != RPC_SUCCESS)
1372 clnt_perrno (status);
1373
1374 return status;
1375}
1376
1377/* Clean up before losing control. */
1378
8616205a 1379static void
dd3b648e
RP
1380vx_close (quitting)
1381 int quitting;
1382{
1383 if (pClient)
1384 clnt_destroy (pClient); /* The net connection */
1385 pClient = 0;
1386
1387 if (vx_host)
1388 free (vx_host); /* The hostname */
1389 vx_host = 0;
1390}
1391
70dcc196
JK
1392/* A vxprocess target should be started via "run" not "target". */
1393/*ARGSUSED*/
1394static void
1395vx_proc_open (name, from_tty)
1396 char *name;
1397 int from_tty;
1398{
1399 error ("Use the \"run\" command to start a VxWorks process.");
1400}
dd3b648e 1401
64aa82eb
SS
1402static void
1403init_vx_ops ()
c719b714 1404{
64aa82eb
SS
1405 vx_ops.to_shortname = "vxworks";
1406 vx_ops.to_longname = "VxWorks target memory via RPC over TCP/IP";
1407 vx_ops.to_doc = "Use VxWorks target memory. \n\
1408Specify the name of the machine to connect to.";
1409 vx_ops.to_open = vx_open;
1410 vx_ops.to_close = vx_close;
1411 vx_ops.to_attach = vx_attach;
1412 vx_ops.to_xfer_memory = vx_xfer_memory;
1413 vx_ops.to_files_info = vx_files_info;
1414 vx_ops.to_load = vx_load_command;
1415 vx_ops.to_lookup_symbol = vx_lookup_symbol;
1416 vx_ops.to_create_inferior = vx_create_inferior;
1417 vx_ops.to_stratum = core_stratum;
1418 vx_ops.to_has_all_memory = 1;
1419 vx_ops.to_has_memory = 1;
1420 vx_ops.to_magic = OPS_MAGIC; /* Always the last thing */
dd3b648e
RP
1421};
1422
64aa82eb
SS
1423static void
1424init_vx_run_ops ()
c719b714 1425{
64aa82eb
SS
1426 vx_run_ops.to_shortname = "vxprocess";
1427 vx_run_ops.to_longname = "VxWorks process";
1428 vx_run_ops.to_doc = "VxWorks process; started by the \"run\" command.";
1429 vx_run_ops.to_open = vx_proc_open;
1430 vx_run_ops.to_close = vx_proc_close;
1431 vx_run_ops.to_detach = vx_detach;
1432 vx_run_ops.to_resume = vx_resume;
1433 vx_run_ops.to_wait = vx_wait;
1434 vx_run_ops.to_fetch_registers = vx_read_register;
1435 vx_run_ops.to_store_registers = vx_write_register;
1436 vx_run_ops.to_prepare_to_store = vx_prepare_to_store;
1437 vx_run_ops.to_xfer_memory = vx_xfer_memory;
1438 vx_run_ops.to_files_info = vx_run_files_info;
1439 vx_run_ops.to_insert_breakpoint = vx_insert_breakpoint;
1440 vx_run_ops.to_remove_breakpoint = vx_remove_breakpoint;
1441 vx_run_ops.to_kill = vx_kill;
1442 vx_run_ops.to_load = vx_load_command;
1443 vx_run_ops.to_lookup_symbol = vx_lookup_symbol;
1444 vx_run_ops.to_mourn_inferior = vx_mourn_inferior ;
1445 vx_run_ops.to_stratum = process_stratum;
1446 vx_run_ops.to_has_memory = 1;
1447 vx_run_ops.to_has_stack = 1;
1448 vx_run_ops.to_has_registers = 1;
1449 vx_run_ops.to_has_execution = 1;
1450 vx_run_ops.to_magic = OPS_MAGIC;
c719b714 1451}
dd3b648e
RP
1452\f
1453void
1454_initialize_vx ()
1455{
64aa82eb
SS
1456 init_vx_ops ();
1457 add_target (&vx_ops);
1458 init_vx_run_ops ();
1459 add_target (&vx_run_ops);
1460
e7b5942b 1461 add_show_from_set
1c5d6049 1462 (add_set_cmd ("vxworks-timeout", class_support, var_uinteger,
56894788
RP
1463 (char *) &rpcTimeout.tv_sec,
1464 "Set seconds to wait for rpc calls to return.\n\
1465Set the number of seconds to wait for rpc calls to return.", &setlist),
1466 &showlist);
dd3b648e 1467}
This page took 0.682754 seconds and 4 git commands to generate.