e5b6c7878b11e96f0afd9de632f4a6f289b5ee23
[binutils-gdb.git] / gdb / defs.h
1 /* *INDENT-OFF* */ /* ATTRIBUTE_PRINTF confuses indent, avoid running it
2 for now. */
3 /* Basic, host-specific, and target-specific definitions for GDB.
4 Copyright (C) 1986-2022 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #ifndef DEFS_H
22 #define DEFS_H
23
24 #ifdef GDBSERVER
25 # error gdbserver should not include gdb/defs.h
26 #endif
27
28 #include "gdbsupport/common-defs.h"
29
30 #undef PACKAGE
31 #undef PACKAGE_NAME
32 #undef PACKAGE_VERSION
33 #undef PACKAGE_STRING
34 #undef PACKAGE_TARNAME
35
36 #include <config.h>
37 #include "bfd.h"
38
39 #include <sys/types.h>
40 #include <limits.h>
41
42 /* The libdecnumber library, on which GDB depends, includes a header file
43 called gstdint.h instead of relying directly on stdint.h. GDB, on the
44 other hand, includes stdint.h directly, relying on the fact that gnulib
45 generates a copy if the system doesn't provide one or if it is missing
46 some features. Unfortunately, gstdint.h and stdint.h cannot be included
47 at the same time, which may happen when we include a file from
48 libdecnumber.
49
50 The following macro definition effectively prevents the inclusion of
51 gstdint.h, as all the definitions it provides are guarded against
52 the GCC_GENERATED_STDINT_H macro. We already have gnulib/stdint.h
53 included, so it's ok to blank out gstdint.h. */
54 #define GCC_GENERATED_STDINT_H 1
55
56 #include <unistd.h>
57
58 #include <fcntl.h>
59
60 #include "gdb_wchar.h"
61
62 #include "ui-file.h"
63
64 #include "gdbsupport/host-defs.h"
65 #include "gdbsupport/enum-flags.h"
66 #include "gdbsupport/array-view.h"
67
68 /* Scope types enumerator. List the types of scopes the compiler will
69 accept. */
70
71 enum compile_i_scope_types
72 {
73 COMPILE_I_INVALID_SCOPE,
74
75 /* A simple scope. Wrap an expression into a simple scope that
76 takes no arguments, returns no value, and uses the generic
77 function name "_gdb_expr". */
78
79 COMPILE_I_SIMPLE_SCOPE,
80
81 /* Do not wrap the expression,
82 it has to provide function "_gdb_expr" on its own. */
83 COMPILE_I_RAW_SCOPE,
84
85 /* A printable expression scope. Wrap an expression into a scope
86 suitable for the "compile print" command. It uses the generic
87 function name "_gdb_expr". COMPILE_I_PRINT_ADDRESS_SCOPE variant
88 is the usual one, taking address of the object.
89 COMPILE_I_PRINT_VALUE_SCOPE is needed for arrays where the array
90 name already specifies its address. See get_out_value_type. */
91 COMPILE_I_PRINT_ADDRESS_SCOPE,
92 COMPILE_I_PRINT_VALUE_SCOPE,
93 };
94
95
96 template<typename T>
97 using RequireLongest = gdb::Requires<gdb::Or<std::is_same<T, LONGEST>,
98 std::is_same<T, ULONGEST>>>;
99
100 /* Just in case they're not defined in stdio.h. */
101
102 #ifndef SEEK_SET
103 #define SEEK_SET 0
104 #endif
105 #ifndef SEEK_CUR
106 #define SEEK_CUR 1
107 #endif
108
109 /* The O_BINARY flag is defined in fcntl.h on some non-Posix platforms.
110 It is used as an access modifier in calls to open(), where it acts
111 similarly to the "b" character in fopen()'s MODE argument. On Posix
112 platforms it should be a no-op, so it is defined as 0 here. This
113 ensures that the symbol may be used freely elsewhere in gdb. */
114
115 #ifndef O_BINARY
116 #define O_BINARY 0
117 #endif
118
119 #include "hashtab.h"
120
121 /* * System root path, used to find libraries etc. */
122 extern std::string gdb_sysroot;
123
124 /* * GDB datadir, used to store data files. */
125 extern std::string gdb_datadir;
126
127 /* * If not empty, the possibly relocated path to python's "lib" directory
128 specified with --with-python. */
129 extern std::string python_libdir;
130
131 /* * Search path for separate debug files. */
132 extern std::string debug_file_directory;
133
134 /* GDB's SIGINT handler basically sets a flag; code that might take a
135 long time before it gets back to the event loop, and which ought to
136 be interruptible, checks this flag using the QUIT macro, which, if
137 GDB has the terminal, throws a quit exception.
138
139 In addition to setting a flag, the SIGINT handler also marks a
140 select/poll-able file descriptor as read-ready. That is used by
141 interruptible_select in order to support interrupting blocking I/O
142 in a race-free manner.
143
144 These functions use the extension_language_ops API to allow extension
145 language(s) and GDB SIGINT handling to coexist seamlessly. */
146
147 /* * Evaluate to non-zero if the quit flag is set, zero otherwise. This
148 will clear the quit flag as a side effect. */
149 extern int check_quit_flag (void);
150 /* * Set the quit flag. */
151 extern void set_quit_flag (void);
152
153 /* The current quit handler (and its type). This is called from the
154 QUIT macro. See default_quit_handler below for default behavior.
155 Parts of GDB temporarily override this to e.g., completely suppress
156 Ctrl-C because it would not be safe to throw. E.g., normally, you
157 wouldn't want to quit between a RSP command and its response, as
158 that would break the communication with the target, but you may
159 still want to intercept the Ctrl-C and offer to disconnect if the
160 user presses Ctrl-C multiple times while the target is stuck
161 waiting for the wedged remote stub. */
162 typedef void (quit_handler_ftype) (void);
163 extern quit_handler_ftype *quit_handler;
164
165 /* The default quit handler. Checks whether Ctrl-C was pressed, and
166 if so:
167
168 - If GDB owns the terminal, throws a quit exception.
169
170 - If GDB does not own the terminal, forwards the Ctrl-C to the
171 target.
172 */
173 extern void default_quit_handler (void);
174
175 /* Flag that function quit should call quit_force. */
176 extern volatile int sync_quit_force_run;
177
178 extern void quit (void);
179
180 /* Helper for the QUIT macro. */
181
182 extern void maybe_quit (void);
183
184 /* Check whether a Ctrl-C was typed, and if so, call the current quit
185 handler. */
186 #define QUIT maybe_quit ()
187
188 /* Set the serial event associated with the quit flag. */
189 extern void quit_serial_event_set (void);
190
191 /* Clear the serial event associated with the quit flag. */
192 extern void quit_serial_event_clear (void);
193
194 /* * Languages represented in the symbol table and elsewhere.
195 This should probably be in language.h, but since enum's can't
196 be forward declared to satisfy opaque references before their
197 actual definition, needs to be here.
198
199 The constants here are in priority order. In particular,
200 demangling is attempted according to this order.
201
202 Note that there's ambiguity between the mangling schemes of some of
203 these languages, so some symbols could be successfully demangled by
204 several languages. For that reason, the constants here are sorted
205 in the order we'll attempt demangling them. For example: Rust uses
206 C++ mangling, so must come after C++; Ada must come last (see
207 ada_sniff_from_mangled_name). (Keep this order in sync with the
208 'languages' array in language.c.) */
209
210 enum language
211 {
212 language_unknown, /* Language not known */
213 language_auto, /* Placeholder for automatic setting */
214 language_c, /* C */
215 language_objc, /* Objective-C */
216 language_cplus, /* C++ */
217 language_d, /* D */
218 language_go, /* Go */
219 language_fortran, /* Fortran */
220 language_m2, /* Modula-2 */
221 language_asm, /* Assembly language */
222 language_pascal, /* Pascal */
223 language_opencl, /* OpenCL */
224 language_rust, /* Rust */
225 language_minimal, /* All other languages, minimal support only */
226 language_ada, /* Ada */
227 nr_languages
228 };
229
230 /* The number of bits needed to represent all languages, with enough
231 padding to allow for reasonable growth. */
232 #define LANGUAGE_BITS 5
233 gdb_static_assert (nr_languages <= (1 << LANGUAGE_BITS));
234
235 /* The number of bytes needed to represent all languages. */
236 #define LANGUAGE_BYTES ((LANGUAGE_BITS + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT)
237
238 enum precision_type
239 {
240 single_precision,
241 double_precision,
242 unspecified_precision
243 };
244
245 /* * A generic, not quite boolean, enumeration. This is used for
246 set/show commands in which the options are on/off/automatic. */
247 enum auto_boolean
248 {
249 AUTO_BOOLEAN_TRUE,
250 AUTO_BOOLEAN_FALSE,
251 AUTO_BOOLEAN_AUTO
252 };
253
254 /* * Potential ways that a function can return a value of a given
255 type. */
256
257 enum return_value_convention
258 {
259 /* * Where the return value has been squeezed into one or more
260 registers. */
261 RETURN_VALUE_REGISTER_CONVENTION,
262 /* * Commonly known as the "struct return convention". The caller
263 passes an additional hidden first parameter to the caller. That
264 parameter contains the address at which the value being returned
265 should be stored. While typically, and historically, used for
266 large structs, this is convention is applied to values of many
267 different types. */
268 RETURN_VALUE_STRUCT_CONVENTION,
269 /* * Like the "struct return convention" above, but where the ABI
270 guarantees that the called function stores the address at which
271 the value being returned is stored in a well-defined location,
272 such as a register or memory slot in the stack frame. Don't use
273 this if the ABI doesn't explicitly guarantees this. */
274 RETURN_VALUE_ABI_RETURNS_ADDRESS,
275 /* * Like the "struct return convention" above, but where the ABI
276 guarantees that the address at which the value being returned is
277 stored will be available in a well-defined location, such as a
278 register or memory slot in the stack frame. Don't use this if
279 the ABI doesn't explicitly guarantees this. */
280 RETURN_VALUE_ABI_PRESERVES_ADDRESS,
281 };
282
283 /* Needed for various prototypes */
284
285 struct symtab;
286 struct breakpoint;
287 struct frame_info;
288 struct gdbarch;
289 struct value;
290
291 /* From main.c. */
292
293 /* This really belong in utils.c (path-utils.c?), but it references some
294 globals that are currently only available to main.c. */
295 extern std::string relocate_gdb_directory (const char *initial, bool relocatable);
296
297 \f
298 /* Annotation stuff. */
299
300 extern int annotation_level; /* in stack.c */
301 \f
302
303 /* From regex.c or libc. BSD 4.4 declares this with the argument type as
304 "const char *" in unistd.h, so we can't declare the argument
305 as "char *". */
306
307 EXTERN_C char *re_comp (const char *);
308
309 /* From symfile.c */
310
311 extern void symbol_file_command (const char *, int);
312
313 /* From top.c */
314
315 typedef void initialize_file_ftype (void);
316
317 extern char *gdb_readline_wrapper (const char *);
318
319 extern const char *command_line_input (const char *, const char *);
320
321 extern void print_prompt (void);
322
323 struct ui;
324
325 extern bool info_verbose;
326
327 /* From printcmd.c */
328
329 extern void set_next_address (struct gdbarch *, CORE_ADDR);
330
331 extern int print_address_symbolic (struct gdbarch *, CORE_ADDR,
332 struct ui_file *, int,
333 const char *);
334
335 extern void print_address (struct gdbarch *, CORE_ADDR, struct ui_file *);
336 extern const char *pc_prefix (CORE_ADDR);
337
338 /* From exec.c */
339
340 /* * Process memory area starting at ADDR with length SIZE. Area is
341 readable iff READ is non-zero, writable if WRITE is non-zero,
342 executable if EXEC is non-zero. Area is possibly changed against
343 its original file based copy if MODIFIED is non-zero. DATA is
344 passed without changes from a caller. */
345
346 typedef int (*find_memory_region_ftype) (CORE_ADDR addr, unsigned long size,
347 int read, int write, int exec,
348 int modified, bool memory_tagged,
349 void *data);
350
351 /* * Possible lvalue types. Like enum language, this should be in
352 value.h, but needs to be here for the same reason. */
353
354 enum lval_type
355 {
356 /* * Not an lval. */
357 not_lval,
358 /* * In memory. */
359 lval_memory,
360 /* * In a register. Registers are relative to a frame. */
361 lval_register,
362 /* * In a gdb internal variable. */
363 lval_internalvar,
364 /* * Value encapsulates a callable defined in an extension language. */
365 lval_xcallable,
366 /* * Part of a gdb internal variable (structure field). */
367 lval_internalvar_component,
368 /* * Value's bits are fetched and stored using functions provided
369 by its creator. */
370 lval_computed
371 };
372
373 /* * Parameters of the "info proc" command. */
374
375 enum info_proc_what
376 {
377 /* * Display the default cmdline, cwd and exe outputs. */
378 IP_MINIMAL,
379
380 /* * Display `info proc mappings'. */
381 IP_MAPPINGS,
382
383 /* * Display `info proc status'. */
384 IP_STATUS,
385
386 /* * Display `info proc stat'. */
387 IP_STAT,
388
389 /* * Display `info proc cmdline'. */
390 IP_CMDLINE,
391
392 /* * Display `info proc exe'. */
393 IP_EXE,
394
395 /* * Display `info proc cwd'. */
396 IP_CWD,
397
398 /* * Display `info proc files'. */
399 IP_FILES,
400
401 /* * Display all of the above. */
402 IP_ALL
403 };
404
405 /* * Default radixes for input and output. Only some values supported. */
406 extern unsigned input_radix;
407 extern unsigned output_radix;
408
409 /* * Possibilities for prettyformat parameters to routines which print
410 things. Like enum language, this should be in value.h, but needs
411 to be here for the same reason. FIXME: If we can eliminate this
412 as an arg to LA_VAL_PRINT, then we can probably move it back to
413 value.h. */
414
415 enum val_prettyformat
416 {
417 Val_no_prettyformat = 0,
418 Val_prettyformat,
419 /* * Use the default setting which the user has specified. */
420 Val_prettyformat_default
421 };
422
423 /* * Optional native machine support. Non-native (and possibly pure
424 multi-arch) targets do not need a "nm.h" file. This will be a
425 symlink to one of the nm-*.h files, built by the `configure'
426 script. */
427
428 #ifdef GDB_NM_FILE
429 #include "nm.h"
430 #endif
431
432 /* Assume that fopen accepts the letter "b" in the mode string.
433 It is demanded by ISO C9X, and should be supported on all
434 platforms that claim to have a standard-conforming C library. On
435 true POSIX systems it will be ignored and have no effect. There
436 may still be systems without a standard-conforming C library where
437 an ISO C9X compiler (GCC) is available. Known examples are SunOS
438 4.x and 4.3BSD. This assumption means these systems are no longer
439 supported. */
440 #ifndef FOPEN_RB
441 # include "fopen-bin.h"
442 #endif
443
444 /* Defaults for system-wide constants (if not defined by xm.h, we fake it).
445 FIXME: Assumes 2's complement arithmetic. */
446
447 #if !defined (UINT_MAX)
448 #define UINT_MAX ((unsigned int)(~0)) /* 0xFFFFFFFF for 32-bits */
449 #endif
450
451 #if !defined (INT_MAX)
452 #define INT_MAX ((int)(UINT_MAX >> 1)) /* 0x7FFFFFFF for 32-bits */
453 #endif
454
455 #if !defined (INT_MIN)
456 #define INT_MIN ((int)((int) ~0 ^ INT_MAX)) /* 0x80000000 for 32-bits */
457 #endif
458
459 #if !defined (ULONG_MAX)
460 #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF for 32-bits */
461 #endif
462
463 #if !defined (LONG_MAX)
464 #define LONG_MAX ((long)(ULONG_MAX >> 1)) /* 0x7FFFFFFF for 32-bits */
465 #endif
466
467 #if !defined (ULONGEST_MAX)
468 #define ULONGEST_MAX (~(ULONGEST)0) /* 0xFFFFFFFFFFFFFFFF for 64-bits */
469 #endif
470
471 #if !defined (LONGEST_MAX) /* 0x7FFFFFFFFFFFFFFF for 64-bits */
472 #define LONGEST_MAX ((LONGEST)(ULONGEST_MAX >> 1))
473 #endif
474
475 /* * Convert a LONGEST to an int. This is used in contexts (e.g. number of
476 arguments to a function, number in a value history, register number, etc.)
477 where the value must not be larger than can fit in an int. */
478
479 extern int longest_to_int (LONGEST);
480
481 /* Enumerate the requirements a symbol has in order to be evaluated.
482 These are listed in order of "strength" -- a later entry subsumes
483 earlier ones. This fine-grained distinction is important because
484 it allows for the evaluation of a TLS symbol during unwinding --
485 when unwinding one has access to registers, but not the frame
486 itself, because that is being constructed. */
487
488 enum symbol_needs_kind
489 {
490 /* No special requirements -- just memory. */
491 SYMBOL_NEEDS_NONE,
492
493 /* The symbol needs registers. */
494 SYMBOL_NEEDS_REGISTERS,
495
496 /* The symbol needs a frame. */
497 SYMBOL_NEEDS_FRAME
498 };
499
500 /* In findvar.c. */
501
502 template<typename T, typename = RequireLongest<T>>
503 T extract_integer (gdb::array_view<const gdb_byte>, enum bfd_endian byte_order);
504
505 static inline LONGEST
506 extract_signed_integer (gdb::array_view<const gdb_byte> buf,
507 enum bfd_endian byte_order)
508 {
509 return extract_integer<LONGEST> (buf, byte_order);
510 }
511
512 static inline LONGEST
513 extract_signed_integer (const gdb_byte *addr, int len,
514 enum bfd_endian byte_order)
515 {
516 return extract_signed_integer (gdb::array_view<const gdb_byte> (addr, len),
517 byte_order);
518 }
519
520 static inline ULONGEST
521 extract_unsigned_integer (gdb::array_view<const gdb_byte> buf,
522 enum bfd_endian byte_order)
523 {
524 return extract_integer<ULONGEST> (buf, byte_order);
525 }
526
527 static inline ULONGEST
528 extract_unsigned_integer (const gdb_byte *addr, int len,
529 enum bfd_endian byte_order)
530 {
531 return extract_unsigned_integer (gdb::array_view<const gdb_byte> (addr, len),
532 byte_order);
533 }
534
535 extern int extract_long_unsigned_integer (const gdb_byte *, int,
536 enum bfd_endian, LONGEST *);
537
538 extern CORE_ADDR extract_typed_address (const gdb_byte *buf,
539 struct type *type);
540
541 /* All 'store' functions accept a host-format integer and store a
542 target-format integer at ADDR which is LEN bytes long. */
543
544 template<typename T, typename = RequireLongest<T>>
545 extern void store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order,
546 T val);
547
548 static inline void
549 store_signed_integer (gdb_byte *addr, int len,
550 enum bfd_endian byte_order, LONGEST val)
551 {
552 return store_integer (addr, len, byte_order, val);
553 }
554
555 static inline void
556 store_unsigned_integer (gdb_byte *addr, int len,
557 enum bfd_endian byte_order, ULONGEST val)
558 {
559 return store_integer (addr, len, byte_order, val);
560 }
561
562 extern void store_typed_address (gdb_byte *buf, struct type *type,
563 CORE_ADDR addr);
564
565 extern void copy_integer_to_size (gdb_byte *dest, int dest_size,
566 const gdb_byte *source, int source_size,
567 bool is_signed, enum bfd_endian byte_order);
568
569 /* Hooks for alternate command interfaces. */
570
571 struct target_waitstatus;
572 struct cmd_list_element;
573
574 extern void (*deprecated_pre_add_symbol_hook) (const char *);
575 extern void (*deprecated_post_add_symbol_hook) (void);
576 extern void (*selected_frame_level_changed_hook) (int);
577 extern int (*deprecated_ui_loop_hook) (int signo);
578 extern void (*deprecated_show_load_progress) (const char *section,
579 unsigned long section_sent,
580 unsigned long section_size,
581 unsigned long total_sent,
582 unsigned long total_size);
583 extern void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
584 int line,
585 int stopline,
586 int noerror);
587 extern int (*deprecated_query_hook) (const char *, va_list)
588 ATTRIBUTE_FPTR_PRINTF(1,0);
589 extern void (*deprecated_warning_hook) (const char *, va_list)
590 ATTRIBUTE_FPTR_PRINTF(1,0);
591 extern void (*deprecated_readline_begin_hook) (const char *, ...)
592 ATTRIBUTE_FPTR_PRINTF_1;
593 extern char *(*deprecated_readline_hook) (const char *);
594 extern void (*deprecated_readline_end_hook) (void);
595 extern void (*deprecated_context_hook) (int);
596 extern ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
597 struct target_waitstatus *status,
598 int options);
599
600 extern void (*deprecated_attach_hook) (void);
601 extern void (*deprecated_detach_hook) (void);
602 extern void (*deprecated_call_command_hook) (struct cmd_list_element * c,
603 const char *cmd, int from_tty);
604
605 extern int (*deprecated_ui_load_progress_hook) (const char *section,
606 unsigned long num);
607
608 /* If this definition isn't overridden by the header files, assume
609 that isatty and fileno exist on this system. */
610 #ifndef ISATTY
611 #define ISATTY(FP) (isatty (fileno (FP)))
612 #endif
613
614 /* * A width that can achieve a better legibility for GDB MI mode. */
615 #define GDB_MI_MSG_WIDTH 80
616
617 /* From progspace.c */
618
619 extern void initialize_progspace (void);
620 extern void initialize_inferiors (void);
621
622 /* * Special block numbers */
623
624 enum block_enum
625 {
626 GLOBAL_BLOCK = 0,
627 STATIC_BLOCK = 1,
628 FIRST_LOCAL_BLOCK = 2
629 };
630
631 /* User selection used in observable.h and multiple print functions. */
632
633 enum user_selected_what_flag
634 {
635 /* Inferior selected. */
636 USER_SELECTED_INFERIOR = 1 << 1,
637
638 /* Thread selected. */
639 USER_SELECTED_THREAD = 1 << 2,
640
641 /* Frame selected. */
642 USER_SELECTED_FRAME = 1 << 3
643 };
644 DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
645
646 #include "utils.h"
647
648 #endif /* #ifndef DEFS_H */