7a67dd45 |
1 | /* Low level interface to ptrace, for GDB when running under Unix. |
2 | Copyright (C) 1988, 1989 Free Software Foundation, Inc. |
3 | |
4 | This file is part of GDB. |
5 | |
6 | GDB is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 1, or (at your option) |
9 | any later version. |
10 | |
11 | GDB is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with GDB; see the file COPYING. If not, write to |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
19 | |
20 | #include <stdio.h> |
21 | #include "defs.h" |
22 | #include "param.h" |
23 | #include "frame.h" |
24 | #include "inferior.h" |
25 | |
26 | #include <sys/param.h> |
27 | #include <sys/dir.h> |
28 | #include <signal.h> |
29 | #include <sys/ioctl.h> |
30 | /* #include <fcntl.h> Can we live without this? */ |
31 | |
32 | #include <a.out.h> |
33 | #ifndef N_SET_MAGIC |
34 | #define N_SET_MAGIC(exec, val) ((exec).a_magic = (val)) |
35 | #endif |
36 | |
37 | #include <sys/user.h> /* After a.out.h */ |
38 | #include <sys/file.h> |
39 | #include <sys/stat.h> |
40 | |
41 | extern int errno; |
42 | \f |
43 | /* This function simply calls ptrace with the given arguments. |
44 | It exists so that all calls to ptrace are isolated in this |
45 | machine-dependent file. */ |
46 | int |
47 | call_ptrace (request, pid, arg3, arg4) |
48 | int request, pid, arg3, arg4; |
49 | { |
50 | return ptrace (request, pid, arg3, arg4); |
51 | } |
52 | |
53 | kill_inferior () |
54 | { |
55 | if (remote_debugging) |
56 | return; |
57 | if (inferior_pid == 0) |
58 | return; |
59 | ptrace (8, inferior_pid, 0, 0); |
60 | wait (0); |
61 | inferior_died (); |
62 | } |
63 | |
64 | /* This is used when GDB is exiting. It gives less chance of error.*/ |
65 | |
66 | kill_inferior_fast () |
67 | { |
68 | if (remote_debugging) |
69 | return; |
70 | if (inferior_pid == 0) |
71 | return; |
72 | ptrace (8, inferior_pid, 0, 0); |
73 | wait (0); |
74 | } |
75 | |
76 | /* Resume execution of the inferior process. |
77 | If STEP is nonzero, single-step it. |
78 | If SIGNAL is nonzero, give it that signal. */ |
79 | |
80 | void |
81 | resume (step, signal) |
82 | int step; |
83 | int signal; |
84 | { |
85 | errno = 0; |
86 | if (remote_debugging) |
87 | remote_resume (step, signal); |
88 | else |
89 | { |
90 | ptrace (step ? 9 : 7, inferior_pid, 1, signal); |
91 | if (errno) |
92 | perror_with_name ("ptrace"); |
93 | } |
94 | } |
95 | \f |
96 | void |
97 | fetch_inferior_registers () |
98 | { |
99 | register int regno, datum; |
100 | register unsigned int regaddr; |
101 | int reg_buf[NUM_REGS+1]; |
102 | struct user u; |
103 | register int skipped_frames = 0; |
104 | |
105 | if (remote_debugging) |
106 | remote_fetch_registers (); |
107 | else |
108 | { |
109 | for (regno = 0; regno < 64; regno++) { |
110 | reg_buf[regno] = ptrace (3, inferior_pid, regno, 0); |
111 | |
112 | #if defined(PYRAMID_CONTROL_FRAME_DEBUGGING) |
113 | printf ("Fetching %s from inferior, got %0x\n", |
114 | reg_names[regno], |
115 | reg_buf[regno]); |
116 | #endif /* PYRAMID_CONTROL_FRAME_DEBUGGING */ |
117 | |
118 | if (reg_buf[regno] == -1 && errno == EIO) { |
119 | printf("fetch_interior_registers: fetching %s from inferior\n", |
120 | reg_names[regno]); |
121 | errno = 0; |
122 | } |
123 | supply_register (regno, reg_buf+regno); |
124 | } |
125 | /* that leaves regs 64, 65, and 66 */ |
126 | datum = ptrace (3, inferior_pid, |
127 | ((char *)&u.u_pcb.pcb_csp) - |
128 | ((char *)&u), 0); |
129 | |
130 | |
131 | |
132 | /* FIXME: Find the Current Frame Pointer (CFP). CFP is a global |
133 | register (ie, NOT windowed), that gets saved in a frame iff |
134 | the code for that frame has a prologue (ie, "adsf N"). If |
135 | there is a prologue, the adsf insn saves the old cfp in |
136 | pr13, cfp is set to sp, and N bytes of locals are allocated |
137 | (sp is decremented by n). |
138 | This makes finding CFP hard. I guess the right way to do it |
139 | is: |
140 | - If this is the innermost frame, believe ptrace() or |
141 | the core area. |
142 | - Otherwise: |
143 | Find the first insn of the current frame. |
144 | - find the saved pc; |
145 | - find the call insn that saved it; |
146 | - figure out where the call is to; |
147 | - if the first insn is an adsf, we got a frame |
148 | pointer. */ |
149 | |
150 | |
151 | /* Normal processors have separate stack pointers for user and |
152 | kernel mode. Getting the last user mode frame on such |
153 | machines is easy: the kernel context of the ptrace()'d |
154 | process is on the kernel stack, and the USP points to what |
155 | we want. But Pyramids only have a single cfp for both user and |
156 | kernel mode. And processes being ptrace()'d have some |
157 | kernel-context control frames on their stack. |
158 | To avoid tracing back into the kernel context of an inferior, |
159 | we skip 0 or more contiguous control frames where the pc is |
160 | in the kernel. */ |
161 | |
162 | while (1) { |
163 | register int inferior_saved_pc; |
164 | inferior_saved_pc = ptrace (1, inferior_pid, datum+((32+15)*4), 0); |
165 | if (inferior_saved_pc > 0) break; |
166 | #if defined(PYRAMID_CONTROL_FRAME_DEBUGGING) |
167 | printf("skipping kernel frame %08x, pc=%08x\n", datum, |
168 | inferior_saved_pc); |
169 | #endif /* PYRAMID_CONTROL_FRAME_DEBUGGING */ |
170 | skipped_frames++; |
171 | datum -= CONTROL_STACK_FRAME_SIZE; |
172 | } |
173 | |
174 | reg_buf[CSP_REGNUM] = datum; |
175 | supply_register(CSP_REGNUM, reg_buf+CSP_REGNUM); |
176 | #ifdef PYRAMID_CONTROL_FRAME_DEBUGGING |
177 | if (skipped_frames) { |
178 | fprintf (stderr, |
179 | "skipped %d frames from %x to %x; cfp was %x, now %x\n", |
180 | skipped_frames, reg_buf[CSP_REGNUM]); |
181 | } |
182 | #endif /* PYRAMID_CONTROL_FRAME_DEBUGGING */ |
183 | } |
184 | } |
185 | |
186 | /* Store our register values back into the inferior. |
187 | If REGNO is -1, do this for all registers. |
188 | Otherwise, REGNO specifies which register (so we can save time). */ |
189 | |
190 | store_inferior_registers (regno) |
191 | int regno; |
192 | { |
193 | register unsigned int regaddr; |
194 | char buf[80]; |
195 | |
196 | if (regno >= 0) |
197 | { |
198 | if ((0 <= regno) && (regno < 64)) { |
199 | /*regaddr = register_addr (regno, offset);*/ |
200 | regaddr = regno; |
201 | errno = 0; |
202 | ptrace (6, inferior_pid, regaddr, read_register (regno)); |
203 | if (errno != 0) |
204 | { |
205 | sprintf (buf, "writing register number %d", regno); |
206 | perror_with_name (buf); |
207 | } |
208 | } |
209 | } |
210 | else for (regno = 0; regno < NUM_REGS; regno++) |
211 | { |
212 | /*regaddr = register_addr (regno, offset);*/ |
213 | regaddr = regno; |
214 | errno = 0; |
215 | ptrace (6, inferior_pid, regaddr, read_register (regno)); |
216 | if (errno != 0) |
217 | { |
218 | sprintf (buf, "writing all regs, number %d", regno); |
219 | perror_with_name (buf); |
220 | } |
221 | } |
222 | } |
223 | \f |
224 | /* Copy LEN bytes from inferior's memory starting at MEMADDR |
225 | to debugger memory starting at MYADDR. |
226 | On failure (cannot read from inferior, usually because address is out |
227 | of bounds) returns the value of errno. */ |
228 | |
229 | int |
230 | read_inferior_memory (memaddr, myaddr, len) |
231 | CORE_ADDR memaddr; |
232 | char *myaddr; |
233 | int len; |
234 | { |
235 | register int i; |
236 | /* Round starting address down to longword boundary. */ |
237 | register CORE_ADDR addr = memaddr & - sizeof (int); |
238 | /* Round ending address up; get number of longwords that makes. */ |
239 | register int count |
240 | = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); |
241 | /* Allocate buffer of that many longwords. */ |
242 | register int *buffer = (int *) alloca (count * sizeof (int)); |
243 | extern int errno; |
244 | |
245 | /* Read all the longwords */ |
246 | for (i = 0; i < count; i++, addr += sizeof (int)) |
247 | { |
248 | errno = 0; |
249 | #if 0 |
250 | /*This is now done by read_memory, because when this function did it, |
251 | reading a byte or short int hardware port read whole longs, causing |
252 | serious side effects |
253 | such as bus errors and unexpected hardware operation. This would |
254 | also be a problem with ptrace if the inferior process could read |
255 | or write hardware registers, but that's not usually the case. */ |
256 | if (remote_debugging) |
257 | buffer[i] = remote_fetch_word (addr); |
258 | else |
259 | #endif |
260 | buffer[i] = ptrace (1, inferior_pid, addr, 0); |
261 | if (errno) |
262 | return errno; |
263 | } |
264 | |
265 | /* Copy appropriate bytes out of the buffer. */ |
266 | bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len); |
267 | return 0; |
268 | } |
269 | |
270 | /* Copy LEN bytes of data from debugger memory at MYADDR |
271 | to inferior's memory at MEMADDR. |
272 | On failure (cannot write the inferior) |
273 | returns the value of errno. */ |
274 | |
275 | int |
276 | write_inferior_memory (memaddr, myaddr, len) |
277 | CORE_ADDR memaddr; |
278 | char *myaddr; |
279 | int len; |
280 | { |
281 | register int i; |
282 | /* Round starting address down to longword boundary. */ |
283 | register CORE_ADDR addr = memaddr & - sizeof (int); |
284 | /* Round ending address up; get number of longwords that makes. */ |
285 | register int count |
286 | = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); |
287 | /* Allocate buffer of that many longwords. */ |
288 | register int *buffer = (int *) alloca (count * sizeof (int)); |
289 | extern int errno; |
290 | |
291 | /* Fill start and end extra bytes of buffer with existing memory data. */ |
292 | |
293 | if (remote_debugging) |
294 | buffer[0] = remote_fetch_word (addr); |
295 | else |
296 | buffer[0] = ptrace (1, inferior_pid, addr, 0); |
297 | |
298 | if (count > 1) |
299 | { |
300 | if (remote_debugging) |
301 | buffer[count - 1] |
302 | = remote_fetch_word (addr + (count - 1) * sizeof (int)); |
303 | else |
304 | buffer[count - 1] |
305 | = ptrace (1, inferior_pid, |
306 | addr + (count - 1) * sizeof (int), 0); |
307 | } |
308 | |
309 | /* Copy data to be written over corresponding part of buffer */ |
310 | |
311 | bcopy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len); |
312 | |
313 | /* Write the entire buffer. */ |
314 | |
315 | for (i = 0; i < count; i++, addr += sizeof (int)) |
316 | { |
317 | errno = 0; |
318 | if (remote_debugging) |
319 | remote_store_word (addr, buffer[i]); |
320 | else |
321 | ptrace (4, inferior_pid, addr, buffer[i]); |
322 | if (errno) |
323 | return errno; |
324 | } |
325 | |
326 | return 0; |
327 | } |
328 | \f |
329 | /*** Extensions to core and dump files, for GDB. */ |
330 | |
331 | extern unsigned int last_frame_offset; |
332 | |
333 | #ifdef PYRAMID_CORE |
334 | |
335 | /* Can't make definitions here static, since core.c needs them |
336 | to do bounds checking on the core-file areas. O well. */ |
337 | |
338 | /* have two stacks: one for data, one for register windows. */ |
339 | extern CORE_ADDR reg_stack_start; |
340 | extern CORE_ADDR reg_stack_end; |
341 | |
342 | /* need this so we can find the global registers: they never get saved. */ |
343 | static CORE_ADDR global_reg_offset; |
344 | static CORE_ADDR last_frame_address; |
345 | static CORE_ADDR last_frame_offset; |
346 | |
347 | |
348 | /* Address in core file of start of register window stack area. |
349 | Don't know if is this any of meaningful, useful or necessary. */ |
350 | static CORE_ADDR reg_stack_offset; |
351 | |
352 | #endif /* PYRAMID_CORE */ |
353 | |
354 | \f |
355 | /* Work with core dump and executable files, for GDB. |
356 | This code would be in core.c if it weren't machine-dependent. */ |
357 | |
358 | #ifndef N_TXTADDR |
359 | #define N_TXTADDR(hdr) 0 |
360 | #endif /* no N_TXTADDR */ |
361 | |
362 | #ifndef N_DATADDR |
363 | #define N_DATADDR(hdr) hdr.a_text |
364 | #endif /* no N_DATADDR */ |
365 | |
366 | /* Make COFF and non-COFF names for things a little more compatible |
367 | to reduce conditionals later. */ |
368 | |
369 | #ifdef COFF_FORMAT |
370 | #define a_magic magic |
371 | #endif |
372 | |
373 | #ifndef COFF_FORMAT |
374 | #ifndef AOUTHDR |
375 | #define AOUTHDR struct exec |
376 | #endif |
377 | #endif |
378 | |
379 | extern char *sys_siglist[]; |
380 | |
381 | |
382 | /* Hook for `exec_file_command' command to call. */ |
383 | |
384 | extern void (*exec_file_display_hook) (); |
385 | |
386 | /* File names of core file and executable file. */ |
387 | |
388 | extern char *corefile; |
389 | extern char *execfile; |
390 | |
391 | /* Descriptors on which core file and executable file are open. |
392 | Note that the execchan is closed when an inferior is created |
393 | and reopened if the inferior dies or is killed. */ |
394 | |
395 | extern int corechan; |
396 | extern int execchan; |
397 | |
398 | /* Last modification time of executable file. |
399 | Also used in source.c to compare against mtime of a source file. */ |
400 | |
401 | extern int exec_mtime; |
402 | |
403 | /* Virtual addresses of bounds of the two areas of memory in the core file. */ |
404 | |
405 | extern CORE_ADDR data_start; |
406 | extern CORE_ADDR data_end; |
407 | extern CORE_ADDR stack_start; |
408 | extern CORE_ADDR stack_end; |
409 | |
410 | #ifdef PYRAMID_CORE |
411 | /* Well, "two areas of memory" on most machines; but pyramids have a |
412 | third area, for the register-window stack, and we need its |
413 | base and bound too. */ |
414 | |
415 | extern CORE_ADDR reg_stack_start; |
416 | extern CORE_ADDR reg_stack_start; |
417 | #endif /* PYRAMID_CORE */ |
418 | |
419 | /* Virtual addresses of bounds of two areas of memory in the exec file. |
420 | Note that the data area in the exec file is used only when there is no core file. */ |
421 | |
422 | extern CORE_ADDR text_start; |
423 | extern CORE_ADDR text_end; |
424 | |
425 | extern CORE_ADDR exec_data_start; |
426 | extern CORE_ADDR exec_data_end; |
427 | |
428 | /* Address in executable file of start of text area data. */ |
429 | |
430 | extern int text_offset; |
431 | |
432 | /* Address in executable file of start of data area data. */ |
433 | |
434 | extern int exec_data_offset; |
435 | |
436 | /* Address in core file of start of data area data. */ |
437 | |
438 | extern int data_offset; |
439 | |
440 | /* Address in core file of start of stack area data. */ |
441 | |
442 | extern int stack_offset; |
443 | |
444 | #ifdef COFF_FORMAT |
445 | /* various coff data structures */ |
446 | |
447 | extern FILHDR file_hdr; |
448 | extern SCNHDR text_hdr; |
449 | extern SCNHDR data_hdr; |
450 | |
451 | #endif /* not COFF_FORMAT */ |
452 | |
453 | /* a.out header saved in core file. */ |
454 | |
455 | extern AOUTHDR core_aouthdr; |
456 | |
457 | /* a.out header of exec file. */ |
458 | |
459 | extern AOUTHDR exec_aouthdr; |
460 | |
461 | extern void validate_files (); |
462 | \f |
463 | core_file_command (filename, from_tty) |
464 | char *filename; |
465 | int from_tty; |
466 | { |
467 | int val; |
468 | extern char registers[]; |
469 | |
470 | /* Discard all vestiges of any previous core file |
471 | and mark data and stack spaces as empty. */ |
472 | |
473 | if (corefile) |
474 | free (corefile); |
475 | corefile = 0; |
476 | |
477 | if (corechan >= 0) |
478 | close (corechan); |
479 | corechan = -1; |
480 | |
481 | data_start = 0; |
482 | data_end = 0; |
483 | stack_start = STACK_END_ADDR; |
484 | stack_end = STACK_END_ADDR; |
485 | |
486 | #ifdef PYRAMID_CORE |
487 | reg_stack_start = CONTROL_STACK_ADDR; |
488 | reg_stack_end = CONTROL_STACK_ADDR; /* this isn't strictly true...*/ |
489 | #endif /* PYRAMID_CORE */ |
490 | |
491 | /* Now, if a new core file was specified, open it and digest it. */ |
492 | |
493 | if (filename) |
494 | { |
495 | filename = tilde_expand (filename); |
496 | make_cleanup (free, filename); |
497 | |
498 | if (have_inferior_p ()) |
499 | error ("To look at a core file, you must kill the inferior with \"kill\"."); |
500 | corechan = open (filename, O_RDONLY, 0); |
501 | if (corechan < 0) |
502 | perror_with_name (filename); |
503 | /* 4.2-style (and perhaps also sysV-style) core dump file. */ |
504 | { |
505 | struct user u; |
506 | |
507 | unsigned int reg_offset; |
508 | |
509 | val = myread (corechan, &u, sizeof u); |
510 | if (val < 0) |
511 | perror_with_name ("Not a core file: reading upage"); |
512 | if (val != sizeof u) |
513 | error ("Not a core file: could only read %d bytes", val); |
514 | data_start = exec_data_start; |
515 | |
516 | data_end = data_start + NBPG * u.u_dsize; |
517 | data_offset = NBPG * UPAGES; |
518 | stack_offset = NBPG * (UPAGES + u.u_dsize); |
519 | |
520 | /* find registers in core file */ |
521 | #ifdef PYRAMID_PTRACE |
522 | stack_start = stack_end - NBPG * u.u_ussize; |
523 | reg_stack_offset = stack_offset + (NBPG *u.u_ussize); |
524 | reg_stack_end = reg_stack_start + NBPG * u.u_cssize; |
525 | |
526 | last_frame_address = ((int) u.u_pcb.pcb_csp); |
527 | last_frame_offset = reg_stack_offset + last_frame_address |
528 | - CONTROL_STACK_ADDR ; |
529 | global_reg_offset = (char *)&u - (char *)&u.u_pcb.pcb_gr0 ; |
530 | |
531 | /* skip any control-stack frames that were executed in the |
532 | kernel. */ |
533 | |
534 | while (1) { |
535 | char buf[4]; |
536 | val = lseek (corechan, last_frame_offset+(47*4), 0); |
537 | if (val < 0) |
538 | perror_with_name (filename); |
539 | val = myread (corechan, buf, sizeof buf); |
540 | if (val < 0) |
541 | perror_with_name (filename); |
542 | |
543 | if (*(int *)buf >= 0) |
544 | break; |
545 | printf ("skipping frame %0x\n", last_frame_address); |
546 | last_frame_offset -= CONTROL_STACK_FRAME_SIZE; |
547 | last_frame_address -= CONTROL_STACK_FRAME_SIZE; |
548 | } |
549 | reg_offset = last_frame_offset; |
550 | |
551 | #if 1 || defined(PYRAMID_CONTROL_FRAME_DEBUGGING) |
552 | printf ("Control stack pointer = 0x%08x\n", |
553 | u.u_pcb.pcb_csp); |
554 | printf ("offset to control stack %d outermost frame %d (%0x)\n", |
555 | reg_stack_offset, reg_offset, last_frame_address); |
556 | #endif /* PYRAMID_CONTROL_FRAME_DEBUGGING */ |
557 | |
558 | #else /* not PYRAMID_CORE */ |
559 | stack_start = stack_end - NBPG * u.u_ssize; |
560 | reg_offset = (int) u.u_ar0 - KERNEL_U_ADDR; |
561 | #endif /* not PYRAMID_CORE */ |
562 | |
563 | #ifdef __not_on_pyr_yet |
564 | /* Some machines put an absolute address in here and some put |
565 | the offset in the upage of the regs. */ |
566 | reg_offset = (int) u.u_ar0; |
567 | if (reg_offset > NBPG * UPAGES) |
568 | reg_offset -= KERNEL_U_ADDR; |
569 | #endif |
570 | |
571 | /* I don't know where to find this info. |
572 | So, for now, mark it as not available. */ |
573 | N_SET_MAGIC (core_aouthdr, 0); |
574 | |
575 | /* Read the register values out of the core file and store |
576 | them where `read_register' will find them. */ |
577 | |
578 | { |
579 | register int regno; |
580 | |
581 | for (regno = 0; regno < 64; regno++) |
582 | { |
583 | char buf[MAX_REGISTER_RAW_SIZE]; |
584 | |
585 | val = lseek (corechan, register_addr (regno, reg_offset), 0); |
586 | if (val < 0 |
587 | || (val = myread (corechan, buf, sizeof buf)) < 0) |
588 | { |
589 | char * buffer = (char *) alloca (strlen (reg_names[regno]) |
590 | + 30); |
591 | strcpy (buffer, "Reading register "); |
592 | strcat (buffer, reg_names[regno]); |
593 | |
594 | perror_with_name (buffer); |
595 | } |
596 | |
597 | if (val < 0) |
598 | perror_with_name (filename); |
599 | #ifdef PYRAMID_CONTROL_FRAME_DEBUGGING |
600 | printf ("[reg %s(%d), offset in file %s=0x%0x, addr =0x%0x, =%0x]\n", |
601 | reg_names[regno], regno, filename, |
602 | register_addr(regno, reg_offset), |
603 | regno * 4 + last_frame_address, |
604 | *((int *)buf)); |
605 | #endif /* PYRAMID_CONTROL_FRAME_DEBUGGING */ |
606 | supply_register (regno, buf); |
607 | } |
608 | } |
609 | } |
610 | if (filename[0] == '/') |
611 | corefile = savestring (filename, strlen (filename)); |
612 | else |
613 | { |
614 | corefile = concat (current_directory, "/", filename); |
615 | } |
616 | |
617 | #if 1 || defined(PYRAMID_CONTROL_FRAME_DEBUGGING) |
618 | printf ("Providing CSP (%0x) as nominal address of current frame.\n", |
619 | last_frame_address); |
620 | #endif PYRAMID_CONTROL_FRAME_DEBUGGING |
621 | /* FIXME: Which of the following is correct? */ |
622 | #if 0 |
623 | set_current_frame ( create_new_frame (read_register (FP_REGNUM), |
624 | read_pc ())); |
625 | #else |
626 | set_current_frame ( create_new_frame (last_frame_address, |
627 | read_pc ())); |
628 | #endif |
629 | |
630 | select_frame (get_current_frame (), 0); |
631 | validate_files (); |
632 | } |
633 | else if (from_tty) |
634 | printf ("No core file now.\n"); |
635 | } |
636 | \f |
637 | exec_file_command (filename, from_tty) |
638 | char *filename; |
639 | int from_tty; |
640 | { |
641 | int val; |
642 | |
643 | /* Eliminate all traces of old exec file. |
644 | Mark text segment as empty. */ |
645 | |
646 | if (execfile) |
647 | free (execfile); |
648 | execfile = 0; |
649 | data_start = 0; |
650 | data_end -= exec_data_start; |
651 | text_start = 0; |
652 | text_end = 0; |
653 | exec_data_start = 0; |
654 | exec_data_end = 0; |
655 | if (execchan >= 0) |
656 | close (execchan); |
657 | execchan = -1; |
658 | |
659 | /* Now open and digest the file the user requested, if any. */ |
660 | |
661 | if (filename) |
662 | { |
663 | filename = tilde_expand (filename); |
664 | make_cleanup (free, filename); |
665 | |
666 | execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0, |
667 | &execfile); |
668 | if (execchan < 0) |
669 | perror_with_name (filename); |
670 | |
671 | #ifdef COFF_FORMAT |
672 | #else /* not COFF_FORMAT */ |
673 | { |
674 | struct stat st_exec; |
675 | |
676 | #ifdef gould |
677 | #endif /* gould */ |
678 | val = myread (execchan, &exec_aouthdr, sizeof (AOUTHDR)); |
679 | |
680 | if (val < 0) |
681 | perror_with_name (filename); |
682 | |
683 | text_start = N_TXTADDR (exec_aouthdr); |
684 | exec_data_start = N_DATADDR (exec_aouthdr); |
685 | #ifdef gould |
686 | #else |
687 | text_offset = N_TXTOFF (exec_aouthdr); |
688 | exec_data_offset = N_TXTOFF (exec_aouthdr) + exec_aouthdr.a_text; |
689 | #endif |
690 | text_end = text_start + exec_aouthdr.a_text; |
691 | exec_data_end = exec_data_start + exec_aouthdr.a_data; |
692 | data_start = exec_data_start; |
693 | data_end += exec_data_start; |
694 | |
695 | fstat (execchan, &st_exec); |
696 | exec_mtime = st_exec.st_mtime; |
697 | } |
698 | #endif /* not COFF_FORMAT */ |
699 | |
700 | validate_files (); |
701 | } |
702 | else if (from_tty) |
703 | printf ("No exec file now.\n"); |
704 | |
705 | /* Tell display code (if any) about the changed file name. */ |
706 | if (exec_file_display_hook) |
707 | (*exec_file_display_hook) (filename); |
708 | } |
709 | \f |
710 | /*** Prettier register printing. ***/ |
711 | |
712 | /* Print registers in the same format as pyramid's dbx, adb, sdb. */ |
713 | pyr_print_registers(reg_buf, regnum) |
714 | long *reg_buf[]; |
715 | { |
716 | register int regno; |
717 | int usp, ksp; |
718 | struct user u; |
719 | |
720 | for (regno = 0; regno < 16; regno++) { |
721 | printf/*_filtered*/ ("%6.6s: %8x %6.6s: %8x %6s: %8x %6s: %8x\n", |
722 | reg_names[regno], reg_buf[regno], |
723 | reg_names[regno+16], reg_buf[regno+16], |
724 | reg_names[regno+32], reg_buf[regno+32], |
725 | reg_names[regno+48], reg_buf[regno+48]); |
726 | } |
727 | usp = ptrace (3, inferior_pid, |
728 | ((char *)&u.u_pcb.pcb_usp) - |
729 | ((char *)&u), 0); |
730 | ksp = ptrace (3, inferior_pid, |
731 | ((char *)&u.u_pcb.pcb_ksp) - |
732 | ((char *)&u), 0); |
733 | printf/*_filtered*/ ("\n%6.6s: %8x %6.6s: %8x (%08x) %6.6s %8x\n", |
734 | reg_names[CSP_REGNUM],reg_buf[CSP_REGNUM], |
735 | reg_names[KSP_REGNUM], reg_buf[KSP_REGNUM], ksp, |
736 | "usp", usp); |
737 | } |
738 | |
739 | /* Print the register regnum, or all registers if regnum is -1. */ |
740 | |
741 | pyr_do_registers_info (regnum) |
742 | int regnum; |
743 | { |
744 | /* On a pyr, we know a virtual register can always fit in an long. |
745 | Here (and elsewhere) we take advantage of that. Yuk. */ |
746 | long raw_regs[MAX_REGISTER_RAW_SIZE*NUM_REGS]; |
747 | register int i; |
748 | |
749 | for (i = 0 ; i < 64 ; i++) { |
750 | read_relative_register_raw_bytes(i, raw_regs+i); |
751 | } |
752 | if (regnum == -1) |
753 | pyr_print_registers (raw_regs, regnum); |
754 | else |
755 | for (i = 0; i < NUM_REGS; i++) |
756 | if (i == regnum) { |
757 | long val = raw_regs[i]; |
758 | |
759 | fputs_filtered (reg_names[i], stdout); |
760 | printf_filtered(":"); |
761 | print_spaces_filtered (6 - strlen (reg_names[i]), stdout); |
762 | if (val == 0) |
763 | printf_filtered ("0"); |
764 | else |
765 | printf_filtered ("0x%08x %d", val, val); |
766 | printf_filtered("\n"); |
767 | } |
768 | } |
769 | \f |
770 | /*** Debugging editions of various macros from m-pyr.h ****/ |
771 | |
772 | CORE_ADDR frame_locals_address (frame) |
773 | FRAME frame; |
774 | { |
775 | register int addr = find_saved_register (frame,CFP_REGNUM); |
776 | register int result = read_memory_integer (addr, 4); |
777 | #ifdef PYRAMID_CONTROL_FRAME_DEBUGGING |
778 | fprintf (stderr, |
779 | "\t[[..frame_locals:%8x, %s= %x @%x fcfp= %x foo= %x\n\t gr13=%x pr13=%x tr13=%x @%x]]\n", |
780 | frame->frame, |
781 | reg_names[CFP_REGNUM], |
782 | result, addr, |
783 | frame->frame_cfp, (CFP_REGNUM), |
784 | |
785 | |
786 | read_register(13), read_register(29), read_register(61), |
787 | find_saved_register(frame, 61)); |
788 | #endif /* PYRAMID_CONTROL_FRAME_DEBUGGING */ |
789 | |
790 | /* FIXME: I thought read_register (CFP_REGNUM) should be the right answer; |
791 | or at least CFP_REGNUM relative to FRAME (ie, result). |
792 | There seems to be a bug in the way the innermost frame is set up. */ |
793 | |
794 | return ((frame->next) ? result: frame->frame_cfp); |
795 | } |
796 | |
797 | CORE_ADDR frame_args_addr (frame) |
798 | FRAME frame; |
799 | { |
800 | register int addr = find_saved_register (frame,CFP_REGNUM); |
801 | register int result = read_memory_integer (addr, 4); |
802 | |
803 | #ifdef PYRAMID_CONTROL_FRAME_DEBUGGING |
804 | fprintf (stderr, |
805 | "\t[[..frame_args:%8x, %s= %x @%x fcfp= %x r_r= %x\n\t gr13=%x pr13=%x tr13=%x @%x]]\n", |
806 | frame->frame, |
807 | reg_names[CFP_REGNUM], |
808 | result, addr, |
809 | frame->frame_cfp, read_register(CFP_REGNUM), |
810 | |
811 | read_register(13), read_register(29), read_register(61), |
812 | find_saved_register(frame, 61)); |
813 | #endif /* PYRAMID_CONTROL_FRAME_DEBUGGING */ |
814 | |
815 | /* FIXME: I thought read_register (CFP_REGNUM) should be the right answer; |
816 | or at least CFP_REGNUM relative to FRAME (ie, result). |
817 | There seems to be a bug in the way the innermost frame is set up. */ |
818 | return ((frame->next) ? result: frame->frame_cfp); |
819 | } |