This is the mail archive of the
frysk@sourceware.org
mailing list for the frysk project.
Re: [patch] Fix bugs of memory window
- From: Zhao Shujing <pearly dot zhao at oracle dot com>
- To: Andrew Cagney <cagney at redhat dot com>
- Cc: Frysk Mailing List <frysk at sourceware dot org>
- Date: Fri, 31 Aug 2007 14:35:02 +0800
- Subject: Re: [patch] Fix bugs of memory window
- Organization: Oracle
- References: <1188446167.7327.22.camel@linux-pzhao.site> <46D6CD2F.9090409@redhat.com>
- Reply-to: pearly dot zhao at oracle dot com
Thanks Andrew.
The patch is updated.
On Thu, 2007-08-30 at 09:59 -0400, Andrew Cagney wrote:
> Zhao Shujing wrote:
> > Hi,
> >
> > This patch is to fix bug #4617 and other bugs of memory window.
> > - Fixed bug converting to bin and hex when memory value is negative
> > number.
> > - Fixed bug to get octal number by convert from hex.
> > - Setting the font to fixed-width font "monospace 10"
> > - Adding leading zero for all of bin, oct and hex.
> > - Adding prefix zero to octal number.
> >
> > Any suggestions are welcomed
> >
> >
> Pearly, perhaps check the constructor <<new BigInteger(int,byte[])>> as
> in <<new BigInteger(1,b)>> it will convert the big-endian byte array
> directly into an unsigned BigInteger letting you use more of:
>
> > + oct = bihex.toString(8);
> and, beyond needing to zero-pad, may make things even simpler.
>
> Andrew
>
Index: MemoryWindow.java
===================================================================
RCS file: /cvs/frysk/frysk-gui/frysk/gui/memory/MemoryWindow.java,v
retrieving revision 1.44
diff -u -r1.44 MemoryWindow.java
--- MemoryWindow.java 28 Aug 2007 06:05:19 -0000 1.44
+++ MemoryWindow.java 31 Aug 2007 06:25:25 -0000
@@ -53,6 +53,7 @@
import org.gnu.gtk.Button;
import org.gnu.gtk.CellRenderer;
import org.gnu.gtk.CellRendererText;
+import org.gnu.pango.FontDescription;
import org.gnu.gtk.DataColumn;
import org.gnu.gtk.DataColumnDouble;
import org.gnu.gtk.DataColumnObject;
@@ -325,6 +326,8 @@
this.bitsCombo.setActive(currentFormat + 1);
this.memoryView = (TreeView) this.glade.getWidget("memoryView");
+ FontDescription fontDesc = new FontDescription("monospace 10");
+ memoryView.setFont(fontDesc);
this.bitsCombo.showAll();
this.diss = new Disassembler(myTask.getMemory());
@@ -649,29 +652,33 @@
String dec = "";
if (bi.signum() < 0)
- {
- for (int i = 0; i < b.length; i++)
- {
- bin = bin + Integer.toBinaryString(b[i] & 0xff);
- oct = oct + Integer.toOctalString(b[i] & 0xff);
- hex = hex + Integer.toHexString(b[i] & 0xff);
- }
- }
- else
- {
- bin = bi.toString(2);
- oct = bi.toString(8);
- hex = bi.toString(16);
- }
+ bi = new BigInteger(1, b);
+ bin = bi.toString(2);
+ oct = bi.toString(8);
+ hex = bi.toString(16);
dec = bi.toString(10);
int diff = bin.length() % BYTE_BITS;
if (diff != 0)
bin = padBytes(bin, false, diff);
+ int length = (int)Math.pow(2, currentFormat + 3);
+
+ while (bin.length() < length)
+ {
+ bin = "0" + bin;
+ }
+ while (oct.length() < (length/3 + 1))
+ {
+ oct = "0" + oct;
+ }
+ while (hex.length() < length/4 )
+ {
+ hex = "0" + hex;
+ }
/* Little endian first */
this.model.setValue(iter, (DataColumnString) cols[1], bin);
- this.model.setValue(iter, (DataColumnString) cols[3], oct);
+ this.model.setValue(iter, (DataColumnString) cols[3], "0"+oct);
this.model.setValue(iter, (DataColumnString) cols[5], dec);
this.model.setValue(iter, (DataColumnString) cols[7], "0x" + hex);
@@ -687,9 +694,21 @@
dec = bi.toString(10);
else
dec = bii.toString(10);
-
+
+ while (bin2.length() < length)
+ {
+ bin2 = "0" + bin2;
+ }
+ while (oct.length() < (length/3 + 1))
+ {
+ oct = "0" + oct;
+ }
+ while (hex.length() < length/4 )
+ {
+ hex = "0" + hex;
+ }
this.model.setValue(iter, (DataColumnString) cols[2], bin2);
- this.model.setValue(iter, (DataColumnString) cols[4], oct);
+ this.model.setValue(iter, (DataColumnString) cols[4], "0"+oct);
this.model.setValue(iter, (DataColumnString) cols[6], dec);
this.model.setValue(iter, (DataColumnString) cols[8], "0x" + hex);