This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patch] new command: 'dump' a region of memory in ascii and hex


Hi,

Here is a new function that I have found useful, maybe you will too.  The only
thing I don't completely like about it is that I have to make my xterm wider
than 80 chars for most of the output to look good.  This means it won't look
very good at all at console.  Since the length of symbol names vary I'm not
sure what can be done about this.  I think dynamically changing the number of
chars per line would be confusing. 

I'm not sure how it ill behave on all archs, but I took a shot at a new test
for the testsuite.

-David


(top-gdb) help dump
Dumps a region of memory, show hex and ascii.
A single argument is the starting address.
Two arguments are taken as a range of memory to dump.
(top-gdb) dump 0x683d3
0x683d3 <internal_error+3>:      8d450c50 ff7508e8 05ffffff 9028756e    .E.P.u.......(un
0x683e3 <internal_error+19>:     646f6375 6d656e74 65642065 72726e6f    documented.errno
0x683f3 <internal_error+35>:     20256429 005589e5 538b5d08 53e84f7d    .%d).U..S.].S.O}
0x68403 <safe_strerror+11>:      0c0083c4 0485c075 155368e0 83060068    .......u.Sh....h
0x68413 <safe_strerror+27>:      bc151400 e8f87c0c 00b8bc15 14008b5d    ......|........]
0x68423 <safe_strerror+43>:      fcc9c328 756e646f 63756d65 6e746564    ...(undocumented
0x68433 <safe_strerror+59>:      20736967 6e616c20 25642900 005589e5    .signal.%d)..U..
0x68443 <safe_strsignal+3>:      538b5d08 53e83355 0a0083c4 0485c075    S.].S.3U.......u
0x68453 <safe_strsignal+19>:     15536826 84060068 dc151400 e8b07c0c    .Sh&...h......|.
0x68463 <safe_strsignal+35>:     00b8dc15 14008b5d fcc9c33a 20002573    .......]...:..%s
(top-gdb) 




2000-11-21  David Whedon <dwhedon@gordian.com>
	* printcmd.c (dump_command) : new command that dumps a region 
	of memory in hex and ascii
	(_initialize_printcmd) : add 'dump' to command list.


--- ../gdb-5.0/gdb/printcmd.c	Thu Apr 20 21:10:46 2000
+++ ./printcmd.c	Tue Nov 21 17:32:17 2000
@@ -2521,6 +2521,65 @@ print_insn (memaddr, stream)
 }
 
 
+#define CHARS_PER_LINE 16
+
+static void
+dump_command (char *arg, int from_tty)
+{
+  value_ptr val;
+
+  CORE_ADDR low, high;
+  char *space_index;
+  struct type *val_type = examine_b_type;
+  int i, j;
+  struct format_data fmt;
+  char buffer[CHARS_PER_LINE + 1];
+
+  if (!arg)
+    {
+      low = next_address;
+      high = low + CHARS_PER_LINE * 10;
+    }
+  else if (!(space_index = (char *) strchr (arg, ' ')))
+    {
+      /* one arg */
+      low = parse_and_eval_address (arg);
+      high = low + CHARS_PER_LINE * 10;
+
+    }
+  else
+    {
+      /* two args */
+      *space_index = '\0';
+      low = parse_and_eval_address (arg);
+      high = parse_and_eval_address (space_index + 1);
+    }
+
+
+  next_address = low;
+  while (next_address < high)
+    {
+      print_address (next_address, gdb_stdout);
+      printf_filtered (":\t");
+
+      for (i = 0; i < CHARS_PER_LINE; i++)
+	{
+	  if (i % 4 == 0)
+	    fprintf_filtered (gdb_stdout, " ");
+
+	  val = value_at (val_type, next_address, next_section);
+	  buffer[i] = 0xFF & *(VALUE_CONTENTS_RAW (val));
+	  fprintf_filtered (gdb_stdout, "%.2x", 0xFF & buffer[i]);
+	  if (buffer[i] < 33 || buffer[i] > 126)
+	    buffer[i] = '.';
+	  next_address++;
+	}
+      buffer[i] = '\0';
+      fprintf_filtered (gdb_stdout, "\t%s\n", buffer);
+
+    }
+}
+
 void
 _initialize_printcmd ()
 {
@@ -2597,6 +2656,11 @@ Do \"info display\" to see current list 
 Arguments are the code numbers of the expressions to stop displaying.\n\
 No argument means cancel all automatic-display expressions.\n\
 Do \"info display\" to see current list of code numbers.", &deletelist);
+
+  add_com ("dump", class_vars, dump_command,
+	   "Dumps a region of memory, show hex and ascii.\n\
+A single argument is the starting address.\n\
+Two arguments are taken as a range of memory to dump.");
 
   add_com ("printf", class_vars, printf_command,
 	   "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\


--- printcmds.exp.orig	Tue Nov 21 18:22:24 2000
+++ printcmds.exp	Tue Nov 21 18:23:01 2000
@@ -680,6 +680,13 @@ proc test_printf {} {
 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
 }
 
+proc test_dump {} {
+
+gdb_test "dump ctable2 ctable2+1" \
+    "0x.*<ctable2>:.*61585858 58585858 58585858 58585858.*aXXXXXXXXXXXXXXX"
+
+
+}
 # Start with a fresh gdb.
 
 gdb_exit
@@ -714,6 +721,7 @@ if [set_lang_c] then {
 	test_print_string_constants
 	test_print_array_constants
 	test_printf
+	test_dump
     }
 } else {
     fail "C print command tests suppressed"


rib /users/davidw> uname -a
Linux rib.gordian.com 2.2.10 #3 SMP Wed Feb 23 15:39:49 PST 2000 i686 unknown


before:
                === gdb Summary ===

# of expected passes            6380
# of unexpected failures        15
# of unexpected successes       32
# of expected failures          167
# of untested testcases         18

after:
                === gdb Summary ===

# of expected passes            6381
# of unexpected failures        15
# of unexpected successes       32
# of expected failures          167
# of untested testcases         18


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]