1 /* Interface to bare machine for GDB running as kernel debugger.
2 Copyright 1986, 1989, 1991, 1992, 1993, 1995, 1996, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <sys/ioctl.h>
25 #include <sys/types.h>
28 #if defined (SIGTSTP) && defined (SIGIO)
30 #include <sys/resource.h>
31 #endif /* SIGTSTP and SIGIO defined (must be 4.2) */
41 /* Random system calls, mostly no-ops to prevent link problems */
43 ioctl (int desc
, int code
, int arg
)
69 getcwd (char *buf
, unsigned int len
)
76 /* Used to check for existence of .gdbinit. Say no. */
85 error ("Fatal error; restarting.");
88 /* Reading "files". The contents of some files are written into kdb's
89 data area before it is run. These files are used to contain the
90 symbol table for kdb to load, and the source files (in case the
91 kdb user wants to print them). The symbols are stored in a file
92 named "kdb-symbols" in a.out format (except that all the text and
93 data have been stripped to save room).
95 The files are stored in the following format:
96 int number of bytes of data for this file, including these four.
97 char[] name of the file, ending with a null.
98 padding to multiple of 4 boundary.
99 char[] file contents. The length can be deduced from what was
100 specified before. There is no terminating null here.
102 If the int at the front is zero, it means there are no more files.
104 Opening a file in kdb returns a nonzero value to indicate success,
105 but the value does not matter. Only one file can be open, and only
106 for reading. All the primitives for input from the file know
107 which file is open and ignore what is specified for the descriptor
108 or for the stdio stream.
110 Input with fgetc can be done either on the file that is open
111 or on stdin (which reads from the terminal through tty_input () */
113 /* Address of data for the files stored in format described above. */
116 /* The file stream currently open: */
118 char *sourcebeg
; /* beginning of contents */
119 int sourcesize
; /* size of contents */
120 char *sourceptr
; /* current read pointer */
121 int sourceleft
; /* number of bytes to eof */
123 /* "descriptor" for the file now open.
124 Incremented at each close.
125 If specified descriptor does not match this,
126 it means the program is trying to use a closed descriptor.
127 We report an error for that. */
131 open (char *filename
, int modes
)
147 for (next
= files_start
; *(int *) next
; next
+= *(int *) next
)
149 if (!strcmp (next
+ 4, filename
))
151 sourcebeg
= next
+ 4 + strlen (next
+ 4) + 1;
152 sourcebeg
= (char *) (((int) sourcebeg
+ 3) & (-4));
153 sourceptr
= sourcebeg
;
154 sourcesize
= next
+ *(int *) next
- sourceptr
;
155 sourceleft
= sourcesize
;
166 /* Don't let sourcedesc get big enough to be confused with stdin. */
167 if (sourcedesc
== 100)
172 fopen (char *filename
, char *modes
)
174 return (FILE *) open (filename
, *modes
== 'w');
180 return (FILE *) desc
;
188 fstat (int desc
, struct stat
*statbuf
)
190 if (desc
!= sourcedesc
)
195 statbuf
->st_size
= sourcesize
;
198 myread (int desc
, char *destptr
, int size
, char *filename
)
200 int len
= min (sourceleft
, size
);
202 if (desc
!= sourcedesc
)
208 memcpy (destptr
, sourceptr
, len
);
214 fread (int bufp
, int numelts
, int eltsize
, int stream
)
216 register int elts
= min (numelts
, sourceleft
/ eltsize
);
217 register int len
= elts
* eltsize
;
219 if (stream
!= sourcedesc
)
225 memcpy (bufp
, sourceptr
, len
);
234 if (desc
== (int) stdin
)
237 if (desc
!= sourcedesc
)
243 if (sourceleft
-- <= 0)
248 lseek (int desc
, int pos
)
251 if (desc
!= sourcedesc
)
257 if (pos
< 0 || pos
> sourcesize
)
263 sourceptr
= sourcebeg
+ pos
;
264 sourceleft
= sourcesize
- pos
;
267 /* Output in kdb can go only to the terminal, so the stream
268 specified may be ignored. */
270 printf (int a1
, int a2
, int a3
, int a4
, int a5
, int a6
, int a7
, int a8
, int a9
)
273 sprintf (buffer
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
274 display_string (buffer
);
277 fprintf (int ign
, int a1
, int a2
, int a3
, int a4
, int a5
, int a6
, int a7
,
281 sprintf (buffer
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
282 display_string (buffer
);
285 fwrite (register char *buf
, int numelts
, int size
, int stream
)
287 register int i
= numelts
* size
;
289 fputc (*buf
++, stream
);
292 fputc (int c
, int ign
)
297 display_string (buf
);
300 /* sprintf refers to this, but loading this from the
301 library would cause fflush to be loaded from it too.
302 In fact there should be no need to call this (I hope). */
306 error ("_flsbuf was actually called.");
313 /* Entries into core and inflow, needed only to make things link ok. */
315 exec_file_command (void)
319 core_file_command (void)
324 get_exec_file (int err
)
326 /* Makes one printout look reasonable; value does not matter otherwise. */
330 /* Nonzero if there is a core file. */
332 have_core_file_p (void)
339 inferior_ptid
= null_ptid
;
342 terminal_inferior (void)
350 terminal_init_inferior (void)
354 write_inferior_register (void)
358 read_inferior_register (void)
362 read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
364 memcpy (myaddr
, memaddr
, len
);
367 /* Always return 0 indicating success. */
369 write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
371 memcpy (memaddr
, myaddr
, len
);
375 static REGISTER_TYPE saved_regs
[NUM_REGS
];
378 read_register (int regno
)
380 if (regno
< 0 || regno
>= NUM_REGS
)
381 error ("Register number %d out of range.", regno
);
382 return saved_regs
[regno
];
386 write_register (int regno
, REGISTER_TYPE value
)
388 if (regno
< 0 || regno
>= NUM_REGS
)
389 error ("Register number %d out of range.", regno
);
390 saved_regs
[regno
] = value
;
393 /* System calls needed in relation to running the "inferior". */
397 /* Just appear to "succeed". Say the inferior's pid is 1. */
401 /* These are called by code that normally runs in the inferior
402 that has just been forked. That code never runs, when standalone,
403 and these definitions are so it will link without errors. */
421 /* Malloc calls these. */
423 malloc_warning (char *str
)
425 printf ("\n%s.\n\n", str
);
434 if (next_free
+ amount
> memory_limit
)
437 return next_free
- amount
;
440 /* Various ways malloc might ask where end of memory is. */
451 return memory_limit
- next_free
;
454 getrlimit (struct rlimit
*addr
)
456 addr
->rlim_cur
= memory_limit
- next_free
;
459 /* Context switching to and from program being debugged. */
461 /* GDB calls here to run the user program.
462 The frame pointer for this function is saved in
463 gdb_stack by save_frame_pointer; then we restore
464 all of the user program's registers, including PC and PS. */
466 static int fault_code
;
467 static REGISTER_TYPE gdb_stack
;
471 REGISTER_TYPE restore
[NUM_REGS
];
474 save_frame_pointer ();
476 memcpy (restore
, saved_regs
, sizeof restore
);
478 /* Control does not drop through here! */
481 save_frame_pointer (CORE_ADDR val
)
486 /* Fault handlers call here, running in the user program stack.
487 They must first push a fault code,
488 old PC, old PS, and any other info about the fault.
489 The exact format is machine-dependent and is known only
490 in the definition of PUSH_REGISTERS. */
494 /* Transfer all registers and fault code to the stack
495 in canonical order: registers in order of GDB register number,
496 followed by fault code. */
499 /* Transfer them to saved_regs and fault_code. */
503 /* Control does not reach here */
508 CORE_ADDR new_fp
= gdb_stack
;
509 /* Switch to GDB's stack */
511 /* Return from the function `resume'. */
514 /* Assuming register contents and fault code have been pushed on the stack as
515 arguments to this function, copy them into the standard place
516 for the program's registers while GDB is running. */
518 save_registers (int firstreg
)
520 memcpy (saved_regs
, &firstreg
, sizeof saved_regs
);
521 fault_code
= (&firstreg
)[NUM_REGS
];
524 /* Store into the structure such as `wait' would return
525 the information on why the program faulted,
526 converted into a machine-independent signal number. */
528 static int fault_table
[] = FAULT_TABLE
;
533 WSETSTOP (*w
, fault_table
[fault_code
/ FAULT_CODE_UNITS
]);
534 return PIDGET (inferior_ptid
);
537 /* Allocate a big space in which files for kdb to read will be stored.
538 Whatever is left is where malloc can allocate storage.
540 Initialize it, so that there will be space in the executable file
541 for it. Then the files can be put into kdb by writing them into
542 kdb's executable file. */
544 /* The default size is as much space as we expect to be available
548 #define HEAP_SIZE 400000
551 char heap
[HEAP_SIZE
] =
555 #define STACK_SIZE 100000
558 int kdb_stack_beg
[STACK_SIZE
/ sizeof (int)];
561 _initialize_standalone (void)
565 /* Find start of data on files. */
569 /* Find the end of the data on files. */
571 for (next
= files_start
; *(int *) next
; next
+= *(int *) next
)
575 /* That is where free storage starts for sbrk to give out. */
578 memory_limit
= heap
+ sizeof heap
;
This page took 0.043691 seconds and 4 git commands to generate.