public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix bug 4613, 4621, 4622
@ 2007-09-06  9:02 Zhao Shujing
  0 siblings, 0 replies; only message in thread
From: Zhao Shujing @ 2007-09-06  9:02 UTC (permalink / raw)
  To: Frysk Mailing List

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

Hi,

This patch is to fix bug 4613, 4621 and 4622.
About bug 4613: Invalid addresses (outside of any accessible segment)
cause a hang, I choose to reset the value to lastKnownFrom/lastKnownTo
when fromSpin/toSpin try to access inaccessible address. 

Best Regards
Pearly

[-- Attachment #2: Type: text/x-patch, Size: 9335 bytes --]

Index: disassembler/DisassemblyWindow.java
===================================================================
RCS file: /cvs/frysk/frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java,v
retrieving revision 1.30
diff -u -r1.30 DisassemblyWindow.java
--- disassembler/DisassemblyWindow.java	21 Aug 2007 06:18:30 -0000	1.30
+++ disassembler/DisassemblyWindow.java	6 Sep 2007 07:46:26 -0000
@@ -80,6 +80,7 @@
 import frysk.proc.Proc;
 import frysk.proc.Task;
 import frysk.stepping.TaskStepEngine;
+import frysk.proc.MemoryMap;
 
 import lib.opcodes.Disassembler;
 import lib.opcodes.Instruction;
@@ -157,6 +158,8 @@
   
   private boolean closed = false;
   
+  private MemoryMap[] mmaps;
+  
   /**
    * The DisassmblyWindow, given a Task, will disassemble the instructions
    * and parameters for that task in memory and display them, as well as their
@@ -253,7 +256,7 @@
   {
     this.myTask = myTask;
     long pc_inc;
-    double highestAddress = Math.pow(2.0, (double)(8 * myTask.getIsa().getWordSize())) - 1.0;
+    final double highestAddress = Math.pow(2.0, (double)(8 * myTask.getIsa().getWordSize())) - 1.0;
 
     this.diss = new Disassembler(myTask.getMemory());
 
@@ -266,6 +269,8 @@
 
     this.disassemblerView = (TreeView) this.glade.getWidget("disassemblerView");
 
+    this.mmaps = this.myTask.getProc().getMaps();
+
     this.diss = new Disassembler(myTask.getMemory());
     this.fromSpin.setRange(0.0, highestAddress);
     this.fromSpin.setValue((double) pc_inc);
@@ -326,7 +331,18 @@
           return;
         
         if (arg0.getType() == SpinEvent.Type.VALUE_CHANGED)
-          handleFromSpin(fromSpin.getValue());
+        {
+            double value = fromSpin.getValue();
+            if (value <= 0.0 || value >= highestAddress)
+        	fromSpin.setValue(lastKnownFrom);
+            else
+            {
+        	if (addressAccessible((long)value))
+        	    handleFromSpin(value);
+        	else
+        	    fromSpin.setValue(lastKnownFrom);
+            }
+        }
       }
     });
 
@@ -338,7 +354,18 @@
           return;
         
         if (arg0.getType() == SpinEvent.Type.VALUE_CHANGED)
-          handleToSpin(toSpin.getValue());
+        {
+            double value = toSpin.getValue();
+            if (value <= 0.0 || value >= highestAddress)
+        	toSpin.setValue(lastKnownTo);
+            else
+            {
+        	if (addressAccessible((long)value))
+        	    handleToSpin(value);
+        	else
+        	    toSpin.setValue(lastKnownTo);      	
+            }
+        }          
       }
     });
     
@@ -356,15 +383,20 @@
             try
             {
               double d = (double) Long.parseLong(str, 16);
-              if (d > lastKnownTo)
+              if (!addressAccessible((long)d))
+        	  fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom));
+              else
               {
-        	  if (lastKnownTo == lastKnownFrom)
-        	      handleFromSpin(lastKnownTo);
-        	  else
-        	      fromSpin.setValue(lastKnownTo);
+                  if (d > lastKnownTo)
+                  {
+                      if (lastKnownTo == lastKnownFrom)
+                	  handleFromSpin(lastKnownTo);
+                      else
+                	  fromSpin.setValue(lastKnownTo);
+                  }
+                  else
+                      fromSpin.setValue(d);
               }
-              else
-        	  fromSpin.setValue(d);
             }
             catch (NumberFormatException nfe)
             {
@@ -388,15 +420,20 @@
               try
               {
                 double d = (double) Long.parseLong(str, 16);
-                if (d < lastKnownFrom) 
+                if (!(addressAccessible((long)d)))
+                    toBox.setText("0x" + Long.toHexString((long) lastKnownTo));
+                else 
                 {
-                    if (lastKnownFrom == lastKnownTo)
-                	handleToSpin(lastKnownFrom);
+                    if (d < lastKnownFrom) 
+                    {
+                        if (lastKnownFrom == lastKnownTo)
+                    	handleToSpin(lastKnownFrom);
+                        else
+                    	toSpin.setValue(lastKnownFrom);
+                    }
                     else
-                	toSpin.setValue(lastKnownFrom);
+                        toSpin.setValue(d);
                 }
-                else
-                    toSpin.setValue(d);
               }
               catch (NumberFormatException nfe)
               {
@@ -502,6 +539,18 @@
       }
     this.refreshList();
   }
+  /**
+   * return a boolean indicating whether or not this address is accessible.
+   * 
+   * @return whether or not this address is accessible
+   */
+  private boolean addressAccessible(long address)
+  {
+      for (int i=0; i< this.mmaps.length; i++)
+	  if (mmaps[i].addressLow <= address && address < mmaps[i].addressHigh)
+	      return true;
+      return false;
+  }
 
   protected void resetPCAndList ()
   {
@@ -822,11 +871,7 @@
           return;
 
         this.toToggle = true;
-
-        this.model.removeRow(this.model.getIter(this.lastPath));
-        this.lastPath.previous();
-        --this.numInstructions;
-        
+  
         Instruction ins = (Instruction) this.model.getValue(this.model.getIter(this.lastPath),
                                                 (DataColumnObject) cols[OBJ]);
         
Index: memory/MemoryWindow.java
===================================================================
RCS file: /cvs/frysk/frysk-gui/frysk/gui/memory/MemoryWindow.java,v
retrieving revision 1.45
diff -u -r1.45 MemoryWindow.java
--- memory/MemoryWindow.java	3 Sep 2007 02:20:31 -0000	1.45
+++ memory/MemoryWindow.java	6 Sep 2007 07:46:26 -0000
@@ -87,6 +87,7 @@
 import frysk.proc.Proc;
 import frysk.proc.Task;
 import frysk.stepping.TaskStepEngine;
+import frysk.proc.MemoryMap;
 
 import lib.opcodes.Disassembler;
 import lib.opcodes.Instruction;
@@ -194,6 +195,8 @@
   private boolean toggle = true;
   
   private boolean closed = false;
+  
+  private MemoryMap[] mmaps;
 
   /**
    * The MemoryWindow displays the information stored at various locations in
@@ -294,7 +297,7 @@
   {
     this.myTask = myTask;
     long pc_inc;
-    double highestAddress = Math.pow(2.0, (double)(8 * myTask.getIsa().getWordSize())) - 1.0;
+    final double highestAddress = Math.pow(2.0, (double)(8 * myTask.getIsa().getWordSize())) - 1.0;
     
     if (currentFormat == 0)
       {
@@ -304,6 +307,8 @@
           currentFormat = THIRTYTWO_BIT;
       }
     
+    this.mmaps = this.myTask.getProc().getMaps();
+    
     this.diss = new Disassembler(myTask.getMemory());
     pc_inc = myTask.getIsa().pc(myTask);
     long end = pc_inc + 50;
@@ -458,7 +463,18 @@
           return;
         
         if (arg0.getType() == SpinEvent.Type.VALUE_CHANGED)
-          handleFromSpin(fromSpin.getValue());
+        {
+            double value = fromSpin.getValue();
+            if (value <= 0.0 || value >= highestAddress)
+        	fromSpin.setValue(lastKnownFrom);
+            else
+            {
+        	if (addressAccessible((long)value))
+        	    handleFromSpin(value);
+        	else
+        	    fromSpin.setValue(lastKnownFrom);
+            }
+        }
       }
     });
 
@@ -470,7 +486,18 @@
           return;
         
         if (arg0.getType() == SpinEvent.Type.VALUE_CHANGED)
-          handleToSpin(toSpin.getValue());
+        {
+            double value = toSpin.getValue();
+            if (value <= 0.0 || value >= highestAddress)
+        	toSpin.setValue(lastKnownTo);
+            else
+            {
+        	if (addressAccessible((long)value))
+        	    handleToSpin(value);
+        	else
+        	    toSpin.setValue(lastKnownTo);      	
+            }
+        } 
       }
     });
     
@@ -488,15 +515,20 @@
             try
             {
               double d = (double) Long.parseLong(str, 16);
-              if (d > lastKnownTo)
+              if (!addressAccessible((long)d))
+        	  fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom));
+              else
               {
-        	  if (lastKnownTo == lastKnownFrom)
-        	      handleFromSpin(lastKnownTo);
-        	  else
-        	      fromSpin.setValue(lastKnownTo);
+                  if (d > lastKnownTo)
+                  {
+                      if (lastKnownTo == lastKnownFrom)
+                	  handleFromSpin(lastKnownTo);
+                      else
+                	  fromSpin.setValue(lastKnownTo);                      
+                  }
+                  else
+                      fromSpin.setValue(d);
               }
-              else
-        	  fromSpin.setValue(d);
             }
             catch (NumberFormatException nfe)
             {
@@ -540,6 +572,19 @@
     
   }
   
+  /**
+   * return a boolean indicating whether or not this address is accessible.
+   * 
+   * @return whether or not this address is accessible
+   */
+  private boolean addressAccessible(long address)
+  {
+      for (int i=0; i< this.mmaps.length; i++)
+	  if (mmaps[i].addressLow <= address && address < mmaps[i].addressHigh)
+	      return true;
+      return false;
+  }
+  
   private boolean refreshLock = false;
   
   public void resetTask (Task task)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-09-06  9:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-06  9:02 [patch] Fix bug 4613, 4621, 4622 Zhao Shujing

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).