diff options
Diffstat (limited to 'gdb/printcmd.c')
| -rw-r--r-- | gdb/printcmd.c | 153 |
1 files changed, 75 insertions, 78 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 1d6a492..c46527a 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1,6 +1,6 @@ /* Print values for GNU debugger GDB. - Copyright (C) 1986-2024 Free Software Foundation, Inc. + Copyright (C) 1986-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -43,7 +43,6 @@ #include "disasm.h" #include "target-float.h" #include "observable.h" -#include "solist.h" #include "parser-defs.h" #include "charset.h" #include "arch-utils.h" @@ -55,8 +54,6 @@ #include "source.h" #include "gdbsupport/byte-vector.h" #include <optional> -#include "gdbsupport/gdb-safe-ctype.h" -#include "gdbsupport/rsp-low.h" #include "inferior.h" /* Chain containing all defined memory-tag subcommands. */ @@ -606,12 +603,11 @@ build_address_symbolic (struct gdbarch *gdbarch, int *line, /* OUT */ int *unmapped) /* OUT */ { - struct bound_minimal_symbol msymbol; struct symbol *symbol; CORE_ADDR name_location = 0; struct obj_section *section = NULL; const char *name_temp = ""; - + /* Let's say it is mapped (not unmapped). */ *unmapped = 0; @@ -627,7 +623,7 @@ build_address_symbolic (struct gdbarch *gdbarch, } } - /* Try to find the address in both the symbol table and the minsyms. + /* Try to find the address in both the symbol table and the minsyms. In most cases, we'll prefer to use the symbol instead of the minsym. However, there are cases (see below) where we'll choose to use the minsym instead. */ @@ -638,8 +634,9 @@ build_address_symbolic (struct gdbarch *gdbarch, save some memory, but for many debug format--ELF/DWARF or anything/stabs--it would be inconvenient to eliminate those minimal symbols anyway). */ - msymbol = lookup_minimal_symbol_by_pc_section (addr, section); - symbol = find_pc_sect_function (addr, section); + bound_minimal_symbol msymbol + = lookup_minimal_symbol_by_pc_section (addr, section); + symbol = find_symbol_for_pc_sect (addr, section); if (symbol) { @@ -668,7 +665,7 @@ build_address_symbolic (struct gdbarch *gdbarch, if (msymbol.minsym != NULL) { /* Use the minsym if no symbol is found. - + Additionally, use the minsym instead of a (found) symbol if the following conditions all hold: 1) The prefer_sym_over_minsym flag is false. @@ -722,7 +719,7 @@ build_address_symbolic (struct gdbarch *gdbarch, { struct symtab_and_line sal; - sal = find_pc_sect_line (addr, section, 0); + sal = find_sal_for_pc_sect (addr, section, 0); if (sal.symtab) { @@ -755,10 +752,10 @@ pc_prefix (CORE_ADDR addr) if (has_stack_frames ()) { frame_info_ptr frame; - CORE_ADDR pc; + std::optional<CORE_ADDR> pc; frame = get_selected_frame (NULL); - if (get_frame_pc_if_available (frame, &pc) && pc == addr) + if ((pc = get_frame_pc_if_available (frame)) && *pc == addr) return "=> "; } return " "; @@ -818,7 +815,7 @@ find_instruction_backward (struct gdbarch *gdbarch, CORE_ADDR addr, do { pcs.clear (); - sal = find_pc_sect_line (loop_start, NULL, 1); + sal = find_sal_for_pc_sect (loop_start, NULL, 1); if (sal.line <= 0) { /* We reach here when line info is not available. In this case, @@ -1292,7 +1289,9 @@ should_validate_memtags (gdbarch *gdbarch, struct value *value) return false; /* We do. Check whether it includes any tags. */ - return target_is_address_tagged (gdbarch, value_as_address (value)); + struct type *val_type = value->type (); + const gdb_byte *data = value->contents ().data (); + return target_is_address_tagged (gdbarch, unpack_pointer (val_type, data)); } /* Helper for parsing arguments for print_command_1. */ @@ -1322,7 +1321,9 @@ process_print_command_args (const char *args, value_print_options *print_opts, value, so invert it for parse_expression. */ parser_flags flags = 0; if (!voidprint) - flags = PARSER_VOID_CONTEXT; + flags |= PARSER_VOID_CONTEXT; + if (parser_debug) + flags |= PARSER_DEBUG; expression_up expr = parse_expression (exp, nullptr, flags); return expr->evaluate (); } @@ -1491,28 +1492,28 @@ info_symbol_command (const char *arg, int from_tty) error_no_arg (_("address")); addr = parse_and_eval_address (arg); - for (objfile *objfile : current_program_space->objfiles ()) - for (obj_section *osect : objfile->sections ()) + for (objfile &objfile : current_program_space->objfiles ()) + for (obj_section &osect : objfile.sections ()) { /* Only process each object file once, even if there's a separate debug file. */ - if (objfile->separate_debug_objfile_backlink) + if (objfile.separate_debug_objfile_backlink) continue; - sect_addr = overlay_mapped_address (addr, osect); + sect_addr = overlay_mapped_address (addr, &osect); - if (osect->contains (sect_addr) + if (osect.contains (sect_addr) && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, - osect).minsym)) + &osect).minsym)) { const char *obj_name, *mapped, *sec_name, *msym_name; const char *loc_string; matches = 1; - offset = sect_addr - msymbol->value_address (objfile); - mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); - sec_name = osect->the_bfd_section->name; + offset = sect_addr - msymbol->value_address (&objfile); + mapped = section_is_mapped (&osect) ? _("mapped") : _("unmapped"); + sec_name = osect.the_bfd_section->name; msym_name = msymbol->print_name (); /* Don't print the offset if it is zero. @@ -1526,12 +1527,12 @@ info_symbol_command (const char *arg, int from_tty) else loc_string = msym_name; - gdb_assert (osect->objfile && objfile_name (osect->objfile)); - obj_name = objfile_name (osect->objfile); + gdb_assert (osect.objfile && objfile_name (osect.objfile)); + obj_name = objfile_name (osect.objfile); if (current_program_space->multi_objfile_p ()) - if (pc_in_unmapped_range (addr, osect)) - if (section_is_overlay (osect)) + if (pc_in_unmapped_range (addr, &osect)) + if (section_is_overlay (&osect)) gdb_printf (_("%s in load address range of " "%s overlay section %s of %s\n"), loc_string, mapped, sec_name, obj_name); @@ -1540,15 +1541,15 @@ info_symbol_command (const char *arg, int from_tty) "section %s of %s\n"), loc_string, sec_name, obj_name); else - if (section_is_overlay (osect)) + if (section_is_overlay (&osect)) gdb_printf (_("%s in %s overlay section %s of %s\n"), loc_string, mapped, sec_name, obj_name); else gdb_printf (_("%s in section %s of %s\n"), loc_string, sec_name, obj_name); else - if (pc_in_unmapped_range (addr, osect)) - if (section_is_overlay (osect)) + if (pc_in_unmapped_range (addr, &osect)) + if (section_is_overlay (&osect)) gdb_printf (_("%s in load address range of %s overlay " "section %s\n"), loc_string, mapped, sec_name); @@ -1557,7 +1558,7 @@ info_symbol_command (const char *arg, int from_tty) (_("%s in load address range of section %s\n"), loc_string, sec_name); else - if (section_is_overlay (osect)) + if (section_is_overlay (&osect)) gdb_printf (_("%s in %s overlay section %s\n"), loc_string, mapped, sec_name); else @@ -1575,7 +1576,6 @@ info_address_command (const char *exp, int from_tty) struct gdbarch *gdbarch; int regno; struct symbol *sym; - struct bound_minimal_symbol msymbol; long val; struct obj_section *section; CORE_ADDR load_addr, context_pc = 0; @@ -1601,7 +1601,8 @@ info_address_command (const char *exp, int from_tty) return; } - msymbol = lookup_bound_minimal_symbol (exp); + bound_minimal_symbol msymbol + = lookup_minimal_symbol (current_program_space, exp); if (msymbol.minsym != NULL) { @@ -1653,7 +1654,7 @@ info_address_command (const char *exp, int from_tty) return; } - switch (sym->aclass ()) + switch (sym->loc_class ()) { case LOC_CONST: case LOC_CONST_BYTES: @@ -1753,9 +1754,9 @@ info_address_command (const char *exp, int from_tty) case LOC_UNRESOLVED: { - struct bound_minimal_symbol msym; - - msym = lookup_bound_minimal_symbol (sym->linkage_name ()); + bound_minimal_symbol msym + = lookup_minimal_symbol (current_program_space, + sym->linkage_name ()); if (msym.minsym == NULL) gdb_printf ("unresolved"); else @@ -2035,7 +2036,7 @@ undisplay_command (const char *args, int from_tty) dont_repeat (); } -/* Display a single auto-display. +/* Display a single auto-display. Do nothing if the display cannot be printed in the current context, or if the display is disabled. */ @@ -2294,11 +2295,11 @@ disable_display_command (const char *args, int from_tty) static void clear_dangling_display_expressions (struct objfile *objfile) { - program_space *pspace = objfile->pspace; + program_space *pspace = objfile->pspace (); if (objfile->separate_debug_objfile_backlink) { objfile = objfile->separate_debug_objfile_backlink; - gdb_assert (objfile->pspace == pspace); + gdb_assert (objfile->pspace () == pspace); } for (auto &d : all_displays) @@ -2324,24 +2325,13 @@ clear_dangling_display_expressions (struct objfile *objfile) } -/* Print the value in stack frame FRAME of a variable specified by a - struct symbol. NAME is the name to print; if NULL then VAR's print - name will be used. STREAM is the ui_file on which to print the - value. INDENT specifies the number of indent levels to print - before printing the variable name. */ +/* See value.h. */ void -print_variable_and_value (const char *name, struct symbol *var, - const frame_info_ptr &frame, - struct ui_file *stream, int indent) +print_variable_value (symbol *var, const frame_info_ptr &frame, + ui_file *stream, int indent, + const language_defn *language) { - - if (!name) - name = var->print_name (); - - gdb_printf (stream, "%*s%ps = ", 2 * indent, "", - styled_string (variable_name_style.style (), name)); - try { struct value *val; @@ -2354,14 +2344,30 @@ print_variable_and_value (const char *name, struct symbol *var, val = read_var_value (var, NULL, frame); get_user_print_options (&opts); opts.deref_ref = true; - common_val_print_checked (val, stream, indent, &opts, current_language); + common_val_print_checked (val, stream, indent, &opts, language); } catch (const gdb_exception_error &except) { fprintf_styled (stream, metadata_style.style (), - "<error reading variable %s (%s)>", name, + "<error reading variable: %s>", except.what ()); } +} + +/* See value.h. */ + +void +print_variable_and_value (const char *name, symbol *var, + const frame_info_ptr &frame, + ui_file *stream, int indent) +{ + if (name == nullptr) + name = var->print_name (); + + gdb_printf (stream, "%*s%ps = ", 2 * indent, "", + styled_string (variable_name_style.style (), name)); + + print_variable_value (var, frame, stream, indent, current_language); gdb_printf (stream, "\n"); } @@ -2394,7 +2400,7 @@ printf_c_string (struct ui_file *stream, const char *format, } else { - CORE_ADDR tem = value_as_address (value);; + CORE_ADDR tem = value_as_address (value); if (tem == 0) { @@ -2689,7 +2695,7 @@ ui_printf (const char *arg, struct ui_file *stream) if (*s++ != '"') error (_("Bad format string, non-terminated '\"'.")); - + s = skip_spaces (s); if (*s != ',' && *s != 0) @@ -2702,7 +2708,6 @@ ui_printf (const char *arg, struct ui_file *stream) { int nargs_wanted; int i; - const char *current_substring; nargs_wanted = 0; for (auto &&piece : fpieces) @@ -2731,7 +2736,8 @@ ui_printf (const char *arg, struct ui_file *stream) i = 0; for (auto &&piece : fpieces) { - current_substring = piece.string; + const char *current_substring = fpieces.piece_str (piece); + switch (piece.argclass) { case string_arg: @@ -2885,7 +2891,7 @@ static void printf_command (const char *arg, int from_tty) { ui_printf (arg, gdb_stdout); - gdb_stdout->reset_style (); + gdb_stdout->emit_style_escape (ui_file_style ()); gdb_stdout->wrap_here (0); gdb_stdout->flush (); } @@ -2922,14 +2928,6 @@ show_memory_tagging_unsupported (void) " architecture.")); } -/* Implement the "memory-tag" prefix command. */ - -static void -memory_tag_command (const char *arg, int from_tty) -{ - help_list (memory_tag_list, "memory-tag ", all_commands, gdb_stdout); -} - /* Helper for print-logical-tag and print-allocation-tag. */ static void @@ -3191,9 +3189,7 @@ memory_tag_check_command (const char *args, int from_tty) } } -void _initialize_printcmd (); -void -_initialize_printcmd () +INIT_GDB_FILE (printcmd) { struct cmd_list_element *c; @@ -3240,7 +3236,7 @@ No argument means cancel all automatic-display expressions.\n\ Do \"info display\" to see current list of code numbers."), &cmdlist); - c = add_com ("display", class_vars, display_command, _("\ + c = add_com ("display", class_vars | class_essential, display_command, _("\ Print value of expression EXP each time the program stops.\n\ Usage: display[/FMT] EXP\n\ /FMT may be used before EXP as in the \"print\" command.\n\ @@ -3354,7 +3350,8 @@ but no count or size letter (see \"x\" command)."), print_opts); cmd_list_element *print_cmd - = add_com ("print", class_vars, print_command, print_help.c_str ()); + = add_com ("print", class_vars | class_essential, print_command, + print_help.c_str ()); set_cmd_completer_handle_brkchars (print_cmd, print_command_completer); add_com_alias ("p", print_cmd, class_vars, 1); add_com_alias ("inspect", print_cmd, class_vars, 1); @@ -3386,7 +3383,7 @@ Convert the arguments to a string as \"printf\" would, but then\n\ treat this string as a command line, and evaluate it.")); /* Memory tagging commands. */ - add_prefix_cmd ("memory-tag", class_vars, memory_tag_command, _("\ + add_basic_prefix_cmd ("memory-tag", class_vars, _("\ Generic command for printing and manipulating memory tag properties."), &memory_tag_list, 0, &cmdlist); add_cmd ("print-logical-tag", class_vars, |
