1 /* Interface to bare machine for GDB running as kernel debugger.
2 Copyright (C) 1986, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program 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 2 of the License, or
9 (at your option) any later version.
11 This program 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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include <sys/ioctl.h>
23 #include <sys/types.h>
26 #if defined (SIGTSTP) && defined (SIGIO)
28 #include <sys/resource.h>
29 #endif /* SIGTSTP and SIGIO defined (must be 4.2) */
39 /* Random system calls, mostly no-ops to prevent link problems */
41 ioctl (desc
, code
, arg
)
71 /* Used to check for existence of .gdbinit. Say no. */
80 error ("Fatal error; restarting.");
83 /* Reading "files". The contents of some files are written into kdb's
84 data area before it is run. These files are used to contain the
85 symbol table for kdb to load, and the source files (in case the
86 kdb user wants to print them). The symbols are stored in a file
87 named "kdb-symbols" in a.out format (except that all the text and
88 data have been stripped to save room).
90 The files are stored in the following format:
91 int number of bytes of data for this file, including these four.
92 char[] name of the file, ending with a null.
93 padding to multiple of 4 boundary.
94 char[] file contents. The length can be deduced from what was
95 specified before. There is no terminating null here.
97 If the int at the front is zero, it means there are no more files.
99 Opening a file in kdb returns a nonzero value to indicate success,
100 but the value does not matter. Only one file can be open, and only
101 for reading. All the primitives for input from the file know
102 which file is open and ignore what is specified for the descriptor
103 or for the stdio stream.
105 Input with fgetc can be done either on the file that is open
106 or on stdin (which reads from the terminal through tty_input () */
108 /* Address of data for the files stored in format described above. */
111 /* The file stream currently open: */
113 char *sourcebeg
; /* beginning of contents */
114 int sourcesize
; /* size of contents */
115 char *sourceptr
; /* current read pointer */
116 int sourceleft
; /* number of bytes to eof */
118 /* "descriptor" for the file now open.
119 Incremented at each close.
120 If specified descriptor does not match this,
121 it means the program is trying to use a closed descriptor.
122 We report an error for that. */
126 open (filename
, modes
)
144 for (next
- files_start
; * (int *) next
;
145 next
+= * (int *) next
)
147 if (!STRCMP (next
+ 4, filename
))
149 sourcebeg
= next
+ 4 + strlen (next
+ 4) + 1;
150 sourcebeg
= (char *) (((int) sourcebeg
+ 3) & (-4));
151 sourceptr
= sourcebeg
;
152 sourcesize
= next
+ * (int *) next
- sourceptr
;
153 sourceleft
= sourcesize
;
165 /* Don't let sourcedesc get big enough to be confused with stdin. */
166 if (sourcedesc
== 100)
171 fopen (filename
, modes
)
175 return (FILE *) open (filename
, *modes
== 'w');
182 return (FILE *) desc
;
191 fstat (desc
, statbuf
)
192 struct stat
*statbuf
;
194 if (desc
!= sourcedesc
)
199 statbuf
->st_size
= sourcesize
;
202 myread (desc
, destptr
, size
, filename
)
208 int len
= min (sourceleft
, size
);
210 if (desc
!= sourcedesc
)
216 bcopy (sourceptr
, destptr
, len
);
222 fread (bufp
, numelts
, eltsize
, stream
)
224 register int elts
= min (numelts
, sourceleft
/ eltsize
);
225 register int len
= elts
* eltsize
;
227 if (stream
!= sourcedesc
)
233 bcopy (sourceptr
, bufp
, len
);
243 if (desc
== (int) stdin
)
246 if (desc
!= sourcedesc
)
252 if (sourceleft
-- <= 0)
262 if (desc
!= sourcedesc
)
268 if (pos
< 0 || pos
> sourcesize
)
274 sourceptr
= sourcebeg
+ pos
;
275 sourceleft
= sourcesize
- pos
;
278 /* Output in kdb can go only to the terminal, so the stream
279 specified may be ignored. */
281 printf (a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
284 sprintf (buffer
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
285 display_string (buffer
);
288 fprintf (ign
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
291 sprintf (buffer
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
292 display_string (buffer
);
295 fwrite (buf
, numelts
, size
, stream
)
299 register int i
= numelts
* size
;
301 fputc (*buf
++, stream
);
309 display_string (buf
);
312 /* sprintf refers to this, but loading this from the
313 library would cause fflush to be loaded from it too.
314 In fact there should be no need to call this (I hope). */
318 error ("_flsbuf was actually called.");
325 /* Entries into core and inflow, needed only to make things link ok. */
337 /* Makes one printout look reasonable; value does not matter otherwise. */
341 /* Nonzero if there is a core file. */
359 terminal_init_inferior ()
362 write_inferior_register ()
365 read_inferior_register ()
368 read_memory (memaddr
, myaddr
, len
)
373 bcopy (memaddr
, myaddr
, len
);
376 /* Always return 0 indicating success. */
378 write_memory (memaddr
, myaddr
, len
)
383 bcopy (myaddr
, memaddr
, len
);
387 static REGISTER_TYPE saved_regs
[NUM_REGS
];
390 read_register (regno
)
393 if (regno
< 0 || regno
>= NUM_REGS
)
394 error ("Register number %d out of range.", regno
);
395 return saved_regs
[regno
];
399 write_register (regno
, value
)
403 if (regno
< 0 || regno
>= NUM_REGS
)
404 error ("Register number %d out of range.", regno
);
405 saved_regs
[regno
] = value
;
408 /* System calls needed in relation to running the "inferior". */
412 /* Just appear to "succeed". Say the inferior's pid is 1. */
416 /* These are called by code that normally runs in the inferior
417 that has just been forked. That code never runs, when standalone,
418 and these definitions are so it will link without errors. */
432 /* Malloc calls these. */
437 printf ("\n%s.\n\n", str
);
447 if (next_free
+ amount
> memory_limit
)
450 return next_free
- amount
;
453 /* Various ways malloc might ask where end of memory is. */
464 return memory_limit
- next_free
;
470 addr
->rlim_cur
= memory_limit
- next_free
;
473 /* Context switching to and from program being debugged. */
475 /* GDB calls here to run the user program.
476 The frame pointer for this function is saved in
477 gdb_stack by save_frame_pointer; then we restore
478 all of the user program's registers, including PC and PS. */
480 static int fault_code
;
481 static REGISTER_TYPE gdb_stack
;
485 REGISTER_TYPE restore
[NUM_REGS
];
488 save_frame_pointer ();
490 bcopy (saved_regs
, restore
, sizeof restore
);
492 /* Control does not drop through here! */
495 save_frame_pointer (val
)
501 /* Fault handlers call here, running in the user program stack.
502 They must first push a fault code,
503 old PC, old PS, and any other info about the fault.
504 The exact format is machine-dependent and is known only
505 in the definition of PUSH_REGISTERS. */
509 /* Transfer all registers and fault code to the stack
510 in canonical order: registers in order of GDB register number,
511 followed by fault code. */
514 /* Transfer them to saved_regs and fault_code. */
518 /* Control does not reach here */
523 CORE_ADDR new_fp
= gdb_stack
;
524 /* Switch to GDB's stack */
526 /* Return from the function `resume'. */
529 /* Assuming register contents and fault code have been pushed on the stack as
530 arguments to this function, copy them into the standard place
531 for the program's registers while GDB is running. */
533 save_registers (firstreg
)
536 bcopy (&firstreg
, saved_regs
, sizeof saved_regs
);
537 fault_code
= (&firstreg
)[NUM_REGS
];
540 /* Store into the structure such as `wait' would return
541 the information on why the program faulted,
542 converted into a machine-independent signal number. */
544 static int fault_table
[] = FAULT_TABLE
;
550 WSETSTOP (*w
, fault_table
[fault_code
/ FAULT_CODE_UNITS
]);
554 /* Allocate a big space in which files for kdb to read will be stored.
555 Whatever is left is where malloc can allocate storage.
557 Initialize it, so that there will be space in the executable file
558 for it. Then the files can be put into kdb by writing them into
559 kdb's executable file. */
561 /* The default size is as much space as we expect to be available
565 #define HEAP_SIZE 400000
568 char heap
[HEAP_SIZE
] = {0};
571 #define STACK_SIZE 100000
574 int kdb_stack_beg
[STACK_SIZE
/ sizeof (int)];
577 _initialize_standalone ()
581 /* Find start of data on files. */
585 /* Find the end of the data on files. */
587 for (next
- files_start
; * (int *) next
;
588 next
+= * (int *) next
)
591 /* That is where free storage starts for sbrk to give out. */
594 memory_limit
= heap
+ sizeof heap
;
This page took 0.048585 seconds and 4 git commands to generate.