public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Arbitrary width memory window.
@ 2006-01-10 14:51 Andrew STUBBS
  2006-01-10 15:56 ` Andrew STUBBS
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew STUBBS @ 2006-01-10 14:51 UTC (permalink / raw)
  To: insight

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

Hi,

The attached patch permits the memory window to be set to any number of 
bytes per row between 1 and 150 (alignment permitting).

It changes the combo box from a fixed list to an editable value. This 
value is then properly validated and adjusted to fit the current word 
size. It is also adjusted automatically when the word size is altered.

Therefore it is now possible to have, say, 10 bytes, or 3 words, or 5 
floats, all of which were not possible before.

Andrew Stubbs

[-- Attachment #2: memwin.patch --]
[-- Type: text/plain, Size: 4840 bytes --]

2005-01-10  Andrew Stubbs  <andrew.stubbs@st.com>

	* library/mempref.itb (MemPref::constructor): Allow the Byte Per Row
	combo box to accept arbitrary values.
	(MemPref::set_bytes_per_row): Validate the new value; reject invalid
	entries and round up to a multiple of the word size.
	(MemPref::apply): Read the value from the text box even if the user
	has not pressed return.
	(MemPref::enable_format): Ensure the bytes per row value is still valid.
	(MemPref::disable_format): Likewise.
	* library/mempref.ith (MemPref): Add $gbprlist.

Index: src/gdb/gdbtk/library/mempref.itb
===================================================================
--- src.orig/gdb/gdbtk/library/mempref.itb	2006-01-03 18:23:57.000000000 +0000
+++ src/gdb/gdbtk/library/mempref.itb	2006-01-10 14:00:00.000000000 +0000
@@ -41,6 +41,7 @@ itcl::body MemPref::constructor {args} {
   
   set gnumbytes $numbytes
   set gbpr $bpr
+  set gbprlist [list 4 8 16 32 64 128]
   set gascii $ascii
   set gascii_char $ascii_char
   
@@ -153,14 +154,11 @@ itcl::body MemPref::build_win {} {
   label $fr.2.l -text "Bytes Per Row "
   set Widgets(b-bytes_per_row) [::combobox::combobox $fr.2.c \
 				  -command [code $this set_bytes_per_row]  \
-				  -width 4 -editable 0 -font global/fixed \
+				  -width 4 -editable 1 -font global/fixed \
 				  -bg $::Colors(textbg)]
-  $fr.2.c list insert end 4
-  $fr.2.c list insert end 8
-  $fr.2.c list insert end 16
-  $fr.2.c list insert end 32
-  $fr.2.c list insert end 64
-  $fr.2.c list insert end 128
+  foreach item $gbprlist {
+    $fr.2.c list insert end $item
+  }
   $fr.2.c configure -value $gbpr
 
   pack $fr.2.l -side left -anchor e
@@ -264,7 +262,40 @@ itcl::body MemPref::check_numbytes {var 
 #  METHOD:  set_bytes_per_row - combobox callback to set the bytes per row
 # ------------------------------------------------------------------
 itcl::body MemPref::set_bytes_per_row {w value} {
-  set gbpr $value
+  if {[string is integer -strict $value] && [expr {$value != 0}]} {
+    # The input is a value number.
+    set gbpr $value
+    set gbpr [string trim $gbpr]
+
+    # Too high a number will cause a Segmentation fault.
+    if {[expr {$gbpr > 150}]} {set gbpr 150}
+
+    # Insert the value into the combo box list, if it isn't there already.
+    set found 0
+    foreach item $gbprlist {
+      if {$item == $gbpr} {
+        set found 1
+      }
+    }
+    if {[expr {$found == 0}]} {
+      lappend gbprlist $gbpr
+      $Widgets(b-bytes_per_row) list insert end $gbpr
+    }
+
+    set s $gsize
+    if {[expr {$s == 3}]} {set s 4}
+    if {[expr {$s == 5}]} {set s 8}
+    set rem [expr {$gbpr % $s}]
+    if {[expr {$rem != 0}]} {
+      # The bytes-per-row is not a multiple of the size.
+      set gbpr [expr {$gbpr + ($s - $rem)}]
+    }
+  }
+
+  # Set the display to the new value. This may be different if the input
+  # was zero or not a number, or if the user entered any whitespace.
+  $Widgets(b-bytes_per_row) delete 0 end
+  $Widgets(b-bytes_per_row) insert end $gbpr
 }
 
 # ------------------------------------------------------------------
@@ -318,6 +349,9 @@ itcl::body MemPref::apply {} {
     }
   }
 
+  # Ensure the value has been read from the text field.
+  set_bytes_per_row "" [$Widgets(b-bytes_per_row) get]
+
   # pass all the changed values back to parent
   debug "$win configChange -size $size -numbytes $numbytes \
 	     -format $format -ascii $gascii \
@@ -338,6 +372,10 @@ itcl::body MemPref::apply {} {
 #  METHOD:  enable_format - turn on the format radio buttons 
 # ------------------------------------------------------------------
 itcl::body MemPref::enable_format {} {
+  # First ensure bytes per row is a multiple of the size.
+  # Use the value of the widget, not $gbpr to ensure the typed value is kept.
+  set_bytes_per_row "" [$Widgets(b-bytes_per_row) get]
+
   if {!$format_disabled} {
     return
   }
@@ -353,6 +391,10 @@ itcl::body MemPref::enable_format {} {
 #  METHOD:  disable_format - turn off the format radio buttons 
 # ------------------------------------------------------------------
 itcl::body MemPref::disable_format {} {
+  # First ensure bytes per row is a multiple of the size.
+  # Use the value of the widget, not $gbpr to ensure the typed value is kept.
+  set_bytes_per_row "" [$Widgets(b-bytes_per_row) get]
+
   if {$format_disabled} {
     return
   }
Index: src/gdb/gdbtk/library/mempref.ith
===================================================================
--- src.orig/gdb/gdbtk/library/mempref.ith	2006-01-03 18:23:57.000000000 +0000
+++ src/gdb/gdbtk/library/mempref.ith	2006-01-06 18:41:05.000000000 +0000
@@ -47,6 +47,7 @@ itcl::class MemPref {
     variable gformat 
     variable gnumbytes 
     variable gbpr 
+    variable gbprlist
     variable gascii  
     variable gascii_char 
     variable gvar

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Arbitrary width memory window.
  2006-01-10 14:51 [PATCH] Arbitrary width memory window Andrew STUBBS
@ 2006-01-10 15:56 ` Andrew STUBBS
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew STUBBS @ 2006-01-10 15:56 UTC (permalink / raw)
  To: insight

[-- Attachment #1: Type: text/plain, Size: 77 bytes --]

Here is the patch again complete with documentation changes I missed before.

[-- Attachment #2: memwin.patch --]
[-- Type: text/plain, Size: 5848 bytes --]

2005-01-10  Andrew Stubbs  <andrew.stubbs@st.com>

	* library/mempref.itb (MemPref::constructor): Allow the Byte Per Row
	combo box to accept arbitrary values.
	(MemPref::set_bytes_per_row): Validate the new value; reject invalid
	entries and round up to a multiple of the word size.
	(MemPref::apply): Read the value from the text box even if the user
	has not pressed return.
	(MemPref::enable_format): Ensure the bytes per row value is still valid.
	(MemPref::disable_format): Likewise.
	* library/mempref.ith (MemPref): Add $gbprlist.
	* library/help/memory.html: Update.

Index: src/gdb/gdbtk/library/mempref.itb
===================================================================
--- src.orig/gdb/gdbtk/library/mempref.itb	2006-01-10 14:59:39.000000000 +0000
+++ src/gdb/gdbtk/library/mempref.itb	2006-01-10 15:19:54.000000000 +0000
@@ -41,6 +41,7 @@ itcl::body MemPref::constructor {args} {
   
   set gnumbytes $numbytes
   set gbpr $bpr
+  set gbprlist [list 4 8 16 32 64 128]
   set gascii $ascii
   set gascii_char $ascii_char
   
@@ -153,14 +154,11 @@ itcl::body MemPref::build_win {} {
   label $fr.2.l -text "Bytes Per Row "
   set Widgets(b-bytes_per_row) [::combobox::combobox $fr.2.c \
 				  -command [code $this set_bytes_per_row]  \
-				  -width 4 -editable 0 -font global/fixed \
+				  -width 4 -editable 1 -font global/fixed \
 				  -bg $::Colors(textbg)]
-  $fr.2.c list insert end 4
-  $fr.2.c list insert end 8
-  $fr.2.c list insert end 16
-  $fr.2.c list insert end 32
-  $fr.2.c list insert end 64
-  $fr.2.c list insert end 128
+  foreach item $gbprlist {
+    $fr.2.c list insert end $item
+  }
   $fr.2.c configure -value $gbpr
 
   pack $fr.2.l -side left -anchor e
@@ -264,7 +262,40 @@ itcl::body MemPref::check_numbytes {var 
 #  METHOD:  set_bytes_per_row - combobox callback to set the bytes per row
 # ------------------------------------------------------------------
 itcl::body MemPref::set_bytes_per_row {w value} {
-  set gbpr $value
+  if {[string is integer -strict $value] && [expr {$value != 0}]} {
+    # The input is a value number.
+    set gbpr $value
+    set gbpr [string trim $gbpr]
+
+    # Too high a number will cause a Segmentation fault.
+    if {[expr {$gbpr > 150}]} {set gbpr 150}
+
+    # Insert the value into the combo box list, if it isn't there already.
+    set found 0
+    foreach item $gbprlist {
+      if {$item == $gbpr} {
+        set found 1
+      }
+    }
+    if {[expr {$found == 0}]} {
+      lappend gbprlist $gbpr
+      $Widgets(b-bytes_per_row) list insert end $gbpr
+    }
+
+    set s $gsize
+    if {[expr {$s == 3}]} {set s 4}
+    if {[expr {$s == 5}]} {set s 8}
+    set rem [expr {$gbpr % $s}]
+    if {[expr {$rem != 0}]} {
+      # The bytes-per-row is not a multiple of the size.
+      set gbpr [expr {$gbpr + ($s - $rem)}]
+    }
+  }
+
+  # Set the display to the new value. This may be different if the input
+  # was zero or not a number, or if the user entered any whitespace.
+  $Widgets(b-bytes_per_row) delete 0 end
+  $Widgets(b-bytes_per_row) insert end $gbpr
 }
 
 # ------------------------------------------------------------------
@@ -318,6 +349,9 @@ itcl::body MemPref::apply {} {
     }
   }
 
+  # Ensure the value has been read from the text field.
+  set_bytes_per_row "" [$Widgets(b-bytes_per_row) get]
+
   # pass all the changed values back to parent
   debug "$win configChange -size $size -numbytes $numbytes \
 	     -format $format -ascii $gascii \
@@ -338,6 +372,10 @@ itcl::body MemPref::apply {} {
 #  METHOD:  enable_format - turn on the format radio buttons 
 # ------------------------------------------------------------------
 itcl::body MemPref::enable_format {} {
+  # First ensure bytes per row is a multiple of the size.
+  # Use the value of the widget, not $gbpr to ensure the typed value is kept.
+  set_bytes_per_row "" [$Widgets(b-bytes_per_row) get]
+
   if {!$format_disabled} {
     return
   }
@@ -353,6 +391,10 @@ itcl::body MemPref::enable_format {} {
 #  METHOD:  disable_format - turn off the format radio buttons 
 # ------------------------------------------------------------------
 itcl::body MemPref::disable_format {} {
+  # First ensure bytes per row is a multiple of the size.
+  # Use the value of the widget, not $gbpr to ensure the typed value is kept.
+  set_bytes_per_row "" [$Widgets(b-bytes_per_row) get]
+
   if {$format_disabled} {
     return
   }
Index: src/gdb/gdbtk/library/mempref.ith
===================================================================
--- src.orig/gdb/gdbtk/library/mempref.ith	2006-01-10 14:59:39.000000000 +0000
+++ src/gdb/gdbtk/library/mempref.ith	2006-01-10 15:19:54.000000000 +0000
@@ -47,6 +47,7 @@ itcl::class MemPref {
     variable gformat 
     variable gnumbytes 
     variable gbpr 
+    variable gbprlist
     variable gascii  
     variable gascii_char 
     variable gvar
Index: src/gdb/gdbtk/library/help/memory.html
===================================================================
--- src.orig/gdb/gdbtk/library/help/memory.html	2006-01-10 15:48:34.000000000 +0000
+++ src/gdb/gdbtk/library/help/memory.html	2006-01-10 15:26:08.000000000 +0000
@@ -232,7 +232,9 @@ of bytes. By default, the Memory Window 
 Miscellaneous memory preferences include the option to display the ASCII
 representation of the memory, including what character to use for non-ASCII
 bytes (the "control" character). Additionally, users may specify the number
-of bytes per row, either four, eight, sixteen, or thirty-two. The default
-is sixteen bytes per row.
+of bytes per row, either by typing a number into the box or by choosing one
+from the list. The default is sixteen bytes per row. If the entered value is
+not a multiple of the cell size then it will be automatically rounded up. The
+maximum permitted value is 150 (before rounding).
 </BODY>
 </HTML>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-10 15:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-10 14:51 [PATCH] Arbitrary width memory window Andrew STUBBS
2006-01-10 15:56 ` Andrew STUBBS

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).