1 1.1 christos /* Declarations for value printing routines for GDB, the GNU debugger. 2 1.1 christos 3 1.11 christos Copyright (C) 1986-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.12 christos #ifndef GDB_VALPRINT_H 21 1.12 christos #define GDB_VALPRINT_H 22 1.1 christos 23 1.9 christos #include "cli/cli-option.h" 24 1.9 christos 25 1.11 christos /* Possibilities for prettyformat parameters to routines which print 26 1.11 christos things. */ 27 1.11 christos 28 1.11 christos enum val_prettyformat 29 1.11 christos { 30 1.11 christos Val_no_prettyformat = 0, 31 1.11 christos Val_prettyformat, 32 1.11 christos /* * Use the default setting which the user has specified. */ 33 1.11 christos Val_prettyformat_default 34 1.11 christos }; 35 1.11 christos 36 1.1 christos /* This is used to pass formatting options to various value-printing 37 1.1 christos functions. */ 38 1.1 christos struct value_print_options 39 1.1 christos { 40 1.1 christos /* Pretty-formatting control. */ 41 1.1 christos enum val_prettyformat prettyformat; 42 1.1 christos 43 1.1 christos /* Controls pretty formatting of arrays. */ 44 1.9 christos bool prettyformat_arrays; 45 1.1 christos 46 1.1 christos /* Controls pretty formatting of structures. */ 47 1.9 christos bool prettyformat_structs; 48 1.1 christos 49 1.1 christos /* Controls printing of virtual tables. */ 50 1.9 christos bool vtblprint; 51 1.1 christos 52 1.1 christos /* Controls printing of nested unions. */ 53 1.9 christos bool unionprint; 54 1.1 christos 55 1.1 christos /* Controls printing of addresses. */ 56 1.9 christos bool addressprint; 57 1.1 christos 58 1.10 christos /* Controls printing of nibbles. */ 59 1.10 christos bool nibblesprint; 60 1.10 christos 61 1.1 christos /* Controls looking up an object's derived type using what we find 62 1.1 christos in its vtables. */ 63 1.9 christos bool objectprint; 64 1.1 christos 65 1.11 christos /* Maximum number of elements to print for vector contents, or UINT_MAX 66 1.11 christos for no limit. Note that "set print elements 0" stores UINT_MAX in 67 1.11 christos print_max, which displays in a show command as "unlimited". */ 68 1.1 christos unsigned int print_max; 69 1.1 christos 70 1.11 christos /* Maximum number of string chars to print for a string pointer value, 71 1.11 christos zero if to follow the value of print_max, or UINT_MAX for no limit. */ 72 1.11 christos unsigned int print_max_chars; 73 1.11 christos 74 1.1 christos /* Print repeat counts if there are more than this many repetitions 75 1.1 christos of an element in an array. */ 76 1.1 christos unsigned int repeat_count_threshold; 77 1.1 christos 78 1.1 christos /* The global output format letter. */ 79 1.1 christos int output_format; 80 1.1 christos 81 1.1 christos /* The current format letter. This is set locally for a given call, 82 1.1 christos e.g. when the user passes a format to "print". */ 83 1.1 christos int format; 84 1.1 christos 85 1.10 christos /* Print memory tag violations for pointers. */ 86 1.10 christos bool memory_tag_violations; 87 1.10 christos 88 1.1 christos /* Stop printing at null character? */ 89 1.9 christos bool stop_print_at_null; 90 1.1 christos 91 1.1 christos /* True if we should print the index of each element when printing 92 1.1 christos an array. */ 93 1.9 christos bool print_array_indexes; 94 1.1 christos 95 1.9 christos /* If true, then dereference references, otherwise just print 96 1.1 christos them like pointers. */ 97 1.9 christos bool deref_ref; 98 1.1 christos 99 1.9 christos /* If true, print static fields. */ 100 1.9 christos bool static_field_print; 101 1.1 christos 102 1.9 christos /* If true, print static fields for Pascal. FIXME: C++ has a 103 1.7 christos flag, why not share with Pascal too? */ 104 1.9 christos bool pascal_static_field_print; 105 1.1 christos 106 1.9 christos /* If true, don't do Python pretty-printing. */ 107 1.9 christos bool raw; 108 1.1 christos 109 1.9 christos /* If true, print the value in "summary" form. 110 1.9 christos If raw and summary are both true, don't print non-scalar values 111 1.1 christos ("..." is printed instead). */ 112 1.9 christos bool summary; 113 1.1 christos 114 1.9 christos /* If true, when printing a pointer, print the symbol to which it 115 1.1 christos points, if any. */ 116 1.9 christos bool symbol_print; 117 1.9 christos 118 1.9 christos /* Maximum print depth when printing nested aggregates. */ 119 1.9 christos int max_depth; 120 1.1 christos }; 121 1.1 christos 122 1.11 christos /* The value to use for `print_max_chars' to follow `print_max'. */ 123 1.11 christos #define PRINT_MAX_CHARS_ELEMENTS 0 124 1.11 christos 125 1.11 christos /* The value to use for `print_max_chars' for no limit. */ 126 1.11 christos #define PRINT_MAX_CHARS_UNLIMITED UINT_MAX 127 1.11 christos 128 1.11 christos /* Return the character count limit for printing strings. */ 129 1.11 christos 130 1.11 christos static inline unsigned int 131 1.11 christos get_print_max_chars (const struct value_print_options *options) 132 1.11 christos { 133 1.11 christos return (options->print_max_chars != PRINT_MAX_CHARS_ELEMENTS 134 1.11 christos ? options->print_max_chars : options->print_max); 135 1.11 christos } 136 1.11 christos 137 1.9 christos /* Create an option_def_group for the value_print options, with OPTS 138 1.9 christos as context. */ 139 1.9 christos extern gdb::option::option_def_group make_value_print_options_def_group 140 1.9 christos (value_print_options *opts); 141 1.9 christos 142 1.1 christos /* The global print options set by the user. In general this should 143 1.1 christos not be directly accessed, except by set/show commands. Ordinary 144 1.1 christos code should call get_user_print_options instead. */ 145 1.1 christos extern struct value_print_options user_print_options; 146 1.1 christos 147 1.1 christos /* Initialize *OPTS to be a copy of the user print options. */ 148 1.1 christos extern void get_user_print_options (struct value_print_options *opts); 149 1.1 christos 150 1.1 christos /* Initialize *OPTS to be a copy of the user print options, but with 151 1.1 christos pretty-formatting disabled. */ 152 1.1 christos extern void get_no_prettyformat_print_options (struct value_print_options *); 153 1.1 christos 154 1.1 christos /* Initialize *OPTS to be a copy of the user print options, but using 155 1.1 christos FORMAT as the formatting option. */ 156 1.1 christos extern void get_formatted_print_options (struct value_print_options *opts, 157 1.1 christos char format); 158 1.1 christos 159 1.1 christos extern void maybe_print_array_index (struct type *index_type, LONGEST index, 160 1.10 christos struct ui_file *stream, 161 1.1 christos const struct value_print_options *); 162 1.1 christos 163 1.9 christos 164 1.9 christos /* Print elements of an array. */ 165 1.9 christos 166 1.9 christos extern void value_print_array_elements (struct value *, struct ui_file *, int, 167 1.1 christos const struct value_print_options *, 168 1.9 christos unsigned int); 169 1.9 christos 170 1.9 christos /* Print a scalar according to OPTIONS and SIZE on STREAM. Format 'i' 171 1.9 christos is not supported at this level. 172 1.9 christos 173 1.9 christos This is how the elements of an array or structure are printed 174 1.9 christos with a format. */ 175 1.9 christos 176 1.9 christos extern void value_print_scalar_formatted 177 1.9 christos (struct value *val, const struct value_print_options *options, 178 1.9 christos int size, struct ui_file *stream); 179 1.1 christos 180 1.1 christos extern void print_binary_chars (struct ui_file *, const gdb_byte *, 181 1.10 christos unsigned int, enum bfd_endian, bool, 182 1.10 christos const struct value_print_options *options); 183 1.1 christos 184 1.1 christos extern void print_octal_chars (struct ui_file *, const gdb_byte *, 185 1.1 christos unsigned int, enum bfd_endian); 186 1.1 christos 187 1.1 christos extern void print_decimal_chars (struct ui_file *, const gdb_byte *, 188 1.8 christos unsigned int, bool, enum bfd_endian); 189 1.1 christos 190 1.1 christos extern void print_hex_chars (struct ui_file *, const gdb_byte *, 191 1.8 christos unsigned int, enum bfd_endian, bool); 192 1.1 christos 193 1.1 christos extern void print_function_pointer_address (const struct value_print_options *options, 194 1.1 christos struct gdbarch *gdbarch, 195 1.1 christos CORE_ADDR address, 196 1.1 christos struct ui_file *stream); 197 1.1 christos 198 1.9 christos /* Helper function to check the validity of some bits of a value. 199 1.9 christos 200 1.9 christos If TYPE represents some aggregate type (e.g., a structure), return 1. 201 1.9 christos 202 1.9 christos Otherwise, any of the bytes starting at OFFSET and extending for 203 1.10 christos TYPE->length () bytes are invalid, print a message to STREAM and 204 1.9 christos return 0. The checking is done using FUNCS. 205 1.9 christos 206 1.9 christos Otherwise, return 1. */ 207 1.9 christos 208 1.9 christos extern int valprint_check_validity (struct ui_file *stream, struct type *type, 209 1.9 christos LONGEST embedded_offset, 210 1.9 christos const struct value *val); 211 1.9 christos 212 1.1 christos extern void val_print_optimized_out (const struct value *val, 213 1.1 christos struct ui_file *stream); 214 1.1 christos 215 1.1 christos /* Prints "<not saved>" to STREAM. */ 216 1.1 christos extern void val_print_not_saved (struct ui_file *stream); 217 1.1 christos 218 1.1 christos extern void val_print_unavailable (struct ui_file *stream); 219 1.1 christos 220 1.1 christos extern void val_print_invalid_address (struct ui_file *stream); 221 1.1 christos 222 1.1 christos /* An instance of this is passed to generic_val_print and describes 223 1.1 christos some language-specific ways to print things. */ 224 1.1 christos 225 1.1 christos struct generic_val_print_decorations 226 1.1 christos { 227 1.1 christos /* Printing complex numbers: what to print before, between the 228 1.1 christos elements, and after. */ 229 1.1 christos 230 1.1 christos const char *complex_prefix; 231 1.1 christos const char *complex_infix; 232 1.1 christos const char *complex_suffix; 233 1.1 christos 234 1.1 christos /* Boolean true and false. */ 235 1.1 christos 236 1.1 christos const char *true_name; 237 1.1 christos const char *false_name; 238 1.1 christos 239 1.1 christos /* What to print when we see TYPE_CODE_VOID. */ 240 1.1 christos 241 1.1 christos const char *void_name; 242 1.6 christos 243 1.6 christos /* Array start and end strings. */ 244 1.6 christos const char *array_start; 245 1.6 christos const char *array_end; 246 1.1 christos }; 247 1.1 christos 248 1.1 christos 249 1.9 christos /* Print a value in a generic way. VAL is the value, STREAM is where 250 1.9 christos to print it, RECURSE is the recursion depth, OPTIONS describe how 251 1.9 christos the printing should be done, and D is the language-specific 252 1.9 christos decorations object. Note that structs and unions cannot be printed 253 1.9 christos by this function. */ 254 1.9 christos 255 1.9 christos extern void generic_value_print (struct value *val, struct ui_file *stream, 256 1.9 christos int recurse, 257 1.9 christos const struct value_print_options *options, 258 1.9 christos const struct generic_val_print_decorations *d); 259 1.1 christos 260 1.1 christos extern void generic_emit_char (int c, struct type *type, struct ui_file *stream, 261 1.1 christos int quoter, const char *encoding); 262 1.1 christos 263 1.1 christos extern void generic_printstr (struct ui_file *stream, struct type *type, 264 1.1 christos const gdb_byte *string, unsigned int length, 265 1.1 christos const char *encoding, int force_ellipses, 266 1.1 christos int quote_char, int c_style_terminator, 267 1.1 christos const struct value_print_options *options); 268 1.1 christos 269 1.1 christos /* Run the "output" command. ARGS and FROM_TTY are the usual 270 1.1 christos arguments passed to all command implementations, except ARGS is 271 1.1 christos const. */ 272 1.1 christos 273 1.8 christos extern void output_command (const char *args, int from_tty); 274 1.1 christos 275 1.1 christos extern int val_print_scalar_type_p (struct type *type); 276 1.1 christos 277 1.5 christos struct format_data 278 1.5 christos { 279 1.5 christos int count; 280 1.5 christos char format; 281 1.5 christos char size; 282 1.10 christos bool print_tags; 283 1.5 christos 284 1.5 christos /* True if the value should be printed raw -- that is, bypassing 285 1.5 christos python-based formatters. */ 286 1.5 christos unsigned char raw; 287 1.5 christos }; 288 1.5 christos 289 1.5 christos extern void print_command_parse_format (const char **expp, const char *cmdname, 290 1.9 christos value_print_options *opts); 291 1.9 christos 292 1.9 christos /* Print VAL to console according to OPTS, including recording it to 293 1.9 christos the history. */ 294 1.9 christos extern void print_value (value *val, const value_print_options &opts); 295 1.9 christos 296 1.9 christos /* Completer for the "print", "call", and "compile print" 297 1.9 christos commands. */ 298 1.9 christos extern void print_command_completer (struct cmd_list_element *ignore, 299 1.9 christos completion_tracker &tracker, 300 1.9 christos const char *text, const char *word); 301 1.5 christos 302 1.8 christos /* Given an address ADDR return all the elements needed to print the 303 1.8 christos address in a symbolic form. NAME can be mangled or not depending 304 1.8 christos on DO_DEMANGLE (and also on the asm_demangle global variable, 305 1.9 christos manipulated via ''set print asm-demangle''). When 306 1.9 christos PREFER_SYM_OVER_MINSYM is true, names (and offsets) from minimal 307 1.9 christos symbols won't be used except in instances where no symbol was 308 1.9 christos found; otherwise, a minsym might be used in some instances (mostly 309 1.9 christos involving function with non-contiguous address ranges). Return 310 1.9 christos 0 in case of success, when all the info in the OUT parameters is 311 1.9 christos valid. Return 1 otherwise. */ 312 1.8 christos 313 1.8 christos extern int build_address_symbolic (struct gdbarch *, 314 1.8 christos CORE_ADDR addr, 315 1.9 christos bool do_demangle, 316 1.9 christos bool prefer_sym_over_minsym, 317 1.8 christos std::string *name, 318 1.8 christos int *offset, 319 1.8 christos std::string *filename, 320 1.8 christos int *line, 321 1.8 christos int *unmapped); 322 1.8 christos 323 1.9 christos /* Check to see if RECURSE is greater than or equal to the allowed 324 1.9 christos printing max-depth (see 'set print max-depth'). If it is then print an 325 1.9 christos ellipsis expression to STREAM and return true, otherwise return false. 326 1.9 christos LANGUAGE determines what type of ellipsis expression is printed. */ 327 1.9 christos 328 1.9 christos extern bool val_print_check_max_depth (struct ui_file *stream, int recurse, 329 1.9 christos const struct value_print_options *opts, 330 1.9 christos const struct language_defn *language); 331 1.9 christos 332 1.9 christos /* Like common_val_print, but call value_check_printable first. */ 333 1.9 christos 334 1.9 christos extern void common_val_print_checked 335 1.9 christos (struct value *val, 336 1.9 christos struct ui_file *stream, int recurse, 337 1.9 christos const struct value_print_options *options, 338 1.9 christos const struct language_defn *language); 339 1.9 christos 340 1.12 christos #endif /* GDB_VALPRINT_H */ 341