public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Zhao Shujing <pearly.zhao@oracle.com>
To: frysk@sourceware.org
Subject: Re: [patch] disassembly window
Date: Mon, 20 Aug 2007 09:07:00 -0000	[thread overview]
Message-ID: <1187601068.25862.16.camel@linux-pzhao.site> (raw)
In-Reply-To: <1187340639.3861.47.camel@linux-pzhao.site>

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

Sorry, I make a mistake with fromBox.entryEvent to use the same code
with toBox.entryEvent at the last patch. It is fixed at this one. 
On Fri, 2007-08-17 at 16:50 +0800, Zhao Shujing wrote:
> Hi
> 
> This patch is to fix bug #4932 and other bugs of disassembly window. 
> rowPrepend is added to prepend rows by calculating memory information
> like rowAppend. Because the methods that are provided by class
> Disassembler, disassembleInstructions and
> disassembleInstructionsStartEnd, can only read the instructions that are
> following some address, rowPrepend have to use two while execution
> control to read the instructions that are preceding some address.
> Any suggestions are welcomed.
> 
> --ChangeLog--
> 2007-08-17  Zhao Shujing <pearly.zhao@oracle.com>
> 
>     *disassembler/DisassemblyWindow.java: fix bug #4932
> 	(fromBox.entryEvent): Use fromSpin.setValue to invoke fromSpin
> entryEvent.
> 	(toBox.entryEvent): Ditto.
> 	(refreshList): Change to get next instruction after finishing model
> setValue.
> 	(rowPrepend): Added.
> 	(handleFromSpin): Prepend rows provided by rowPrepend and remove
> redundant instructions according to the change of memory address.
> 
> 
> Cheers
> Pearly

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

Index: frysk/gui/disassembler/DisassemblyWindow.java
===================================================================
RCS file: /cvs/frysk/frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java,v
retrieving revision 1.29
diff -u -r1.29 DisassemblyWindow.java
--- frysk/gui/disassembler/DisassemblyWindow.java	27 Jul 2007 21:07:22 -0000	1.29
+++ frysk/gui/disassembler/DisassemblyWindow.java	20 Aug 2007 08:56:51 -0000
@@ -44,6 +44,7 @@
 import java.util.prefs.Preferences;
 import java.util.List;
 import java.util.Iterator;
+import java.util.ListIterator;
 import java.util.Observable;
 import java.util.Observer;
 
@@ -354,7 +355,15 @@
             try
             {
               double d = (double) Long.parseLong(str, 16);
-              handleFromSpin(d);
+              if (d > lastKnownTo)
+              {
+        	  if (lastKnownTo == lastKnownFrom)
+        	      handleFromSpin(lastKnownTo);
+        	  else
+        	      fromSpin.setValue(lastKnownTo);
+              }
+              else
+        	  fromSpin.setValue(d);
             }
             catch (NumberFormatException nfe)
             {
@@ -377,7 +386,15 @@
               try
               {
                 double d = (double) Long.parseLong(str, 16);
-                handleToSpin(d);
+                if (d < lastKnownFrom) 
+                {
+                    if (lastKnownFrom == lastKnownTo)
+                	handleToSpin(lastKnownFrom);
+                    else
+                	toSpin.setValue(lastKnownFrom);
+                }
+                else
+                    toSpin.setValue(d);
               }
               catch (NumberFormatException nfe)
               {
@@ -537,22 +554,23 @@
             this.model.setValue(iter, (DataColumnString) cols[2], ins.instruction);
             
             this.pcOffset += ins.address;
-            
-            if (li.hasNext())
-              ins = (Instruction) li.next();
-            else
-              {
-                this.toSpin.setValue((double) ins.address);
-                this.toBox.setText(Long.toHexString(ins.address));
-                this.lastKnownTo = ins.address;
-                ins = null;
-              }
           }
         else
           this.model.setValue(iter, (DataColumnString) cols[1], "");
 
         this.model.setValue(iter, (DataColumnObject) cols[OBJ], ins);
         
+        
+        if (li.hasNext())
+            ins = (Instruction) li.next();
+        else
+        {
+            this.toSpin.setValue((double) ins.address);
+            this.toBox.setText(Long.toHexString(ins.address));
+            this.lastKnownTo = ins.address;
+            ins = null;        
+        }
+        
         iter = iter.getNextIter();
       }
     
@@ -568,7 +586,7 @@
   /**
    * Helper function for calculating memory information and putting it into rows
    * to be displayed.
-   * By default append rows to the end; occasionally prepend rows to the front.
+   * By default append rows to the end.
    * 
    * @param i   The address to be displayed
    * @param iter    The TreeIter representing the row to be added.
@@ -617,6 +635,70 @@
     this.lastKnownTo = ins.address;
   }
   
+  /**
+   * Helper function for calculating memory information and putting it into rows
+   * to be displayed.
+   * By default prepend rows to the front.
+   * 
+   * @param val   The address to be displayed
+   * @param nums   The numbers of rows to be prepend.
+   */
+  private synchronized void rowPrepend(long val, int addressAdded)
+  {
+      TreeIter iter = model.getFirstIter();
+      TreePath path = iter.getPath();
+      List instructionsList = diss.disassembleInstructions((long)(val-20), addressAdded+20);
+      ListIterator li = instructionsList.listIterator(0);
+      Instruction ins = (Instruction) li.next();
+      while (li.hasNext() && ins.address < lastKnownFrom)
+      {
+	  ins = (Instruction) li.next();
+	  if (ins.address == lastKnownFrom)
+	      break;
+	  
+      }
+      while (li.hasPrevious())
+      {
+	  if (ins.address < (long) val) {
+	      ins = (Instruction) li.next();
+	      break;
+	  }
+	  ins = (Instruction) li.previous();	 
+      }
+      if (addressAdded > 1) // if num==1, it should fetch the previous instruction
+	  ins = (Instruction) li.next();
+      
+      long newlastFrom = ins.address;
+      
+      while (ins != null && ins.address < lastKnownFrom) {
+	  iter = model.insertRowBefore(model.getIter(path));
+	  this.lastPath.next();
+	  if (ins != null) {
+	      model.setValue(iter, (DataColumnString) cols[1], "<pc+"
+		      + (ins.address - this.pc) + ">: ");
+	      model.setValue(iter, (DataColumnString) cols[LOC], "0x"
+		      + Long.toHexString(ins.address));
+	      model.setValue(iter, (DataColumnString) cols[2],
+		      ins.instruction);
+	      model.setValue(iter, (DataColumnObject) cols[3], ins);
+	      this.numInstructions++;		  
+	      if (li.hasNext()) {
+		  ins = (Instruction) li.next();
+		  path.next();
+	      }
+	      else
+		  ins = null;
+	    }
+	  else
+	      model.setValue(iter, (DataColumnString) cols[1], "");
+	  
+      }
+
+      this.lastKnownFrom = newlastFrom;
+      this.fromSpin.setValue((double) newlastFrom);
+      this.fromBox.setText(Long.toHexString(newlastFrom));
+  }
+  
   private void desensitize ()
   {
     this.disassemblerView.setSensitive(false);
@@ -661,28 +743,38 @@
 
     if (val > this.lastKnownFrom)
       {
-        TreeIter iter = model.getFirstIter();
-
-        for (int i = (int) lastKnownFrom; i < (int) val; i++)
-          {
-            this.numInstructions--;
-            model.removeRow(iter);
-            iter = iter.getNextIter();
-          }
+	if (this.numInstructions < 1)
+            return;
+        
+	TreeIter iter = model.getFirstIter();
+	Instruction ins = (Instruction) this.model.getValue(iter, (DataColumnObject) cols[OBJ]);
+	//--this.numInstructions;
+        
+	while (ins != null && ins.address < val)
+	{
+	    this.model.removeRow(iter);
+	    this.lastPath.previous();
+	    ins = (Instruction) this.model.getValue(iter,(DataColumnObject) cols[OBJ]);
+	    --this.numInstructions;
+	}
+	if (ins == null)
+	    return;
+
+	this.lastKnownFrom = ins.address;
+	this.fromBox.setText(Long.toHexString(ins.address));
+	this.fromSpin.setValue((double)ins.address);
+	refreshList();
+	return;
       }
     else
       {
-        for (long i = (long) val; i < lastKnownFrom; i++)
-          {
-            this.numInstructions++;
-            model.prependRow();
-          }
+	int addressAdded = 0;
+	for (long i = (long)lastKnownFrom; i > (long)val; i--)
+	    addressAdded++;
+	if (addressAdded == 0)
+	    return;
+	rowPrepend((long)val, addressAdded);
       }
-    
-    this.fromSpin.setValue(val);
-    this.lastKnownFrom = val;
-    this.fromBox.setText(Long.toHexString((long) val));
-    refreshList();
   }
 
   boolean toToggle = false;

  reply	other threads:[~2007-08-20  9:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-17  8:47 Zhao Shujing
2007-08-20  9:07 ` Zhao Shujing [this message]
2007-08-20 13:32 ` Andrew Cagney
2007-08-22  9:14   ` Zhao Shujing
2007-08-22 13:09     ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1187601068.25862.16.camel@linux-pzhao.site \
    --to=pearly.zhao@oracle.com \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).