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