Add negative repeat count to 'x' command
authorToshihito Kikuchi <k.toshihito@yahoo.de>
Fri, 10 Jun 2016 05:47:42 +0000 (22:47 -0700)
committerToshihito Kikuchi <k.toshihito@yahoo.de>
Fri, 10 Jun 2016 05:50:47 +0000 (22:50 -0700)
commitbb556f1facb86cdd1591d490f2d2d670bdd5a1ee
treeccc99d237487ee5952ff66d92a4f2a207dd41f6a
parentc040f3fb55315f06ceb9e6de6ac167a95a445ace
Add negative repeat count to 'x' command

This change adds support for specifying a negative repeat count to
all the formats of the 'x' command to examine memory backward.
A new testcase 'examine-backward' is added to cover this new feature.

Here's the example output from the new feature:

<format 'i'>
(gdb) bt
#0  Func1 (n=42, p=0x40432e "hogehoge") at main.cpp:5
#1  0x00000000004041fa in main (argc=1, argv=0x7fffffffdff8) at main.cpp:19
(gdb) x/-4i 0x4041fa
  0x4041e5 <main(int, char**)+11>: mov   %rsi,-0x10(%rbp)
  0x4041e9 <main(int, char**)+15>: lea   0x13e(%rip),%rsi
  0x4041f0 <main(int, char**)+22>: mov   $0x2a,%edi
  0x4041f5 <main(int, char**)+27>: callq 0x404147

<format 'x'>
(gdb) x/-4xw 0x404200
0x4041f0 <main(int, char**)+22>: 0x00002abf 0xff4de800 0x76e8ffff 0xb8ffffff
(gdb) x/-4
0x4041e0 <main(int, char**)+6>:  0x7d8910ec 0x758948fc 0x358d48f0 0x0000013e

gdb/ChangeLog:

* NEWS: Mention that GDB now supports a negative repeat count in
the 'x' command.
* printcmd.c (decode_format): Allow '-' in the parameter
"string_ptr" to accept a negative repeat count.
(find_instruction_backward): New function.
(read_memory_backward): New function.
(integer_is_zero): New function.
(find_string_backward): New function.
(do_examine): Use new functions to examine memory backward.
(_initialize_printcmd): Mention that 'x' command supports a negative
repeat count.

gdb/doc/ChangeLog:

* gdb.texinfo (Examining Memory): Document negative repeat
count in the 'x' command.

gdb/testsuite/ChangeLog:

* gdb.base/examine-backward.c: New file.
* gdb.base/examine-backward.exp: New file.
gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/printcmd.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/examine-backward.c [new file with mode: 0644]
gdb/testsuite/gdb.base/examine-backward.exp [new file with mode: 0644]