1 /* Basic, host-specific, and target-specific definitions for GDB.
2    Copyright (C) 1986-2024 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 3 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, see <http://www.gnu.org/licenses/>.  */
18 
19 #ifndef DEFS_H
20 #define DEFS_H
21 
22 #ifdef GDBSERVER
23 #  error gdbserver should not include gdb/defs.h
24 #endif
25 
26 #include "gdbsupport/common-defs.h"
27 
28 #undef PACKAGE
29 #undef PACKAGE_NAME
30 #undef PACKAGE_VERSION
31 #undef PACKAGE_STRING
32 #undef PACKAGE_TARNAME
33 
34 #include <config.h>
35 #include "bfd.h"
36 
37 #include <sys/types.h>
38 #include <climits>
39 
40 /* The libdecnumber library, on which GDB depends, includes a header file
41    called gstdint.h instead of relying directly on stdint.h.  GDB, on the
42    other hand, includes stdint.h directly, relying on the fact that gnulib
43    generates a copy if the system doesn't provide one or if it is missing
44    some features.  Unfortunately, gstdint.h and stdint.h cannot be included
45    at the same time, which may happen when we include a file from
46    libdecnumber.
47 
48    The following macro definition effectively prevents the inclusion of
49    gstdint.h, as all the definitions it provides are guarded against
50    the GCC_GENERATED_STDINT_H macro.  We already have gnulib/stdint.h
51    included, so it's ok to blank out gstdint.h.  */
52 #define GCC_GENERATED_STDINT_H 1
53 
54 #include <unistd.h>
55 
56 #include <fcntl.h>
57 
58 #include "gdb_wchar.h"
59 
60 #include "ui-file.h"
61 
62 #include "gdbsupport/host-defs.h"
63 #include "gdbsupport/enum-flags.h"
64 
65 /* Just in case they're not defined in stdio.h.  */
66 
67 #ifndef SEEK_SET
68 #define SEEK_SET 0
69 #endif
70 #ifndef SEEK_CUR
71 #define SEEK_CUR 1
72 #endif
73 
74 /* The O_BINARY flag is defined in fcntl.h on some non-Posix platforms.
75    It is used as an access modifier in calls to open(), where it acts
76    similarly to the "b" character in fopen()'s MODE argument.  On Posix
77    platforms it should be a no-op, so it is defined as 0 here.  This
78    ensures that the symbol may be used freely elsewhere in gdb.  */
79 
80 #ifndef O_BINARY
81 #define O_BINARY 0
82 #endif
83 
84 /* * System root path, used to find libraries etc.  */
85 extern std::string gdb_sysroot;
86 
87 /* * GDB datadir, used to store data files.  */
88 extern std::string gdb_datadir;
89 
90 /* * If not empty, the possibly relocated path to python's "lib" directory
91    specified with --with-python.  */
92 extern std::string python_libdir;
93 
94 /* * Search path for separate debug files.  */
95 extern std::string debug_file_directory;
96 
97 /* * Languages represented in the symbol table and elsewhere.
98    This should probably be in language.h, but since enum's can't
99    be forward declared to satisfy opaque references before their
100    actual definition, needs to be here.
101 
102    The constants here are in priority order.  In particular,
103    demangling is attempted according to this order.
104 
105    Note that there's ambiguity between the mangling schemes of some of
106    these languages, so some symbols could be successfully demangled by
107    several languages.  For that reason, the constants here are sorted
108    in the order we'll attempt demangling them.  For example: Rust uses
109    a C++-compatible mangling, so must come before C++; Ada must come
110    last (see ada_sniff_from_mangled_name).  */
111 
112 enum language
113   {
114     language_unknown,                   /* Language not known */
115     language_c,                         /* C */
116     language_objc,            /* Objective-C */
117     language_rust,            /* Rust */
118     language_cplus,           /* C++ */
119     language_d,                         /* D */
120     language_go,              /* Go */
121     language_fortran,                   /* Fortran */
122     language_m2,              /* Modula-2 */
123     language_asm,             /* Assembly language */
124     language_pascal,                    /* Pascal */
125     language_opencl,                    /* OpenCL */
126     language_minimal,                   /* All other languages, minimal support only */
127     language_ada,             /* Ada */
128     nr_languages
129   };
130 
131 /* The number of bits needed to represent all languages, with enough
132    padding to allow for reasonable growth.  */
133 #define LANGUAGE_BITS 5
134 static_assert (nr_languages <= (1 << LANGUAGE_BITS));
135 
136 /* The number of bytes needed to represent all languages.  */
137 #define LANGUAGE_BYTES ((LANGUAGE_BITS + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT)
138 
139 /* * A generic, not quite boolean, enumeration.  This is used for
140    set/show commands in which the options are on/off/automatic.  */
141 enum auto_boolean
142 {
143   AUTO_BOOLEAN_TRUE,
144   AUTO_BOOLEAN_FALSE,
145   AUTO_BOOLEAN_AUTO
146 };
147 
148 /* * Potential ways that a function can return a value of a given
149    type.  */
150 
151 enum return_value_convention
152 {
153   /* * Where the return value has been squeezed into one or more
154      registers.  */
155   RETURN_VALUE_REGISTER_CONVENTION,
156   /* * Commonly known as the "struct return convention".  The caller
157      passes an additional hidden first parameter to the caller.  That
158      parameter contains the address at which the value being returned
159      should be stored.  While typically, and historically, used for
160      large structs, this is convention is applied to values of many
161      different types.  */
162   RETURN_VALUE_STRUCT_CONVENTION,
163   /* * Like the "struct return convention" above, but where the ABI
164      guarantees that the called function stores the address at which
165      the value being returned is stored in a well-defined location,
166      such as a register or memory slot in the stack frame.  Don't use
167      this if the ABI doesn't explicitly guarantees this.  */
168   RETURN_VALUE_ABI_RETURNS_ADDRESS,
169   /* * Like the "struct return convention" above, but where the ABI
170      guarantees that the address at which the value being returned is
171      stored will be available in a well-defined location, such as a
172      register or memory slot in the stack frame.  Don't use this if
173      the ABI doesn't explicitly guarantees this.  */
174   RETURN_VALUE_ABI_PRESERVES_ADDRESS,
175 };
176 
177 /* Needed for various prototypes */
178 
179 struct symtab;
180 struct breakpoint;
181 class frame_info_ptr;
182 struct gdbarch;
183 struct value;
184 
185 /* From main.c.  */
186 
187 /* This really belong in utils.c (path-utils.c?), but it references some
188    globals that are currently only available to main.c.  */
189 extern std::string relocate_gdb_directory (const char *initial, bool relocatable);
190 
191 /* From top.c */
192 
193 typedef void initialize_file_ftype (void);
194 
195 extern char *gdb_readline_wrapper (const char *);
196 
197 extern const char *command_line_input (std::string &cmd_line_buffer,
198                                                const char *, const char *);
199 
200 extern void print_prompt (void);
201 
202 struct ui;
203 
204 extern bool info_verbose;
205 
206 /* From printcmd.c */
207 
208 extern void set_next_address (struct gdbarch *, CORE_ADDR);
209 
210 extern int print_address_symbolic (struct gdbarch *, CORE_ADDR,
211                                            struct ui_file *, int,
212                                            const char *);
213 
214 extern void print_address (struct gdbarch *, CORE_ADDR, struct ui_file *);
215 extern const char *pc_prefix (CORE_ADDR);
216 
217 /* From exec.c */
218 
219 /* * Process memory area starting at ADDR with length SIZE.  Area is
220    readable iff READ is non-zero, writable if WRITE is non-zero,
221    executable if EXEC is non-zero.  Area is possibly changed against
222    its original file based copy if MODIFIED is non-zero.
223 
224    MEMORY_TAGGED is true if the memory region contains memory tags, false
225    otherwise.
226 
227    DATA is passed without changes from a caller.  */
228 
229 typedef int (*find_memory_region_ftype) (CORE_ADDR addr, unsigned long size,
230                                                    int read, int write, int exec,
231                                                    int modified, bool memory_tagged,
232                                                    void *data);
233 
234 /* * Possible lvalue types.  Like enum language, this should be in
235    value.h, but needs to be here for the same reason.  */
236 
237 enum lval_type
238   {
239     /* * Not an lval.  */
240     not_lval,
241     /* * In memory.  */
242     lval_memory,
243     /* * In a register.  Registers are relative to a frame.  */
244     lval_register,
245     /* * In a gdb internal variable.  */
246     lval_internalvar,
247     /* * Value encapsulates a callable defined in an extension language.  */
248     lval_xcallable,
249     /* * Part of a gdb internal variable (structure field).  */
250     lval_internalvar_component,
251     /* * Value's bits are fetched and stored using functions provided
252        by its creator.  */
253     lval_computed
254   };
255 
256 /* * Parameters of the "info proc" command.  */
257 
258 enum info_proc_what
259   {
260     /* * Display the default cmdline, cwd and exe outputs.  */
261     IP_MINIMAL,
262 
263     /* * Display `info proc mappings'.  */
264     IP_MAPPINGS,
265 
266     /* * Display `info proc status'.  */
267     IP_STATUS,
268 
269     /* * Display `info proc stat'.  */
270     IP_STAT,
271 
272     /* * Display `info proc cmdline'.  */
273     IP_CMDLINE,
274 
275     /* * Display `info proc exe'.  */
276     IP_EXE,
277 
278     /* * Display `info proc cwd'.  */
279     IP_CWD,
280 
281     /* * Display `info proc files'.  */
282     IP_FILES,
283 
284     /* * Display all of the above.  */
285     IP_ALL
286   };
287 
288 /* * Default radixes for input and output.  Only some values supported.  */
289 extern unsigned input_radix;
290 extern unsigned output_radix;
291 
292 /* * Optional native machine support.  Non-native (and possibly pure
293    multi-arch) targets do not need a "nm.h" file.  This will be a
294    symlink to one of the nm-*.h files, built by the `configure'
295    script.  */
296 
297 #ifdef GDB_NM_FILE
298 #include "nm.h"
299 #endif
300 
301 /* Assume that fopen accepts the letter "b" in the mode string.
302    It is demanded by ISO C9X, and should be supported on all
303    platforms that claim to have a standard-conforming C library.  On
304    true POSIX systems it will be ignored and have no effect.  There
305    may still be systems without a standard-conforming C library where
306    an ISO C9X compiler (GCC) is available.  Known examples are SunOS
307    4.x and 4.3BSD.  This assumption means these systems are no longer
308    supported.  */
309 #ifndef FOPEN_RB
310 # include "fopen-bin.h"
311 #endif
312 
313 /* * Convert a LONGEST to an int.  This is used in contexts (e.g. number of
314    arguments to a function, number in a value history, register number, etc.)
315    where the value must not be larger than can fit in an int.  */
316 
317 extern int longest_to_int (LONGEST);
318 
319 /* Enumerate the requirements a symbol has in order to be evaluated.
320    These are listed in order of "strength" -- a later entry subsumes
321    earlier ones.  This fine-grained distinction is important because
322    it allows for the evaluation of a TLS symbol during unwinding --
323    when unwinding one has access to registers, but not the frame
324    itself, because that is being constructed.  */
325 
326 enum symbol_needs_kind
327 {
328   /* No special requirements -- just memory.  */
329   SYMBOL_NEEDS_NONE,
330 
331   /* The symbol needs registers.  */
332   SYMBOL_NEEDS_REGISTERS,
333 
334   /* The symbol needs a frame.  */
335   SYMBOL_NEEDS_FRAME
336 };
337 
338 /* Hooks for alternate command interfaces.  */
339 
340 struct target_waitstatus;
341 struct cmd_list_element;
342 
343 extern void (*deprecated_pre_add_symbol_hook) (const char *);
344 extern void (*deprecated_post_add_symbol_hook) (void);
345 extern void (*selected_frame_level_changed_hook) (int);
346 extern int (*deprecated_ui_loop_hook) (int signo);
347 extern void (*deprecated_show_load_progress) (const char *section,
348                                                         unsigned long section_sent,
349                                                         unsigned long section_size,
350                                                         unsigned long total_sent,
351                                                         unsigned long total_size);
352 extern void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
353                                                                        int line,
354                                                                        int stopline,
355                                                                        int noerror);
356 extern int (*deprecated_query_hook) (const char *, va_list)
357      ATTRIBUTE_FPTR_PRINTF(1,0);
358 extern void (*deprecated_readline_begin_hook) (const char *, ...)
359      ATTRIBUTE_FPTR_PRINTF_1;
360 extern char *(*deprecated_readline_hook) (const char *);
361 extern void (*deprecated_readline_end_hook) (void);
362 extern void (*deprecated_context_hook) (int);
363 extern ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
364                                                         struct target_waitstatus *status,
365                                                         int options);
366 
367 extern void (*deprecated_attach_hook) (void);
368 extern void (*deprecated_detach_hook) (void);
369 extern void (*deprecated_call_command_hook) (struct cmd_list_element * c,
370                                                        const char *cmd, int from_tty);
371 
372 extern int (*deprecated_ui_load_progress_hook) (const char *section,
373                                                             unsigned long num);
374 
375 /* If this definition isn't overridden by the header files, assume
376    that isatty and fileno exist on this system.  */
377 #ifndef ISATTY
378 #define ISATTY(FP)  (isatty (fileno (FP)))
379 #endif
380 
381 /* * A width that can achieve a better legibility for GDB MI mode.  */
382 #define GDB_MI_MSG_WIDTH  80
383 
384 /* * Special block numbers */
385 
386 enum block_enum
387 {
388   GLOBAL_BLOCK = 0,
389   STATIC_BLOCK = 1,
390   FIRST_LOCAL_BLOCK = 2
391 };
392 
393 /* User selection used in observable.h and multiple print functions.  */
394 
395 enum user_selected_what_flag
396   {
397     /* Inferior selected.  */
398     USER_SELECTED_INFERIOR = 1 << 1,
399 
400     /* Thread selected.  */
401     USER_SELECTED_THREAD = 1 << 2,
402 
403     /* Frame selected.  */
404     USER_SELECTED_FRAME = 1 << 3
405   };
406 DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
407 
408 #include "utils.h"
409 
410 #endif /* #ifndef DEFS_H */
411