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