1 /* *INDENT-OFF* */ /* ATTR_FORMAT confuses indent, avoid running it for now */
2 /* Basic, host-specific, and target-specific definitions for GDB.
3 Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
27 #include "config.h" /* Generated by configure. */
30 #include <errno.h> /* System call error return status. */
36 #include <sys/types.h> /* For size_t. */
43 /* First include ansidecl.h so we can use the various macro definitions
44 here and in all subsequent file inclusions. */
48 #include "gdb_locale.h"
50 /* For ``enum target_signal''. */
51 #include "gdb/signals.h"
53 /* Just in case they're not defined in stdio.h. */
62 #include <stdarg.h> /* For va_list. */
64 #include "libiberty.h"
68 /* For BFD64 and bfd_vma. */
72 /* The target is partially multi-arched. Both "tm.h" and the
73 multi-arch vector provide definitions. "tm.h" normally overrides
74 the multi-arch vector (but there are a few exceptions). */
76 #define GDB_MULTI_ARCH_PARTIAL 1
78 /* The target is partially multi-arched. Both the multi-arch vector
79 and "tm.h" provide definitions. "tm.h" cannot override a definition
80 provided by the multi-arch vector. It is detected as a compilation
83 This setting is only useful during a multi-arch conversion. */
85 #define GDB_MULTI_ARCH_TM 2
87 /* The target is pure multi-arch. The MULTI-ARCH vector provides all
88 definitions. "tm.h" is linked to an empty file. */
90 #define GDB_MULTI_ARCH_PURE 3
94 /* An address in the program being debugged. Host byte order. Rather
95 than duplicate all the logic in BFD which figures out what type
96 this is (long, long long, etc.) and whether it needs to be 64
97 bits (the host/target interactions are subtle), we just use
100 typedef bfd_vma CORE_ADDR;
102 /* This is to make sure that LONGEST is at least as big as CORE_ADDR. */
108 #define LONGEST BFD_HOST_64_BIT
109 #define ULONGEST BFD_HOST_U_64_BIT
113 #ifdef CC_HAS_LONG_LONG
114 #define LONGEST long long
115 #define ULONGEST unsigned long long
117 #ifdef BFD_HOST_64_BIT
118 /* BFD_HOST_64_BIT is defined for some hosts that don't have long long
119 (e.g. i386-windows) so try it. */
120 #define LONGEST BFD_HOST_64_BIT
121 #define ULONGEST BFD_HOST_U_64_BIT
124 #define ULONGEST unsigned long
128 #endif /* No BFD64 */
130 #endif /* ! LONGEST */
133 #define min(a, b) ((a) < (b) ? (a) : (b))
136 #define max(a, b) ((a) > (b) ? (a) : (b))
139 /* Macros to do string compares.
141 NOTE: cagney/2000-03-14:
143 While old code can continue to refer to these macros, new code is
144 probably better off using strcmp() directly vis: ``strcmp() == 0''
145 and ``strcmp() != 0''.
147 This is because modern compilers can directly inline strcmp()
148 making the original justification for these macros - avoid function
149 call overhead by pre-testing the first characters
150 (``*X==*Y?...:0'') - redundant.
152 ``Even if [...] testing the first character does have a modest
153 performance improvement, I'd rather that whenever a performance
154 issue is found that we spend the effort on algorithmic
155 optimizations than micro-optimizing.'' J.T. */
157 /* NOTE: cagney/2003-11-23: All instances of STREQ[N] covered by
158 testing GDB on a stabs system have been replaced by equivalent
159 str[n]cmp calls. To avoid the possability of introducing bugs when
160 making untested changes, the remaining references were deprecated
161 rather than replaced. */
163 /* DISCLAIMER: cagney/2003-11-23: Simplified definition of these
164 macros so that they just map directly onto strcmp equivalent. I'm
165 not responsible for any breakage due to code that relied on the old
166 underlying implementation. */
168 #define DEPRECATED_STREQ(a,b) (strcmp ((a), (b)) == 0)
169 #define DEPRECATED_STREQN(a,b,c) (strncmp ((a), (b), (c)) == 0)
171 /* Check if a character is one of the commonly used C++ marker characters. */
172 extern int is_cplus_marker (int);
174 /* enable xdb commands if set */
175 extern int xdb_commands;
177 /* enable dbx commands if set */
178 extern int dbx_commands;
180 /* System root path, used to find libraries etc. */
181 extern char *gdb_sysroot;
183 extern int quit_flag;
184 extern int immediate_quit;
185 extern int sevenbit_strings;
187 extern void quit (void);
189 /* FIXME: cagney/2000-03-13: It has been suggested that the peformance
190 benefits of having a ``QUIT'' macro rather than a function are
191 marginal. If the overhead of a QUIT function call is proving
192 significant then its calling frequency should probably be reduced
193 [kingdon]. A profile analyzing the current situtation is
197 /* do twice to force compiler warning */
198 #define QUIT_FIXME "FIXME"
199 #define QUIT_FIXME "ignoring redefinition of QUIT"
202 if (quit_flag) quit (); \
203 if (interactive_hook) interactive_hook (); \
208 /* Languages represented in the symbol table and elsewhere.
209 This should probably be in language.h, but since enum's can't
210 be forward declared to satisfy opaque references before their
211 actual definition, needs to be here. */
215 language_unknown, /* Language not known */
216 language_auto, /* Placeholder for automatic setting */
218 language_cplus, /* C++ */
219 language_objc, /* Objective-C */
220 language_java, /* Java */
221 language_fortran, /* Fortran */
222 language_m2, /* Modula-2 */
223 language_asm, /* Assembly language */
224 language_scm, /* Scheme / Guile */
225 language_pascal, /* Pascal */
226 language_minimal /* All other languages, minimal support only */
233 unspecified_precision
236 /* A generic, not quite boolean, enumeration. */
244 /* Potential ways that a function can return a value of a given type. */
245 enum return_value_convention
247 /* Where the return value has been squeezed into one or more
249 RETURN_VALUE_REGISTER_CONVENTION,
250 /* Commonly known as the "struct return convention". The caller
251 passes an additional hidden first parameter to the caller. That
252 parameter contains the address at which the value being returned
253 should be stored. While typically, and historically, used for
254 large structs, this is convention is applied to values of many
256 RETURN_VALUE_STRUCT_CONVENTION
259 /* the cleanup list records things that have to be undone
260 if an error happens (descriptors to be closed, memory to be freed, etc.)
261 Each link in the chain records a function to call and an
264 Use make_cleanup to add an element to the cleanup chain.
265 Use do_cleanups to do all cleanup actions back to a given
266 point in the chain. Use discard_cleanups to remove cleanups
267 from the chain back to a given point, not doing them. */
271 struct cleanup *next;
272 void (*function) (void *);
277 /* The ability to declare that a function never returns is useful, but
278 not really required to compile GDB successfully, so the NORETURN and
279 ATTR_NORETURN macros normally expand into nothing. */
281 /* If compiling with older versions of GCC, a function may be declared
282 "volatile" to indicate that it does not return. */
285 #if defined(__GNUC__) \
286 && (__GNUC__ == 1 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
287 #define NORETURN volatile
289 #define NORETURN /* nothing */
293 /* GCC 2.5 and later versions define a function attribute "noreturn",
294 which is the preferred way to declare that a function never returns.
295 However GCC 2.7 appears to be the first version in which this fully
296 works everywhere we use it. */
298 #ifndef ATTR_NORETURN
299 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
300 #define ATTR_NORETURN __attribute__ ((noreturn))
302 #define ATTR_NORETURN /* nothing */
307 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 4))
308 #define ATTR_FORMAT(type, x, y) __attribute__ ((format(type, x, y)))
310 #define ATTR_FORMAT(type, x, y) /* nothing */
314 /* Be conservative and use enum bitfields only with GCC.
315 This is copied from gcc 3.3.1, system.h. */
317 #if defined(__GNUC__) && (__GNUC__ >= 2)
318 #define ENUM_BITFIELD(TYPE) enum TYPE
320 #define ENUM_BITFIELD(TYPE) unsigned int
323 /* Needed for various prototypes */
329 /* From blockframe.c */
331 extern int inside_entry_func (struct frame_info *this_frame);
333 extern int deprecated_inside_entry_file (CORE_ADDR addr);
335 extern int inside_main_func (CORE_ADDR pc);
339 extern void initialize_utils (void);
341 extern void notice_quit (void);
343 extern int strcmp_iw (const char *, const char *);
345 extern int strcmp_iw_ordered (const char *, const char *);
347 extern int streq (const char *, const char *);
349 extern int subset_compare (char *, char *);
351 extern char *safe_strerror (int);
353 extern void init_malloc (void *);
355 extern void request_quit (int);
357 extern void do_cleanups (struct cleanup *);
358 extern void do_final_cleanups (struct cleanup *);
359 extern void do_run_cleanups (struct cleanup *);
360 extern void do_exec_cleanups (struct cleanup *);
361 extern void do_exec_error_cleanups (struct cleanup *);
363 extern void discard_cleanups (struct cleanup *);
364 extern void discard_final_cleanups (struct cleanup *);
365 extern void discard_exec_error_cleanups (struct cleanup *);
366 extern void discard_my_cleanups (struct cleanup **, struct cleanup *);
368 /* NOTE: cagney/2000-03-04: This typedef is strictly for the
369 make_cleanup function declarations below. Do not use this typedef
370 as a cast when passing functions into the make_cleanup() code.
371 Instead either use a bounce function or add a wrapper function.
372 Calling a f(char*) function with f(void*) is non-portable. */
373 typedef void (make_cleanup_ftype) (void *);
375 extern struct cleanup *make_cleanup (make_cleanup_ftype *, void *);
377 extern struct cleanup *make_cleanup_freeargv (char **);
380 extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *);
382 extern struct cleanup *make_cleanup_close (int fd);
384 extern struct cleanup *make_cleanup_bfd_close (bfd *abfd);
386 extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *);
388 extern struct cleanup *make_my_cleanup (struct cleanup **,
389 make_cleanup_ftype *, void *);
391 extern struct cleanup *make_run_cleanup (make_cleanup_ftype *, void *);
393 extern struct cleanup *make_exec_cleanup (make_cleanup_ftype *, void *);
394 extern struct cleanup *make_exec_error_cleanup (make_cleanup_ftype *, void *);
396 extern struct cleanup *save_cleanups (void);
397 extern struct cleanup *save_final_cleanups (void);
398 extern struct cleanup *save_my_cleanups (struct cleanup **);
400 extern void restore_cleanups (struct cleanup *);
401 extern void restore_final_cleanups (struct cleanup *);
402 extern void restore_my_cleanups (struct cleanup **, struct cleanup *);
404 extern void free_current_contents (void *);
406 extern void null_cleanup (void *);
408 extern int myread (int, char *, int);
410 extern int query (const char *, ...) ATTR_FORMAT (printf, 1, 2);
412 extern void init_page_info (void);
414 extern char *gdb_realpath (const char *);
415 extern char *xfullpath (const char *);
417 extern unsigned long gnu_debuglink_crc32 (unsigned long crc,
418 unsigned char *buf, size_t len);
420 /* From demangle.c */
422 extern void set_demangling_style (char *);
427 typedef int (use_struct_convention_fn) (int gcc_p, struct type * value_type);
428 extern use_struct_convention_fn generic_use_struct_convention;
431 /* Annotation stuff. */
433 extern int annotation_level; /* in stack.c */
435 extern void begin_line (void);
437 extern void wrap_here (char *);
439 extern void reinitialize_more_filter (void);
442 extern struct ui_file *gdb_stdout;
444 extern struct ui_file *gdb_stdin;
445 /* Serious error notifications */
446 extern struct ui_file *gdb_stderr;
447 /* Log/debug/trace messages that should bypass normal stdout/stderr
448 filtering. For moment, always call this stream using
449 *_unfiltered. In the very near future that restriction shall be
450 removed - either call shall be unfiltered. (cagney 1999-06-13). */
451 extern struct ui_file *gdb_stdlog;
452 /* Target output that should bypass normal stdout/stderr filtering.
453 For moment, always call this stream using *_unfiltered. In the
454 very near future that restriction shall be removed - either call
455 shall be unfiltered. (cagney 1999-07-02). */
456 extern struct ui_file *gdb_stdtarg;
457 extern struct ui_file *gdb_stdtargerr;
458 extern struct ui_file *gdb_stdtargin;
462 /* More generic printf like operations. Filtered versions may return
463 non-locally on error. */
465 extern void fputs_filtered (const char *, struct ui_file *);
467 extern void fputs_unfiltered (const char *, struct ui_file *);
469 extern int fputc_filtered (int c, struct ui_file *);
471 extern int fputc_unfiltered (int c, struct ui_file *);
473 extern int putchar_filtered (int c);
475 extern int putchar_unfiltered (int c);
477 extern void puts_filtered (const char *);
479 extern void puts_unfiltered (const char *);
481 extern void puts_filtered_tabular (char *string, int width, int right);
483 extern void puts_debug (char *prefix, char *string, char *suffix);
485 extern void vprintf_filtered (const char *, va_list) ATTR_FORMAT (printf, 1, 0);
487 extern void vfprintf_filtered (struct ui_file *, const char *, va_list) ATTR_FORMAT (printf, 2, 0);
489 extern void fprintf_filtered (struct ui_file *, const char *, ...) ATTR_FORMAT (printf, 2, 3);
491 extern void fprintfi_filtered (int, struct ui_file *, const char *, ...) ATTR_FORMAT (printf, 3, 4);
493 extern void printf_filtered (const char *, ...) ATTR_FORMAT (printf, 1, 2);
495 extern void printfi_filtered (int, const char *, ...) ATTR_FORMAT (printf, 2, 3);
497 extern void vprintf_unfiltered (const char *, va_list) ATTR_FORMAT (printf, 1, 0);
499 extern void vfprintf_unfiltered (struct ui_file *, const char *, va_list) ATTR_FORMAT (printf, 2, 0);
501 extern void fprintf_unfiltered (struct ui_file *, const char *, ...) ATTR_FORMAT (printf, 2, 3);
503 extern void printf_unfiltered (const char *, ...) ATTR_FORMAT (printf, 1, 2);
505 extern void print_spaces (int, struct ui_file *);
507 extern void print_spaces_filtered (int, struct ui_file *);
509 extern char *n_spaces (int);
511 extern void fputstr_filtered (const char *str, int quotr, struct ui_file * stream);
513 extern void fputstr_unfiltered (const char *str, int quotr, struct ui_file * stream);
515 extern void fputstrn_unfiltered (const char *str, int n, int quotr, struct ui_file * stream);
517 /* Display the host ADDR on STREAM formatted as ``0x%x''. */
518 extern void gdb_print_host_address (const void *addr, struct ui_file *stream);
520 /* Convert a CORE_ADDR into a HEX string. paddr() is like %08lx.
521 paddr_nz() is like %lx. paddr_u() is like %lu. paddr_width() is
523 extern int strlen_paddr (void);
524 extern char *paddr (CORE_ADDR addr);
525 extern char *paddr_nz (CORE_ADDR addr);
526 extern char *paddr_u (CORE_ADDR addr);
527 extern char *paddr_d (LONGEST addr);
529 extern char *phex (ULONGEST l, int sizeof_l);
530 extern char *phex_nz (ULONGEST l, int sizeof_l);
532 /* Like paddr() only print/scan raw CORE_ADDR. The output from
533 core_addr_to_string() can be passed direct to
534 string_to_core_addr(). */
535 extern const char *core_addr_to_string (const CORE_ADDR addr);
536 extern const char *core_addr_to_string_nz (const CORE_ADDR addr);
537 extern CORE_ADDR string_to_core_addr (const char *my_string);
539 extern void fprintf_symbol_filtered (struct ui_file *, char *,
542 extern NORETURN void perror_with_name (const char *) ATTR_NORETURN;
544 extern void print_sys_errmsg (const char *, int);
546 /* From regex.c or libc. BSD 4.4 declares this with the argument type as
547 "const char *" in unistd.h, so we can't declare the argument
550 extern char *re_comp (const char *);
554 extern void symbol_file_command (char *, int);
556 /* Remote targets may wish to use this as their load function. */
557 extern void generic_load (char *name, int from_tty);
559 /* Summarise a download */
560 extern void print_transfer_performance (struct ui_file *stream,
561 unsigned long data_count,
562 unsigned long write_count,
563 unsigned long time_count);
567 typedef void initialize_file_ftype (void);
569 extern char *skip_quoted (char *);
571 extern char *gdb_readline (char *);
573 extern char *gdb_readline_wrapper (char *);
575 extern char *command_line_input (char *, int, char *);
577 extern void print_prompt (void);
579 extern int input_from_terminal_p (void);
581 extern int info_verbose;
583 /* From printcmd.c */
585 extern void set_next_address (CORE_ADDR);
587 extern void print_address_symbolic (CORE_ADDR, struct ui_file *, int,
590 extern int build_address_symbolic (CORE_ADDR addr,
598 extern void print_address_numeric (CORE_ADDR, int, struct ui_file *);
600 extern void print_address (CORE_ADDR, struct ui_file *);
604 extern int openp (const char *, int, const char *, int, int, char **);
606 extern int source_full_path_of (char *, char **);
608 extern void mod_path (char *, char **);
610 extern void add_path (char *, char **, int);
612 extern void directory_command (char *, int);
614 extern char *source_path;
616 extern void init_source_path (void);
618 extern void init_last_source_visited (void);
620 extern char *symtab_to_filename (struct symtab *);
624 extern void exec_set_section_offsets (bfd_signed_vma text_off,
625 bfd_signed_vma data_off,
626 bfd_signed_vma bss_off);
628 /* Take over the 'find_mapped_memory' vector from exec.c. */
629 extern void exec_set_find_memory_regions (int (*) (int (*) (CORE_ADDR,
635 /* Possible lvalue types. Like enum language, this should be in
636 value.h, but needs to be here for the same reason. */
642 /* In memory. Could be a saved register. */
646 /* In a gdb internal variable. */
648 /* Part of a gdb internal variable (structure field). */
649 lval_internalvar_component,
650 /* In a register series in a frame not the current one, which may have been
651 partially saved or saved in different places (otherwise would be
652 lval_register or lval_memory). */
653 lval_reg_frame_relative
656 /* Control types for commands */
658 enum misc_command_type
666 enum command_control_type
676 /* Structure for saved commands lines
677 (for breakpoints, defined commands, etc). */
681 struct command_line *next;
683 enum command_control_type control_type;
685 struct command_line **body_list;
688 extern struct command_line *read_command_lines (char *, int);
690 extern void free_command_lines (struct command_line **);
692 /* To continue the execution commands when running gdb asynchronously.
693 A continuation structure contains a pointer to a function to be called
694 to finish the command, once the target has stopped. Such mechanism is
695 used bt the finish and until commands, and in the remote protocol
696 when opening an extended-remote connection. */
698 struct continuation_arg
700 struct continuation_arg *next;
701 union continuation_data {
710 void (*continuation_hook) (struct continuation_arg *);
711 struct continuation_arg *arg_list;
712 struct continuation *next;
716 extern struct continuation *cmd_continuation;
717 /* Used only by the step_1 function. */
718 extern struct continuation *intermediate_continuation;
721 extern void add_continuation (void (*)(struct continuation_arg *),
722 struct continuation_arg *);
723 extern void do_all_continuations (void);
724 extern void discard_all_continuations (void);
726 extern void add_intermediate_continuation (void (*)(struct continuation_arg *),
727 struct continuation_arg *);
728 extern void do_all_intermediate_continuations (void);
729 extern void discard_all_intermediate_continuations (void);
731 /* String containing the current directory (what getwd would return). */
733 extern char *current_directory;
735 /* Default radixes for input and output. Only some values supported. */
736 extern unsigned input_radix;
737 extern unsigned output_radix;
739 /* Possibilities for prettyprint parameters to routines which print
740 things. Like enum language, this should be in value.h, but needs
741 to be here for the same reason. FIXME: If we can eliminate this
742 as an arg to LA_VAL_PRINT, then we can probably move it back to
747 Val_no_prettyprint = 0,
749 /* Use the default setting which the user has specified. */
753 /* The ptid struct is a collection of the various "ids" necessary
754 for identifying the inferior. This consists of the process id
755 (pid), thread id (tid), and other fields necessary for uniquely
756 identifying the inferior process/thread being debugged. When
757 manipulating ptids, the constructors, accessors, and predicate
758 declared in inferior.h should be used. These are as follows:
760 ptid_build - Make a new ptid from a pid, lwp, and tid.
761 pid_to_ptid - Make a new ptid from just a pid.
762 ptid_get_pid - Fetch the pid component of a ptid.
763 ptid_get_lwp - Fetch the lwp component of a ptid.
764 ptid_get_tid - Fetch the tid component of a ptid.
765 ptid_equal - Test to see if two ptids are equal.
767 Please do NOT access the struct ptid members directly (except, of
768 course, in the implementation of the above ptid manipulation
776 /* Lightweight process id */
783 typedef struct ptid ptid_t;
787 /* Optional host machine definition. Pure autoconf targets will not
788 need a "xm.h" file. This will be a symlink to one of the xm-*.h
789 files, built by the `configure' script. */
795 /* Optional native machine support. Non-native (and possibly pure
796 multi-arch) targets do not need a "nm.h" file. This will be a
797 symlink to one of the nm-*.h files, built by the `configure'
804 /* Optional target machine definition. Pure multi-arch configurations
805 do not need a "tm.h" file. This will be a symlink to one of the
806 tm-*.h files, built by the `configure' script. */
812 /* If the xm.h file did not define the mode string used to open the
813 files, assume that binary files are opened the same way as text
816 #include "fopen-same.h"
819 /* Defaults for system-wide constants (if not defined by xm.h, we fake it).
820 FIXME: Assumes 2's complement arithmetic */
822 #if !defined (UINT_MAX)
823 #define UINT_MAX ((unsigned int)(~0)) /* 0xFFFFFFFF for 32-bits */
826 #if !defined (INT_MAX)
827 #define INT_MAX ((int)(UINT_MAX >> 1)) /* 0x7FFFFFFF for 32-bits */
830 #if !defined (INT_MIN)
831 #define INT_MIN ((int)((int) ~0 ^ INT_MAX)) /* 0x80000000 for 32-bits */
834 #if !defined (ULONG_MAX)
835 #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF for 32-bits */
838 #if !defined (LONG_MAX)
839 #define LONG_MAX ((long)(ULONG_MAX >> 1)) /* 0x7FFFFFFF for 32-bits */
842 #if !defined (ULONGEST_MAX)
843 #define ULONGEST_MAX (~(ULONGEST)0) /* 0xFFFFFFFFFFFFFFFF for 64-bits */
846 #if !defined (LONGEST_MAX) /* 0x7FFFFFFFFFFFFFFF for 64-bits */
847 #define LONGEST_MAX ((LONGEST)(ULONGEST_MAX >> 1))
850 /* Convert a LONGEST to an int. This is used in contexts (e.g. number of
851 arguments to a function, number in a value history, register number, etc.)
852 where the value must not be larger than can fit in an int. */
854 extern int longest_to_int (LONGEST);
856 /* Assorted functions we can declare, now that const and volatile are
859 extern char *savestring (const char *, size_t);
861 extern char *msavestring (void *, const char *, size_t);
863 extern char *mstrsave (void *, const char *);
865 /* Robust versions of same. Throw an internal error when no memory,
866 guard against stray NULL arguments. */
867 extern void *xmmalloc (void *md, size_t size);
868 extern void *xmrealloc (void *md, void *ptr, size_t size);
869 extern void *xmcalloc (void *md, size_t number, size_t size);
870 extern void xmfree (void *md, void *ptr);
872 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
874 extern void xfree (void *);
876 /* Utility macros to allocate typed memory. Avoids errors like:
877 struct foo *foo = xmalloc (sizeof struct bar); and memset (foo,
878 sizeof (struct foo), 0). */
879 #define XZALLOC(TYPE) ((TYPE*) memset (xmalloc (sizeof (TYPE)), 0, sizeof (TYPE)))
880 #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
881 #define XCALLOC(NMEMB, TYPE) ((TYPE*) xcalloc ((NMEMB), sizeof (TYPE)))
883 /* Like asprintf/vasprintf but get an internal_error if the call
885 extern void xasprintf (char **ret, const char *format, ...) ATTR_FORMAT (printf, 2, 3);
886 extern void xvasprintf (char **ret, const char *format, va_list ap);
888 /* Like asprintf, but return the string, throw an error if no memory. */
889 extern char *xstrprintf (const char *format, ...) ATTR_FORMAT (printf, 1, 2);
891 extern int parse_escape (char **);
893 /* Message to be printed before the error message, when an error occurs. */
895 extern char *error_pre_print;
897 /* Message to be printed before the error message, when an error occurs. */
899 extern char *quit_pre_print;
901 /* Message to be printed before the warning message, when a warning occurs. */
903 extern char *warning_pre_print;
905 extern NORETURN void verror (const char *fmt, va_list ap) ATTR_NORETURN;
907 extern NORETURN void error (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
909 extern NORETURN void error_silent (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
911 extern NORETURN void error_stream (struct ui_file *) ATTR_NORETURN;
913 /* Initialize the error buffer. */
914 extern void error_init (void);
916 /* Returns a freshly allocate buffer containing the last error
918 extern char *error_last_message (void);
920 /* Output arbitrary error message. */
921 extern void error_output_message (char *pre_print, char *msg);
923 extern NORETURN void internal_verror (const char *file, int line,
924 const char *, va_list ap) ATTR_NORETURN;
926 extern NORETURN void internal_error (const char *file, int line,
927 const char *, ...) ATTR_NORETURN ATTR_FORMAT (printf, 3, 4);
929 extern void internal_vwarning (const char *file, int line,
930 const char *, va_list ap);
932 extern void internal_warning (const char *file, int line,
933 const char *, ...) ATTR_FORMAT (printf, 3, 4);
935 extern NORETURN void nomem (long) ATTR_NORETURN;
937 /* Reasons for calling throw_exception(). NOTE: all reason values
938 must be less than zero. enum value 0 is reserved for internal use
939 as the return value from an initial setjmp(). The function
940 catch_exceptions() reserves values >= 0 as legal results from its
945 /* User interrupt. */
947 /* Any other error. */
951 #define ALL_CLEANUPS ((struct cleanup *)0)
953 #define RETURN_MASK(reason) (1 << (int)(-reason))
954 #define RETURN_MASK_QUIT RETURN_MASK (RETURN_QUIT)
955 #define RETURN_MASK_ERROR RETURN_MASK (RETURN_ERROR)
956 #define RETURN_MASK_ALL (RETURN_MASK_QUIT | RETURN_MASK_ERROR)
957 typedef int return_mask;
959 /* Throw an exception of type RETURN_REASON. Will execute a LONG JUMP
960 to the inner most containing exception handler established using
961 catch_exceptions() (or the legacy catch_errors()).
963 Code normally throws an exception using error() et.al. For various
964 reaons, GDB also contains code that throws an exception directly.
965 For instance, the remote*.c targets contain CNTRL-C signal handlers
966 that propogate the QUIT event up the exception chain. ``This could
967 be a good thing or a dangerous thing.'' -- the Existential Wombat. */
969 extern NORETURN void throw_exception (enum return_reason) ATTR_NORETURN;
971 /* Call FUNC(UIOUT, FUNC_ARGS) but wrapped within an exception
972 handler. If an exception (enum return_reason) is thrown using
973 throw_exception() than all cleanups installed since
974 catch_exceptions() was entered are invoked, the (-ve) exception
975 value is then returned by catch_exceptions. If FUNC() returns
976 normally (with a postive or zero return value) then that value is
977 returned by catch_exceptions(). It is an internal_error() for
978 FUNC() to return a negative value.
980 For the period of the FUNC() call: UIOUT is installed as the output
981 builder; ERRSTRING is installed as the error/quit message; and a
982 new cleanup_chain is established. The old values are restored
983 before catch_exceptions() returns.
985 The variant catch_exceptions_with_msg() is the same as
986 catch_exceptions() but adds the ability to return an allocated
987 copy of the gdb error message. This is used when a silent error is
988 issued and the caller wants to manually issue the error message.
990 FIXME; cagney/2001-08-13: The need to override the global UIOUT
991 builder variable should just go away.
993 This function superseeds catch_errors().
995 This function uses SETJMP() and LONGJUMP(). */
998 typedef int (catch_exceptions_ftype) (struct ui_out *ui_out, void *args);
999 extern int catch_exceptions (struct ui_out *uiout,
1000 catch_exceptions_ftype *func, void *func_args,
1001 char *errstring, return_mask mask);
1002 extern int catch_exceptions_with_msg (struct ui_out *uiout,
1003 catch_exceptions_ftype *func,
1005 char *errstring, char **gdberrmsg,
1008 /* If CATCH_ERRORS_FTYPE throws an error, catch_errors() returns zero
1009 otherwize the result from CATCH_ERRORS_FTYPE is returned. It is
1010 probably useful for CATCH_ERRORS_FTYPE to always return a non-zero
1011 value. It's unfortunate that, catch_errors() does not return an
1012 indication of the exact exception that it caught - quit_flag might
1015 This function is superseeded by catch_exceptions(). */
1017 typedef int (catch_errors_ftype) (void *);
1018 extern int catch_errors (catch_errors_ftype *, void *, char *, return_mask);
1020 /* Template to catch_errors() that wraps calls to command
1023 typedef void (catch_command_errors_ftype) (char *, int);
1024 extern int catch_command_errors (catch_command_errors_ftype *func, char *command, int from_tty, return_mask);
1026 extern void warning (const char *, ...) ATTR_FORMAT (printf, 1, 2);
1028 extern void vwarning (const char *, va_list args);
1030 /* List of known OS ABIs. If you change this, make sure to update the
1031 table in osabi.c. */
1034 GDB_OSABI_UNINITIALIZED = -1, /* For struct gdbarch_info. */
1036 GDB_OSABI_UNKNOWN = 0, /* keep this zero */
1043 GDB_OSABI_FREEBSD_AOUT,
1044 GDB_OSABI_FREEBSD_ELF,
1045 GDB_OSABI_NETBSD_AOUT,
1046 GDB_OSABI_NETBSD_ELF,
1047 GDB_OSABI_OPENBSD_ELF,
1057 GDB_OSABI_ARM_EABI_V1,
1058 GDB_OSABI_ARM_EABI_V2,
1064 GDB_OSABI_INVALID /* keep this last */
1067 /* Global functions from other, non-gdb GNU thingies.
1068 Libiberty thingies are no longer declared here. We include libiberty.h
1071 #ifndef GETENV_PROVIDED
1072 extern char *getenv (const char *);
1075 /* From other system libraries */
1077 #ifdef HAVE_STDDEF_H
1081 #ifdef HAVE_STDLIB_H
1085 #define min(a, b) ((a) < (b) ? (a) : (b))
1088 #define max(a, b) ((a) > (b) ? (a) : (b))
1092 /* We take the address of fclose later, but some stdio's forget
1093 to declare this. We can't always declare it since there's
1094 no way to declare the parameters without upsetting some compiler
1097 #ifndef FCLOSE_PROVIDED
1098 extern int fclose (FILE *);
1102 extern double atof (const char *); /* X3.159-1989 4.10.1.1 */
1105 /* Various possibilities for alloca. */
1108 #define alloca __builtin_alloca
1109 #else /* Not GNU C */
1110 #ifdef HAVE_ALLOCA_H
1117 /* We need to be careful not to declare this in a way which conflicts with
1118 bison. Bison never declares it as char *, but under various circumstances
1119 (like __hpux) we need to use void *. */
1120 extern void *alloca ();
1121 #endif /* Not _AIX */
1122 #endif /* Not HAVE_ALLOCA_H */
1123 #endif /* Not GNU C */
1124 #endif /* alloca not defined */
1126 /* Is GDB multi-arch? If there's a "tm.h" file, it is not. */
1127 #ifndef GDB_MULTI_ARCH
1129 #define GDB_MULTI_ARCH GDB_MULTI_ARCH_PARTIAL
1131 #define GDB_MULTI_ARCH GDB_MULTI_ARCH_PURE
1135 /* Dynamic target-system-dependent parameters for GDB. */
1136 #include "gdbarch.h"
1138 /* Maximum size of a register. Something small, but large enough for
1139 all known ISAs. If it turns out to be too small, make it bigger. */
1141 enum { MAX_REGISTER_SIZE = 16 };
1143 /* Static target-system-dependent parameters for GDB. */
1145 /* Number of bits in a char or unsigned char for the target machine.
1146 Just like CHAR_BIT in <limits.h> but describes the target machine. */
1147 #if !defined (TARGET_CHAR_BIT)
1148 #define TARGET_CHAR_BIT 8
1151 /* If we picked up a copy of CHAR_BIT from a configuration file
1152 (which may get it by including <limits.h>) then use it to set
1153 the number of bits in a host char. If not, use the same size
1156 #if defined (CHAR_BIT)
1157 #define HOST_CHAR_BIT CHAR_BIT
1159 #define HOST_CHAR_BIT TARGET_CHAR_BIT
1162 /* The bit byte-order has to do just with numbering of bits in
1163 debugging symbols and such. Conceptually, it's quite separate
1164 from byte/word byte order. */
1166 #if !defined (BITS_BIG_ENDIAN)
1167 #define BITS_BIG_ENDIAN (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1172 extern LONGEST extract_signed_integer (const void *, int);
1174 extern ULONGEST extract_unsigned_integer (const void *, int);
1176 extern int extract_long_unsigned_integer (const void *, int, LONGEST *);
1178 extern CORE_ADDR extract_typed_address (const void *buf, struct type *type);
1180 extern void store_signed_integer (void *, int, LONGEST);
1182 extern void store_unsigned_integer (void *, int, ULONGEST);
1184 extern void store_typed_address (void *buf, struct type *type, CORE_ADDR addr);
1189 extern CORE_ADDR push_bytes (CORE_ADDR, char *, int);
1191 extern CORE_ADDR push_word (CORE_ADDR, ULONGEST);
1193 extern int watchdog;
1195 /* Hooks for alternate command interfaces. */
1197 /* The name of the interpreter if specified on the command line. */
1198 extern char *interpreter_p;
1200 /* If a given interpreter matches INTERPRETER_P then it should update
1201 command_loop_hook and init_ui_hook with the per-interpreter
1203 /* FIXME: command_loop_hook and init_ui_hook should be moved here. */
1205 struct target_waitstatus;
1206 struct cmd_list_element;
1208 /* Should the asynchronous variant of the interpreter (using the
1209 event-loop) be enabled? */
1210 extern int event_loop_p;
1212 extern void (*init_ui_hook) (char *argv0);
1213 extern void (*command_loop_hook) (void);
1214 extern void (*show_load_progress) (const char *section,
1215 unsigned long section_sent,
1216 unsigned long section_size,
1217 unsigned long total_sent,
1218 unsigned long total_size);
1219 extern void (*print_frame_info_listing_hook) (struct symtab * s,
1220 int line, int stopline,
1222 extern struct frame_info *parse_frame_specification (char *frame_exp);
1223 extern int (*query_hook) (const char *, va_list);
1224 extern void (*warning_hook) (const char *, va_list);
1225 extern void (*flush_hook) (struct ui_file * stream);
1226 extern void (*create_breakpoint_hook) (struct breakpoint * b);
1227 extern void (*delete_breakpoint_hook) (struct breakpoint * bpt);
1228 extern void (*modify_breakpoint_hook) (struct breakpoint * bpt);
1229 extern void (*interactive_hook) (void);
1230 extern void (*registers_changed_hook) (void);
1231 extern void (*readline_begin_hook) (char *,...);
1232 extern char *(*readline_hook) (char *);
1233 extern void (*readline_end_hook) (void);
1234 extern void (*register_changed_hook) (int regno);
1235 extern void (*memory_changed_hook) (CORE_ADDR addr, int len);
1236 extern void (*context_hook) (int);
1237 extern ptid_t (*target_wait_hook) (ptid_t ptid,
1238 struct target_waitstatus * status);
1240 extern void (*attach_hook) (void);
1241 extern void (*detach_hook) (void);
1242 extern void (*call_command_hook) (struct cmd_list_element * c,
1243 char *cmd, int from_tty);
1245 extern void (*set_hook) (struct cmd_list_element * c);
1247 extern NORETURN void (*error_hook) (void) ATTR_NORETURN;
1249 extern void (*error_begin_hook) (void);
1251 extern int (*ui_load_progress_hook) (const char *section, unsigned long num);
1254 /* Inhibit window interface if non-zero. */
1256 extern int use_windows;
1258 /* Symbolic definitions of filename-related things. */
1259 /* FIXME, this doesn't work very well if host and executable
1260 filesystems conventions are different. */
1262 #ifndef DIRNAME_SEPARATOR
1263 #define DIRNAME_SEPARATOR ':'
1266 #ifndef SLASH_STRING
1267 #define SLASH_STRING "/"
1272 # define GLOBAL_CURDIR
1275 /* Provide default definitions of PIDGET, TIDGET, and MERGEPID.
1276 The name ``TIDGET'' is a historical accident. Many uses of TIDGET
1277 in the code actually refer to a lightweight process id, i.e,
1278 something that can be considered a process id in its own right for
1279 certain purposes. */
1282 #define PIDGET(PTID) (ptid_get_pid (PTID))
1283 #define TIDGET(PTID) (ptid_get_lwp (PTID))
1284 #define MERGEPID(PID, TID) ptid_build (PID, TID, 0)
1287 /* Define well known filenos if the system does not define them. */
1288 #ifndef STDIN_FILENO
1289 #define STDIN_FILENO 0
1291 #ifndef STDOUT_FILENO
1292 #define STDOUT_FILENO 1
1294 #ifndef STDERR_FILENO
1295 #define STDERR_FILENO 2
1298 /* If this definition isn't overridden by the header files, assume
1299 that isatty and fileno exist on this system. */
1301 #define ISATTY(FP) (isatty (fileno (FP)))
1304 /* Ensure that V is aligned to an N byte boundary (B's assumed to be a
1305 power of 2). Round up/down when necessary. Examples of correct
1308 addr = align_up (addr, 8); -- VALUE needs 8 byte alignment
1309 write_memory (addr, value, len);
1314 sp = align_down (sp - len, 16); -- Keep SP 16 byte aligned
1315 write_memory (sp, value, len);
1317 Note that uses such as:
1319 write_memory (addr, value, len);
1320 addr += align_up (len, 8);
1324 sp -= align_up (len, 8);
1325 write_memory (sp, value, len);
1327 are typically not correct as they don't ensure that the address (SP
1328 or ADDR) is correctly aligned (relying on previous alignment to
1329 keep things right). This is also why the methods are called
1330 "align_..." instead of "round_..." as the latter reads better with
1331 this incorrect coding style. */
1333 extern ULONGEST align_up (ULONGEST v, int n);
1334 extern ULONGEST align_down (ULONGEST v, int n);
1336 #endif /* #ifndef DEFS_H */