fa6d6fc44fd6dcee38b8cdad24f36e3ff0c7ed8f
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
)
70 /* Used to check for existence of .gdbinit. Say no. */
79 error ("Fatal error; restarting.");
82 /* Reading "files". The contents of some files are written into kdb's
83 data area before it is run. These files are used to contain the
84 symbol table for kdb to load, and the source files (in case the
85 kdb user wants to print them). The symbols are stored in a file
86 named "kdb-symbols" in a.out format (except that all the text and
87 data have been stripped to save room).
89 The files are stored in the following format:
90 int number of bytes of data for this file, including these four.
91 char[] name of the file, ending with a null.
92 padding to multiple of 4 boundary.
93 char[] file contents. The length can be deduced from what was
94 specified before. There is no terminating null here.
96 If the int at the front is zero, it means there are no more files.
98 Opening a file in kdb returns a nonzero value to indicate success,
99 but the value does not matter. Only one file can be open, and only
100 for reading. All the primitives for input from the file know
101 which file is open and ignore what is specified for the descriptor
102 or for the stdio stream.
104 Input with fgetc can be done either on the file that is open
105 or on stdin (which reads from the terminal through tty_input () */
107 /* Address of data for the files stored in format described above. */
110 /* The file stream currently open: */
112 char *sourcebeg
; /* beginning of contents */
113 int sourcesize
; /* size of contents */
114 char *sourceptr
; /* current read pointer */
115 int sourceleft
; /* number of bytes to eof */
117 /* "descriptor" for the file now open.
118 Incremented at each close.
119 If specified descriptor does not match this,
120 it means the program is trying to use a closed descriptor.
121 We report an error for that. */
125 open (filename
, modes
)
143 for (next
- files_start
; * (int *) next
;
144 next
+= * (int *) next
)
146 if (!strcmp (next
+ 4, filename
))
148 sourcebeg
= next
+ 4 + strlen (next
+ 4) + 1;
149 sourcebeg
= (char *) (((int) sourcebeg
+ 3) & (-4));
150 sourceptr
= sourcebeg
;
151 sourcesize
= next
+ * (int *) next
- sourceptr
;
152 sourceleft
= sourcesize
;
164 /* Don't let sourcedesc get big enough to be confused with stdin. */
165 if (sourcedesc
== 100)
170 fopen (filename
, modes
)
174 return (FILE *) open (filename
, *modes
== 'w');
181 return (FILE *) desc
;
190 fstat (desc
, statbuf
)
191 struct stat
*statbuf
;
193 if (desc
!= sourcedesc
)
198 statbuf
->st_size
= sourcesize
;
201 myread (desc
, destptr
, size
, filename
)
207 int len
= min (sourceleft
, size
);
209 if (desc
!= sourcedesc
)
215 bcopy (sourceptr
, destptr
, len
);
221 fread (bufp
, numelts
, eltsize
, stream
)
223 register int elts
= min (numelts
, sourceleft
/ eltsize
);
224 register int len
= elts
* eltsize
;
226 if (stream
!= sourcedesc
)
232 bcopy (sourceptr
, bufp
, len
);
242 if (desc
== (int) stdin
)
245 if (desc
!= sourcedesc
)
251 if (sourceleft
-- <= 0)
261 if (desc
!= sourcedesc
)
267 if (pos
< 0 || pos
> sourcesize
)
273 sourceptr
= sourcebeg
+ pos
;
274 sourceleft
= sourcesize
- pos
;
277 /* Output in kdb can go only to the terminal, so the stream
278 specified may be ignored. */
280 printf (a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
283 sprintf (buffer
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
284 display_string (buffer
);
287 fprintf (ign
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
290 sprintf (buffer
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
291 display_string (buffer
);
294 fwrite (buf
, numelts
, size
, stream
)
298 register int i
= numelts
* size
;
300 fputc (*buf
++, stream
);
308 display_string (buf
);
311 /* sprintf refers to this, but loading this from the
312 library would cause fflush to be loaded from it too.
313 In fact there should be no need to call this (I hope). */
317 error ("_flsbuf was actually called.");
324 /* Entries into core and inflow, needed only to make things link ok. */
336 /* Makes one printout look reasonable; value does not matter otherwise. */
356 terminal_init_inferior ()
359 write_inferior_register ()
362 read_inferior_register ()
365 read_memory (memaddr
, myaddr
, len
)
370 bcopy (memaddr
, myaddr
, len
);
373 /* Always return 0 indicating success. */
375 write_memory (memaddr
, myaddr
, len
)
380 bcopy (myaddr
, memaddr
, len
);
384 static REGISTER_TYPE saved_regs
[NUM_REGS
];
387 read_register (regno
)
390 if (regno
< 0 || regno
>= NUM_REGS
)
391 error ("Register number %d out of range.", regno
);
392 return saved_regs
[regno
];
396 write_register (regno
, value
)
400 if (regno
< 0 || regno
>= NUM_REGS
)
401 error ("Register number %d out of range.", regno
);
402 saved_regs
[regno
] = value
;
405 /* System calls needed in relation to running the "inferior". */
409 /* Just appear to "succeed". Say the inferior's pid is 1. */
413 /* These are called by code that normally runs in the inferior
414 that has just been forked. That code never runs, when standalone,
415 and these definitions are so it will link without errors. */
429 /* Malloc calls these. */
434 printf ("\n%s.\n\n", str
);
444 if (next_free
+ amount
> memory_limit
)
447 return next_free
- amount
;
450 /* Various ways malloc might ask where end of memory is. */
461 return memory_limit
- next_free
;
467 addr
->rlim_cur
= memory_limit
- next_free
;
470 /* Context switching to and from program being debugged. */
472 /* GDB calls here to run the user program.
473 The frame pointer for this function is saved in
474 gdb_stack by save_frame_pointer; then we restore
475 all of the user program's registers, including PC and PS. */
477 static int fault_code
;
478 static REGISTER_TYPE gdb_stack
;
482 REGISTER_TYPE restore
[NUM_REGS
];
485 save_frame_pointer ();
487 bcopy (saved_regs
, restore
, sizeof restore
);
489 /* Control does not drop through here! */
492 save_frame_pointer (val
)
498 /* Fault handlers call here, running in the user program stack.
499 They must first push a fault code,
500 old PC, old PS, and any other info about the fault.
501 The exact format is machine-dependent and is known only
502 in the definition of PUSH_REGISTERS. */
506 /* Transfer all registers and fault code to the stack
507 in canonical order: registers in order of GDB register number,
508 followed by fault code. */
511 /* Transfer them to saved_regs and fault_code. */
515 /* Control does not reach here */
520 CORE_ADDR new_fp
= gdb_stack
;
521 /* Switch to GDB's stack */
523 /* Return from the function `resume'. */
526 /* Assuming register contents and fault code have been pushed on the stack as
527 arguments to this function, copy them into the standard place
528 for the program's registers while GDB is running. */
530 save_registers (firstreg
)
533 bcopy (&firstreg
, saved_regs
, sizeof saved_regs
);
534 fault_code
= (&firstreg
)[NUM_REGS
];
537 /* Store into the structure such as `wait' would return
538 the information on why the program faulted,
539 converted into a machine-independent signal number. */
541 static int fault_table
[] = FAULT_TABLE
;
547 WSETSTOP (*w
, fault_table
[fault_code
/ FAULT_CODE_UNITS
]);
551 /* Allocate a big space in which files for kdb to read will be stored.
552 Whatever is left is where malloc can allocate storage.
554 Initialize it, so that there will be space in the executable file
555 for it. Then the files can be put into kdb by writing them into
556 kdb's executable file. */
558 /* The default size is as much space as we expect to be available
562 #define HEAP_SIZE 400000
565 char heap
[HEAP_SIZE
] = {0};
568 #define STACK_SIZE 100000
571 int kdb_stack_beg
[STACK_SIZE
/ sizeof (int)];
574 _initialize_standalone ()
578 /* Find start of data on files. */
582 /* Find the end of the data on files. */
584 for (next
- files_start
; * (int *) next
;
585 next
+= * (int *) next
)
588 /* That is where free storage starts for sbrk to give out. */
591 memory_limit
= heap
+ sizeof heap
;
This page took 0.04248 seconds and 4 git commands to generate.