From 1c35a88f1d8399902c08a8334d3e3303df833538 Mon Sep 17 00:00:00 2001 From: Luis Machado Date: Wed, 9 Dec 2015 10:56:27 -0200 Subject: varobj zero-padded hexadecimal format This set of patches add support for the zero-padded hexadecimal format for varobj's, defined as "zero-hexadecimal". We currently only support regular non-zero-padded hexadecimal. Talking with IDE developers, they would like to have this option that is already available to GDB's print/x commands, in the CLI, as 'z'. gdb/ChangeLog: 2015-12-09 Luis Machado * gdb/mi/mi-cmd-var.c (mi_parse_format): Handle new "zero-hexadecimal" format. * gdb/varobj.c (varobj_format_string): Add "zero-hexadecimal" entry. (format_code): Add 'z' entry. (varobj_set_display_format): Handle FORMAT_ZHEXADECIMAL. * gdb/varobj.h (varobj_display_formats) : New enum field. * NEWS: Add new note to MI changes citing the new zero-hexadecimal format for -var-set-format. gdb/doc/ChangeLog: 2015-12-09 Luis Machado * gdb.texinfo (GDB/MI Variable Objects): Update text to mention -var-set-format's new zero-hexadecimal format. gdb/testsuite/ChangeLog: 2015-12-09 Luis Machado * gdb.mi/mi-var-display.exp: Add new checks for the zero-hexadecimal format and change test names to make them unique. --- gdb/ChangeLog | 12 ++++++++++++ gdb/NEWS | 6 ++++++ gdb/doc/ChangeLog | 5 +++++ gdb/doc/gdb.texinfo | 7 ++++++- gdb/mi/mi-cmd-var.c | 4 +++- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.mi/mi-var-display.exp | 25 +++++++++++++++++++++++-- gdb/varobj.c | 5 +++-- gdb/varobj.h | 3 ++- 9 files changed, 65 insertions(+), 7 deletions(-) (limited to 'gdb') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8a8202c..bafae52 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2015-12-09 Luis Machado + + * gdb/mi/mi-cmd-var.c (mi_parse_format): Handle new "zero-hexadecimal" + format. + * gdb/varobj.c (varobj_format_string): Add "zero-hexadecimal" entry. + (format_code): Add 'z' entry. + (varobj_set_display_format): Handle FORMAT_ZHEXADECIMAL. + * gdb/varobj.h (varobj_display_formats) : New enum + field. + * NEWS: Add new note to MI changes citing the new zero-hexadecimal + format for -var-set-format. + 2015-12-09 Ruslan Kabatsayev (tiny patch) PR gdb/18702 diff --git a/gdb/NEWS b/gdb/NEWS index 280c8fe..9ca7f49 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -135,6 +135,12 @@ show remote exec-event-feature-packet The reply to qXfer:threads:read may now include a name attribute for each thread. +* MI changes + + ** The -var-set-format command now accepts the zero-hexadecimal + format. It outputs data in hexadecimal format with zero-padding on the + left. + *** Changes in GDB 7.10 * Support for process record-replay and reverse debugging on aarch64*-linux* diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 6f05e36..7b0dc35 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2015-12-09 Luis Machado + + * gdb.texinfo (GDB/MI Variable Objects): Update text to mention + -var-set-format's new zero-hexadecimal format. + 2015-12-08 Pierre-Marie de Rodat * gdb.texinfo (Ada Mode Into): Move overloading support diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9f72c52..be39f1c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -28980,13 +28980,18 @@ The syntax for the @var{format-spec} is as follows: @smallexample @var{format-spec} @expansion{} - @{binary | decimal | hexadecimal | octal | natural@} + @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@} @end smallexample The natural format is the default format choosen automatically based on the variable type (like decimal for an @code{int}, hex for pointers, etc.). +The zero-hexadecimal format has a representation similar to hexadecimal +but with padding zeroes to the left of the value. For example, a 32-bit +hexadecimal value of 0x1234 would be represented as 0x00001234 in the +zero-hexadecimal format. + For a variable with children, the format is set only on the variable itself, and the children are not affected. diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index e316812..643fd7a 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -233,10 +233,12 @@ mi_parse_format (const char *arg) return FORMAT_HEXADECIMAL; else if (strncmp (arg, "octal", len) == 0) return FORMAT_OCTAL; + else if (strncmp (arg, "zero-hexadecimal", len) == 0) + return FORMAT_ZHEXADECIMAL; } error (_("Must specify the format as: \"natural\", " - "\"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); + "\"binary\", \"decimal\", \"hexadecimal\", \"octal\" or \"zero-hexadecimal\"")); } void diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d959e7b..e4b396f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-12-09 Luis Machado + + * gdb.mi/mi-var-display.exp: Add new checks for the zero-hexadecimal + format and change test names to make them unique. + 2015-12-09 Ruslan Kabatsayev Pedro Alves diff --git a/gdb/testsuite/gdb.mi/mi-var-display.exp b/gdb/testsuite/gdb.mi/mi-var-display.exp index 31bdce4..d65233b 100644 --- a/gdb/testsuite/gdb.mi/mi-var-display.exp +++ b/gdb/testsuite/gdb.mi/mi-var-display.exp @@ -81,6 +81,11 @@ mi_gdb_test "-var-evaluate-expression bar" \ "eval variable bar" # Test: c_variable-6.5 +# Desc: change format of bar to zero-padded hexadecimal +mi_gdb_test "-var-set-format bar zero-hexadecimal" \ + "\\^done,format=\"zero-hexadecimal\",value=\"0x0.*849\"" \ + "set format variable bar in zero-padded hexadecimal" + # Desc: change format of bar to hex mi_gdb_test "-var-set-format bar hexadecimal" \ "\\^done,format=\"hexadecimal\",value=\"0x849\"" \ @@ -241,7 +246,7 @@ mi_gdb_test "-var-set-format weird.func_ptr hexadecimal" \ mi_gdb_test "-var-show-format weird.func_ptr" \ "\\^done,format=\"hexadecimal\"" \ - "show format variable weird.func_ptr" + "show format variable weird.func_ptr (hex)" mi_gdb_test "-var-set-format weird.func_ptr_ptr hexadecimal" \ "\\^done,format=\"hexadecimal\",value=\"$hex\"" \ @@ -249,7 +254,23 @@ mi_gdb_test "-var-set-format weird.func_ptr_ptr hexadecimal" \ mi_gdb_test "-var-show-format weird.func_ptr_ptr" \ "\\^done,format=\"hexadecimal\"" \ - "show format variable weird.func_ptr_ptr" + "show format variable weird.func_ptr_ptr (hex)" + +mi_gdb_test "-var-set-format weird.func_ptr zero-hexadecimal" \ + "\\^done,format=\"zero-hexadecimal\",value=\"$hex\"" \ + "set format variable weird.func_ptr in zero-padded hex" + +mi_gdb_test "-var-show-format weird.func_ptr" \ + "\\^done,format=\"zero-hexadecimal\"" \ + "show format variable weird.func_ptr (zhex)" + +mi_gdb_test "-var-set-format weird.func_ptr_ptr zero-hexadecimal" \ + "\\^done,format=\"zero-hexadecimal\",value=\"$hex\"" \ + "set format variable weird.func_ptr_ptr in zero-padded hex" + +mi_gdb_test "-var-show-format weird.func_ptr_ptr" \ + "\\^done,format=\"zero-hexadecimal\"" \ + "show format variable weird.func_ptr_ptr (zhex)" # Test: c_variable-6.24 # Desc: format of weird and children diff --git a/gdb/varobj.c b/gdb/varobj.c index 92b0f33..0b19d84 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -50,7 +50,7 @@ show_varobjdebug (struct ui_file *file, int from_tty, /* String representations of gdb's format codes. */ char *varobj_format_string[] = - { "natural", "binary", "decimal", "hexadecimal", "octal" }; + { "natural", "binary", "decimal", "hexadecimal", "octal", "zero-hexadecimal" }; /* True if we want to allow Python-based pretty-printing. */ static int pretty_printing = 0; @@ -214,7 +214,7 @@ static struct varobj *varobj_add_child (struct varobj *var, /* Private data */ /* Mappings of varobj_display_formats enums to gdb's format codes. */ -static int format_code[] = { 0, 't', 'd', 'x', 'o' }; +static int format_code[] = { 0, 't', 'd', 'x', 'o', 'z' }; /* Header of the list of root variable objects. */ static struct varobj_root *rootlist; @@ -583,6 +583,7 @@ varobj_set_display_format (struct varobj *var, case FORMAT_DECIMAL: case FORMAT_HEXADECIMAL: case FORMAT_OCTAL: + case FORMAT_ZHEXADECIMAL: var->format = format; break; diff --git a/gdb/varobj.h b/gdb/varobj.h index 8860526..179b2a5 100644 --- a/gdb/varobj.h +++ b/gdb/varobj.h @@ -28,7 +28,8 @@ enum varobj_display_formats FORMAT_BINARY, /* Binary display */ FORMAT_DECIMAL, /* Decimal display */ FORMAT_HEXADECIMAL, /* Hex display */ - FORMAT_OCTAL /* Octal display */ + FORMAT_OCTAL, /* Octal display */ + FORMAT_ZHEXADECIMAL /* Zero padded hexadecimal */ }; enum varobj_type -- cgit v1.1