PTR vs. void*. Sorry.
[binutils-gdb.git] / gdb / defs.h
1 /* Basic, host-specific, and target-specific definitions for GDB.
2 Copyright (C) 1986, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #if !defined (DEFS_H)
21 #define DEFS_H 1
22
23 #include <stdio.h>
24
25 /* First include ansidecl.h so we can use the various macro definitions
26 in all subsequent file inclusions. FIXME: This inclusion can now
27 be removed from all files that include defs.h */
28
29 #include "ansidecl.h"
30
31 /* We could use the EXFUN macro in ansidecl.h to handle prototypes, but
32 the name is misleading the the result is ugly. So just define a simple
33 macro to handle the parameter lists. */
34
35 #ifdef __STDC__
36 #define PARAMS(paramlist) paramlist
37 #else
38 #define PARAMS(paramlist) ()
39 #endif
40
41 /* An address in the program being debugged. Host byte order. */
42 typedef unsigned int CORE_ADDR;
43
44 #define min(a, b) ((a) < (b) ? (a) : (b))
45 #define max(a, b) ((a) > (b) ? (a) : (b))
46
47 /* The character C++ uses to build identifiers that must be unique from
48 the program's identifiers (such as $this and $$vptr). */
49 #define CPLUS_MARKER '$' /* May be overridden to '.' for SysV */
50
51 #include <errno.h> /* System call error return status */
52
53 extern int quit_flag;
54 extern int immediate_quit;
55
56 extern void
57 quit PARAMS ((void));
58
59 #define QUIT { if (quit_flag) quit (); }
60
61 /* Notes on classes: class_alias is for alias commands which are not
62 abbreviations of the original command. */
63
64 enum command_class
65 {
66 /* Special args to help_list */
67 all_classes = -2, all_commands = -1,
68 /* Classes of commands */
69 no_class = -1, class_run = 0, class_vars, class_stack,
70 class_files, class_support, class_info, class_breakpoint,
71 class_alias, class_obscure, class_user
72 };
73
74 /* the cleanup list records things that have to be undone
75 if an error happens (descriptors to be closed, memory to be freed, etc.)
76 Each link in the chain records a function to call and an
77 argument to give it.
78
79 Use make_cleanup to add an element to the cleanup chain.
80 Use do_cleanups to do all cleanup actions back to a given
81 point in the chain. Use discard_cleanups to remove cleanups
82 from the chain back to a given point, not doing them. */
83
84 struct cleanup
85 {
86 struct cleanup *next;
87 void (*function) PARAMS ((PTR));
88 PTR arg;
89 };
90
91 /* From blockframe.c */
92
93 extern int
94 inside_entry_func PARAMS ((CORE_ADDR));
95
96 extern int
97 inside_entry_file PARAMS ((CORE_ADDR addr));
98
99 extern int
100 inside_main_func PARAMS ((CORE_ADDR pc));
101
102 /* From cplus-dem.c */
103
104 extern char *
105 cplus_demangle PARAMS ((const char *, int));
106
107 extern char *
108 cplus_mangle_opname PARAMS ((char *, int));
109
110 /* From libmmalloc.a (memory mapped malloc library) */
111
112 extern PTR
113 mmalloc_attach PARAMS ((int, PTR));
114
115 extern PTR
116 mmalloc_detach PARAMS ((PTR));
117
118 extern PTR
119 mmalloc PARAMS ((PTR, long));
120
121 extern PTR
122 mrealloc PARAMS ((PTR, PTR, long));
123
124 extern void
125 mfree PARAMS ((PTR, PTR));
126
127 extern int
128 mmalloc_setkey PARAMS ((PTR, int, PTR));
129
130 extern PTR
131 mmalloc_getkey PARAMS ((PTR, int));
132
133 /* From utils.c */
134
135 extern char *
136 safe_strerror PARAMS ((int));
137
138 extern char *
139 safe_strsignal PARAMS ((int));
140
141 extern void
142 init_malloc PARAMS ((PTR));
143
144 extern void
145 request_quit PARAMS ((int));
146
147 extern void
148 do_cleanups PARAMS ((struct cleanup *));
149
150 extern void
151 discard_cleanups PARAMS ((struct cleanup *));
152
153 /* The bare make_cleanup function is one of those rare beasts that
154 takes almost any type of function as the first arg and anything that
155 will fit in a "void *" as the second arg.
156
157 Should be, once all calls and called-functions are cleaned up:
158 extern struct cleanup *
159 make_cleanup PARAMS ((void (*function) (PTR), PTR));
160
161 Until then, lint and/or various type-checking compiler options will
162 complain about make_cleanup calls. It'd be wrong to just cast things,
163 since the type actually passed when the function is called would be
164 wrong. */
165
166 extern struct cleanup *
167 make_cleanup ();
168
169 extern struct cleanup *
170 save_cleanups PARAMS ((void));
171
172 extern void
173 restore_cleanups PARAMS ((struct cleanup *));
174
175 extern void
176 free_current_contents PARAMS ((char **));
177
178 extern void
179 null_cleanup PARAMS ((char **));
180
181 extern int
182 myread PARAMS ((int, char *, int));
183
184 extern int
185 query ();
186
187 extern void
188 wrap_here PARAMS ((char *));
189
190 extern void
191 reinitialize_more_filter PARAMS ((void));
192
193 extern int
194 print_insn PARAMS ((CORE_ADDR, FILE *));
195
196 extern void
197 fputs_filtered PARAMS ((const char *, FILE *));
198
199 extern void
200 puts_filtered PARAMS ((char *));
201
202 extern void
203 fprintf_filtered ();
204
205 extern void
206 printf_filtered ();
207
208 extern void
209 print_spaces PARAMS ((int, FILE *));
210
211 extern void
212 print_spaces_filtered PARAMS ((int, FILE *));
213
214 extern char *
215 n_spaces PARAMS ((int));
216
217 extern void
218 printchar PARAMS ((int, FILE *, int));
219
220 extern void
221 fprint_symbol PARAMS ((FILE *, char *));
222
223 extern void
224 fputs_demangled PARAMS ((char *, FILE *, int));
225
226 extern void
227 perror_with_name PARAMS ((char *));
228
229 extern void
230 print_sys_errmsg PARAMS ((char *, int));
231
232 /* From regex.c */
233
234 extern char *
235 re_comp PARAMS ((char *));
236
237 /* From symfile.c */
238
239 extern void
240 symbol_file_command PARAMS ((char *, int));
241
242 /* From main.c */
243
244 extern char *
245 gdb_readline PARAMS ((char *));
246
247 extern char *
248 command_line_input PARAMS ((char *, int));
249
250 extern void
251 print_prompt PARAMS ((void));
252
253 extern int
254 batch_mode PARAMS ((void));
255
256 extern int
257 input_from_terminal_p PARAMS ((void));
258
259 extern int
260 catch_errors PARAMS ((int (*) (char *), char *, char *));
261
262 /* From printcmd.c */
263
264 extern void
265 set_next_address PARAMS ((CORE_ADDR));
266
267 extern void
268 print_address_symbolic PARAMS ((CORE_ADDR, FILE *, int, char *));
269
270 extern void
271 print_address PARAMS ((CORE_ADDR, FILE *));
272
273 /* From source.c */
274
275 extern int
276 openp PARAMS ((char *, int, char *, int, int, char **));
277
278 extern void
279 mod_path PARAMS ((char *, char **));
280
281 extern void
282 directory_command PARAMS ((char *, int));
283
284 extern void
285 init_source_path PARAMS ((void));
286
287 /* From findvar.c */
288
289 extern int
290 read_relative_register_raw_bytes PARAMS ((int, char *));
291
292 /* From readline (but not in any readline .h files). */
293
294 extern char *
295 tilde_expand PARAMS ((char *));
296
297 /* Structure for saved commands lines
298 (for breakpoints, defined commands, etc). */
299
300 struct command_line
301 {
302 struct command_line *next;
303 char *line;
304 };
305
306 extern struct command_line *
307 read_command_lines PARAMS ((void));
308
309 extern void
310 free_command_lines PARAMS ((struct command_line **));
311
312 /* String containing the current directory (what getwd would return). */
313
314 extern char *current_directory;
315
316 /* Default radixes for input and output. Only some values supported. */
317 extern unsigned input_radix;
318 extern unsigned output_radix;
319
320 /* Baud rate specified for communication with serial target systems. */
321 extern char *baud_rate;
322
323 /* Languages represented in the symbol table and elsewhere. */
324
325 enum language
326 {
327 language_unknown, /* Language not known */
328 language_auto, /* Placeholder for automatic setting */
329 language_c, /* C */
330 language_cplus, /* C++ */
331 language_m2 /* Modula-2 */
332 };
333
334 /* Return a format string for printf that will print a number in the local
335 (language-specific) hexadecimal format. Result is static and is
336 overwritten by the next call. local_hex_format_custom takes printf
337 options like "08" or "l" (to produce e.g. %08x or %lx). */
338
339 #define local_hex_format() (current_language->la_hex_format)
340
341 extern char *
342 local_hex_format_custom PARAMS ((char *)); /* language.c */
343
344 /* Return a string that contains a number formatted in the local
345 (language-specific) hexadecimal format. Result is static and is
346 overwritten by the next call. local_hex_string_custom takes printf
347 options like "08" or "l". */
348
349 extern char *
350 local_hex_string PARAMS ((int)); /* language.c */
351
352 extern char *
353 local_hex_string_custom PARAMS ((int, char *)); /* language.c */
354
355 \f
356 /* Host machine definition. This will be a symlink to one of the
357 xm-*.h files, built by the `configure' script. */
358
359 #include "xm.h"
360
361 /* If the xm.h file did not define the mode string used to open the
362 files, assume that binary files are opened the same way as text
363 files */
364 #ifndef FOPEN_RB
365 #include "fopen-same.h"
366 #endif
367
368 /*
369 * Allow things in gdb to be declared "const". If compiling ANSI, it
370 * just works. If compiling with gcc but non-ansi, redefine to __const__.
371 * If non-ansi, non-gcc, then eliminate "const" entirely, making those
372 * objects be read-write rather than read-only.
373 */
374
375 #ifndef const
376 #ifndef __STDC__
377 # ifdef __GNUC__
378 # define const __const__
379 # else
380 # define const /*nothing*/
381 # endif /* GNUC */
382 #endif /* STDC */
383 #endif /* const */
384
385 #ifndef volatile
386 #ifndef __STDC__
387 # ifdef __GNUC__
388 # define volatile __volatile__
389 # else
390 # define volatile /*nothing*/
391 # endif /* GNUC */
392 #endif /* STDC */
393 #endif /* volatile */
394
395 /* Some compilers (many AT&T SVR4 compilers for instance), do not accept
396 declarations of functions that never return (exit for instance) as
397 "volatile void". For such compilers "NORETURN" can be defined away
398 to keep them happy */
399
400 #ifndef NORETURN
401 # define NORETURN volatile
402 #endif
403
404 /* Defaults for system-wide constants (if not defined by xm.h, we fake it). */
405
406 #if !defined (UINT_MAX)
407 #define UINT_MAX 0xffffffff
408 #endif
409
410 #if !defined (LONG_MAX)
411 #define LONG_MAX 0x7fffffff
412 #endif
413
414 #if !defined (INT_MAX)
415 #define INT_MAX 0x7fffffff
416 #endif
417
418 #if !defined (INT_MIN)
419 /* Two's complement, 32 bit. */
420 #define INT_MIN -0x80000000
421 #endif
422
423 /* Number of bits in a char or unsigned char for the target machine.
424 Just like CHAR_BIT in <limits.h> but describes the target machine. */
425 #if !defined (TARGET_CHAR_BIT)
426 #define TARGET_CHAR_BIT 8
427 #endif
428
429 /* Number of bits in a short or unsigned short for the target machine. */
430 #if !defined (TARGET_SHORT_BIT)
431 #define TARGET_SHORT_BIT (sizeof (short) * TARGET_CHAR_BIT)
432 #endif
433
434 /* Number of bits in an int or unsigned int for the target machine. */
435 #if !defined (TARGET_INT_BIT)
436 #define TARGET_INT_BIT (sizeof (int) * TARGET_CHAR_BIT)
437 #endif
438
439 /* Number of bits in a long or unsigned long for the target machine. */
440 #if !defined (TARGET_LONG_BIT)
441 #define TARGET_LONG_BIT (sizeof (long) * TARGET_CHAR_BIT)
442 #endif
443
444 /* Number of bits in a long long or unsigned long long for the target machine. */
445 #if !defined (TARGET_LONG_LONG_BIT)
446 #define TARGET_LONG_LONG_BIT (2 * TARGET_LONG_BIT)
447 #endif
448
449 /* Number of bits in a float for the target machine. */
450 #if !defined (TARGET_FLOAT_BIT)
451 #define TARGET_FLOAT_BIT (sizeof (float) * TARGET_CHAR_BIT)
452 #endif
453
454 /* Number of bits in a double for the target machine. */
455 #if !defined (TARGET_DOUBLE_BIT)
456 #define TARGET_DOUBLE_BIT (sizeof (double) * TARGET_CHAR_BIT)
457 #endif
458
459 /* Number of bits in a long double for the target machine. */
460 #if !defined (TARGET_LONG_DOUBLE_BIT)
461 #define TARGET_LONG_DOUBLE_BIT (2 * TARGET_DOUBLE_BIT)
462 #endif
463
464 /* Number of bits in a "complex" for the target machine. */
465 #if !defined (TARGET_COMPLEX_BIT)
466 #define TARGET_COMPLEX_BIT (2 * TARGET_FLOAT_BIT)
467 #endif
468
469 /* Number of bits in a "double complex" for the target machine. */
470 #if !defined (TARGET_DOUBLE_COMPLEX_BIT)
471 #define TARGET_DOUBLE_COMPLEX_BIT (2 * TARGET_DOUBLE_BIT)
472 #endif
473
474 /* Number of bits in a pointer for the target machine */
475 #if !defined (TARGET_PTR_BIT)
476 #define TARGET_PTR_BIT TARGET_INT_BIT
477 #endif
478
479 /* Convert a LONGEST to an int. This is used in contexts (e.g. number
480 of arguments to a function, number in a value history, register
481 number, etc.) where the value must not be larger than can fit
482 in an int. */
483 #if !defined (longest_to_int)
484 #if defined (LONG_LONG)
485 #define longest_to_int(x) (((x) > INT_MAX || (x) < INT_MIN) \
486 ? error ("Value out of range.") : (int) (x))
487 #else /* No LONG_LONG. */
488 /* Assume sizeof (int) == sizeof (long). */
489 #define longest_to_int(x) ((int) (x))
490 #endif /* No LONG_LONG. */
491 #endif /* No longest_to_int. */
492
493 /* This should not be a typedef, because "unsigned LONGEST" needs
494 to work. LONG_LONG is defined if the host has "long long". */
495
496 #ifndef LONGEST
497 # ifdef LONG_LONG
498 # define LONGEST long long
499 # else
500 # define LONGEST long
501 # endif
502 #endif
503
504 /* Assorted functions we can declare, now that const and volatile are
505 defined. */
506
507 extern char *
508 savestring PARAMS ((const char *, int));
509
510 extern char *
511 msavestring PARAMS ((void *, const char *, int));
512
513 extern char *
514 strsave PARAMS ((const char *));
515
516 extern char *
517 mstrsave PARAMS ((void *, const char *));
518
519 extern char *
520 concat PARAMS ((char *, ...));
521
522 extern PTR
523 xmalloc PARAMS ((long));
524
525 extern PTR
526 xrealloc PARAMS ((PTR, long));
527
528 extern PTR
529 xmmalloc PARAMS ((PTR, long));
530
531 extern PTR
532 xmrealloc PARAMS ((PTR, PTR, long));
533
534 extern PTR
535 mmalloc PARAMS ((PTR, long));
536
537 extern PTR
538 mrealloc PARAMS ((PTR, PTR, long));
539
540 extern void
541 mfree PARAMS ((PTR, PTR));
542
543 extern int
544 mmcheck PARAMS ((PTR, void (*) (void)));
545
546 extern int
547 mmtrace PARAMS ((void));
548
549 extern int
550 parse_escape PARAMS ((char **));
551
552 extern char *reg_names[];
553
554 extern NORETURN void /* Does not return to the caller. */
555 error ();
556
557 extern NORETURN void /* Does not return to the caller. */
558 fatal ();
559
560 extern NORETURN void /* Not specified as volatile in ... */
561 exit PARAMS ((int)); /* 4.10.4.3 */
562
563 extern NORETURN void /* Does not return to the caller. */
564 nomem PARAMS ((long));
565
566 extern NORETURN void /* Does not return to the caller. */
567 return_to_top_level PARAMS ((void));
568
569 extern void
570 warning_setup PARAMS ((void));
571
572 extern void
573 warning ();
574
575 /* Global functions from other, non-gdb GNU thingies (libiberty for
576 instance) */
577
578 extern char *
579 basename PARAMS ((char *));
580
581 extern char *
582 getenv PARAMS ((CONST char *));
583
584 extern char **
585 buildargv PARAMS ((char *));
586
587 extern void
588 freeargv PARAMS ((char **));
589
590 extern char *
591 strerrno PARAMS ((int));
592
593 extern char *
594 strsigno PARAMS ((int));
595
596 extern int
597 errno_max PARAMS ((void));
598
599 extern int
600 signo_max PARAMS ((void));
601
602 extern int
603 strtoerrno PARAMS ((char *));
604
605 extern int
606 strtosigno PARAMS ((char *));
607
608 extern char *
609 strsignal PARAMS ((int));
610
611 /* From other system libraries */
612
613 #ifndef PSIGNAL_IN_SIGNAL_H
614 extern void
615 psignal PARAMS ((unsigned, char *));
616 #endif
617
618 /* For now, we can't include <stdlib.h> because it conflicts with
619 "../include/getopt.h". (FIXME)
620
621 However, if a function is defined in the ANSI C standard and a prototype
622 for that function is defined and visible in any header file in an ANSI
623 conforming environment, then that prototype must match the definition in
624 the ANSI standard. So we can just duplicate them here without conflict,
625 since they must be the same in all conforming ANSI environments. If
626 these cause problems, then the environment is not ANSI conformant. */
627
628 #ifdef __STDC__
629 #include <stddef.h>
630 #endif
631
632 extern int
633 fclose PARAMS ((FILE *stream)); /* 4.9.5.1 */
634
635 extern void
636 perror PARAMS ((const char *)); /* 4.9.10.4 */
637
638 extern double
639 atof PARAMS ((const char *nptr)); /* 4.10.1.1 */
640
641 #ifndef MALLOC_INCOMPATIBLE
642
643 extern PTR
644 malloc PARAMS ((size_t size)); /* 4.10.3.3 */
645
646 extern PTR
647 realloc PARAMS ((void *ptr, size_t size)); /* 4.10.3.4 */
648
649 extern void
650 free PARAMS ((void *)); /* 4.10.3.2 */
651
652 #endif /* MALLOC_INCOMPATIBLE */
653
654 extern PTR
655 qsort PARAMS ((void *base, size_t nmemb, /* 4.10.5.2 */
656 size_t size,
657 int (*comp)(const void *, const void *)));
658
659 extern char *
660 strchr PARAMS ((const char *, int)); /* 4.11.5.2 */
661
662 extern char *
663 strrchr PARAMS ((const char *, int)); /* 4.11.5.5 */
664
665 extern char *
666 strstr PARAMS ((const char *, const char *)); /* 4.11.5.7 */
667
668 extern char *
669 strtok PARAMS ((char *, const char *)); /* 4.11.5.8 */
670
671 extern char *
672 strerror PARAMS ((int)); /* 4.11.6.2 */
673
674 /* Various possibilities for alloca. */
675 #ifndef alloca
676 # ifdef __GNUC__
677 # define alloca __builtin_alloca
678 # else
679 # ifdef sparc
680 # include <alloca.h>
681 # endif
682 extern char *alloca ();
683 # endif
684 #endif
685
686 /* TARGET_BYTE_ORDER and HOST_BYTE_ORDER should be defined to one of these. */
687
688 #if !defined (BIG_ENDIAN)
689 #define BIG_ENDIAN 4321
690 #endif
691
692 #if !defined (LITTLE_ENDIAN)
693 #define LITTLE_ENDIAN 1234
694 #endif
695
696 /* Target-system-dependent parameters for GDB.
697
698 The standard thing is to include defs.h. However, files that are
699 specific to a particular target can define TM_FILE_OVERRIDE before
700 including defs.h, then can include any particular tm-file they desire. */
701
702 /* Target machine definition. This will be a symlink to one of the
703 tm-*.h files, built by the `configure' script. */
704
705 #ifndef TM_FILE_OVERRIDE
706 #include "tm.h"
707 #endif
708
709 /* The bit byte-order has to do just with numbering of bits in
710 debugging symbols and such. Conceptually, it's quite separate
711 from byte/word byte order. */
712
713 #if !defined (BITS_BIG_ENDIAN)
714 #if TARGET_BYTE_ORDER == BIG_ENDIAN
715 #define BITS_BIG_ENDIAN 1
716 #endif /* Big endian. */
717
718 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
719 #define BITS_BIG_ENDIAN 0
720 #endif /* Little endian. */
721 #endif /* BITS_BIG_ENDIAN not defined. */
722
723 /* Swap LEN bytes at BUFFER between target and host byte-order. */
724 #if TARGET_BYTE_ORDER == HOST_BYTE_ORDER
725 #define SWAP_TARGET_AND_HOST(buffer,len)
726 #else /* Target and host byte order differ. */
727 #define SWAP_TARGET_AND_HOST(buffer,len) \
728 { \
729 char tmp; \
730 char *p = (char *)(buffer); \
731 char *q = ((char *)(buffer)) + len - 1; \
732 for (; p < q; p++, q--) \
733 { \
734 tmp = *q; \
735 *q = *p; \
736 *p = tmp; \
737 } \
738 }
739 #endif /* Target and host byte order differ. */
740
741 /* On some machines there are bits in addresses which are not really
742 part of the address, but are used by the kernel, the hardware, etc.
743 for special purposes. ADDR_BITS_REMOVE takes out any such bits
744 so we get a "real" address such as one would find in a symbol
745 table. ADDR_BITS_SET sets those bits the way the system wants
746 them. */
747 #if !defined (ADDR_BITS_REMOVE)
748 #define ADDR_BITS_REMOVE(addr) (addr)
749 #define ADDR_BITS_SET(addr) (addr)
750 #endif /* No ADDR_BITS_REMOVE. */
751
752 /* From valops.c */
753
754 extern CORE_ADDR
755 push_bytes PARAMS ((CORE_ADDR, char *, int));
756
757 /* In some modules, we don't have a definition of REGISTER_TYPE yet, so we
758 must avoid prototyping this function for now. FIXME. Should be:
759 extern CORE_ADDR
760 push_word PARAMS ((CORE_ADDR, REGISTER_TYPE));
761 */
762 extern CORE_ADDR
763 push_word ();
764
765 #endif /* !defined (DEFS_H) */