poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] fix bugs in dump


From: John Darrington
Subject: [PATCH] fix bugs in dump
Date: Wed, 20 Nov 2019 21:52:56 +0100

---
 src/pk-dump.pk               | 154 ++++++++++++++++++++++++-------------------
 testsuite/poke.cmd/dump-5.pk |  10 +++
 testsuite/poke.cmd/dump-6.pk |   9 +++
 3 files changed, 107 insertions(+), 66 deletions(-)
 create mode 100644 testsuite/poke.cmd/dump-5.pk
 create mode 100644 testsuite/poke.cmd/dump-6.pk

diff --git a/src/pk-dump.pk b/src/pk-dump.pk
index 451d379..5a9513a 100644
--- a/src/pk-dump.pk
+++ b/src/pk-dump.pk
@@ -42,71 +42,93 @@ defun dump = (off64 from = pk_dump_offset,
               off64 group_by = pk_dump_group_by,
               int ruler = pk_dump_ruler,
               int ascii = pk_dump_ascii) void:
+{
+  defun print_ruler = void:
   {
-   defun print_ruler = void:
-     {
-      defvar o = 0#B;
-
-      printf "%<dump-ruler:76543210 %>";
-      for (s in ["00", "11", "22", "33", "44", "55", "66",
-                 "77", "88", "99", "aa", "bb", "cc", "dd",
-                 "ee", "ff"])
-        {
-          if (o % group_by == 0#B)
-            printf "%<dump-ruler: %>";
-          printf "%<dump-ruler:%s%>", s;
-          o = o + 1#B;
-        }
-       if (ascii)
-         printf "%<dump-ruler:  0123456789ABCDEF%>";
-       print "\n";
-     }
-
-   defun print_data = (off64 offset, off64 top, off64 step) void:
-     {
-      while (offset < top)
-        {
-         printf ("%<dump-address:%u32x:%>", offset / #B);
-
-         defvar o = 0#B;
-         while (o < step && offset + o < top)
-           {
-             if (o % group_by == 0#B)
-               print " ";
-             printf ("%u8x", int<8> @ (offset + o));
-             o = o + 1#B;
-           }
-         if (ascii)
-          {
-            print("  ");
-            o = 0#B;
-            while (o < step && offset + o < top)
-              {
-                defvar v = int<8> @ (offset + o);
-                if (v < ' ' || v > '~')
-                  printf "%<dump-ascii:%c%>", '.';
-                else
-                  printf "%<dump-ascii:%c%>", v;
-                o = o + 1#B;
-              }
-          }
-         print "\n";
-
-         offset = offset + step;
-       }
-     }
-
-   /* The `dump' command is byte-oriented.  Both the base offset and
-      the size of the dump are truncated to bytes.  Hence the casts
-      below.  */
-   defvar offset = from as offset<uint<64>,B>;
-   defvar top = (from + size) as offset<uint<64>,B>;
-
-   if (ruler)
-     print_ruler;
-
-   try print_data :offset offset :top top :step 16#B;
-   catch if E_eof { print "\n"; }
-
-   pk_dump_offset = from;
+    defvar o = 0#B;
+
+    printf "%<dump-ruler:76543210 %>";
+    for (s in ["00", "11", "22", "33", "44", "55", "66",
+              "77", "88", "99", "aa", "bb", "cc", "dd",
+              "ee", "ff"])
+      {
+       if (o % group_by == 0#B)
+         printf "%<dump-ruler: %>";
+       printf "%<dump-ruler:%s%>", s;
+       o = o + 1#B;
+      }
+    if (ascii)
+      printf "%<dump-ruler:  0123456789ABCDEF%>";
+    print "\n";
   }
+
+  defun print_ascii = (off64 offset, off64 top, off64 step) void:
+  {
+    if (ascii)
+      {
+       print("  ");
+       defvar o = 0#B;
+       while (o < step && offset + o < top)
+         {
+           defvar v = int<8> @ (offset + o);
+           if (v < ' ' || v > '~')
+             printf "%<dump-ascii:%c%>", '.';
+           else
+             printf "%<dump-ascii:%c%>", v;
+           o = o + 1#B;
+         }
+      }
+  }
+
+  defun print_hex = (char c, off64 o) void:
+  {
+    if (o % group_by == 0#B)
+      print " ";
+    printf ("%u8x", c);
+  }
+
+  defun print_data = (off64 offset, off64 top, off64 step) void:
+  {
+    while (offset < top)
+      {
+       printf ("%<dump-address:%u32x:%>", offset / #B);
+
+       defvar o = 0#B;
+       try
+       {
+         while (o < step && offset + o < top)
+           {
+             print_hex (byte @ (offset + o), o);
+             o = o + 1#B;
+           }
+       }
+       catch if E_eof {}
+       while (o < step && ((offset + o) % 16#B) != 0#B)
+         {
+           if (o % group_by == 0#B)
+             print " ";
+           print ("  ");
+           o = o + 1#B;
+         }
+
+       print_ascii (offset, top, step);
+       print "\n";
+
+       offset = offset + step;
+      }
+  }
+
+  /* The `dump' command is byte-oriented.  Both the base offset and
+     the size of the dump are truncated to bytes.  Hence the casts
+     below.  */
+  defvar offset = from as offset<uint<64>,B>;
+  defvar top = (from + size) as offset<uint<64>,B>;
+
+  if (ruler)
+    print_ruler;
+
+  try print_data :offset offset :top top :step 16#B;
+  catch if E_eof { print "\n"; }
+
+  pk_dump_offset = from;
+}
diff --git a/testsuite/poke.cmd/dump-5.pk b/testsuite/poke.cmd/dump-5.pk
new file mode 100644
index 0000000..546feb1
--- /dev/null
+++ b/testsuite/poke.cmd/dump-5.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x41 0x42 
0x43 0x44 0x45 0x46 0x47 0x48 0x49} } */
+
+pk_dump_size = 18#B;
+pk_dump_group_by = 2#B;
+pk_dump_ruler = 0;
+pk_dump_ascii = 1;
+
+/* { dg-command { dump :from 0#B :group_by 2#B } } */
+/* { dg-output "00000000: 3031 3233 3435 3637 3839 4142 4344 4546  
0123456789ABCDEF\n00000010: 4748                                     GH"} */
diff --git a/testsuite/poke.cmd/dump-6.pk b/testsuite/poke.cmd/dump-6.pk
new file mode 100644
index 0000000..a884bde
--- /dev/null
+++ b/testsuite/poke.cmd/dump-6.pk
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x61 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x41 0x42 
0x43 0x44 0x45 0x46 0x47 0x48 0x49} } */
+
+pk_dump_group_by = 2#B;
+pk_dump_ruler = 0;
+pk_dump_ascii = 1;
+
+/* { dg-command { dump :from 0#B :group_by 2#B } } */
+/* { dg-output "00000000: 6131 3233 3435 3637 3839 4142 4344 4546  
a123456789ABCDEF\n00000010: 4748 49                                  GHI" } */
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]