X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fprintcmd.c;h=a6d6d7e12d36fedf1f5aa9c871cd597e6af5d6e6;hb=76af0f26356580771a18c37de4ebccdfbc449356;hp=fc9d7e4dd9ad4e8b13d0321fdc2a7fcae46c0b7f;hpb=aee1fcdf979d65c7623533ddd6d871767be9de13;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/printcmd.c b/gdb/printcmd.c index fc9d7e4dd9..a6d6d7e12d 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -39,7 +39,7 @@ #include "block.h" #include "disasm.h" #include "target-float.h" -#include "observer.h" +#include "observable.h" #include "solist.h" #include "parser-defs.h" #include "charset.h" @@ -78,7 +78,7 @@ static CORE_ADDR last_examine_address; /* Contents of last address examined. This is not valid past the end of the `x' command! */ -static struct value *last_examine_value; +static value_ref_ptr last_examine_value; /* Largest offset between a symbolic value and an address, that will be printed as `0x1234 '. */ @@ -1093,9 +1093,6 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) object. */ last_examine_address = next_address; - if (last_examine_value) - value_free (last_examine_value); - /* The value to be displayed is not fetched greedily. Instead, to avoid the possibility of a fetched value not being used, its retrieval is delayed until the print code @@ -1105,12 +1102,10 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) the disassembler be modified so that LAST_EXAMINE_VALUE is left with the byte sequence from the last complete instruction fetched from memory? */ - last_examine_value = value_at_lazy (val_type, next_address); - - if (last_examine_value) - release_value (last_examine_value); + last_examine_value + = release_value (value_at_lazy (val_type, next_address)); - print_formatted (last_examine_value, size, &opts, gdb_stdout); + print_formatted (last_examine_value.get (), size, &opts, gdb_stdout); /* Display any branch delay slots following the final insn. */ if (format == 'i' && count == 1) @@ -1668,12 +1663,12 @@ x_command (const char *exp, int from_tty) last_format = fmt.format; /* Set a couple of internal variables if appropriate. */ - if (last_examine_value) + if (last_examine_value != nullptr) { /* Make last address examined available to the user as $_. Use the correct pointer type. */ struct type *pointer_type - = lookup_pointer_type (value_type (last_examine_value)); + = lookup_pointer_type (value_type (last_examine_value.get ())); set_internalvar (lookup_internalvar ("_"), value_from_pointer (pointer_type, last_examine_address)); @@ -1682,10 +1677,10 @@ x_command (const char *exp, int from_tty) as $__. If the last value has not been fetched from memory then don't fetch it now; instead mark it by voiding the $__ variable. */ - if (value_lazy (last_examine_value)) + if (value_lazy (last_examine_value.get ())) clear_internalvar (lookup_internalvar ("__")); else - set_internalvar (lookup_internalvar ("__"), last_examine_value); + set_internalvar (lookup_internalvar ("__"), last_examine_value.get ()); } } @@ -2220,6 +2215,11 @@ printf_c_string (struct ui_file *stream, const char *format, int j; tem = value_as_address (value); + if (tem == 0) + { + fprintf_filtered (stream, format, "(null)"); + return; + } /* This is a %s argument. Find the length of the string. */ for (j = 0;; j++) @@ -2260,6 +2260,11 @@ printf_wide_c_string (struct ui_file *stream, const char *format, gdb_byte *buf = (gdb_byte *) alloca (wcwidth); tem = value_as_address (value); + if (tem == 0) + { + fprintf_filtered (stream, format, "(null)"); + return; + } /* This is a %s argument. Find the length of the string. */ for (j = 0;; j += wcwidth) @@ -2399,8 +2404,9 @@ printf_pointer (struct ui_file *stream, const char *format, if (val != 0) *fmt_p++ = '#'; - /* Copy any width. */ - while (*p >= '0' && *p < '9') + /* Copy any width or flags. Only the "-" flag is valid for pointers + -- see the format_pieces constructor. */ + while (*p == '-' || (*p >= '0' && *p < '9')) *fmt_p++ = *p++; gdb_assert (*p == 'p' && *(p + 1) == '\0'); @@ -2612,7 +2618,7 @@ _initialize_printcmd (void) current_display_number = -1; - observer_attach_free_objfile (clear_dangling_display_expressions); + gdb::observers::free_objfile.attach (clear_dangling_display_expressions); add_info ("address", info_address_command, _("Describe where symbol SYM is stored.")); @@ -2680,8 +2686,9 @@ No argument means cancel all automatic-display expressions.\n\ Do \"info display\" to see current list of code numbers."), &deletelist); add_com ("printf", class_vars, printf_command, _("\ -printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ -This is useful for formatted output in user-defined commands.")); +Formatted printing, like the C \"printf\" function.\n\ +Usage: printf \"format string\", arg1, arg2, arg3, ..., argn\n\ +This supports most C printf format specifications, like %s, %d, etc.")); add_com ("output", class_vars, output_command, _("\ Like \"print\" but don't put in value history and don't print newline.\n\ @@ -2725,6 +2732,7 @@ with $), a register (a few standard names starting with $), or an actual\n\ variable in the program being debugged. EXP is any valid expression.\n\ This may usually be abbreviated to simply \"set\"."), &setlist); + add_alias_cmd ("var", "variable", class_vars, 0, &setlist); c = add_com ("print", class_vars, print_command, _("\ Print value of expression EXP.\n\