Re: Debugger problem
        Date:
             Mon, 08 Jan 2001 14:16:30 -0800
       From:
             Christopher Oliver <coliver@mminternet.com>
 Organization:
             Primary Interface LLC
         To:
             Kurt Westerfeld <kurt@ManagedObjects.com>
         CC:
             Norris Boyd <nboyd@atg.com>
  References:
             1 , 2 , 3




Kurt, Norris,

Yes, with the change to the shell this should be possible.  The problem before
was that if you loaded the same file with different relative path names, two
different windows in the debugger were created because everything (windows,
breakpoints, etc) is keyed off the source name.

The attached file contains the fix (and includes the workaround for
Desktop.getSelectedFrame).

There are still some bugs in transferring focus between the windows in the
Desktop.  I haven't had time to track down the problem or a solution.

Chris

Kurt Westerfeld wrote:

> I would point out that "Source Name" of a script isn't necessarily a
> filename.  In our system, scripts are run remotely from a script library
> that has no file system backing.  Canonicalizing the file names is really
> unnecessary.
>
> Can't you just modify JSDebugger to not care what the name of the file is?
> If access to the original script is unavailable except through the file
> system, I'd be surprised.
>
> ----- Original Message -----
> From: Christopher Oliver <coliver@mminternet.com>
> To: Kurt Westerfeld <kurt@ManagedObjects.com>
> Cc: Norris Boyd <nboyd@atg.com>
> Sent: Sunday, January 07, 2001 2:23 AM
> Subject: Re: Debugger problem
>
> > Hi Kurt,
> >
> > I rather would say that it is a problem with the processFile method in the
> > shell's Main class.  If you change the current working directory or the
> value
> > of the System property "user.dir" after compiling a script, relative path
> names
> > can become ambiguous.  Norris, would it be ok to modify the shell to
> > "canonicalize" the names of files it compiles?  That way the source name
> that
> > shows up in the stack and in DebuggableScript will always be unique.  For
> > example:
> >
> > public static void processFile(Context cx, Scriptable scope,
> >                                    String filename)
> >     {
> >             Reader in = null;
> >             try {
> >                 in = new PushbackReader(new FileReader(filename));
> >                 int c = in.read();
> >                 // Support the executable script #! syntax:  If
> >                 // the first line begins with a '#', treat the whole
> >                 // line as a comment.
> >                 if (c == '#') {
> >                     while ((c = in.read()) != -1) {
> >                         if (c == '\n' || c == '\r')
> >                             break;
> >                     }
> >                     ((PushbackReader) in).unread(c);
> >                 } else {
> >                     // No '#' line, just reopen the file and forget it
> >                     // ever happened.  OPT closing and reopening
> >                     // undoubtedly carries some cost.  Is this faster
> >                     // or slower than leaving the PushbackReader
> >                     // around?
> >                     in.close();
> >                     in = new FileReader(filename);
> >                 }
> >                 filename = new java.io.File(filename).getCanonicalPath();
> > <<<====== Add this
> >             }
> >             catch (FileNotFoundException ex) {
> >                 Context.reportError(ToolErrorReporter.getMessage(
> >                     "msg.couldnt.open",
> >                     filename));
> >                 exitCode = EXITCODE_FILE_NOT_FOUND;
> >                 return;
> >             } catch (IOException ioe) {
> >                 globalState.getErr().println(ioe.toString());
> >             }
> >
> >             // Here we evalute the entire contents of the file as
> >             // a script. Text is printed only if the print() function
> >             // is called.
> >             evaluateReader(cx, scope, in, filename, 1);
> >     }
> >
> >
> > Attached is *my* latest version of the debugger code.  Norris, have you
> made
> > any progress on cvs commit priveledges?  The attached version fixes a
> number of
> > GUI bugs:
> >
> > 1) If you undocked the Variables window and popped up the Context
> combo-box and
> > then closed the window with the system menu, the Context pop-up was not
> cleaned
> > up properly.
> > 2) The first time you minimize a file window it appeared to dissappear
> when you
> > tried to restore it.  This was due to the fact that I forgot to "pack" its
> > contents and as a result its requested size was 0x0.
> >
> > I also added a menu item to toggle whether to break on exceptions and one
> which
> > allows you to open (and compile) a JavaScript file without actually
> executing
> > it.
> >
> > I have also attached a Word document with some basic documentation for the
> > Debugger.
> >
> > Note that this version also includes all the changes to support debugging
> > scripts in the AWT dispatch thread.
> >
> > Chris
> >
> > Kurt Westerfeld wrote:
> >
> > > Hello.  I ran into a null pointer exception in JSDebugger tonight, and I
> > > thought I'd drop you a note.
> > >
> > > The problem line is 2336, where a breakpoint is hit.  To simulate, load
> the
> > > debugger using the command line syntax on a file that has not been
> resolved
> > > to cannonical path.
> > >
> > > Example,
> > >
> > >      jshell -debug -f \myfile.fs
> > >
> > > At any rate, the "handleCompilationDone" routine takes \myfile.fs and
> turns
> > > it into a canonical path.  If you hit a breakpoint in this file and say
> > > "go", when the breakpoint hits the file is not found, because the same
> > > canonical path resolution is not done.  The resolution seems dubious,
> since
> > > it is only done in the compilation done callback, but I don't know the
> best
> > > way to suggest a fix since it seems that code had some purpose.
> > >
> > > Anyway, thought you'd wanna know.
> > >
> > > ________________________________________________________________________
> > >   Kurt Westerfeld
> > >   Senior Software Architect
> > >   Managed Objects
> > >   mailto:kwester@ManagedObjects.com
> > >   703.770.7225
> > >   http://www.ManagedObjects.com
> > >
> > >   Managed Objects: manage technology > rule business
> >



   JSDebugger.java

                    Name:
                          JSDebugger.java
                    Type:
                          Java Class File (java/*)
                 Encoding:
                          base64
This commit is contained in:
nboyd%atg.com 2001-01-09 14:10:40 +00:00
parent 864bb13d47
commit b8ac59c406
2 changed files with 94 additions and 124 deletions

View File

@ -318,9 +318,10 @@ class JSInternalConsole extends JInternalFrame
addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameActivated(InternalFrameEvent e) {
// hack
consoleTextArea.requestFocus();
consoleTextArea.getCaret().setVisible(false);
consoleTextArea.getCaret().setVisible(true);
if(consoleTextArea.hasFocus()) {
consoleTextArea.getCaret().setVisible(false);
consoleTextArea.getCaret().setVisible(true);
}
}
});
}
@ -631,10 +632,6 @@ class FindFunction extends JDialog implements ActionListener {
DebuggableScript script = sourceEntry.fnOrScript;
if(script != null) {
String sourceName = script.getSourceName();
try {
sourceName = new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
Enumeration ee = script.getLineNumbers();
int lineNumber = -1;
while(ee.hasMoreElements()) {
@ -645,6 +642,7 @@ class FindFunction extends JDialog implements ActionListener {
lineNumber = ival.intValue();
}
}
FileWindow w = db.getFileWindow(sourceName);
if(w == null) {
(new CreateFileWindow(db, sourceName, sourceEntry.source.toString(), lineNumber)).run();
@ -2066,9 +2064,15 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
super.setVisible(b);
if(b) {
// this needs to be done after the window is visible
context.split.setDividerLocation(0.5);
console.show();
console.consoleTextArea.requestFocus();
context.split.setDividerLocation(0.5);
try {
console.setMaximum(true);
console.setSelected(true);
console.show();
console.consoleTextArea.requestFocus();
} catch(Exception exc) {
}
}
}
@ -2121,12 +2125,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
public void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
StringBuffer source) {
String sourceName = fnOrScript.getSourceName();
if (sourceName != null && !sourceName.equals("<stdin>")) {
try {
sourceName = new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
} else {
if (sourceName == null) {
sourceName = "<stdin>";
}
Vector v = (Vector) sourceNames.get(sourceName);
@ -2205,6 +2204,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
toolBar = new JToolBar();
JButton button;
toolBar.add(button = new JButton("Break"));
JButton focusButton = button;
button.setToolTipText("Break");
button.setActionCommand("Break");
button.addActionListener(menubar);
@ -2245,6 +2245,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
context = new ContextWindow(this);
context.setPreferredSize(new Dimension(600, 120));
context.setMinimumSize(new Dimension(50, 50));
split1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, desk,
context);
split1.setOneTouchExpandable(true);
@ -2277,13 +2278,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
};
dlg.addChoosableFileFilter(filter);
try {
console.setMaximum(true);
console.setSelected(true);
console.consoleTextArea.requestFocus();
} catch(Exception exc) {
}
final JSDebugger self = this;
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
@ -2305,19 +2299,15 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
if(fileName == null || fileName.equals("<stdin>") || fileName.equals("<eval>")) {
return null;
}
try {
// Can't do this if we're remote debugging
String file = new File(fileName).getCanonicalPath();
Enumeration e = fileWindows.keys();
for(; e.hasMoreElements(); ) {
String name = (String)e.nextElement();
if(file.equals(new File(name).getCanonicalPath())) {
FileWindow w = (FileWindow)fileWindows.get(name);
w.setUrl(fileName);
return w;
}
String file = fileName;
Enumeration e = fileWindows.keys();
for(; e.hasMoreElements(); ) {
String name = (String)e.nextElement();
if(file.equals(name)) {
FileWindow w = (FileWindow)fileWindows.get(name);
w.setUrl(fileName);
return w;
}
} catch(IOException exc) {
}
return (FileWindow)fileWindows.get(fileName);
}
@ -2326,6 +2316,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
FileWindow w = getFileWindow(fileName);
if(w != null) {
swingInvoke(new SetFileText(w, text));
w.show();
} else if(!fileName.equals("<stdin>")) {
swingInvoke(new CreateFileWindow(this,
fileName,
@ -2380,10 +2371,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
helper.reset();
return;
}
try {
sourceName = new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
int lineNumber = frame.getLineNumber();
this.frameIndex = frameIndex;
FileWindow w = getFileWindow(sourceName);
@ -2481,11 +2468,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
DebugFrame frame = engine.getFrame(0);
String sourceName = frame.getSourceName();
if(sourceName != null) {
try {
sourceName =
new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
if(sourceName.equals(runToCursorFile)) {
int lineNumber = frame.getLineNumber();
if(lineNumber == runToCursorLine) {
@ -2522,12 +2504,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
DebugFrame frame = engine.getFrame(0);
String fileName = frame.getSourceName();
if(fileName != null && !fileName.equals("<stdin>")) {
try {
fileName = new File(fileName).getCanonicalPath();
} catch(IOException exc) {
}
}
engine.setBreakNextLine(false);
line = frame.getLineNumber();
int enterCount = 0;
@ -2687,26 +2663,35 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
int returnVal = dlg.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
String result = dlg.getSelectedFile().getPath();
CWD = dlg.getSelectedFile().getParentFile();
java.lang.System.setProperty("user.dir", CWD.getPath());
return result;
try {
String result = dlg.getSelectedFile().getCanonicalPath();
CWD = dlg.getSelectedFile().getParentFile();
java.lang.System.setProperty("user.dir", CWD.getPath());
return result;
} catch(IOException ignored) {
}
}
return null;
}
JInternalFrame getSelectedFrame() {
JInternalFrame[] frames = desk.getAllFrames();
for(int i = 0; i < frames.length; i++) {
if(frames[i].isShowing()) {
return frames[i];
}
}
return frames[frames.length - 1];
}
void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
int returnValue = -1;
if(cmd.equals("Cut") || cmd.equals("Copy") || cmd.equals("Paste")) {
JInternalFrame[] frames = desk.getAllFrames();
for( int i = 0 ; i < frames.length ; ++i )
if( frames[i].isShowing() &&
frames[i] instanceof ActionListener )
{
((ActionListener)frames[i]).actionPerformed(e);
break;
}
JInternalFrame f = getSelectedFrame();
if(f != null && f instanceof ActionListener) {
((ActionListener)f).actionPerformed(e);
}
} else if(cmd.equals("Step Over")) {
returnValue = STEP_OVER;
} else if(cmd.equals("Step Into")) {
@ -2753,7 +2738,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
console.show();
desk.getDesktopManager().activateFrame(console);
//console.consoleTextArea.requestFocus();
console.consoleTextArea.requestFocus();
} else if(cmd.equals("Cut")) {
} else if(cmd.equals("Copy")) {
} else if(cmd.equals("Paste")) {

View File

@ -318,9 +318,10 @@ class JSInternalConsole extends JInternalFrame
addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameActivated(InternalFrameEvent e) {
// hack
consoleTextArea.requestFocus();
consoleTextArea.getCaret().setVisible(false);
consoleTextArea.getCaret().setVisible(true);
if(consoleTextArea.hasFocus()) {
consoleTextArea.getCaret().setVisible(false);
consoleTextArea.getCaret().setVisible(true);
}
}
});
}
@ -631,10 +632,6 @@ class FindFunction extends JDialog implements ActionListener {
DebuggableScript script = sourceEntry.fnOrScript;
if(script != null) {
String sourceName = script.getSourceName();
try {
sourceName = new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
Enumeration ee = script.getLineNumbers();
int lineNumber = -1;
while(ee.hasMoreElements()) {
@ -645,6 +642,7 @@ class FindFunction extends JDialog implements ActionListener {
lineNumber = ival.intValue();
}
}
FileWindow w = db.getFileWindow(sourceName);
if(w == null) {
(new CreateFileWindow(db, sourceName, sourceEntry.source.toString(), lineNumber)).run();
@ -2066,9 +2064,15 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
super.setVisible(b);
if(b) {
// this needs to be done after the window is visible
context.split.setDividerLocation(0.5);
console.show();
console.consoleTextArea.requestFocus();
context.split.setDividerLocation(0.5);
try {
console.setMaximum(true);
console.setSelected(true);
console.show();
console.consoleTextArea.requestFocus();
} catch(Exception exc) {
}
}
}
@ -2121,12 +2125,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
public void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
StringBuffer source) {
String sourceName = fnOrScript.getSourceName();
if (sourceName != null && !sourceName.equals("<stdin>")) {
try {
sourceName = new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
} else {
if (sourceName == null) {
sourceName = "<stdin>";
}
Vector v = (Vector) sourceNames.get(sourceName);
@ -2205,6 +2204,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
toolBar = new JToolBar();
JButton button;
toolBar.add(button = new JButton("Break"));
JButton focusButton = button;
button.setToolTipText("Break");
button.setActionCommand("Break");
button.addActionListener(menubar);
@ -2245,6 +2245,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
context = new ContextWindow(this);
context.setPreferredSize(new Dimension(600, 120));
context.setMinimumSize(new Dimension(50, 50));
split1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, desk,
context);
split1.setOneTouchExpandable(true);
@ -2277,13 +2278,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
};
dlg.addChoosableFileFilter(filter);
try {
console.setMaximum(true);
console.setSelected(true);
console.consoleTextArea.requestFocus();
} catch(Exception exc) {
}
final JSDebugger self = this;
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
@ -2305,19 +2299,15 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
if(fileName == null || fileName.equals("<stdin>") || fileName.equals("<eval>")) {
return null;
}
try {
// Can't do this if we're remote debugging
String file = new File(fileName).getCanonicalPath();
Enumeration e = fileWindows.keys();
for(; e.hasMoreElements(); ) {
String name = (String)e.nextElement();
if(file.equals(new File(name).getCanonicalPath())) {
FileWindow w = (FileWindow)fileWindows.get(name);
w.setUrl(fileName);
return w;
}
String file = fileName;
Enumeration e = fileWindows.keys();
for(; e.hasMoreElements(); ) {
String name = (String)e.nextElement();
if(file.equals(name)) {
FileWindow w = (FileWindow)fileWindows.get(name);
w.setUrl(fileName);
return w;
}
} catch(IOException exc) {
}
return (FileWindow)fileWindows.get(fileName);
}
@ -2326,6 +2316,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
FileWindow w = getFileWindow(fileName);
if(w != null) {
swingInvoke(new SetFileText(w, text));
w.show();
} else if(!fileName.equals("<stdin>")) {
swingInvoke(new CreateFileWindow(this,
fileName,
@ -2380,10 +2371,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
helper.reset();
return;
}
try {
sourceName = new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
int lineNumber = frame.getLineNumber();
this.frameIndex = frameIndex;
FileWindow w = getFileWindow(sourceName);
@ -2481,11 +2468,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
DebugFrame frame = engine.getFrame(0);
String sourceName = frame.getSourceName();
if(sourceName != null) {
try {
sourceName =
new File(sourceName).getCanonicalPath();
} catch(IOException exc) {
}
if(sourceName.equals(runToCursorFile)) {
int lineNumber = frame.getLineNumber();
if(lineNumber == runToCursorLine) {
@ -2522,12 +2504,6 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
DebugFrame frame = engine.getFrame(0);
String fileName = frame.getSourceName();
if(fileName != null && !fileName.equals("<stdin>")) {
try {
fileName = new File(fileName).getCanonicalPath();
} catch(IOException exc) {
}
}
engine.setBreakNextLine(false);
line = frame.getLineNumber();
int enterCount = 0;
@ -2687,26 +2663,35 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
int returnVal = dlg.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
String result = dlg.getSelectedFile().getPath();
CWD = dlg.getSelectedFile().getParentFile();
java.lang.System.setProperty("user.dir", CWD.getPath());
return result;
try {
String result = dlg.getSelectedFile().getCanonicalPath();
CWD = dlg.getSelectedFile().getParentFile();
java.lang.System.setProperty("user.dir", CWD.getPath());
return result;
} catch(IOException ignored) {
}
}
return null;
}
JInternalFrame getSelectedFrame() {
JInternalFrame[] frames = desk.getAllFrames();
for(int i = 0; i < frames.length; i++) {
if(frames[i].isShowing()) {
return frames[i];
}
}
return frames[frames.length - 1];
}
void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
int returnValue = -1;
if(cmd.equals("Cut") || cmd.equals("Copy") || cmd.equals("Paste")) {
JInternalFrame[] frames = desk.getAllFrames();
for( int i = 0 ; i < frames.length ; ++i )
if( frames[i].isShowing() &&
frames[i] instanceof ActionListener )
{
((ActionListener)frames[i]).actionPerformed(e);
break;
}
JInternalFrame f = getSelectedFrame();
if(f != null && f instanceof ActionListener) {
((ActionListener)f).actionPerformed(e);
}
} else if(cmd.equals("Step Over")) {
returnValue = STEP_OVER;
} else if(cmd.equals("Step Into")) {
@ -2753,7 +2738,7 @@ public class JSDebugger extends JFrame implements Debugger, ContextListener {
}
console.show();
desk.getDesktopManager().activateFrame(console);
//console.consoleTextArea.requestFocus();
console.consoleTextArea.requestFocus();
} else if(cmd.equals("Cut")) {
} else if(cmd.equals("Copy")) {
} else if(cmd.equals("Paste")) {