* [patch] Accept symbolic addresses in spin button, bug 4673. @ 2007-09-12 8:05 Zhao Shujing 2007-09-12 13:33 ` PEARLY.ZHAO 0 siblings, 1 reply; 4+ messages in thread From: Zhao Shujing @ 2007-09-12 8:05 UTC (permalink / raw) To: Frysk Mailing List [-- Attachment #1: Type: text/plain, Size: 625 bytes --] Hi, This patch can make the disassembly/memory window accept symbol name in spin Button. Here is what it does: - When input a available symbol name at fromBox, the window would display the disassembly/memory of this symbol. The fromBox/fromSpin would be set the start address of this symbol and the toBox/toSpin would be set the end address of this symbol. - When input a available symbol name at toBox, it would do as same as when input at fromBox. - When input a unavailable symbol name, the fromBox/fromSpin or toBox/toSpin would be reset to the lastKnownFrom or lastKnownTo. Any suggestions are welcomed. Pearly Zhao [-- Attachment #2: Type: text/x-patch, Size: 17554 bytes --] Index: disassembler/DisassemblyWindow.java =================================================================== RCS file: /cvs/frysk/frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java,v retrieving revision 1.31 diff -u -r1.31 DisassemblyWindow.java --- disassembler/DisassemblyWindow.java 7 Sep 2007 03:18:50 -0000 1.31 +++ disassembler/DisassemblyWindow.java 12 Sep 2007 07:43:28 -0000 @@ -42,6 +42,7 @@ package frysk.gui.disassembler; import java.util.prefs.Preferences; +import java.util.LinkedList; import java.util.List; import java.util.Iterator; import java.util.ListIterator; @@ -74,6 +75,7 @@ import org.gnu.gtk.event.SpinEvent; import org.gnu.gtk.event.SpinListener; +import frysk.dwfl.DwflCache; import frysk.gui.common.IconManager; import frysk.gui.prefs.PreferenceManager; import frysk.gui.monitor.Saveable; @@ -81,7 +83,12 @@ import frysk.proc.Task; import frysk.stepping.TaskStepEngine; import frysk.proc.MemoryMap; +import frysk.symtab.Symbol; +import frysk.symtab.SymbolFactory; +import lib.dwfl.Dwfl; +import lib.dwfl.DwflModule; +import lib.dwfl.SymbolBuilder; import lib.opcodes.Disassembler; import lib.opcodes.Instruction; @@ -379,28 +386,42 @@ return; String str = fromBox.getText(); - str = str.substring(2); - try + + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (!addressAccessible((long)d)) - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); - else - { - if (d > lastKnownTo) + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + if (!addressAccessible((long)d)) + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else { - if (lastKnownTo == lastKnownFrom) - handleFromSpin(lastKnownTo); + if (d > lastKnownTo) + { + if (lastKnownTo == lastKnownFrom) + handleFromSpin(lastKnownTo); + else + fromSpin.setValue(lastKnownTo); + } else - fromSpin.setValue(lastKnownTo); + fromSpin.setValue(d); } - else - fromSpin.setValue(d); - } + } + catch (NumberFormatException nfe) + { + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } - catch (NumberFormatException nfe) - { - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } } } @@ -416,28 +437,41 @@ return; String str = toBox.getText(); - str = str.substring(2); - try + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (!(addressAccessible((long)d))) - toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); - else - { - if (d < lastKnownFrom) + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + 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) + { + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } - catch (NumberFormatException nfe) - { - toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } } } @@ -539,6 +573,32 @@ } this.refreshList(); } + + /** + * Get the address list from symbol name; + * @param name + * @return address list + */ + private LinkedList addressesForSymbol(String name) { + Dwfl dwfl = DwflCache.getDwfl(this.myTask); + DwflModule[] modules = dwfl.getModules(); + final LinkedList addrs = new LinkedList(); + SymbolBuilder builder = new SymbolBuilder() { + public void symbol(String name, long value, long size, + int type, int bind, int visibility) { + addrs.add(new Long(value)); + } + }; + for (int i = 0; i < modules.length; i++) + { + DwflModule module = modules[i]; + module.getSymbolByName(name, builder); + } + if (addrs.size() == 0) + throw new RuntimeException("Couldn't find symbol " + name); + else + return addrs; + } /** * return a boolean indicating whether or not this address is accessible. * @@ -640,16 +700,17 @@ * By default append rows to the end. * * @param i The address to be displayed + * @param numIns The Instructions that maybe be added * @param iter The TreeIter representing the row to be added. */ - public synchronized void rowAppend (long i, TreeIter iter) + public synchronized void rowAppend (long i, int numIns, TreeIter iter) { // if (iter == null) // iter = model.appendRow(); List instructionsList = diss.disassembleInstructions((long) this.lastKnownTo, - numInstructions); + numInstructions+numIns); Iterator li = instructionsList.listIterator(0); Instruction ins = (Instruction) li.next(); @@ -661,8 +722,10 @@ this.lastPath.next(); if (ins != null) { - if (li.hasNext()) + if (li.hasNext()){ ins = (Instruction) li.next(); + this.numInstructions++; + } else { this.toSpin.setValue((double) ins.address); @@ -858,10 +921,11 @@ if (val > this.lastKnownTo) { - for (long i = (long) lastKnownTo + 1; i < val + 1; i++) - ++this.numInstructions; + int numIns = 0; + for (long i = (long) lastKnownTo + 1; i < val + 1; i++) + ++numIns; - rowAppend((long) val, null); + rowAppend((long) val, numIns, null); return; } @@ -895,6 +959,48 @@ refreshList(); } } + + /** + * When the box is inputed a symbol, update the displayed information to the symbol. + * @param symbolName + */ + private synchronized void handleSymbol(String symbolName) + { + LinkedList addressList = addressesForSymbol(symbolName); + long startAddress = ((Long)addressList.getFirst()).longValue(); + Symbol symbol = SymbolFactory.getSymbol(this.myTask, startAddress); + long endAddress = symbol.getAddress() + symbol.getSize(); + + List instructionsList + = diss.disassembleInstructionsStartEnd((long)startAddress, (long)endAddress); + Iterator li = instructionsList.listIterator(0); + int insnum = 1; + Instruction ins = (Instruction)li.next(); + this.lastKnownFrom = (double)ins.address; + while (li.hasNext()){ + ins = (Instruction)li.next(); + insnum++; + } + this.lastKnownTo = (double)ins.address; + + TreeIter iter = this.model.getFirstIter(); + while (insnum < numInstructions) + { + this.model.removeRow(iter); + this.lastPath.previous(); + numInstructions--; + } + while(insnum > numInstructions) + { + this.model.appendRow(); + this.lastPath.next(); + numInstructions++; + } + + refreshList(); + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); + fromSpin.setValue(lastKnownFrom); + } /**************************************************************************** * Save and Load Index: memory/MemoryWindow.java =================================================================== RCS file: /cvs/frysk/frysk-gui/frysk/gui/memory/MemoryWindow.java,v retrieving revision 1.46 diff -u -r1.46 MemoryWindow.java --- memory/MemoryWindow.java 7 Sep 2007 03:18:50 -0000 1.46 +++ memory/MemoryWindow.java 12 Sep 2007 07:43:29 -0000 @@ -42,6 +42,7 @@ package frysk.gui.memory; import java.util.prefs.Preferences; +import java.util.LinkedList; import java.util.List; import java.util.Iterator; import java.util.Observable; @@ -78,6 +79,7 @@ import org.gnu.gtk.event.SpinEvent; import org.gnu.gtk.event.SpinListener; +import frysk.dwfl.DwflCache; import frysk.gui.common.IconManager; import frysk.gui.prefs.PreferenceManager; import frysk.gui.monitor.GuiObject; @@ -87,8 +89,13 @@ import frysk.proc.Proc; import frysk.proc.Task; import frysk.stepping.TaskStepEngine; +import frysk.symtab.Symbol; +import frysk.symtab.SymbolFactory; import frysk.proc.MemoryMap; +import lib.dwfl.Dwfl; +import lib.dwfl.DwflModule; +import lib.dwfl.SymbolBuilder; import lib.opcodes.Disassembler; import lib.opcodes.Instruction; @@ -511,28 +518,41 @@ return; String str = fromBox.getText(); - str = str.substring(2); - try + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (!addressAccessible((long)d)) - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); - else - { - if (d > lastKnownTo) + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + if (!addressAccessible((long)d)) + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else { - if (lastKnownTo == lastKnownFrom) - handleFromSpin(lastKnownTo); + if (d > lastKnownTo) + { + if (lastKnownTo == lastKnownFrom) + handleFromSpin(lastKnownTo); + else + fromSpin.setValue(lastKnownTo); + } else - fromSpin.setValue(lastKnownTo); + fromSpin.setValue(d); } - else - fromSpin.setValue(d); - } + } + catch (NumberFormatException nfe) + { + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } - catch (NumberFormatException nfe) - { - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } } } @@ -548,23 +568,41 @@ return; String str = toBox.getText(); - str = str.substring(2); - try + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (d < lastKnownFrom) - { - if (lastKnownFrom == lastKnownTo) - handleToSpin(lastKnownFrom); - else - toSpin.setValue(lastKnownFrom); - } - else - toSpin.setValue(d); + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + if (!(addressAccessible((long)d))) + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + else + { + if (d < lastKnownFrom) + { + if (lastKnownFrom == lastKnownTo) + handleToSpin(lastKnownFrom); + else + toSpin.setValue(lastKnownFrom); + } + else + toSpin.setValue(d); + } + } + catch (NumberFormatException nfe) + { + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } - catch (NumberFormatException nfe) - { - toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } } } @@ -573,6 +611,32 @@ } /** + * Get the address list from symbol name; + * @param name + * @return address list + */ + private LinkedList addressesForSymbol(String name) { + Dwfl dwfl = DwflCache.getDwfl(this.myTask); + DwflModule[] modules = dwfl.getModules(); + final LinkedList addrs = new LinkedList(); + SymbolBuilder builder = new SymbolBuilder() { + public void symbol(String name, long value, long size, + int type, int bind, int visibility) { + addrs.add(new Long(value)); + } + }; + for (int i = 0; i < modules.length; i++) + { + DwflModule module = modules[i]; + module.getSymbolByName(name, builder); + } + if (addrs.size() == 0) + throw new RuntimeException("Couldn't find symbol " + name); + else + return addrs; + } + + /** * return a boolean indicating whether or not this address is accessible. * * @return whether or not this address is accessible @@ -612,6 +676,7 @@ this.refreshLock = false; } + /***************************************************************************** * Calculation, memory reading, and information display methods ****************************************************************************/ @@ -1011,6 +1076,47 @@ this.lastKnownTo = val; refreshList(); } + + /** + * When the box is inputed a symbol, update the displayed information to the symbol. + * @param symbolName + */ + private synchronized void handleSymbol(String symbolName) + { + LinkedList addressList = addressesForSymbol(symbolName); + long startAddress = ((Long)addressList.getFirst()).longValue(); + Symbol symbol = SymbolFactory.getSymbol(this.myTask, startAddress); + long endAddress = symbol.getAddress() + symbol.getSize(); + long size = endAddress - startAddress + 1; + long modelSize = (long)lastKnownTo - (long)lastKnownFrom + 1; + TreeIter iter = this.model.getFirstIter(); + while (size < modelSize) + { + this.model.removeRow(iter); + this.lastPath.previous(); + modelSize--; + } + while(size > modelSize) + { + this.model.appendRow(); + this.lastPath.next(); + modelSize++; + } + this.lastKnownFrom = (double)startAddress; + this.lastKnownTo = (double)endAddress; + iter = this.model.getFirstIter(); + this.lastPath = iter.getPath(); + for(long i= startAddress; i < endAddress+1; i++) + { + rowAppend(i, iter); + iter = iter.getNextIter(); + } + refreshList(); + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); + fromSpin.setValue(lastKnownFrom); + toBox.setText("0x" + Long.toHexString((long)lastKnownTo)); + toSpin.setValue(lastKnownTo); + } /**************************************************************************** * Save and Load ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] Accept symbolic addresses in spin button, bug 4673. 2007-09-12 8:05 [patch] Accept symbolic addresses in spin button, bug 4673 Zhao Shujing @ 2007-09-12 13:33 ` PEARLY.ZHAO 2007-09-19 1:19 ` Zhao Shujing 0 siblings, 1 reply; 4+ messages in thread From: PEARLY.ZHAO @ 2007-09-12 13:33 UTC (permalink / raw) To: Frysk Mailing List, pearly.zhao Actually, retrieving symbol addresses in the classes implementing the disssembly and memory windows is a wrong way to implement this functionality. Maybe it should be designed at core. The classes handling the windows merely use it to obtain the information. Pearly > Hi, > > This patch can make the disassembly/memory window accept symbol > name in > spin Button. > > Here is what it does: > - When input a available symbol name at fromBox, the window > would > display the disassembly/memory of this symbol. The fromBox/fromSpin > would be set the start address of this symbol and the toBox/toSpin > would > be set the end address of this symbol. > - When input a available symbol name at toBox, it would do as > same as > when input at fromBox. > - When input a unavailable symbol name, the fromBox/fromSpin > or > toBox/toSpin would be reset to the lastKnownFrom or lastKnownTo. > > Any suggestions are welcomed. > > Pearly Zhao > > --------Index: disassembler/DisassemblyWindow.java > =================================================================== > RCS file: /cvs/frysk/frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java,v > retrieving revision 1.31 > diff -u -r1.31 DisassemblyWindow.java > --- disassembler/DisassemblyWindow.java 7 Sep 2007 03:18:50 > -0000 1.31 > +++ disassembler/DisassemblyWindow.java 12 Sep 2007 07:43:28 > -0000 > @@ -42,6 +42,7 @@ > package frysk.gui.disassembler; > > import java.util.prefs.Preferences; > +import java.util.LinkedList; > import java.util.List; > import java.util.Iterator; > import java.util.ListIterator; > @@ -74,6 +75,7 @@ > import org.gnu.gtk.event.SpinEvent; > import org.gnu.gtk.event.SpinListener; > > +import frysk.dwfl.DwflCache; > import frysk.gui.common.IconManager; > import frysk.gui.prefs.PreferenceManager; > import frysk.gui.monitor.Saveable; > @@ -81,7 +83,12 @@ > import frysk.proc.Task; > import frysk.stepping.TaskStepEngine; > import frysk.proc.MemoryMap; > +import frysk.symtab.Symbol; > +import frysk.symtab.SymbolFactory; > > +import lib.dwfl.Dwfl; > +import lib.dwfl.DwflModule; > +import lib.dwfl.SymbolBuilder; > import lib.opcodes.Disassembler; > import lib.opcodes.Instruction; > > @@ -379,28 +386,42 @@ > return; > > String str = fromBox.getText(); > - str = str.substring(2); > - try > + > + if (str.startsWith("0x")) > { > - double d = (double) Long.parseLong(str, 16); > - if (!addressAccessible((long)d)) > - fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > - else > - { > - if (d > lastKnownTo) > + str = str.substring(2); > + try > + { > + double d = (double) Long.parseLong(str, > 16); > + if (!addressAccessible((long)d)) > + fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + else > { > - if (lastKnownTo == lastKnownFrom) > - handleFromSpin(lastKnownTo); > + if (d > lastKnownTo) > + { > + if (lastKnownTo == lastKnownFrom) > + handleFromSpin(lastKnownTo); > + else > + fromSpin.setValue(lastKnownTo); > + } > else > - fromSpin.setValue(lastKnownTo); > + fromSpin.setValue(d); > } > - else > - fromSpin.setValue(d); > - } > + } > + catch (NumberFormatException nfe) > + { > + fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + } > } > - catch (NumberFormatException nfe) > - { > - fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + else > + { > + try > + { > + handleSymbol(str); > + } > + catch (RuntimeException e){ > + fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + } > } > } > } > @@ -416,28 +437,41 @@ > return; > > String str = toBox.getText(); > - str = str.substring(2); > - try > + if (str.startsWith("0x")) > { > - double d = (double) Long.parseLong(str, 16); > - if (!(addressAccessible((long)d))) > - toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > - else > - { > - if (d < lastKnownFrom) > + str = str.substring(2); > + try > + { > + double d = (double) Long.parseLong(str, > 16); > + 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) > + { > + toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > + } > } > - catch (NumberFormatException nfe) > - { > - toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > + else > + { > + try > + { > + handleSymbol(str); > + } > + catch (RuntimeException e){ > + toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > + } > } > } > } > @@ -539,6 +573,32 @@ > } > this.refreshList(); > } > + > + /** > + * Get the address list from symbol name; > + * @param name > + * @return address list > + */ > + private LinkedList addressesForSymbol(String name) { > + Dwfl dwfl = DwflCache.getDwfl(this.myTask); > + DwflModule[] modules = dwfl.getModules(); > + final LinkedList addrs = new LinkedList(); > + SymbolBuilder builder = new SymbolBuilder() { > + public void symbol(String name, long value, long size, > + int type, int bind, int visibility) { > + addrs.add(new Long(value)); > + } > + }; > + for (int i = 0; i < modules.length; i++) > + { > + DwflModule module = modules[i]; > + module.getSymbolByName(name, builder); > + } > + if (addrs.size() == 0) > + throw new RuntimeException("Couldn't find symbol " + > name); > + else > + return addrs; > + } > /** > * return a boolean indicating whether or not this address > is accessible. > * > @@ -640,16 +700,17 @@ > * By default append rows to the end. > * > * @param i The address to be displayed > + * @param numIns The Instructions that maybe be added > * @param iter The TreeIter representing the row to be > added. > */ > - public synchronized void rowAppend (long i, TreeIter iter) > + public synchronized void rowAppend (long i, int numIns, > TreeIter iter) > { > // if (iter == null) > // iter = model.appendRow(); > > List instructionsList > = diss.disassembleInstructions((long) this.lastKnownTo, > - numInstructions); > + numInstructions+numIns); > Iterator li = instructionsList.listIterator(0); > Instruction ins = (Instruction) li.next(); > > @@ -661,8 +722,10 @@ > this.lastPath.next(); > if (ins != null) > { > - if (li.hasNext()) > + if (li.hasNext()){ > ins = (Instruction) li.next(); > + this.numInstructions++; > + } > else > { > this.toSpin.setValue((double) ins.address); > @@ -858,10 +921,11 @@ > > if (val > this.lastKnownTo) > { > - for (long i = (long) lastKnownTo + 1; i < val + 1; > i++) > - ++this.numInstructions; > + int numIns = 0; > + for (long i = (long) lastKnownTo + 1; i < val + 1; i++) > + ++numIns; > > - rowAppend((long) val, null); > + rowAppend((long) val, numIns, null); > > return; > } > @@ -895,6 +959,48 @@ > refreshList(); > } > } > + > + /** > + * When the box is inputed a symbol, update the displayed > information to the symbol. > + * @param symbolName > + */ > + private synchronized void handleSymbol(String symbolName) > + { > + LinkedList addressList = addressesForSymbol(symbolName); > + long startAddress = ((Long)addressList.getFirst()).longValue(); > + Symbol symbol = SymbolFactory.getSymbol(this.myTask, > startAddress); > + long endAddress = symbol.getAddress() + symbol.getSize(); > + > + List instructionsList > + = diss.disassembleInstructionsStartEnd((long)startAddress, > (long)endAddress); > + Iterator li = instructionsList.listIterator(0); > + int insnum = 1; > + Instruction ins = (Instruction)li.next(); > + this.lastKnownFrom = (double)ins.address; > + while (li.hasNext()){ > + ins = (Instruction)li.next(); > + insnum++; > + } > + this.lastKnownTo = (double)ins.address; > + > + TreeIter iter = this.model.getFirstIter(); > + while (insnum < numInstructions) > + { > + this.model.removeRow(iter); > + this.lastPath.previous(); > + numInstructions--; > + } > + while(insnum > numInstructions) > + { > + this.model.appendRow(); > + this.lastPath.next(); > + numInstructions++; > + } > + > + refreshList(); > + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); > + fromSpin.setValue(lastKnownFrom); > + } > > /**************************************************************************** > * Save and Load > Index: memory/MemoryWindow.java > =================================================================== > RCS file: /cvs/frysk/frysk-gui/frysk/gui/memory/MemoryWindow.java,v > retrieving revision 1.46 > diff -u -r1.46 MemoryWindow.java > --- memory/MemoryWindow.java 7 Sep 2007 03:18:50 -0000 1.46 > +++ memory/MemoryWindow.java 12 Sep 2007 07:43:29 -0000 > @@ -42,6 +42,7 @@ > package frysk.gui.memory; > > import java.util.prefs.Preferences; > +import java.util.LinkedList; > import java.util.List; > import java.util.Iterator; > import java.util.Observable; > @@ -78,6 +79,7 @@ > import org.gnu.gtk.event.SpinEvent; > import org.gnu.gtk.event.SpinListener; > > +import frysk.dwfl.DwflCache; > import frysk.gui.common.IconManager; > import frysk.gui.prefs.PreferenceManager; > import frysk.gui.monitor.GuiObject; > @@ -87,8 +89,13 @@ > import frysk.proc.Proc; > import frysk.proc.Task; > import frysk.stepping.TaskStepEngine; > +import frysk.symtab.Symbol; > +import frysk.symtab.SymbolFactory; > import frysk.proc.MemoryMap; > > +import lib.dwfl.Dwfl; > +import lib.dwfl.DwflModule; > +import lib.dwfl.SymbolBuilder; > import lib.opcodes.Disassembler; > import lib.opcodes.Instruction; > > @@ -511,28 +518,41 @@ > return; > > String str = fromBox.getText(); > - str = str.substring(2); > - try > + if (str.startsWith("0x")) > { > - double d = (double) Long.parseLong(str, 16); > - if (!addressAccessible((long)d)) > - fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > - else > - { > - if (d > lastKnownTo) > + str = str.substring(2); > + try > + { > + double d = (double) Long.parseLong(str, > 16); > + if (!addressAccessible((long)d)) > + fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + else > { > - if (lastKnownTo == lastKnownFrom) > - handleFromSpin(lastKnownTo); > + if (d > lastKnownTo) > + { > + if (lastKnownTo == lastKnownFrom) > + handleFromSpin(lastKnownTo); > + else > + fromSpin.setValue(lastKnownTo); > + } > else > - fromSpin.setValue(lastKnownTo); > > + fromSpin.setValue(d); > } > - else > - fromSpin.setValue(d); > - } > + } > + catch (NumberFormatException nfe) > + { > + fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + } > } > - catch (NumberFormatException nfe) > - { > - fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + else > + { > + try > + { > + handleSymbol(str); > + } > + catch (RuntimeException e){ > + fromBox.setText("0x" + Long.toHexString((long) > lastKnownFrom)); > + } > } > } > } > @@ -548,23 +568,41 @@ > return; > > String str = toBox.getText(); > - str = str.substring(2); > - try > + if (str.startsWith("0x")) > { > - double d = (double) Long.parseLong(str, 16); > - if (d < lastKnownFrom) > - { > - if (lastKnownFrom == lastKnownTo) > - handleToSpin(lastKnownFrom); > - else > - toSpin.setValue(lastKnownFrom); > - } > - else > - toSpin.setValue(d); > + str = str.substring(2); > + try > + { > + double d = (double) Long.parseLong(str, > 16); > + if (!(addressAccessible((long)d))) > + toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > + else > + { > + if (d < lastKnownFrom) > + { > + if (lastKnownFrom == lastKnownTo) > + handleToSpin(lastKnownFrom); > + else > + toSpin.setValue(lastKnownFrom); > + } > + else > + toSpin.setValue(d); > + } > + } > + catch (NumberFormatException nfe) > + { > + toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > + } > } > - catch (NumberFormatException nfe) > - { > - toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > + else > + { > + try > + { > + handleSymbol(str); > + } > + catch (RuntimeException e){ > + toBox.setText("0x" + Long.toHexString((long) > lastKnownTo)); > + } > } > } > } > @@ -573,6 +611,32 @@ > } > > /** > + * Get the address list from symbol name; > + * @param name > + * @return address list > + */ > + private LinkedList addressesForSymbol(String name) { > + Dwfl dwfl = DwflCache.getDwfl(this.myTask); > + DwflModule[] modules = dwfl.getModules(); > + final LinkedList addrs = new LinkedList(); > + SymbolBuilder builder = new SymbolBuilder() { > + public void symbol(String name, long value, long size, > + int type, int bind, int visibility) { > + addrs.add(new Long(value)); > + } > + }; > + for (int i = 0; i < modules.length; i++) > + { > + DwflModule module = modules[i]; > + module.getSymbolByName(name, builder); > + } > + if (addrs.size() == 0) > + throw new RuntimeException("Couldn't find symbol " + > name); > + else > + return addrs; > + } > + > + /** > * return a boolean indicating whether or not this address > is accessible. > * > * @return whether or not this address is accessible > @@ -612,6 +676,7 @@ > this.refreshLock = false; > } > > + > /***************************************************************************** > * Calculation, memory reading, and information display > methods > ****************************************************************************/ > @@ -1011,6 +1076,47 @@ > this.lastKnownTo = val; > refreshList(); > } > + > + /** > + * When the box is inputed a symbol, update the displayed > information to the symbol. > + * @param symbolName > + */ > + private synchronized void handleSymbol(String symbolName) > + { > + LinkedList addressList = addressesForSymbol(symbolName); > + long startAddress = ((Long)addressList.getFirst()).longValue(); > + Symbol symbol = SymbolFactory.getSymbol(this.myTask, > startAddress); > + long endAddress = symbol.getAddress() + symbol.getSize(); > + long size = endAddress - startAddress + 1; > + long modelSize = (long)lastKnownTo - (long)lastKnownFrom > + 1; > + TreeIter iter = this.model.getFirstIter(); > + while (size < modelSize) > + { > + this.model.removeRow(iter); > + this.lastPath.previous(); > + modelSize--; > + } > + while(size > modelSize) > + { > + this.model.appendRow(); > + this.lastPath.next(); > + modelSize++; > + } > + this.lastKnownFrom = (double)startAddress; > + this.lastKnownTo = (double)endAddress; > + iter = this.model.getFirstIter(); > + this.lastPath = iter.getPath(); > + for(long i= startAddress; i < endAddress+1; i++) > + { > + rowAppend(i, iter); > + iter = iter.getNextIter(); > + } > + refreshList(); > + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); > + fromSpin.setValue(lastKnownFrom); > + toBox.setText("0x" + Long.toHexString((long)lastKnownTo)); > + toSpin.setValue(lastKnownTo); > + } > > /**************************************************************************** > * Save and Load > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] Accept symbolic addresses in spin button, bug 4673. 2007-09-12 13:33 ` PEARLY.ZHAO @ 2007-09-19 1:19 ` Zhao Shujing 2007-09-21 21:53 ` Andrew Cagney 0 siblings, 1 reply; 4+ messages in thread From: Zhao Shujing @ 2007-09-19 1:19 UTC (permalink / raw) To: Frysk Mailing List [-- Attachment #1: Type: text/plain, Size: 21140 bytes --] Hi, This is a new patch. It adds getSymbol(task, name) method to SymbolFactory. The BreakpointManager and FunctionBreakpoint are changed to use this method instead of using the one defined by themselves. Any suggestions are welcomed. Pearly On Wed, 2007-09-12 at 08:33 -0500, PEARLY.ZHAO@oracle.com wrote: > Actually, retrieving symbol addresses in the classes implementing the disssembly and memory windows is a wrong way to implement this functionality. Maybe it should be designed at core. The classes handling the windows merely use it to obtain the information. > > Pearly > > > Hi, > > > > This patch can make the disassembly/memory window accept symbol > > name in > > spin Button. > > > > Here is what it does: > > - When input a available symbol name at fromBox, the window > > would > > display the disassembly/memory of this symbol. The fromBox/fromSpin > > would be set the start address of this symbol and the toBox/toSpin > > would > > be set the end address of this symbol. > > - When input a available symbol name at toBox, it would do as > > same as > > when input at fromBox. > > - When input a unavailable symbol name, the fromBox/fromSpin > > or > > toBox/toSpin would be reset to the lastKnownFrom or lastKnownTo. > > > > Any suggestions are welcomed. > > > > Pearly Zhao > > > > --------Index: disassembler/DisassemblyWindow.java > > =================================================================== > > RCS file: /cvs/frysk/frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java,v > > retrieving revision 1.31 > > diff -u -r1.31 DisassemblyWindow.java > > --- disassembler/DisassemblyWindow.java 7 Sep 2007 03:18:50 > > -0000 1.31 > > +++ disassembler/DisassemblyWindow.java 12 Sep 2007 07:43:28 > > -0000 > > @@ -42,6 +42,7 @@ > > package frysk.gui.disassembler; > > > > import java.util.prefs.Preferences; > > +import java.util.LinkedList; > > import java.util.List; > > import java.util.Iterator; > > import java.util.ListIterator; > > @@ -74,6 +75,7 @@ > > import org.gnu.gtk.event.SpinEvent; > > import org.gnu.gtk.event.SpinListener; > > > > +import frysk.dwfl.DwflCache; > > import frysk.gui.common.IconManager; > > import frysk.gui.prefs.PreferenceManager; > > import frysk.gui.monitor.Saveable; > > @@ -81,7 +83,12 @@ > > import frysk.proc.Task; > > import frysk.stepping.TaskStepEngine; > > import frysk.proc.MemoryMap; > > +import frysk.symtab.Symbol; > > +import frysk.symtab.SymbolFactory; > > > > +import lib.dwfl.Dwfl; > > +import lib.dwfl.DwflModule; > > +import lib.dwfl.SymbolBuilder; > > import lib.opcodes.Disassembler; > > import lib.opcodes.Instruction; > > > > @@ -379,28 +386,42 @@ > > return; > > > > String str = fromBox.getText(); > > - str = str.substring(2); > > - try > > + > > + if (str.startsWith("0x")) > > { > > - double d = (double) Long.parseLong(str, 16); > > - if (!addressAccessible((long)d)) > > - fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > - else > > - { > > - if (d > lastKnownTo) > > + str = str.substring(2); > > + try > > + { > > + double d = (double) Long.parseLong(str, > > 16); > > + if (!addressAccessible((long)d)) > > + fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + else > > { > > - if (lastKnownTo == lastKnownFrom) > > - handleFromSpin(lastKnownTo); > > + if (d > lastKnownTo) > > + { > > + if (lastKnownTo == lastKnownFrom) > > + handleFromSpin(lastKnownTo); > > + else > > + fromSpin.setValue(lastKnownTo); > > + } > > else > > - fromSpin.setValue(lastKnownTo); > > + fromSpin.setValue(d); > > } > > - else > > - fromSpin.setValue(d); > > - } > > + } > > + catch (NumberFormatException nfe) > > + { > > + fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + } > > } > > - catch (NumberFormatException nfe) > > - { > > - fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + else > > + { > > + try > > + { > > + handleSymbol(str); > > + } > > + catch (RuntimeException e){ > > + fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + } > > } > > } > > } > > @@ -416,28 +437,41 @@ > > return; > > > > String str = toBox.getText(); > > - str = str.substring(2); > > - try > > + if (str.startsWith("0x")) > > { > > - double d = (double) Long.parseLong(str, 16); > > - if (!(addressAccessible((long)d))) > > - toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > - else > > - { > > - if (d < lastKnownFrom) > > + str = str.substring(2); > > + try > > + { > > + double d = (double) Long.parseLong(str, > > 16); > > + 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) > > + { > > + toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > + } > > } > > - catch (NumberFormatException nfe) > > - { > > - toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > + else > > + { > > + try > > + { > > + handleSymbol(str); > > + } > > + catch (RuntimeException e){ > > + toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > + } > > } > > } > > } > > @@ -539,6 +573,32 @@ > > } > > this.refreshList(); > > } > > + > > + /** > > + * Get the address list from symbol name; > > + * @param name > > + * @return address list > > + */ > > + private LinkedList addressesForSymbol(String name) { > > + Dwfl dwfl = DwflCache.getDwfl(this.myTask); > > + DwflModule[] modules = dwfl.getModules(); > > + final LinkedList addrs = new LinkedList(); > > + SymbolBuilder builder = new SymbolBuilder() { > > + public void symbol(String name, long value, long size, > > + int type, int bind, int visibility) { > > + addrs.add(new Long(value)); > > + } > > + }; > > + for (int i = 0; i < modules.length; i++) > > + { > > + DwflModule module = modules[i]; > > + module.getSymbolByName(name, builder); > > + } > > + if (addrs.size() == 0) > > + throw new RuntimeException("Couldn't find symbol " + > > name); > > + else > > + return addrs; > > + } > > /** > > * return a boolean indicating whether or not this address > > is accessible. > > * > > @@ -640,16 +700,17 @@ > > * By default append rows to the end. > > * > > * @param i The address to be displayed > > + * @param numIns The Instructions that maybe be added > > * @param iter The TreeIter representing the row to be > > added. > > */ > > - public synchronized void rowAppend (long i, TreeIter iter) > > + public synchronized void rowAppend (long i, int numIns, > > TreeIter iter) > > { > > // if (iter == null) > > // iter = model.appendRow(); > > > > List instructionsList > > = diss.disassembleInstructions((long) this.lastKnownTo, > > - numInstructions); > > + numInstructions+numIns); > > Iterator li = instructionsList.listIterator(0); > > Instruction ins = (Instruction) li.next(); > > > > @@ -661,8 +722,10 @@ > > this.lastPath.next(); > > if (ins != null) > > { > > - if (li.hasNext()) > > + if (li.hasNext()){ > > ins = (Instruction) li.next(); > > + this.numInstructions++; > > + } > > else > > { > > this.toSpin.setValue((double) ins.address); > > @@ -858,10 +921,11 @@ > > > > if (val > this.lastKnownTo) > > { > > - for (long i = (long) lastKnownTo + 1; i < val + 1; > > i++) > > - ++this.numInstructions; > > + int numIns = 0; > > + for (long i = (long) lastKnownTo + 1; i < val + 1; i++) > > + ++numIns; > > > > - rowAppend((long) val, null); > > + rowAppend((long) val, numIns, null); > > > > return; > > } > > @@ -895,6 +959,48 @@ > > refreshList(); > > } > > } > > + > > + /** > > + * When the box is inputed a symbol, update the displayed > > information to the symbol. > > + * @param symbolName > > + */ > > + private synchronized void handleSymbol(String symbolName) > > + { > > + LinkedList addressList = addressesForSymbol(symbolName); > > + long startAddress = ((Long)addressList.getFirst()).longValue(); > > + Symbol symbol = SymbolFactory.getSymbol(this.myTask, > > startAddress); > > + long endAddress = symbol.getAddress() + symbol.getSize(); > > + > > + List instructionsList > > + = diss.disassembleInstructionsStartEnd((long)startAddress, > > (long)endAddress); > > + Iterator li = instructionsList.listIterator(0); > > + int insnum = 1; > > + Instruction ins = (Instruction)li.next(); > > + this.lastKnownFrom = (double)ins.address; > > + while (li.hasNext()){ > > + ins = (Instruction)li.next(); > > + insnum++; > > + } > > + this.lastKnownTo = (double)ins.address; > > + > > + TreeIter iter = this.model.getFirstIter(); > > + while (insnum < numInstructions) > > + { > > + this.model.removeRow(iter); > > + this.lastPath.previous(); > > + numInstructions--; > > + } > > + while(insnum > numInstructions) > > + { > > + this.model.appendRow(); > > + this.lastPath.next(); > > + numInstructions++; > > + } > > + > > + refreshList(); > > + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); > > + fromSpin.setValue(lastKnownFrom); > > + } > > > > /**************************************************************************** > > * Save and Load > > Index: memory/MemoryWindow.java > > =================================================================== > > RCS file: /cvs/frysk/frysk-gui/frysk/gui/memory/MemoryWindow.java,v > > retrieving revision 1.46 > > diff -u -r1.46 MemoryWindow.java > > --- memory/MemoryWindow.java 7 Sep 2007 03:18:50 -0000 1.46 > > +++ memory/MemoryWindow.java 12 Sep 2007 07:43:29 -0000 > > @@ -42,6 +42,7 @@ > > package frysk.gui.memory; > > > > import java.util.prefs.Preferences; > > +import java.util.LinkedList; > > import java.util.List; > > import java.util.Iterator; > > import java.util.Observable; > > @@ -78,6 +79,7 @@ > > import org.gnu.gtk.event.SpinEvent; > > import org.gnu.gtk.event.SpinListener; > > > > +import frysk.dwfl.DwflCache; > > import frysk.gui.common.IconManager; > > import frysk.gui.prefs.PreferenceManager; > > import frysk.gui.monitor.GuiObject; > > @@ -87,8 +89,13 @@ > > import frysk.proc.Proc; > > import frysk.proc.Task; > > import frysk.stepping.TaskStepEngine; > > +import frysk.symtab.Symbol; > > +import frysk.symtab.SymbolFactory; > > import frysk.proc.MemoryMap; > > > > +import lib.dwfl.Dwfl; > > +import lib.dwfl.DwflModule; > > +import lib.dwfl.SymbolBuilder; > > import lib.opcodes.Disassembler; > > import lib.opcodes.Instruction; > > > > @@ -511,28 +518,41 @@ > > return; > > > > String str = fromBox.getText(); > > - str = str.substring(2); > > - try > > + if (str.startsWith("0x")) > > { > > - double d = (double) Long.parseLong(str, 16); > > - if (!addressAccessible((long)d)) > > - fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > - else > > - { > > - if (d > lastKnownTo) > > + str = str.substring(2); > > + try > > + { > > + double d = (double) Long.parseLong(str, > > 16); > > + if (!addressAccessible((long)d)) > > + fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + else > > { > > - if (lastKnownTo == lastKnownFrom) > > - handleFromSpin(lastKnownTo); > > + if (d > lastKnownTo) > > + { > > + if (lastKnownTo == lastKnownFrom) > > + handleFromSpin(lastKnownTo); > > + else > > + fromSpin.setValue(lastKnownTo); > > + } > > else > > - fromSpin.setValue(lastKnownTo); > > > > + fromSpin.setValue(d); > > } > > - else > > - fromSpin.setValue(d); > > - } > > + } > > + catch (NumberFormatException nfe) > > + { > > + fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + } > > } > > - catch (NumberFormatException nfe) > > - { > > - fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + else > > + { > > + try > > + { > > + handleSymbol(str); > > + } > > + catch (RuntimeException e){ > > + fromBox.setText("0x" + Long.toHexString((long) > > lastKnownFrom)); > > + } > > } > > } > > } > > @@ -548,23 +568,41 @@ > > return; > > > > String str = toBox.getText(); > > - str = str.substring(2); > > - try > > + if (str.startsWith("0x")) > > { > > - double d = (double) Long.parseLong(str, 16); > > - if (d < lastKnownFrom) > > - { > > - if (lastKnownFrom == lastKnownTo) > > - handleToSpin(lastKnownFrom); > > - else > > - toSpin.setValue(lastKnownFrom); > > - } > > - else > > - toSpin.setValue(d); > > + str = str.substring(2); > > + try > > + { > > + double d = (double) Long.parseLong(str, > > 16); > > + if (!(addressAccessible((long)d))) > > + toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > + else > > + { > > + if (d < lastKnownFrom) > > + { > > + if (lastKnownFrom == lastKnownTo) > > + handleToSpin(lastKnownFrom); > > + else > > + toSpin.setValue(lastKnownFrom); > > + } > > + else > > + toSpin.setValue(d); > > + } > > + } > > + catch (NumberFormatException nfe) > > + { > > + toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > + } > > } > > - catch (NumberFormatException nfe) > > - { > > - toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > + else > > + { > > + try > > + { > > + handleSymbol(str); > > + } > > + catch (RuntimeException e){ > > + toBox.setText("0x" + Long.toHexString((long) > > lastKnownTo)); > > + } > > } > > } > > } > > @@ -573,6 +611,32 @@ > > } > > > > /** > > + * Get the address list from symbol name; > > + * @param name > > + * @return address list > > + */ > > + private LinkedList addressesForSymbol(String name) { > > + Dwfl dwfl = DwflCache.getDwfl(this.myTask); > > + DwflModule[] modules = dwfl.getModules(); > > + final LinkedList addrs = new LinkedList(); > > + SymbolBuilder builder = new SymbolBuilder() { > > + public void symbol(String name, long value, long size, > > + int type, int bind, int visibility) { > > + addrs.add(new Long(value)); > > + } > > + }; > > + for (int i = 0; i < modules.length; i++) > > + { > > + DwflModule module = modules[i]; > > + module.getSymbolByName(name, builder); > > + } > > + if (addrs.size() == 0) > > + throw new RuntimeException("Couldn't find symbol " + > > name); > > + else > > + return addrs; > > + } > > + > > + /** > > * return a boolean indicating whether or not this address > > is accessible. > > * > > * @return whether or not this address is accessible > > @@ -612,6 +676,7 @@ > > this.refreshLock = false; > > } > > > > + > > /***************************************************************************** > > * Calculation, memory reading, and information display > > methods > > ****************************************************************************/ > > @@ -1011,6 +1076,47 @@ > > this.lastKnownTo = val; > > refreshList(); > > } > > + > > + /** > > + * When the box is inputed a symbol, update the displayed > > information to the symbol. > > + * @param symbolName > > + */ > > + private synchronized void handleSymbol(String symbolName) > > + { > > + LinkedList addressList = addressesForSymbol(symbolName); > > + long startAddress = ((Long)addressList.getFirst()).longValue(); > > + Symbol symbol = SymbolFactory.getSymbol(this.myTask, > > startAddress); > > + long endAddress = symbol.getAddress() + symbol.getSize(); > > + long size = endAddress - startAddress + 1; > > + long modelSize = (long)lastKnownTo - (long)lastKnownFrom > > + 1; > > + TreeIter iter = this.model.getFirstIter(); > > + while (size < modelSize) > > + { > > + this.model.removeRow(iter); > > + this.lastPath.previous(); > > + modelSize--; > > + } > > + while(size > modelSize) > > + { > > + this.model.appendRow(); > > + this.lastPath.next(); > > + modelSize++; > > + } > > + this.lastKnownFrom = (double)startAddress; > > + this.lastKnownTo = (double)endAddress; > > + iter = this.model.getFirstIter(); > > + this.lastPath = iter.getPath(); > > + for(long i= startAddress; i < endAddress+1; i++) > > + { > > + rowAppend(i, iter); > > + iter = iter.getNextIter(); > > + } > > + refreshList(); > > + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); > > + fromSpin.setValue(lastKnownFrom); > > + toBox.setText("0x" + Long.toHexString((long)lastKnownTo)); > > + toSpin.setValue(lastKnownTo); > > + } > > > > /**************************************************************************** > > * Save and Load > > > [-- Attachment #2: Type: text/x-patch, Size: 19600 bytes --] Index: frysk-core/frysk/rt/BreakpointManager.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/rt/BreakpointManager.java,v retrieving revision 1.12 diff -u -r1.12 BreakpointManager.java --- frysk-core/frysk/rt/BreakpointManager.java 3 Sep 2007 21:34:31 -0000 1.12 +++ frysk-core/frysk/rt/BreakpointManager.java 14 Sep 2007 06:10:24 -0000 @@ -56,6 +56,7 @@ import frysk.proc.TaskObserver; import frysk.stepping.SteppingEngine; import frysk.util.CountDownLatch; +import frysk.symtab.SymbolFactory; import lib.dwfl.DwarfDie; /** @@ -234,7 +235,7 @@ managedProcs.add(proc); // Assume that the Proc's main task is stopped. LinkedList sharedLibBptAddrs - = FunctionBreakpoint.addressesForSymbol("_dl_debug_state", task); + = SymbolFactory.getSymbol(task, "_dl_debug_state"); if (sharedLibBptAddrs.size() == 0) return; long sharedLibBptAddr Index: frysk-core/frysk/rt/FunctionBreakpoint.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/rt/FunctionBreakpoint.java,v retrieving revision 1.11 diff -u -r1.11 FunctionBreakpoint.java --- frysk-core/frysk/rt/FunctionBreakpoint.java 16 Jul 2007 22:11:35 -0000 1.11 +++ frysk-core/frysk/rt/FunctionBreakpoint.java 14 Sep 2007 06:10:24 -0000 @@ -46,12 +46,9 @@ import java.util.ListIterator; import lib.dwfl.DwarfDie; -import lib.dwfl.Dwfl; -import lib.dwfl.DwflModule; -import lib.dwfl.SymbolBuilder; import lib.dwfl.die.InlinedSubroutine; import frysk.proc.Task; -import frysk.dwfl.DwflCache; +import frysk.symtab.SymbolFactory; public class FunctionBreakpoint extends SourceBreakpoint @@ -93,7 +90,7 @@ return addrs; } else { - return addressesForSymbol(name, task); + return SymbolFactory.getSymbol(task, name); } } @@ -120,26 +117,4 @@ writer.print("*"); return writer; } - - static LinkedList addressesForSymbol(String name, Task task) { - Dwfl dwfl = DwflCache.getDwfl(task); - DwflModule[] modules = dwfl.getModules(); - final LinkedList addrs = new LinkedList(); - SymbolBuilder builder = new SymbolBuilder() { - public void symbol(String name, long value, long size, - int type, int bind, int visibility) { - addrs.add(new Long(value)); - } - }; - for (int i = 0; i < modules.length; i++) - { - DwflModule module = modules[i]; - module.getSymbolByName(name, builder); - } - if (addrs.size() == 0) - throw new RuntimeException("Couldn't find symbol " + name); - else - return addrs; - - } } Index: frysk-core/frysk/symtab/SymbolFactory.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/symtab/SymbolFactory.java,v retrieving revision 1.3 diff -u -r1.3 SymbolFactory.java --- frysk-core/frysk/symtab/SymbolFactory.java 12 Sep 2007 14:35:54 -0000 1.3 +++ frysk-core/frysk/symtab/SymbolFactory.java 14 Sep 2007 06:10:24 -0000 @@ -40,10 +40,12 @@ package frysk.symtab; +import java.util.LinkedList; import frysk.proc.Task; import frysk.dwfl.DwflCache; import lib.dwfl.Dwfl; import lib.dwfl.DwflModule; +import lib.dwfl.SymbolBuilder; /** * The object-file symbol. Typically obtained by reading ELF @@ -79,4 +81,31 @@ return symbol; } + + /** + * Get address list by symbol name + * @param task + * @param name + * @return address list + */ + public static LinkedList getSymbol(Task task, String name) { + Dwfl dwfl = DwflCache.getDwfl(task); + DwflModule[] modules = dwfl.getModules(); + final LinkedList addrs = new LinkedList(); + SymbolBuilder builder = new SymbolBuilder() { + public void symbol(String name, long value, long size, + int type, int bind, int visibility) { + addrs.add(new Long(value)); + } + }; + for (int i = 0; i < modules.length; i++) + { + DwflModule module = modules[i]; + module.getSymbolByName(name, builder); + } + if (addrs.size() == 0) + throw new RuntimeException("Couldn't find symbol " + name); + else + return addrs; + } } Index: frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java =================================================================== RCS file: /cvs/frysk/frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java,v retrieving revision 1.31 diff -u -r1.31 DisassemblyWindow.java --- frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java 7 Sep 2007 03:18:50 -0000 1.31 +++ frysk-gui/frysk/gui/disassembler/DisassemblyWindow.java 14 Sep 2007 06:10:24 -0000 @@ -42,6 +42,7 @@ package frysk.gui.disassembler; import java.util.prefs.Preferences; +import java.util.LinkedList; import java.util.List; import java.util.Iterator; import java.util.ListIterator; @@ -81,6 +82,8 @@ import frysk.proc.Task; import frysk.stepping.TaskStepEngine; import frysk.proc.MemoryMap; +import frysk.symtab.Symbol; +import frysk.symtab.SymbolFactory; import lib.opcodes.Disassembler; import lib.opcodes.Instruction; @@ -379,28 +382,42 @@ return; String str = fromBox.getText(); - str = str.substring(2); - try + + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (!addressAccessible((long)d)) - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); - else - { - if (d > lastKnownTo) + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + if (!addressAccessible((long)d)) + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else { - if (lastKnownTo == lastKnownFrom) - handleFromSpin(lastKnownTo); + if (d > lastKnownTo) + { + if (lastKnownTo == lastKnownFrom) + handleFromSpin(lastKnownTo); + else + fromSpin.setValue(lastKnownTo); + } else - fromSpin.setValue(lastKnownTo); + fromSpin.setValue(d); } - else - fromSpin.setValue(d); - } + } + catch (NumberFormatException nfe) + { + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } - catch (NumberFormatException nfe) - { - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } } } @@ -416,28 +433,41 @@ return; String str = toBox.getText(); - str = str.substring(2); - try + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (!(addressAccessible((long)d))) - toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); - else - { - if (d < lastKnownFrom) + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + 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) + { + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } - catch (NumberFormatException nfe) - { - toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } } } @@ -539,6 +569,8 @@ } this.refreshList(); } + + /** * return a boolean indicating whether or not this address is accessible. * @@ -640,16 +672,17 @@ * By default append rows to the end. * * @param i The address to be displayed + * @param numIns The Instructions that maybe be added * @param iter The TreeIter representing the row to be added. */ - public synchronized void rowAppend (long i, TreeIter iter) + public synchronized void rowAppend (long i, int numIns, TreeIter iter) { // if (iter == null) // iter = model.appendRow(); List instructionsList = diss.disassembleInstructions((long) this.lastKnownTo, - numInstructions); + numInstructions+numIns); Iterator li = instructionsList.listIterator(0); Instruction ins = (Instruction) li.next(); @@ -661,8 +694,10 @@ this.lastPath.next(); if (ins != null) { - if (li.hasNext()) + if (li.hasNext()){ ins = (Instruction) li.next(); + this.numInstructions++; + } else { this.toSpin.setValue((double) ins.address); @@ -858,10 +893,11 @@ if (val > this.lastKnownTo) { - for (long i = (long) lastKnownTo + 1; i < val + 1; i++) - ++this.numInstructions; + int numIns = 0; + for (long i = (long) lastKnownTo + 1; i < val + 1; i++) + ++numIns; - rowAppend((long) val, null); + rowAppend((long) val, numIns, null); return; } @@ -895,6 +931,48 @@ refreshList(); } } + + /** + * When the box is inputed a symbol, update the displayed information to the symbol. + * @param symbolName + */ + private synchronized void handleSymbol(String symbolName) + { + LinkedList addressList = SymbolFactory.getSymbol(this.myTask, symbolName); + long startAddress = ((Long)addressList.getFirst()).longValue(); + Symbol symbol = SymbolFactory.getSymbol(this.myTask, startAddress); + long endAddress = symbol.getAddress() + symbol.getSize(); + + List instructionsList + = diss.disassembleInstructionsStartEnd((long)startAddress, (long)endAddress); + Iterator li = instructionsList.listIterator(0); + int insnum = 1; + Instruction ins = (Instruction)li.next(); + this.lastKnownFrom = (double)ins.address; + while (li.hasNext()){ + ins = (Instruction)li.next(); + insnum++; + } + this.lastKnownTo = (double)ins.address; + + TreeIter iter = this.model.getFirstIter(); + while (insnum < numInstructions) + { + this.model.removeRow(iter); + this.lastPath.previous(); + numInstructions--; + } + while(insnum > numInstructions) + { + this.model.appendRow(); + this.lastPath.next(); + numInstructions++; + } + + refreshList(); + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); + fromSpin.setValue(lastKnownFrom); + } /**************************************************************************** * Save and Load Index: frysk-gui/frysk/gui/memory/MemoryWindow.java =================================================================== RCS file: /cvs/frysk/frysk-gui/frysk/gui/memory/MemoryWindow.java,v retrieving revision 1.46 diff -u -r1.46 MemoryWindow.java --- frysk-gui/frysk/gui/memory/MemoryWindow.java 7 Sep 2007 03:18:50 -0000 1.46 +++ frysk-gui/frysk/gui/memory/MemoryWindow.java 14 Sep 2007 06:10:24 -0000 @@ -42,6 +42,7 @@ package frysk.gui.memory; import java.util.prefs.Preferences; +import java.util.LinkedList; import java.util.List; import java.util.Iterator; import java.util.Observable; @@ -87,6 +88,8 @@ import frysk.proc.Proc; import frysk.proc.Task; import frysk.stepping.TaskStepEngine; +import frysk.symtab.Symbol; +import frysk.symtab.SymbolFactory; import frysk.proc.MemoryMap; import lib.opcodes.Disassembler; @@ -511,28 +514,41 @@ return; String str = fromBox.getText(); - str = str.substring(2); - try + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (!addressAccessible((long)d)) - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); - else - { - if (d > lastKnownTo) + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + if (!addressAccessible((long)d)) + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else { - if (lastKnownTo == lastKnownFrom) - handleFromSpin(lastKnownTo); + if (d > lastKnownTo) + { + if (lastKnownTo == lastKnownFrom) + handleFromSpin(lastKnownTo); + else + fromSpin.setValue(lastKnownTo); + } else - fromSpin.setValue(lastKnownTo); + fromSpin.setValue(d); } - else - fromSpin.setValue(d); - } + } + catch (NumberFormatException nfe) + { + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } - catch (NumberFormatException nfe) - { - fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + fromBox.setText("0x" + Long.toHexString((long) lastKnownFrom)); + } } } } @@ -548,23 +564,41 @@ return; String str = toBox.getText(); - str = str.substring(2); - try + if (str.startsWith("0x")) { - double d = (double) Long.parseLong(str, 16); - if (d < lastKnownFrom) - { - if (lastKnownFrom == lastKnownTo) - handleToSpin(lastKnownFrom); - else - toSpin.setValue(lastKnownFrom); - } - else - toSpin.setValue(d); + str = str.substring(2); + try + { + double d = (double) Long.parseLong(str, 16); + if (!(addressAccessible((long)d))) + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + else + { + if (d < lastKnownFrom) + { + if (lastKnownFrom == lastKnownTo) + handleToSpin(lastKnownFrom); + else + toSpin.setValue(lastKnownFrom); + } + else + toSpin.setValue(d); + } + } + catch (NumberFormatException nfe) + { + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } - catch (NumberFormatException nfe) - { - toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + else + { + try + { + handleSymbol(str); + } + catch (RuntimeException e){ + toBox.setText("0x" + Long.toHexString((long) lastKnownTo)); + } } } } @@ -572,6 +606,7 @@ } + /** * return a boolean indicating whether or not this address is accessible. * @@ -612,6 +647,7 @@ this.refreshLock = false; } + /***************************************************************************** * Calculation, memory reading, and information display methods ****************************************************************************/ @@ -1011,6 +1047,47 @@ this.lastKnownTo = val; refreshList(); } + + /** + * When the box is inputed a symbol, update the displayed information to the symbol. + * @param symbolName + */ + private synchronized void handleSymbol(String symbolName) + { + LinkedList addressList = SymbolFactory.getSymbol(this.myTask, symbolName); + long startAddress = ((Long)addressList.getFirst()).longValue(); + Symbol symbol = SymbolFactory.getSymbol(this.myTask, startAddress); + long endAddress = symbol.getAddress() + symbol.getSize(); + long size = endAddress - startAddress + 1; + long modelSize = (long)lastKnownTo - (long)lastKnownFrom + 1; + TreeIter iter = this.model.getFirstIter(); + while (size < modelSize) + { + this.model.removeRow(iter); + this.lastPath.previous(); + modelSize--; + } + while(size > modelSize) + { + this.model.appendRow(); + this.lastPath.next(); + modelSize++; + } + this.lastKnownFrom = (double)startAddress; + this.lastKnownTo = (double)endAddress; + iter = this.model.getFirstIter(); + this.lastPath = iter.getPath(); + for(long i= startAddress; i < endAddress+1; i++) + { + rowAppend(i, iter); + iter = iter.getNextIter(); + } + refreshList(); + fromBox.setText("0x" + Long.toHexString((long)lastKnownFrom)); + fromSpin.setValue(lastKnownFrom); + toBox.setText("0x" + Long.toHexString((long)lastKnownTo)); + toSpin.setValue(lastKnownTo); + } /**************************************************************************** * Save and Load ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] Accept symbolic addresses in spin button, bug 4673. 2007-09-19 1:19 ` Zhao Shujing @ 2007-09-21 21:53 ` Andrew Cagney 0 siblings, 0 replies; 4+ messages in thread From: Andrew Cagney @ 2007-09-21 21:53 UTC (permalink / raw) To: pearly.zhao; +Cc: Frysk Mailing List Pearly, > Hi, > This is a new patch. It adds getSymbol(task, name) method to > SymbolFactory. The BreakpointManager and FunctionBreakpoint are changed > to use this method instead of using the one defined by themselves. > > Any suggestions are welcomed. > > Pearly > On Wed, 2007-09-12 at 08:33 -0500, PEARLY.ZHAO@oracle.com wrote: > > > Actually, retrieving symbol addresses in the classes implementing the disssembly and memory windows is a wrong way to implement this functionality. Maybe it should be designed at core. The classes handling the windows merely use it to obtain the information. Yes, agreed; but rather than assuming the string is a symbol, would it be more robust to evaluate the string as an expression? Thus allowing arbitrary expressions and symbols vis: foo+10 and not limiting things to symbols (See DisassembleCommand for how it evaluates its parameters). BTW, + + /** + * Get address list by symbol name + * @param task + * @param name + * @return address list + */ + public static LinkedList getSymbol(Task task, String name) { + Dwfl dwfl = DwflCache.getDwfl(task); + DwflModule[] modules = dwfl.getModules(); + final LinkedList addrs = new LinkedList(); is for searching out duplicate symbols so that a breakpoint can be inserted at all locations; since here only a single location (based on the current pc and elf/c scope rules) is needed, using it and discarding all but the first address isn't correct. You can assume that the expression evaluator will get this right, and if it doesn't we've an expression evaluation bug. In refactoring getSymbol to frysk.symtab.SymbolFactory did you take the opportunity to add a test case? Andrew ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-09-21 21:53 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2007-09-12 8:05 [patch] Accept symbolic addresses in spin button, bug 4673 Zhao Shujing 2007-09-12 13:33 ` PEARLY.ZHAO 2007-09-19 1:19 ` Zhao Shujing 2007-09-21 21:53 ` Andrew Cagney
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).