poke-devel
[Top][All Lists]
Advanced

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

Re: [Discussion] Side-by-side dump format


From: Jose E. Marchesi
Subject: Re: [Discussion] Side-by-side dump format
Date: Mon, 21 Aug 2023 23:01:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Yet another version that uses saner indexes.

diff --git a/etc/poke-dark.css b/etc/poke-dark.css
index e1fff1dc..6880e53a 100644
--- a/etc/poke-dark.css
+++ b/etc/poke-dark.css
@@ -26,6 +26,10 @@
 .dump-address { color : green; }
 .dump-ascii { color : brown; }
 .dump-unknown { color : yellow; }
+.dump-val1 { color : green; }
+.dump-val2 { color : red; }
+.dump-val3 { color : yellow; }
+.dump-val4 { color : brown; }
 
 .diff-thunk-header { font-weight: bold; }
 .diff-minus { color : red; }
diff --git a/pickles/ios.pk b/pickles/ios.pk
index be7fad3e..9d8a47fe 100644
--- a/pickles/ios.pk
+++ b/pickles/ios.pk
@@ -18,6 +18,22 @@
 
 /* This pickle contains utilities related to poke IO spaces.  */
 
+var ios_dumpval_styles
+  = ["dump-val1", "dump-val2", "dump-val3", "dump-val4"];
+
+type IOS_Dumpval_Info =
+  struct
+  {
+    string name;
+    int<32> index; /* 0 means non-mapped.  */
+    int<32> style;
+    offset<uint<64>,b> offset;
+    offset<uint<64>,b> size;
+  };
+
+var ios_dumpval = any[]();
+var ios_dumpval_info = IOS_Dumpval_Info[]();
+
 /* Print a byte dump of an area in a given IO space.
 
    IOS is the IO space from which dump bytes.
@@ -53,6 +69,7 @@
 fun ios_dump_bytes = (int<32> ios,
                       offset<uint<64>,b> from,
                       offset<uint<64>,b> size,
+                      any val = -1,
                       offset<uint<64>,b> group_by = 2#B,
                       int<32> cluster_by = 8,
                       int<32> ruler_p = 0,
@@ -60,6 +77,8 @@ fun ios_dump_bytes = (int<32> ios,
                       string unknown_byte = "??",
                       uint<8> nonprintable_char = '.') void:
 {
+  var print_val_p = 0;
+
   fun print_ruler = (offset<uint<64>,b> offset) void:
   {
     var o = 0#B;
@@ -131,6 +150,39 @@ fun ios_dump_bytes = (int<32> ios,
       }
   }
 
+  fun print_values = (offset<uint<64>,b> offset,
+                      offset<uint<64>,b> step,
+                      offset<uint<64>,b> top) void:
+  {
+    var o = 0#B;
+    while (o < step && offset + o < top)
+      {
+        for (var idx = 0; idx < ios_dumpval'length; ++idx)
+          {
+            var info = ios_dumpval_info[idx];
+            if (info.offset == offset + o)
+              {
+                var val = ios_dumpval[idx];
+                var style = ios_dumpval_styles[info.style % 
ios_dumpval_styles'length];
+
+                print " ";
+                if (info.index >= 0)
+                  {
+                    hserver_print_hl ('e',
+                                       format ("%i32d", idx),
+                                       format (".dump :val %i32d", idx));
+                    print ("=");
+                  }
+                term_begin_class (style);
+                print (info.name);
+                term_end_class (style);
+                break;
+              }
+          }
+        o += 1#B;
+      }
+  }
+
   fun print_data = (offset<uint<64>,b> offset,
                     offset<uint<64>,b> top,
                     offset<uint<64>,b> step,
@@ -154,7 +206,27 @@ fun ios_dump_bytes = (int<32> ios,
                 var b = uint<8> @ ios : (offset + o);
                 if (o % group_by == 0#B)
                      print " ";
+
+                var style = "";
+                if (print_val_p)
+                  {
+                    for (var idx = 0; idx < ios_dumpval'length; ++idx)
+                      {
+                        var info = ios_dumpval_info[idx];
+                        if (offset + o >= info.offset
+                            && offset + o < info.offset + info.size)
+                          {
+                            style = ios_dumpval_styles[info.style % 
ios_dumpval_styles'length];
+                            break;
+                          }
+                      }
+                  }
+
+                if (style != "")
+                  term_begin_class (style);
                 printf ("%u8x", b);
+                if (style != "")
+                  term_end_class (style);
              }
               catch if E_io
               {
@@ -171,15 +243,38 @@ fun ios_dump_bytes = (int<32> ios,
        catch if E_eof {}
        if (ascii_p)
          {
-           while (o < step)
+            var ob = o, ot = o;
+           while (ot < step)
              {
-               if (o % group_by == 0#B)
+               if (ot % group_by == 0#B)
                  print " ";
                print ("  ");
-                o++;
+                ot++;
              }
            print_ascii (offset, top, step, group_by, cluster_by);
+            if (print_val_p)
+              {
+                while (ob < step)
+                  {
+                    print " ";
+                    ob++;
+                  }
+              }
          }
+        if (print_val_p)
+          {
+            if (!ascii_p)
+              {
+               while (o < step)
+                 {
+                   if (o % group_by == 0#B)
+                     print " ";
+                   print ("  ");
+                    o++;
+                  }
+             }
+            print_values (offset, step, top);
+          }
        print "\n";
       }
   }
@@ -188,6 +283,61 @@ fun ios_dump_bytes = (int<32> ios,
   if (! (ioflags (ios) & IOS_F_READ))
     raise E_perm;
 
+  /* If `val' is specified, it can be:
+     negative -> for "no value".
+     int<32> -> for a mapped value stored in ios_dumpval.
+     other   -> mapped value from which to derive `from'
+                and `size'.
+   */
+  if (val isa int<32>)
+    {
+      if (val as int<32> > ios_dumpval'length)
+        raise Exception { code = EC_inval,
+                          name = "invalid argument",
+                          msg = "invalid VAL index" };
+
+      if (val as int<32> >= 0)
+        {
+          val = ios_dumpval[val as int<32>];
+
+          if (!val'mapped)
+            raise Exception { code = EC_inval,
+                              name = "invalid argument",
+                              msg = "indexed VAL is not mapped" };
+        }
+    }
+
+  if (val'mapped)
+    {
+      from = val'offset;
+      size = val'size;
+      print_val_p = 1;
+
+      /* Reset ios_dumpval and ios_dumpval_info.  */
+      ios_dumpval = any[]();
+      ios_dumpval_info = IOS_Dumpval_Info[]();
+
+      /* Populate the array with the fields of VAL.  */
+      for (var idx = 0UL, style = 0; idx < val'length; ++idx)
+        {
+          /* If the field is optional, check it is actually present.  If it
+             is not, do not add it to the array.  */
+          if (val'elem (idx) ?! E_inval)
+            continue;
+
+          /* Add the element and its info to the arrays.  */
+          var elem = val'elem (idx);
+          apush (ios_dumpval, val'elem (idx));
+          apush (ios_dumpval_info,
+                 IOS_Dumpval_Info {
+                   name = val'ename (idx) == "" ? "<anon>" : val'ename (idx),
+                   index = elem'mapped ? idx as int<32> : -1,
+                   offset = val'eoffset (idx),
+                   size = val'esize (idx),
+                   style = style++ });
+        }
+    }
+
   /* The `dump' command is byte-oriented.
      The base offset is truncated to bytes.
      The offset is rounded up to the next byte.  */
diff --git a/poke/pk-dump.pk b/poke/pk-dump.pk
index 62eb8035..9a052933 100644
--- a/poke/pk-dump.pk
+++ b/poke/pk-dump.pk
@@ -117,12 +117,13 @@ fun pk_dump_set_offset = (int<32> ios, offset<int<64>,b> 
offset) void:
 fun dump = (int<32> ios = get_ios,
             offset<int<64>,b> from = pk_dump_get_offset (ios),
             offset<int<64>,b> size = pk_dump_size,
+            any val = 0,
             offset<int<64>,b> group_by = pk_dump_group_by,
             int<32> cluster_by = pk_dump_cluster_by,
             int<32> ruler = pk_dump_ruler,
             int<32> ascii = pk_dump_ascii) void:
 {
-  ios_dump_bytes :ios ios :from from :size size :group_by group_by
+  ios_dump_bytes :ios ios :from from :size size :group_by group_by :val val
                  :cluster_by cluster_by :ruler_p ruler :ascii_p ascii
                  :unknown_byte pk_dump_unknown_byte;
   pk_dump_set_offset (ios, from);



reply via email to

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