1 /* Basic, host-specific, and target-specific definitions for GDB.
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. */
25 /* First include ansidecl.h so we can use the various macro definitions
26 here and in all subsequent file inclusions. */
30 /* For BFD64 and bfd_vma. */
33 /* An address in the program being debugged. Host byte order. Rather
34 than duplicate all the logic in BFD which figures out what type
35 this is (long, long long, etc.) and whether it needs to be 64
36 bits (the host/target interactions are subtle), we just use
39 typedef bfd_vma CORE_ADDR;
41 #define min(a, b) ((a) < (b) ? (a) : (b))
42 #define max(a, b) ((a) > (b) ? (a) : (b))
44 /* Gdb does *lots* of string compares. Use macros to speed them up by
45 avoiding function calls if the first characters are not the same. */
47 #define STRCMP(a,b) (*(a) == *(b) ? strcmp ((a), (b)) : (int)*(a) - (int)*(b))
48 #define STREQ(a,b) (*(a) == *(b) ? !strcmp ((a), (b)) : 0)
49 #define STREQN(a,b,c) (*(a) == *(b) ? !strncmp ((a), (b), (c)) : 0)
51 /* The character GNU C++ uses to build identifiers that must be unique from
52 the program's identifiers (such as $this and $$vptr). */
53 #define CPLUS_MARKER '$' /* May be overridden to '.' for SysV */
55 #include <errno.h> /* System call error return status */
58 extern int immediate_quit;
59 extern int sevenbit_strings;
64 #define QUIT { if (quit_flag) quit (); }
66 /* Command classes are top-level categories into which commands are broken
67 down for "help" purposes.
68 Notes on classes: class_alias is for alias commands which are not
69 abbreviations of the original command. class-pseudo is for commands
70 which are not really commands nor help topics ("stop"). */
74 /* Special args to help_list */
75 all_classes = -2, all_commands = -1,
76 /* Classes of commands */
77 no_class = -1, class_run = 0, class_vars, class_stack,
78 class_files, class_support, class_info, class_breakpoint,
79 class_alias, class_obscure, class_user, class_maintenance,
83 /* Languages represented in the symbol table and elsewhere.
84 This should probably be in language.h, but since enum's can't
85 be forward declared to satisfy opaque references before their
86 actual definition, needs to be here. */
90 language_unknown, /* Language not known */
91 language_auto, /* Placeholder for automatic setting */
93 language_cplus, /* C++ */
94 language_chill, /* Chill */
95 language_m2 /* Modula-2 */
98 /* the cleanup list records things that have to be undone
99 if an error happens (descriptors to be closed, memory to be freed, etc.)
100 Each link in the chain records a function to call and an
103 Use make_cleanup to add an element to the cleanup chain.
104 Use do_cleanups to do all cleanup actions back to a given
105 point in the chain. Use discard_cleanups to remove cleanups
106 from the chain back to a given point, not doing them. */
110 struct cleanup *next;
111 void (*function) PARAMS ((PTR));
115 /* From blockframe.c */
118 inside_entry_func PARAMS ((CORE_ADDR));
121 inside_entry_file PARAMS ((CORE_ADDR addr));
124 inside_main_func PARAMS ((CORE_ADDR pc));
126 /* From ch-lang.c, for the moment. (FIXME) */
129 chill_demangle PARAMS ((const char *));
131 /* From libiberty.a */
134 cplus_demangle PARAMS ((const char *, int));
137 cplus_mangle_opname PARAMS ((char *, int));
139 /* From libmmalloc.a (memory mapped malloc library) */
142 mmalloc_attach PARAMS ((int, PTR));
145 mmalloc_detach PARAMS ((PTR));
148 mmalloc PARAMS ((PTR, long));
151 mrealloc PARAMS ((PTR, PTR, long));
154 mfree PARAMS ((PTR, PTR));
157 mmalloc_setkey PARAMS ((PTR, int, PTR));
160 mmalloc_getkey PARAMS ((PTR, int));
165 strcmp_iw PARAMS ((const char *, const char *));
168 safe_strerror PARAMS ((int));
171 safe_strsignal PARAMS ((int));
174 init_malloc PARAMS ((void *));
177 request_quit PARAMS ((int));
180 do_cleanups PARAMS ((struct cleanup *));
183 discard_cleanups PARAMS ((struct cleanup *));
185 /* The bare make_cleanup function is one of those rare beasts that
186 takes almost any type of function as the first arg and anything that
187 will fit in a "void *" as the second arg.
189 Should be, once all calls and called-functions are cleaned up:
190 extern struct cleanup *
191 make_cleanup PARAMS ((void (*function) (void *), void *));
193 Until then, lint and/or various type-checking compiler options will
194 complain about make_cleanup calls. It'd be wrong to just cast things,
195 since the type actually passed when the function is called would be
198 extern struct cleanup *
201 extern struct cleanup *
202 save_cleanups PARAMS ((void));
205 restore_cleanups PARAMS ((struct cleanup *));
208 free_current_contents PARAMS ((char **));
211 null_cleanup PARAMS ((char **));
214 myread PARAMS ((int, char *, int));
219 /* Annotation stuff. */
221 extern int annotation_level; /* in stack.c */
224 extern void print_value_flags PARAMS ((struct type *));
227 begin_line PARAMS ((void));
230 wrap_here PARAMS ((char *));
233 reinitialize_more_filter PARAMS ((void));
235 typedef FILE GDB_FILE;
236 #define gdb_stdout stdout
237 #define gdb_stderr stderr
240 print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
243 gdb_flush PARAMS ((GDB_FILE *));
246 gdb_fopen PARAMS ((char * name, char * mode));
249 fputs_filtered PARAMS ((const char *, GDB_FILE *));
252 fputs_unfiltered PARAMS ((const char *, GDB_FILE *));
255 fputc_unfiltered PARAMS ((int, GDB_FILE *));
258 putc_unfiltered PARAMS ((int));
260 #define putchar_unfiltered(C) putc_unfiltered(C)
263 puts_filtered PARAMS ((char *));
266 puts_unfiltered PARAMS ((char *));
272 vfprintf_filtered ();
278 fprintfi_filtered ();
287 vprintf_unfiltered ();
290 vfprintf_unfiltered ();
293 fprintf_unfiltered ();
296 printf_unfiltered ();
299 print_spaces PARAMS ((int, GDB_FILE *));
302 print_spaces_filtered PARAMS ((int, GDB_FILE *));
305 n_spaces PARAMS ((int));
308 gdb_printchar PARAMS ((int, GDB_FILE *, int));
310 /* Print a host address. */
311 extern void gdb_print_address PARAMS ((void *, GDB_FILE *));
314 fprintf_symbol_filtered PARAMS ((GDB_FILE *, char *, enum language, int));
317 perror_with_name PARAMS ((char *));
320 print_sys_errmsg PARAMS ((char *, int));
322 /* From regex.c or libc. BSD 4.4 declares this with the argument type as
323 "const char *" in unistd.h, so we can't declare the argument
327 re_comp PARAMS ((const char *));
332 symbol_file_command PARAMS ((char *, int));
337 skip_quoted PARAMS ((char *));
340 gdb_readline PARAMS ((char *));
343 command_line_input PARAMS ((char *, int));
346 print_prompt PARAMS ((void));
349 batch_mode PARAMS ((void));
352 input_from_terminal_p PARAMS ((void));
354 /* From printcmd.c */
357 set_next_address PARAMS ((CORE_ADDR));
360 print_address_symbolic PARAMS ((CORE_ADDR, GDB_FILE *, int, char *));
363 print_address_numeric PARAMS ((CORE_ADDR, GDB_FILE *));
366 print_address PARAMS ((CORE_ADDR, GDB_FILE *));
371 openp PARAMS ((char *, int, char *, int, int, char **));
374 mod_path PARAMS ((char *, char **));
377 directory_command PARAMS ((char *, int));
380 init_source_path PARAMS ((void));
385 read_relative_register_raw_bytes PARAMS ((int, char *));
387 /* From readline (but not in any readline .h files). */
390 tilde_expand PARAMS ((char *));
392 /* Structure for saved commands lines
393 (for breakpoints, defined commands, etc). */
397 struct command_line *next;
401 extern struct command_line *
402 read_command_lines PARAMS ((void));
405 free_command_lines PARAMS ((struct command_line **));
407 /* String containing the current directory (what getwd would return). */
409 extern char *current_directory;
411 /* Default radixes for input and output. Only some values supported. */
412 extern unsigned input_radix;
413 extern unsigned output_radix;
415 /* Possibilities for prettyprint parameters to routines which print
416 things. Like enum language, this should be in value.h, but needs
417 to be here for the same reason. FIXME: If we can eliminate this
418 as an arg to LA_VAL_PRINT, then we can probably move it back to
423 Val_no_prettyprint = 0,
425 /* Use the default setting which the user has specified. */
430 /* Host machine definition. This will be a symlink to one of the
431 xm-*.h files, built by the `configure' script. */
435 /* Native machine support. This will be a symlink to one of the
436 nm-*.h files, built by the `configure' script. */
440 /* If the xm.h file did not define the mode string used to open the
441 files, assume that binary files are opened the same way as text
444 #include "fopen-same.h"
448 * Allow things in gdb to be declared "const". If compiling ANSI, it
449 * just works. If compiling with gcc but non-ansi, redefine to __const__.
450 * If non-ansi, non-gcc, then eliminate "const" entirely, making those
451 * objects be read-write rather than read-only.
457 # define const __const__
459 # define const /*nothing*/
467 # define volatile __volatile__
469 # define volatile /*nothing*/
472 #endif /* volatile */
475 #define NORETURN /*nothing*/
477 /* FIXME: This is bogus. Having "volatile void" mean a function doesn't
478 return is a gcc extension and should be based on #ifdef __GNUC__.
479 Also, as of Sep 93 I'm told gcc is changing the syntax for ansi
480 reasons (so declaring exit here as "volatile void" and as "void" in
481 a system header loses). Using the new "__attributes__ ((noreturn));"
482 syntax would lose for old versions of gcc; using
483 typedef void exit_fn_type PARAMS ((int));
484 volatile exit_fn_type exit;
486 /* Some compilers (many AT&T SVR4 compilers for instance), do not accept
487 declarations of functions that never return (exit for instance) as
488 "volatile void". For such compilers "NORETURN" can be defined away
489 to keep them happy */
493 # define NORETURN /*nothing*/
495 # define NORETURN volatile
500 /* Defaults for system-wide constants (if not defined by xm.h, we fake it). */
502 #if !defined (UINT_MAX)
503 #define UINT_MAX ((unsigned int)(~0)) /* 0xFFFFFFFF for 32-bits */
506 #if !defined (INT_MAX)
507 #define INT_MAX ((int)(UINT_MAX >> 1)) /* 0x7FFFFFFF for 32-bits */
510 #if !defined (INT_MIN)
511 #define INT_MIN (-INT_MAX - 1) /* 0x80000000 for 32-bits */
514 #if !defined (ULONG_MAX)
515 #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF for 32-bits */
518 #if !defined (LONG_MAX)
519 #define LONG_MAX ((long)(ULONG_MAX >> 1)) /* 0x7FFFFFFF for 32-bits */
524 /* This is to make sure that LONGEST is at least as big as CORE_ADDR. */
526 #define LONGEST BFD_HOST_64_BIT
530 /* If all compilers for this host support "long long" and we want to
531 use it for LONGEST (the performance hit is about 10% on a testsuite
532 run based on one DECstation test), then the xm.h file can define
535 Using GCC 1.39 on BSDI with long long causes about 700 new
536 testsuite failures. Using long long for LONGEST on the DECstation
537 causes 3 new FAILs in the testsuite and many heuristic fencepost
538 warnings. These are not investigated, but a first guess would be
539 that the BSDI problems are GCC bugs in long long support and the
540 latter are GDB bugs. */
542 #ifndef CC_HAS_LONG_LONG
543 # if defined (__GNUC__) && defined (FORCE_LONG_LONG)
544 # define CC_HAS_LONG_LONG 1
548 /* LONGEST should not be a typedef, because "unsigned LONGEST" needs to work.
549 CC_HAS_LONG_LONG is defined if the host compiler supports "long long"
550 variables and we wish to make use of that support. */
553 # ifdef CC_HAS_LONG_LONG
554 # define LONGEST long long
556 # define LONGEST long
560 #endif /* No BFD64 */
562 /* Convert a LONGEST to an int. This is used in contexts (e.g. number of
563 arguments to a function, number in a value history, register number, etc.)
564 where the value must not be larger than can fit in an int. */
566 extern int longest_to_int PARAMS ((LONGEST));
568 /* Assorted functions we can declare, now that const and volatile are
572 savestring PARAMS ((const char *, int));
575 msavestring PARAMS ((void *, const char *, int));
578 strsave PARAMS ((const char *));
581 mstrsave PARAMS ((void *, const char *));
584 concat PARAMS ((char *, ...));
587 xmalloc PARAMS ((long));
590 xrealloc PARAMS ((PTR, long));
593 xmmalloc PARAMS ((PTR, long));
596 xmrealloc PARAMS ((PTR, PTR, long));
599 mmalloc PARAMS ((PTR, long));
602 mrealloc PARAMS ((PTR, PTR, long));
605 mfree PARAMS ((PTR, PTR));
608 mmcheck PARAMS ((PTR, void (*) (void)));
611 mmtrace PARAMS ((void));
614 parse_escape PARAMS ((char **));
616 extern const char * const reg_names[];
618 /* Message to be printed before the error message, when an error occurs. */
620 extern char *error_pre_print;
622 /* Message to be printed before the warning message, when a warning occurs. */
624 extern char *warning_pre_print;
626 extern NORETURN void /* Does not return to the caller. */
629 extern NORETURN void /* Does not return to the caller. */
632 extern NORETURN void /* Not specified as volatile in ... */
633 exit PARAMS ((int)); /* 4.10.4.3 */
635 extern NORETURN void /* Does not return to the caller. */
636 nomem PARAMS ((long));
638 /* Reasons for calling return_to_top_level. */
640 /* User interrupt. */
643 /* Any other error. */
647 #define RETURN_MASK_QUIT (1 << (int)RETURN_QUIT)
648 #define RETURN_MASK_ERROR (1 << (int)RETURN_ERROR)
649 #define RETURN_MASK_ALL (RETURN_MASK_QUIT | RETURN_MASK_ERROR)
650 typedef int return_mask;
652 extern NORETURN void /* Does not return to the caller. */
653 return_to_top_level PARAMS ((enum return_reason));
655 extern int catch_errors PARAMS ((int (*) (char *), void *, char *,
659 warning_setup PARAMS ((void));
664 /* Global functions from other, non-gdb GNU thingies (libiberty for
668 basename PARAMS ((char *));
671 getenv PARAMS ((const char *));
674 buildargv PARAMS ((char *));
677 freeargv PARAMS ((char **));
680 strerrno PARAMS ((int));
683 strsigno PARAMS ((int));
686 errno_max PARAMS ((void));
689 signo_max PARAMS ((void));
692 strtoerrno PARAMS ((char *));
695 strtosigno PARAMS ((char *));
698 strsignal PARAMS ((int));
700 /* From other system libraries */
702 #ifndef PSIGNAL_IN_SIGNAL_H
704 psignal PARAMS ((unsigned, const char *));
707 /* For now, we can't include <stdlib.h> because it conflicts with
708 "../include/getopt.h". (FIXME)
710 However, if a function is defined in the ANSI C standard and a prototype
711 for that function is defined and visible in any header file in an ANSI
712 conforming environment, then that prototype must match the definition in
713 the ANSI standard. So we can just duplicate them here without conflict,
714 since they must be the same in all conforming ANSI environments. If
715 these cause problems, then the environment is not ANSI conformant. */
722 fclose PARAMS ((GDB_FILE *stream)); /* 4.9.5.1 */
725 perror PARAMS ((const char *)); /* 4.9.10.4 */
728 atof PARAMS ((const char *nptr)); /* 4.10.1.1 */
731 atoi PARAMS ((const char *)); /* 4.10.1.2 */
733 #ifndef MALLOC_INCOMPATIBLE
736 malloc PARAMS ((size_t size)); /* 4.10.3.3 */
739 realloc PARAMS ((void *ptr, size_t size)); /* 4.10.3.4 */
742 free PARAMS ((void *)); /* 4.10.3.2 */
744 #endif /* MALLOC_INCOMPATIBLE */
747 qsort PARAMS ((void *base, size_t nmemb, /* 4.10.5.2 */
749 int (*compar)(const void *, const void *)));
751 #ifndef MEM_FNS_DECLARED /* Some non-ANSI use void *, not char *. */
753 memcpy PARAMS ((void *, const void *, size_t)); /* 4.11.2.1 */
756 memcmp PARAMS ((const void *, const void *, size_t)); /* 4.11.4.1 */
760 strchr PARAMS ((const char *, int)); /* 4.11.5.2 */
763 strrchr PARAMS ((const char *, int)); /* 4.11.5.5 */
766 strstr PARAMS ((const char *, const char *)); /* 4.11.5.7 */
769 strtok PARAMS ((char *, const char *)); /* 4.11.5.8 */
771 #ifndef MEM_FNS_DECLARED /* Some non-ANSI use void *, not char *. */
773 memset PARAMS ((void *, int, size_t)); /* 4.11.6.1 */
777 strerror PARAMS ((int)); /* 4.11.6.2 */
779 /* Various possibilities for alloca. */
782 # define alloca __builtin_alloca
783 # else /* Not GNU C */
785 # include <alloca.h> /* NOTE: Doesn't declare alloca() */
788 /* We need to be careful not to declare this in a way which conflicts with
789 bison. Bison never declares it as char *, but under various circumstances
790 (like __hpux) we need to use void *. */
791 # if defined (__STDC__) || defined (__hpux)
792 extern void *alloca ();
793 # else /* Don't use void *. */
794 extern char *alloca ();
795 # endif /* Don't use void *. */
796 # endif /* Not GNU C */
797 #endif /* alloca not defined */
799 /* TARGET_BYTE_ORDER and HOST_BYTE_ORDER must be defined to one of these. */
801 #if !defined (BIG_ENDIAN)
802 #define BIG_ENDIAN 4321
805 #if !defined (LITTLE_ENDIAN)
806 #define LITTLE_ENDIAN 1234
809 /* Target-system-dependent parameters for GDB. */
811 /* Target machine definition. This will be a symlink to one of the
812 tm-*.h files, built by the `configure' script. */
816 /* Number of bits in a char or unsigned char for the target machine.
817 Just like CHAR_BIT in <limits.h> but describes the target machine. */
818 #if !defined (TARGET_CHAR_BIT)
819 #define TARGET_CHAR_BIT 8
822 /* Number of bits in a short or unsigned short for the target machine. */
823 #if !defined (TARGET_SHORT_BIT)
824 #define TARGET_SHORT_BIT (2 * TARGET_CHAR_BIT)
827 /* Number of bits in an int or unsigned int for the target machine. */
828 #if !defined (TARGET_INT_BIT)
829 #define TARGET_INT_BIT (4 * TARGET_CHAR_BIT)
832 /* Number of bits in a long or unsigned long for the target machine. */
833 #if !defined (TARGET_LONG_BIT)
834 #define TARGET_LONG_BIT (4 * TARGET_CHAR_BIT)
837 /* Number of bits in a long long or unsigned long long for the target machine. */
838 #if !defined (TARGET_LONG_LONG_BIT)
839 #define TARGET_LONG_LONG_BIT (2 * TARGET_LONG_BIT)
842 /* Number of bits in a float for the target machine. */
843 #if !defined (TARGET_FLOAT_BIT)
844 #define TARGET_FLOAT_BIT (4 * TARGET_CHAR_BIT)
847 /* Number of bits in a double for the target machine. */
848 #if !defined (TARGET_DOUBLE_BIT)
849 #define TARGET_DOUBLE_BIT (8 * TARGET_CHAR_BIT)
852 /* Number of bits in a long double for the target machine. */
853 #if !defined (TARGET_LONG_DOUBLE_BIT)
854 #define TARGET_LONG_DOUBLE_BIT (2 * TARGET_DOUBLE_BIT)
857 /* Number of bits in a "complex" for the target machine. */
858 #if !defined (TARGET_COMPLEX_BIT)
859 #define TARGET_COMPLEX_BIT (2 * TARGET_FLOAT_BIT)
862 /* Number of bits in a "double complex" for the target machine. */
863 #if !defined (TARGET_DOUBLE_COMPLEX_BIT)
864 #define TARGET_DOUBLE_COMPLEX_BIT (2 * TARGET_DOUBLE_BIT)
867 /* Number of bits in a pointer for the target machine */
868 #if !defined (TARGET_PTR_BIT)
869 #define TARGET_PTR_BIT TARGET_INT_BIT
872 /* If we picked up a copy of CHAR_BIT from a configuration file
873 (which may get it by including <limits.h>) then use it to set
874 the number of bits in a host char. If not, use the same size
877 #if defined (CHAR_BIT)
878 #define HOST_CHAR_BIT CHAR_BIT
880 #define HOST_CHAR_BIT TARGET_CHAR_BIT
883 /* The bit byte-order has to do just with numbering of bits in
884 debugging symbols and such. Conceptually, it's quite separate
885 from byte/word byte order. */
887 #if !defined (BITS_BIG_ENDIAN)
888 #if TARGET_BYTE_ORDER == BIG_ENDIAN
889 #define BITS_BIG_ENDIAN 1
890 #endif /* Big endian. */
892 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
893 #define BITS_BIG_ENDIAN 0
894 #endif /* Little endian. */
895 #endif /* BITS_BIG_ENDIAN not defined. */
898 LONGEST extract_signed_integer PARAMS ((void *, int));
899 unsigned LONGEST extract_unsigned_integer PARAMS ((void *, int));
900 CORE_ADDR extract_address PARAMS ((void *, int));
902 void store_signed_integer PARAMS ((void *, int, LONGEST));
903 void store_unsigned_integer PARAMS ((void *, int, unsigned LONGEST));
904 void store_address PARAMS ((void *, int, CORE_ADDR));
906 double extract_floating PARAMS ((void *, int));
907 void store_floating PARAMS ((void *, int, double));
909 /* On some machines there are bits in addresses which are not really
910 part of the address, but are used by the kernel, the hardware, etc.
911 for special purposes. ADDR_BITS_REMOVE takes out any such bits
912 so we get a "real" address such as one would find in a symbol
913 table. This is used only for addresses of instructions, and even then
914 I'm not sure it's used in all contexts. It exists to deal with there
915 being a few stray bits in the PC which would mislead us, not as some sort
916 of generic thing to handle alignment or segmentation (it's possible it
917 should be in TARGET_READ_PC instead). */
918 #if !defined (ADDR_BITS_REMOVE)
919 #define ADDR_BITS_REMOVE(addr) (addr)
920 #endif /* No ADDR_BITS_REMOVE. */
925 push_bytes PARAMS ((CORE_ADDR, char *, int));
928 push_word PARAMS ((CORE_ADDR, unsigned LONGEST));
930 /* Some parts of gdb might be considered optional, in the sense that they
931 are not essential for being able to build a working, usable debugger
932 for a specific environment. For example, the maintenance commands
933 are there for the benefit of gdb maintainers. As another example,
934 some environments really don't need gdb's that are able to read N
935 different object file formats. In order to make it possible (but
936 not necessarily recommended) to build "stripped down" versions of
937 gdb, the following defines control selective compilation of those
938 parts of gdb which can be safely left out when necessary. Note that
939 the default is to include everything. */
941 #ifndef MAINTENANCE_CMDS
942 #define MAINTENANCE_CMDS 1
945 #endif /* !defined (DEFS_H) */