Repository: flex-falcon Updated Branches: refs/heads/develop c189d65e9 -> 4606617a4
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/70b8151b/debugger/src/flex/tools/debugger/cli/DebugCLI.java ---------------------------------------------------------------------- diff --git a/debugger/src/flex/tools/debugger/cli/DebugCLI.java b/debugger/src/flex/tools/debugger/cli/DebugCLI.java index 0223f43..58ce94c 100644 --- a/debugger/src/flex/tools/debugger/cli/DebugCLI.java +++ b/debugger/src/flex/tools/debugger/cli/DebugCLI.java @@ -1,94 +1,30 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package flex.tools.debugger.cli; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.io.PrintStream; -import java.io.StringReader; -import java.net.SocketException; -import java.net.SocketTimeoutException; -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Properties; -import java.util.Set; -import java.util.Stack; -import java.util.StringTokenizer; -import java.util.Vector; - +import com.sun.org.apache.xml.internal.utils.LocaleUtility; import flash.localization.LocalizationManager; -import flash.tools.debugger.Bootstrap; -import flash.tools.debugger.DebuggerLocalizer; -import flash.tools.debugger.Frame; -import flash.tools.debugger.InProgressException; -import flash.tools.debugger.Isolate; -import flash.tools.debugger.IsolateSession; -import flash.tools.debugger.Location; -import flash.tools.debugger.NoResponseException; -import flash.tools.debugger.NotConnectedException; -import flash.tools.debugger.NotSupportedException; -import flash.tools.debugger.NotSuspendedException; -import flash.tools.debugger.PlayerDebugException; -import flash.tools.debugger.Session; -import flash.tools.debugger.SessionManager; -import flash.tools.debugger.SourceFile; -import flash.tools.debugger.SourceLocator; -import flash.tools.debugger.SuspendReason; -import flash.tools.debugger.SuspendedException; -import flash.tools.debugger.SwfInfo; -import flash.tools.debugger.Value; -import flash.tools.debugger.Variable; -import flash.tools.debugger.VariableAttribute; -import flash.tools.debugger.VariableType; -import flash.tools.debugger.VersionException; -import flash.tools.debugger.Watch; -import flash.tools.debugger.WatchKind; +import flash.tools.debugger.*; import flash.tools.debugger.concrete.DProtocol; import flash.tools.debugger.concrete.DSwfInfo; -import flash.tools.debugger.events.BreakEvent; -import flash.tools.debugger.events.ConsoleErrorFault; -import flash.tools.debugger.events.DebugEvent; -import flash.tools.debugger.events.ExceptionFault; -import flash.tools.debugger.events.FaultEvent; -import flash.tools.debugger.events.FileListModifiedEvent; -import flash.tools.debugger.events.FunctionMetaDataAvailableEvent; -import flash.tools.debugger.events.IsolateCreateEvent; -import flash.tools.debugger.events.IsolateExitEvent; -import flash.tools.debugger.events.SwfLoadedEvent; -import flash.tools.debugger.events.SwfUnloadedEvent; -import flash.tools.debugger.events.TraceEvent; +import flash.tools.debugger.events.*; import flash.tools.debugger.expression.ECMA; import flash.tools.debugger.expression.NoSuchVariableException; import flash.tools.debugger.expression.PlayerFaultException; @@ -98,174 +34,181 @@ import flash.util.Trace; import flex.tools.debugger.cli.ExpressionCache.EvaluationResult; import flex.tools.debugger.cli.FaultActions.FaultActionsBuilder; +import java.io.*; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.*; + /** * This is a front end command line interface to the Flash Debugger * Player. - *<p> - * This tool utilizes the Debugger Java API (DJAPI) for Flash + * <p/> + * This tool utilizes the Debugger Java API (DJAPI) for Flash * Player that exists in flash.tools.debuggger. - *<p> + * <p/> * This tool is not completely compliant with the API, since * some commands expose implementation specific information for * debugging purposes. Instances where this occurs are kept to a - * minimum and are isolated in a special class called Extensions. - * If you wish to build a version that is completely API - * compatible. Replace Extensions with ExtensionsDisabled in - * the static method calls at the end of this file. + * minimum and are isolated in a special class called Extensions. + * If you wish to build a version that is completely API + * compatible. Replace Extensions with ExtensionsDisabled in + * the static method calls at the end of this file. */ -public class DebugCLI implements Runnable, SourceLocator -{ - public static final String VERSION = "82"; //$NON-NLS-1$ - - public static final int CMD_UNKNOWN = 0; - public static final int CMD_QUIT = 1; - public static final int CMD_CONTINUE = 2; - public static final int CMD_STEP = 3; - public static final int CMD_NEXT = 4; - public static final int CMD_FINISH = 5; - public static final int CMD_BREAK = 6; - public static final int CMD_SET = 7; - public static final int CMD_LIST = 8; - public static final int CMD_PRINT = 9; - public static final int CMD_TUTORIAL = 10; - public static final int CMD_INFO = 11; - public static final int CMD_HOME = 12; - public static final int CMD_RUN = 13; - public static final int CMD_FILE = 14; - public static final int CMD_DELETE = 15; - public static final int CMD_SOURCE = 16; - public static final int CMD_COMMENT = 17; - public static final int CMD_CLEAR = 18; - public static final int CMD_HELP = 19; - public static final int CMD_SHOW = 20; - public static final int CMD_KILL = 21; - public static final int CMD_HANDLE = 22; - public static final int CMD_ENABLE = 23; - public static final int CMD_DISABLE = 24; - public static final int CMD_DISPLAY = 25; - public static final int CMD_UNDISPLAY = 26; - public static final int CMD_COMMANDS = 27; - public static final int CMD_PWD = 28; - public static final int CMD_CF = 29; - public static final int CMD_CONDITION = 30; - public static final int CMD_AWATCH = 31; - public static final int CMD_WATCH = 32; - public static final int CMD_RWATCH = 33; - public static final int CMD_WHAT = 34; - public static final int CMD_DISASSEMBLE = 35; - public static final int CMD_HALT = 36; - public static final int CMD_MCTREE = 37; - public static final int CMD_VIEW_SWF = 38; - public static final int CMD_DOWN = 39; - public static final int CMD_UP = 40; - public static final int CMD_FRAME = 41; - public static final int CMD_DIRECTORY = 42; - public static final int CMD_CATCH = 43; - public static final int CMD_CONNECT = 44; - public static final int CMD_WORKER = 45; +public class DebugCLI implements Runnable, SourceLocator { + public static final String VERSION = "82"; //$NON-NLS-1$ + + public static final int CMD_UNKNOWN = 0; + public static final int CMD_QUIT = 1; + public static final int CMD_CONTINUE = 2; + public static final int CMD_STEP = 3; + public static final int CMD_NEXT = 4; + public static final int CMD_FINISH = 5; + public static final int CMD_BREAK = 6; + public static final int CMD_SET = 7; + public static final int CMD_LIST = 8; + public static final int CMD_PRINT = 9; + public static final int CMD_TUTORIAL = 10; + public static final int CMD_INFO = 11; + public static final int CMD_HOME = 12; + public static final int CMD_RUN = 13; + public static final int CMD_FILE = 14; + public static final int CMD_DELETE = 15; + public static final int CMD_SOURCE = 16; + public static final int CMD_COMMENT = 17; + public static final int CMD_CLEAR = 18; + public static final int CMD_HELP = 19; + public static final int CMD_SHOW = 20; + public static final int CMD_KILL = 21; + public static final int CMD_HANDLE = 22; + public static final int CMD_ENABLE = 23; + public static final int CMD_DISABLE = 24; + public static final int CMD_DISPLAY = 25; + public static final int CMD_UNDISPLAY = 26; + public static final int CMD_COMMANDS = 27; + public static final int CMD_PWD = 28; + public static final int CMD_CF = 29; + public static final int CMD_CONDITION = 30; + public static final int CMD_AWATCH = 31; + public static final int CMD_WATCH = 32; + public static final int CMD_RWATCH = 33; + public static final int CMD_WHAT = 34; + public static final int CMD_DISASSEMBLE = 35; + public static final int CMD_HALT = 36; + public static final int CMD_MCTREE = 37; + public static final int CMD_VIEW_SWF = 38; + public static final int CMD_DOWN = 39; + public static final int CMD_UP = 40; + public static final int CMD_FRAME = 41; + public static final int CMD_DIRECTORY = 42; + public static final int CMD_CATCH = 43; + public static final int CMD_CONNECT = 44; + public static final int CMD_WORKER = 45; /* info sub commands */ - public static final int INFO_UNKNOWN_CMD = 100; - public static final int INFO_ARGS_CMD = 101; - public static final int INFO_BREAK_CMD = 102; - public static final int INFO_FILES_CMD = 103; - public static final int INFO_HANDLE_CMD = 104; - public static final int INFO_FUNCTIONS_CMD = 105; - public static final int INFO_LOCALS_CMD = 106; - public static final int INFO_SCOPECHAIN_CMD = 107; - public static final int INFO_SOURCES_CMD = 108; - public static final int INFO_STACK_CMD = 109; - public static final int INFO_VARIABLES_CMD = 110; - public static final int INFO_DISPLAY_CMD = 111; - public static final int INFO_TARGETS_CMD = 112; - public static final int INFO_SWFS_CMD = 113; - public static final int INFO_WORKERS_CMD = 114; + public static final int INFO_UNKNOWN_CMD = 100; + public static final int INFO_ARGS_CMD = 101; + public static final int INFO_BREAK_CMD = 102; + public static final int INFO_FILES_CMD = 103; + public static final int INFO_HANDLE_CMD = 104; + public static final int INFO_FUNCTIONS_CMD = 105; + public static final int INFO_LOCALS_CMD = 106; + public static final int INFO_SCOPECHAIN_CMD = 107; + public static final int INFO_SOURCES_CMD = 108; + public static final int INFO_STACK_CMD = 109; + public static final int INFO_VARIABLES_CMD = 110; + public static final int INFO_DISPLAY_CMD = 111; + public static final int INFO_TARGETS_CMD = 112; + public static final int INFO_SWFS_CMD = 113; + public static final int INFO_WORKERS_CMD = 114; /* show subcommands */ - public static final int SHOW_UNKNOWN_CMD = 200; - public static final int SHOW_NET_CMD = 201; - public static final int SHOW_FUNC_CMD = 202; - public static final int SHOW_URI_CMD = 203; - public static final int SHOW_PROPERTIES_CMD = 204; - public static final int SHOW_FILES_CMD = 205; - public static final int SHOW_BREAK_CMD = 206; - public static final int SHOW_VAR_CMD = 207; - public static final int SHOW_MEM_CMD = 208; - public static final int SHOW_LOC_CMD = 209; - public static final int SHOW_DIRS_CMD = 210; + public static final int SHOW_UNKNOWN_CMD = 200; + public static final int SHOW_NET_CMD = 201; + public static final int SHOW_FUNC_CMD = 202; + public static final int SHOW_URI_CMD = 203; + public static final int SHOW_PROPERTIES_CMD = 204; + public static final int SHOW_FILES_CMD = 205; + public static final int SHOW_BREAK_CMD = 206; + public static final int SHOW_VAR_CMD = 207; + public static final int SHOW_MEM_CMD = 208; + public static final int SHOW_LOC_CMD = 209; + public static final int SHOW_DIRS_CMD = 210; /* misc subcommands */ - public static final int ENABLE_ONCE_CMD = 301; - - // default metadata retry count 8 attempts per waitForMetadata() call * 5 calls - public static final int METADATA_RETRIES = 8*5; - - /** - * Whether the break command will show it changed workers. - * true at the moment because the break function itself does not display in - * which worker the breakpoint has been set. - */ - public static final boolean WORKER_DISPLAY_INTERNAL_SWAP_INFO = true; + public static final int ENABLE_ONCE_CMD = 301; + + // default metadata retry count 8 attempts per waitForMetadata() call * 5 calls + public static final int METADATA_RETRIES = 8 * 5; + + /** + * Whether the break command will show it changed workers. + * true at the moment because the break function itself does not display in + * which worker the breakpoint has been set. + */ + public static final boolean WORKER_DISPLAY_INTERNAL_SWAP_INFO = true; - /* Enum for the state of the initial prompt shown when a swf is loaded */ - public static enum InitialPromptState { NEVER_SHOWN, SHOWN_ONCE, DONE } + /* Enum for the state of the initial prompt shown when a swf is loaded */ + public static enum InitialPromptState { + NEVER_SHOWN, SHOWN_ONCE, DONE + } Stack<LineNumberReader> m_readerStack = new Stack<LineNumberReader>(); public PrintStream m_err; public PrintStream m_out; - Session m_session; - String m_launchURI; - boolean m_fullnameOption; // emacs mode - String m_cdPath; - String m_mruURI; + Session m_session; + String m_launchURI; + boolean m_fullnameOption; // emacs mode + String m_cdPath; + String m_mruURI; String m_connectPort; - private boolean m_quietMode; // Don't dump out the state of the execution when WORKER_DISPLAY_INTERNAL_SWAP_INFO is set to false. - public final static String m_newline = System.getProperty("line.separator"); //$NON-NLS-1$ + private boolean m_quietMode; // Don't dump out the state of the execution when WORKER_DISPLAY_INTERNAL_SWAP_INFO is set to false. + public final static String m_newline = System.getProperty("line.separator"); //$NON-NLS-1$ private final static LocalizationManager m_localizationManager = new LocalizationManager(); private final static FaultActionsBuilder faultActionsBuilder = new FaultActionsBuilder(m_localizationManager); - - List<String> m_sourceDirectories; // List of String - int m_sourceDirectoriesChangeCount; - private File m_flexHomeDirectory; // <application.home>/frameworks/projects/*/src always goes in m_sourceDirectories - private boolean m_initializedFlexHomeDirectory; + + List<String> m_sourceDirectories; // List of String + int m_sourceDirectoriesChangeCount; + private File m_flexHomeDirectory; // <application.home>/frameworks/projects/*/src always goes in m_sourceDirectories + private boolean m_initializedFlexHomeDirectory; // context information for our current session - FileInfoCache m_fileInfo; - FaultActions m_faultTable; + FileInfoCache m_fileInfo; + FaultActions m_faultTable; Vector<Integer> m_breakIsolates; ExpressionCache m_exprCache; - Vector<BreakAction> m_breakpoints; - Vector<WatchAction> m_watchpoints; - Vector<CatchAction> m_catchpoints; - ArrayList<DisplayAction> m_displays; -// boolean m_requestResume; + Vector<BreakAction> m_breakpoints; + Vector<WatchAction> m_watchpoints; + Vector<CatchAction> m_catchpoints; + ArrayList<DisplayAction> m_displays; + // boolean m_requestResume; // boolean m_requestHalt; // boolean m_stepResume; int m_activeIsolate; DebugCLIIsolateState m_mainState; - - /* This indicates the isolate for which we have been showing prompts for setting - * breakpoints( so that we don't switch worker while the user is setting breakpoints) */ + + /* This indicates the isolate for which we have been showing prompts for setting + * breakpoints( so that we don't switch worker while the user is setting breakpoints) */ int m_lastPromptIsolate; - + private HashMap<Integer, DebugCLIIsolateState> m_isolateState; - - class DebugCLIIsolateState - { -// public FileInfoCache m_fileInfo; + + class DebugCLIIsolateState { + // public FileInfoCache m_fileInfo; // public ExpressionCache m_exprCache; - public boolean m_requestResume; - public boolean m_requestHalt; - public boolean m_stepResume; + public boolean m_requestResume; + public boolean m_requestHalt; + public boolean m_stepResume; /* Indicates whether the prompt for setting initial breakpoints has been displayed for this isolate */ - public InitialPromptState m_promptState; + public InitialPromptState m_promptState; // public Vector<BreakAction> m_breakpoints; // public Vector<WatchAction> m_watchpoints; // public Vector<CatchAction> m_catchpoints; // public ArrayList<DisplayAction> m_displays; - + public DebugCLIIsolateState(DebugCLI debugcli) { // m_exprCache = new ExpressionCache(debugcli); m_faultTable = faultActionsBuilder.build();//new FaultActions(); @@ -275,7 +218,7 @@ public class DebugCLI implements Runnable, SourceLocator // m_displays = new ArrayList<DisplayAction>(); } } - + private DebugCLIIsolateState getIsolateState(int isolateId) { if (isolateId == Isolate.DEFAULT_ID) return m_mainState; @@ -283,58 +226,57 @@ public class DebugCLI implements Runnable, SourceLocator if (!m_isolateState.containsKey(isolateId)) { isolateState = new DebugCLIIsolateState(this); m_isolateState.put(isolateId, isolateState); - } - else + } else isolateState = m_isolateState.get(isolateId); return isolateState; } - + public int getActiveIsolateId() { return m_activeIsolate; } - + private boolean getRequestResume(int isolateId) { return getIsolateState(isolateId).m_requestResume; } - + private void setRequestResume(boolean value, int isolateId) { getIsolateState(isolateId).m_requestResume = value; } - + private boolean getStepResume(int isolateId) { return getIsolateState(isolateId).m_stepResume; } - + private void setStepResume(boolean value, int isolateId) { getIsolateState(isolateId).m_stepResume = value; } - + private boolean getRequestHalt(int isolateId) { return getIsolateState(isolateId).m_requestHalt; } - + private void setRequestHalt(boolean value, int isolateId) { getIsolateState(isolateId).m_requestHalt = value; } - + private InitialPromptState getPromptState(int isolateId) { return getIsolateState(isolateId).m_promptState; } - + private void setPromptState(InitialPromptState value, int isolateId) { getIsolateState(isolateId).m_promptState = value; } /* our current input processing context */ - LineNumberReader m_in; - public LineNumberReader m_keyboardStream; - Vector<String> m_keyboardInput; - boolean m_keyboardReadRequest; - StringTokenizer m_currentTokenizer; - String m_currentToken; - String m_currentLine; - public String m_repeatLine; - private boolean m_isIde; + LineNumberReader m_in; + public LineNumberReader m_keyboardStream; + Vector<String> m_keyboardInput; + boolean m_keyboardReadRequest; + StringTokenizer m_currentTokenizer; + String m_currentToken; + String m_currentLine; + public String m_repeatLine; + private boolean m_isIde; /** * The module that the next "list" command should display if no @@ -347,7 +289,7 @@ public class DebugCLI implements Runnable, SourceLocator * line number is explicitly specified. */ public static final String LIST_LINE = "$listline"; //$NON-NLS-1$ - + public static final String LIST_WORKER = "$listworker"; //$NON-NLS-1$ /** @@ -396,16 +338,14 @@ public class DebugCLI implements Runnable, SourceLocator * Whether the "print" command will display attributes of members. */ public static final String DISPLAY_ATTRIBUTES = "$displayattributes"; //$NON-NLS-1$ - + /* class's static init */ - static - { - // set up for localizing messages - m_localizationManager.addLocalizer( new DebuggerLocalizer("flex.tools.debugger.cli.fdb.") ); //$NON-NLS-1$ + static { + // set up for localizing messages + m_localizationManager.addLocalizer(new DebuggerLocalizer("flex.tools.debugger.cli.fdb.")); //$NON-NLS-1$ } - public static void main(String[] args) - { + public static void main(String[] args) { DebugCLI cli = new DebugCLI(); /* attach our 'main' input method and out/err*/ @@ -429,17 +369,15 @@ public class DebugCLI implements Runnable, SourceLocator /* * If the current directory is not $HOME, and a .fdbinit file exists in the current directory, * then push it onto the stack of files to read. - * + * * Note, we want ./.fdbinit to be read AFTER $HOME/.fdbinit, but we push them in reverse * order, because they're going onto a stack. If we push them in reverse order, then they * will be read in the correct order (last one pushed is the first one read). */ - if (userDir != null && !userDir.equals(userHome)) - { - try - { + if (userDir != null && !userDir.equals(userHome)) { + try { FileReader sr = new FileReader(new File(userDir, ".fdbinit")); //$NON-NLS-1$ - cli.pushStream( new LineNumberReader(sr) ); + cli.pushStream(new LineNumberReader(sr)); } catch(FileNotFoundException fnf) {} } @@ -447,17 +385,15 @@ public class DebugCLI implements Runnable, SourceLocator /* * If a .fdbinit file exists in the $HOME directory, then push it onto the stack of files * to read. - * + * * Note, we want ./.fdbinit to be read AFTER $HOME/.fdbinit, but we push them in reverse * order, because they're going onto a stack. If we push them in reverse order, then they * will be read in the correct order (last one pushed is the first one read). */ - if (userHome != null) - { - try - { + if (userHome != null) { + try { FileReader sr = new FileReader(new File(userHome, ".fdbinit")); //$NON-NLS-1$ - cli.pushStream( new LineNumberReader(sr) ); + cli.pushStream(new LineNumberReader(sr)); } catch(FileNotFoundException fnf) {} } @@ -465,8 +401,7 @@ public class DebugCLI implements Runnable, SourceLocator cli.execute(); } - public DebugCLI() - { + public DebugCLI() { m_fullnameOption = false; m_faultTable = faultActionsBuilder.build(); m_exprCache = new ExpressionCache(this); @@ -477,38 +412,41 @@ public class DebugCLI implements Runnable, SourceLocator m_keyboardInput = new Vector<String>(); m_mruURI = null; m_sourceDirectories = new LinkedList<String>(); - + initProperties(); m_mainState = new DebugCLIIsolateState(this); m_lastPromptIsolate = -1; initIsolateState(); } - public static LocalizationManager getLocalizationManager() { return m_localizationManager; } - public Session getSession() { return m_session; } - - public FileInfoCache getFileCache() { - return m_fileInfo; + public static LocalizationManager getLocalizationManager() { + return m_localizationManager; + } + + public Session getSession() { + return m_session; } - - public boolean isIde() { return m_isIde; } - + + public FileInfoCache getFileCache() { + return m_fileInfo; + } + + public boolean isIde() { + return m_isIde; + } + /** * Convert a module to class name. This is used * by the ExpressionCache to find variables * that live at royale package scope. That * is variables such as mx.core.Component. */ - public String module2ClassName(int moduleId) - { + public String module2ClassName(int moduleId) { String pkg = null; - try - { + try { SourceFile file = m_fileInfo.getFile(moduleId); pkg = file.getPackageName(); - } - catch(Exception npe) - { + } catch (Exception npe) { // didn't work ignore it. } return pkg; @@ -518,49 +456,43 @@ public class DebugCLI implements Runnable, SourceLocator public void pushStream(LineNumberReader r) { m_readerStack.push(r); } boolean haveStreams() { return !m_readerStack.empty(); } - public void processArgs(String[] args) - { - for(int i=0; i<args.length; i++) - { + public void processArgs(String[] args) { + for (int i = 0; i < args.length; i++) { String arg = args[i]; // System.out.println("arg["+i+"]= '"+arg+"'"); - if (arg.charAt(0) == '-') - { + if (arg.charAt(0) == '-') { // its an option if (arg.equals("-unit")) // unit-testing mode //$NON-NLS-1$ { System.setProperty("fdbunit", ""); //$NON-NLS-1$ //$NON-NLS-2$ - } - else if (arg.equals("-fullname") || arg.equals("-f")) //$NON-NLS-1$ //$NON-NLS-2$ + } else if (arg.equals("-fullname") || arg.equals("-f")) //$NON-NLS-1$ //$NON-NLS-2$ { m_fullnameOption = true; // emacs mode - } - else if (arg.equals("-cd")) //$NON-NLS-1$ + } else if (arg.equals("-cd")) //$NON-NLS-1$ { // consume the path - if (i+1 < args.length) + if (i + 1 < args.length) m_cdPath = args[i++]; - } - else if (arg.equals("-p")) //$NON-NLS-1$ + } else if (arg.equals("-p")) //$NON-NLS-1$ { // consume the port - if (i+1 < args.length) + if (i + 1 < args.length) m_connectPort = args[++i]; - } - else if (arg.equals("-ide")) //$NON-NLS-1$ - { - m_isIde = true; - } - else + } else if (arg.equals("-ide")) //$NON-NLS-1$ { + m_isIde = true; + } else if (arg.equals("-lang")) //$NON-NLS-1$ + { + if (i + 1 < args.length) + getLocalizationManager().setLocale(LocaleUtility.langToLocale(args[++i])); + + } else { err("Unknown command-line argument: " + arg); //$NON-NLS-1$ } - } - else - { + } else { // its a URI to run - StringReader sr = new StringReader("run "+arg+m_newline); //$NON-NLS-1$ - pushStream( new LineNumberReader(sr) ); + StringReader sr = new StringReader("run " + arg + m_newline); //$NON-NLS-1$ + pushStream(new LineNumberReader(sr)); } } } @@ -569,8 +501,7 @@ public class DebugCLI implements Runnable, SourceLocator * Dispose of the current line and read the next from the current stream, if its an empty * line and we are console then repeat last line. */ - protected String readLine() throws IOException - { + protected String readLine() throws IOException { String line = null; if (haveStreams()) line = m_in.readLine(); @@ -585,11 +516,13 @@ public class DebugCLI implements Runnable, SourceLocator * The reader portion of our keyboard input routine * Block until input arrives. */ - synchronized String keyboardReadLine() - { + synchronized String keyboardReadLine() { // enable a request then block on the queue m_keyboardReadRequest = true; - try { wait(); } catch(InterruptedException ie) {} + try { + wait(); + } catch (InterruptedException ie) { + } // pull from the front of the queue return m_keyboardInput.remove(0); @@ -609,16 +542,12 @@ public class DebugCLI implements Runnable, SourceLocator * Thus we needed to take a request response approach * so that we only block when requested to do so. */ - public void run() - { + public void run() { // while we have this stream - while(m_keyboardStream != null) - { - try - { + while (m_keyboardStream != null) { + try { // only if someone is requesting us to read do we do so... - if (m_keyboardReadRequest) - { + if (m_keyboardReadRequest) { // block on keyboard input and put it onto the end of the queue String s = m_keyboardStream.readLine(); m_keyboardInput.add(s); @@ -626,10 +555,10 @@ public class DebugCLI implements Runnable, SourceLocator // fullfilled request, now notify blocking thread. m_keyboardReadRequest = false; synchronized(this) { notifyAll(); } - } + } else try { Thread.sleep(50); } catch(InterruptedException ie) {} - } + } catch(IOException io) { // io.printStackTrace(); @@ -637,13 +566,11 @@ public class DebugCLI implements Runnable, SourceLocator } } - public void setCurrentLine(String s) - { + public void setCurrentLine(String s) { m_currentLine = s; if (m_currentLine == null) m_currentTokenizer = null; /* eof */ - else - { + else { m_currentLine = m_currentLine.trim(); /* if nothing provided on this command then pull our 'repeat' command */ @@ -661,29 +588,22 @@ public class DebugCLI implements Runnable, SourceLocator public long nextLongToken() throws NumberFormatException { nextToken(); return Long.parseLong(m_currentToken); } public String restOfLine() { return m_currentTokenizer.nextToken("").trim(); } //$NON-NLS-1$ - public void execute() - { + public void execute() { /* dump console message */ displayStartMessage(); - + /* now fire our keyboard input thread */ Thread t = new Thread(this, "Keyboard input"); //$NON-NLS-1$ t.start(); /* keep processing streams until we have no more to do */ - while(haveStreams()) - { - try - { + while (haveStreams()) { + try { m_in = popStream(); process(); - } - catch(EOFException eof) - { + } catch (EOFException eof) { ; /* quite allright */ - } - catch(IOException io) - { + } catch (IOException io) { Map<String, Object> args = new HashMap<String, Object>(); args.put("exceptionMessage", io); //$NON-NLS-1$ err(getLocalizationManager().getLocalizedTextString("errorWhileProcessingFile", args)); //$NON-NLS-1$ @@ -697,52 +617,47 @@ public class DebugCLI implements Runnable, SourceLocator m_keyboardStream = null; } - public PrintStream getOut() { return m_out; } - - private void displayStartMessage() - { - String build = getLocalizationManager().getLocalizedTextString("defaultBuildName"); //$NON-NLS-1$ - - try - { - Properties p = new Properties(); - p.load(this.getClass().getResourceAsStream("version.properties")); //$NON-NLS-1$ - String buildString = p.getProperty("build"); //$NON-NLS-1$ - if ((buildString != null) && (! buildString.equals(""))) //$NON-NLS-1$ - { - build = buildString; - } - } - catch (Throwable t) - { - // ignore - } - - Map<String, Object> aboutMap = new HashMap<String, Object>(); aboutMap.put("build", build); //$NON-NLS-1$ - out(getLocalizationManager().getLocalizedTextString("about", aboutMap)); //$NON-NLS-1$ + public PrintStream getOut() { + return m_out; + } + + private void displayStartMessage() { + String build = getLocalizationManager().getLocalizedTextString("defaultBuildName"); //$NON-NLS-1$ + + try { + Properties p = new Properties(); + p.load(this.getClass().getResourceAsStream("version.properties")); //$NON-NLS-1$ + String buildString = p.getProperty("build"); //$NON-NLS-1$ + if ((buildString != null) && (!buildString.equals(""))) //$NON-NLS-1$ + { + build = buildString; + } + } catch (Throwable t) { + // ignore + } + + Map<String, Object> aboutMap = new HashMap<String, Object>(); + aboutMap.put("build", build); //$NON-NLS-1$ + out(getLocalizationManager().getLocalizedTextString("about", aboutMap)); //$NON-NLS-1$ out(getLocalizationManager().getLocalizedTextString("copyright")); //$NON-NLS-1$ } - void displayPrompt() - { + void displayPrompt() { m_out.print("(fdb) "); //$NON-NLS-1$ } - void displayCommandPrompt() - { + void displayCommandPrompt() { m_out.print(">"); //$NON-NLS-1$ } // add the given character n times to sb - void repeat(StringBuilder sb, char c, int n) - { - while(n-- > 0) + void repeat(StringBuilder sb, char c, int n) { + while (n-- > 0) sb.append(c); } // Prompt the user to respond to a yes or no type question - boolean yesNoQuery(String prompt) throws IOException - { + boolean yesNoQuery(String prompt) throws IOException { boolean result = false; m_out.print(prompt); m_out.print(getLocalizationManager().getLocalizedTextString("yesOrNoAppendedToAllQuestions")); //$NON-NLS-1$ @@ -757,8 +672,7 @@ public class DebugCLI implements Runnable, SourceLocator return result; } - public void err(String s) - { + public void err(String s) { // Doesn't make sense to send messages to stderr, because this is // an interactive application; and besides that, sending a combination // of interwoven but related messages to both stdout and stderr causes @@ -766,29 +680,26 @@ public class DebugCLI implements Runnable, SourceLocator out(s); } - public void out(String s) - { - if (s.length() > 0 && (s.charAt(s.length()-1) == '\n') ) + public void out(String s) { + if (s.length() > 0 && (s.charAt(s.length() - 1) == '\n')) m_out.print(s); else m_out.println(s); } - static String uft() - { + static String uft() { Runtime rt = Runtime.getRuntime(); - long free = rt.freeMemory(), total = rt.totalMemory(), used = total - free; + long free = rt.freeMemory(), total = rt.totalMemory(), used = total - free; // long max = rt.maxMemory(); - java.text.NumberFormat nf = java.text.NumberFormat.getInstance() ; + java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); // System.out.println("used: "+nf.format(used)+" free: "+nf.format(free)+" total: "+nf.format(total)+" max: "+nf.format(max)); - return "Used "+nf.format(used)+" - free "+nf.format(free)+" - total "+nf.format(total); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } + return "Used " + nf.format(used) + " - free " + nf.format(free) + " - total " + nf.format(total); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } /** * Add all properties that we know about */ - void initProperties() - { + void initProperties() { propertyPut(LIST_SIZE, 10); propertyPut(LIST_LINE, 1); propertyPut(LIST_MODULE, 1); // default to module #1 @@ -796,8 +707,8 @@ public class DebugCLI implements Runnable, SourceLocator propertyPut(COLUMN_WIDTH, 70); propertyPut(UPDATE_DELAY, 25); propertyPut(HALT_TIMEOUT, 7000); - propertyPut(BPNUM, 0); // set current breakpoint number as something bad - propertyPut(LAST_FRAME_DEPTH, 0); // used to determine how much context information should be displayed + propertyPut(BPNUM, 0); // set current breakpoint number as something bad + propertyPut(LAST_FRAME_DEPTH, 0); // used to determine how much context information should be displayed propertyPut(CURRENT_FRAME_DEPTH, 0); // used to determine how much context information should be displayed propertyPut(DISPLAY_FRAME_NUMBER, 0); // houses the current frame we are viewing propertyPut(FILE_LIST_WRAP, 999999); // default 1 file name per line @@ -806,20 +717,25 @@ public class DebugCLI implements Runnable, SourceLocator } // getter/setter for properties; in the expression cache, so that they can be used in expressions! - public void propertyPut(String k, int v) { m_exprCache.put(k,v); } - public int propertyGet(String k) { return ((Integer)m_exprCache.get(k)).intValue(); } - public Set<String> propertyKeys() { return m_exprCache.keySet(); } + public void propertyPut(String k, int v) { + m_exprCache.put(k, v); + } + + public int propertyGet(String k) { + return ((Integer) m_exprCache.get(k)).intValue(); + } + + public Set<String> propertyKeys() { + return m_exprCache.keySet(); + } /** * Process this reader until its done */ - void process() throws IOException - { + void process() throws IOException { boolean done = false; - while(!done) - { - try - { + while (!done) { + try { /** * Now if we are in a session and that session is suspended then we go * into a state where we wait for some user interaction to get us out @@ -836,65 +752,39 @@ public class DebugCLI implements Runnable, SourceLocator break; done = processLine(); - } - catch(NoResponseException nre) - { + } catch (NoResponseException nre) { err(getLocalizationManager().getLocalizedTextString("noResponseException")); //$NON-NLS-1$ - } - catch(NotSuspendedException nse) - { + } catch (NotSuspendedException nse) { err(getLocalizationManager().getLocalizedTextString("notSuspendedException")); //$NON-NLS-1$ - } - catch(AmbiguousException ae) - { + } catch (AmbiguousException ae) { // we already put up a warning for the user - } - catch(IllegalStateException ise) - { + } catch (IllegalStateException ise) { err(getLocalizationManager().getLocalizedTextString("illegalStateException")); //$NON-NLS-1$ - } - catch(IllegalMonitorStateException ime) - { + } catch (IllegalMonitorStateException ime) { err(getLocalizationManager().getLocalizedTextString("illegalMonitorStateException")); //$NON-NLS-1$ - } - catch(NoSuchElementException nse) - { + } catch (NoSuchElementException nse) { err(getLocalizationManager().getLocalizedTextString("noSuchElementException")); //$NON-NLS-1$ - } - catch(NumberFormatException nfe) - { + } catch (NumberFormatException nfe) { err(getLocalizationManager().getLocalizedTextString("numberFormatException")); //$NON-NLS-1$ - } - catch(SocketException se) - { + } catch (SocketException se) { Map<String, Object> socketArgs = new HashMap<String, Object>(); socketArgs.put("message", se.getMessage()); //$NON-NLS-1$ err(getLocalizationManager().getLocalizedTextString("socketException", socketArgs)); //$NON-NLS-1$ - } - catch(VersionException ve) - { + } catch (VersionException ve) { err(getLocalizationManager().getLocalizedTextString("versionException")); //$NON-NLS-1$ - } - catch(NotConnectedException nce) - { + } catch (NotConnectedException nce) { // handled by isConnectionLost() - } - catch(Exception e) - { + } catch (Exception e) { err(getLocalizationManager().getLocalizedTextString("unexpectedError")); //$NON-NLS-1$ err(getLocalizationManager().getLocalizedTextString("stackTraceFollows")); //$NON-NLS-1$ e.printStackTrace(); } // check for a lost connection and if it is clean-up! - if (isConnectionLost()) - { - try - { + if (isConnectionLost()) { + try { dumpHaltState(false); - } - catch(PlayerDebugException pde) - { + } catch (PlayerDebugException pde) { err(getLocalizationManager().getLocalizedTextString("sessionEndedAbruptly")); //$NON-NLS-1$ } } @@ -902,8 +792,7 @@ public class DebugCLI implements Runnable, SourceLocator } // check if we have lost the connect without our help... - boolean isConnectionLost() - { + boolean isConnectionLost() { boolean lost = false; if (m_session != null && !m_session.isConnected()) @@ -912,8 +801,7 @@ public class DebugCLI implements Runnable, SourceLocator return lost; } - boolean haveConnection() - { + boolean haveConnection() { boolean have = false; if (m_session != null && m_session.isConnected()) @@ -922,18 +810,15 @@ public class DebugCLI implements Runnable, SourceLocator return have; } - void doShow() throws AmbiguousException, PlayerDebugException - { + void doShow() throws AmbiguousException, PlayerDebugException { /* show without any args brings up help */ if (!hasMoreTokens()) - out( getHelpTopic("show") ); //$NON-NLS-1$ - else - { + out(getHelpTopic("show")); //$NON-NLS-1$ + else { /* otherwise we have a boatload of options */ String subCmdString = nextToken(); int subCmd = showCommandFor(subCmdString); - switch(subCmd) - { + switch (subCmd) { case SHOW_NET_CMD: doShowStats(); break; @@ -981,18 +866,14 @@ public class DebugCLI implements Runnable, SourceLocator } } - void doShowUri() - { + void doShowUri() { // dump the URI that the player has sent us - try - { + try { StringBuilder sb = new StringBuilder(); sb.append("URI = "); //$NON-NLS-1$ - sb.append( m_session.getURI() ); - out( sb.toString() ); - } - catch(Exception e) - { + sb.append(m_session.getURI()); + out(sb.toString()); + } catch (Exception e) { err(getLocalizationManager().getLocalizedTextString("noUriReceived")); //$NON-NLS-1$ } } @@ -1000,18 +881,15 @@ public class DebugCLI implements Runnable, SourceLocator /** * Dump the content of files in a raw format */ - void doShowFiles() - { - try - { + void doShowFiles() { + try { StringBuilder sb = new StringBuilder(); for (Isolate isolate : m_session.getWorkers()) { - + Iterator itr = m_fileInfo.getAllFiles(isolate.getId()); - while(itr.hasNext()) - { - SourceFile m = (SourceFile) ((Map.Entry)itr.next()).getValue(); + while (itr.hasNext()) { + SourceFile m = (SourceFile) ((Map.Entry) itr.next()).getValue(); String name = m.getName(); int id = m.getId(); @@ -1025,8 +903,7 @@ public class DebugCLI implements Runnable, SourceLocator sb.append(" ("); //$NON-NLS-1$ if (isolate.getId() == Isolate.DEFAULT_ID) { sb.append(getLocalizationManager().getLocalizedTextString("mainThread")); //$NON-NLS-1$ - } - else { + } else { HashMap<String, Object> wArgs = new HashMap<String, Object>(); wArgs.put("worker", isolate.getId() - 1); //$NON-NLS-1$ sb.append(getLocalizationManager().getLocalizedTextString("inWorker", wArgs)); //$NON-NLS-1$ @@ -1035,28 +912,23 @@ public class DebugCLI implements Runnable, SourceLocator sb.append(m_newline); } } - out( sb.toString() ); - } - catch(NullPointerException npe) - { + out(sb.toString()); + } catch (NullPointerException npe) { err(getLocalizationManager().getLocalizedTextString("noSourceFilesFound")); //$NON-NLS-1$ } } - void doShowMemory() - { + void doShowMemory() { out(uft()); } - void doShowLocations() - { + void doShowLocations() { StringBuilder sb = new StringBuilder(); - sb.append("Num Type Disp Enb Address What"+m_newline); //$NON-NLS-1$ + sb.append("Num Type Disp Enb Address What" + m_newline); //$NON-NLS-1$ // our list of breakpoints int count = breakpointCount(); - for(int i=0; i<count; i++) - { + for (int i = 0; i < count; i++) { BreakAction b = breakpointAt(i); int num = b.getId(); @@ -1076,62 +948,55 @@ public class DebugCLI implements Runnable, SourceLocator sb.append("n "); //$NON-NLS-1$ Iterator<Location> itr = b.getLocations().iterator(); - while(itr.hasNext()) - { + while (itr.hasNext()) { Location l = itr.next(); SourceFile file = l.getFile(); String funcName = (file == null) ? getLocalizationManager().getLocalizedTextString("unknownBreakpointLocation") //$NON-NLS-1$ - : file.getFunctionNameForLine(m_session, l.getLine()) ; - int offset = adjustOffsetForUnitTests((file == null) ? 0 : file.getOffsetForLine(l.getLine())); + : file.getFunctionNameForLine(m_session, l.getLine()); + int offset = adjustOffsetForUnitTests((file == null) ? 0 : file.getOffsetForLine(l.getLine())); - sb.append("0x"); //$NON-NLS-1$ - FieldFormat.formatLongToHex(sb, offset, 8); - sb.append(' '); + sb.append("0x"); //$NON-NLS-1$ + FieldFormat.formatLongToHex(sb, offset, 8); + sb.append(' '); - if (funcName != null) - { - Map<String, Object> funcArgs = new HashMap<String, Object>(); - funcArgs.put("functionName", funcName); //$NON-NLS-1$ - sb.append(getLocalizationManager().getLocalizedTextString("inFunctionAt", funcArgs)); //$NON-NLS-1$ - } + if (funcName != null) { + Map<String, Object> funcArgs = new HashMap<String, Object>(); + funcArgs.put("functionName", funcName); //$NON-NLS-1$ + sb.append(getLocalizationManager().getLocalizedTextString("inFunctionAt", funcArgs)); //$NON-NLS-1$ + } - sb.append(file.getName()); - if (file != null) - { - sb.append("#"); //$NON-NLS-1$ - sb.append(file.getId()); - } - sb.append(':'); - sb.append(l.getLine()); + sb.append(file.getName()); + if (file != null) { + sb.append("#"); //$NON-NLS-1$ + sb.append(file.getId()); + } + sb.append(':'); + sb.append(l.getLine()); - try - { - SwfInfo info = m_fileInfo.swfForFile(file, l.getIsolateId()); - Map<String, Object> swfArgs = new HashMap<String, Object>(); - swfArgs.put("swf", FileInfoCache.shortNameOfSwf(info)); //$NON-NLS-1$ - sb.append(getLocalizationManager().getLocalizedTextString("inSwf", swfArgs)); //$NON-NLS-1$ - if (l.getIsolateId() == Isolate.DEFAULT_ID) { - sb.append(" ("); //$NON-NLS-1$ - sb.append(getLocalizationManager().getLocalizedTextString("mainThread")); //$NON-NLS-1$ - sb.append(")"); //$NON-NLS-1$ - } - else { - swfArgs = new HashMap<String, Object>(); - swfArgs.put("worker", l.getIsolateId() - 1); //$NON-NLS-1$ - sb.append(" ("); //$NON-NLS-1$ - sb.append(getLocalizationManager().getLocalizedTextString("inWorker", swfArgs)); //$NON-NLS-1$ - sb.append(")"); //$NON-NLS-1$ - } - } - catch(NullPointerException npe) - { - // can't find the swf - sb.append(getLocalizationManager().getLocalizedTextString("nonRestorable")); //$NON-NLS-1$ - } - sb.append(m_newline); - if (itr.hasNext()) - sb.append(" "); //$NON-NLS-1$ + try { + SwfInfo info = m_fileInfo.swfForFile(file, l.getIsolateId()); + Map<String, Object> swfArgs = new HashMap<String, Object>(); + swfArgs.put("swf", FileInfoCache.shortNameOfSwf(info)); //$NON-NLS-1$ + sb.append(getLocalizationManager().getLocalizedTextString("inSwf", swfArgs)); //$NON-NLS-1$ + if (l.getIsolateId() == Isolate.DEFAULT_ID) { + sb.append(" ("); //$NON-NLS-1$ + sb.append(getLocalizationManager().getLocalizedTextString("mainThread")); //$NON-NLS-1$ + sb.append(")"); //$NON-NLS-1$ + } else { + swfArgs = new HashMap<String, Object>(); + swfArgs.put("worker", l.getIsolateId() - 1); //$NON-NLS-1$ + sb.append(" ("); //$NON-NLS-1$ + sb.append(getLocalizationManager().getLocalizedTextString("inWorker", swfArgs)); //$NON-NLS-1$ + sb.append(")"); //$NON-NLS-1$ + } + } catch (NullPointerException npe) { + // can't find the swf + sb.append(getLocalizationManager().getLocalizedTextString("nonRestorable")); //$NON-NLS-1$ + } + sb.append(m_newline); + if (itr.hasNext()) + sb.append(" "); //$NON-NLS-1$ } } out(sb.toString()); @@ -1143,27 +1008,23 @@ public class DebugCLI implements Runnable, SourceLocator * results will match up with the actual results. This is just a * simple helper function that deals with that. */ - private int adjustOffsetForUnitTests(int offset) - { - if (System.getProperty("fdbunit")==null) //$NON-NLS-1$ + private int adjustOffsetForUnitTests(int offset) { + if (System.getProperty("fdbunit") == null) //$NON-NLS-1$ return offset; else return 0; } - void doShowDirectories() - { + void doShowDirectories() { out(getLocalizationManager().getLocalizedTextString("sourceDirectoriesSearched")); //$NON-NLS-1$ Iterator<String> iter = m_sourceDirectories.iterator(); - while (iter.hasNext()) - { + while (iter.hasNext()) { String dir = iter.next(); out(" " + dir); //$NON-NLS-1$ } } - void doHalt() throws SuspendedException, NotConnectedException, NoResponseException - { + void doHalt() throws SuspendedException, NotConnectedException, NoResponseException { out(getLocalizationManager().getLocalizedTextString("attemptingToSuspend")); //$NON-NLS-1$ IsolateSession session = m_session.getWorkerSession(getActiveIsolateId()); if (!session.isSuspended()) @@ -1174,10 +1035,8 @@ public class DebugCLI implements Runnable, SourceLocator out(getLocalizationManager().getLocalizedTextString("playerRunning")); //$NON-NLS-1$ } - public void appendReason(StringBuilder sb, int reason) - { - switch(reason) - { + public void appendReason(StringBuilder sb, int reason) { + switch (reason) { case SuspendReason.Unknown: sb.append(getLocalizationManager().getLocalizedTextString("suspendReason_Unknown")); //$NON-NLS-1$ break; @@ -1216,18 +1075,15 @@ public class DebugCLI implements Runnable, SourceLocator * The big ticket item, where all your questions are answered. * */ - void doInfo() throws AmbiguousException, PlayerDebugException - { + void doInfo() throws AmbiguousException, PlayerDebugException { /* info without any args brings up help */ if (!hasMoreTokens()) - out( getHelpTopic("info") ); //$NON-NLS-1$ - else - { + out(getHelpTopic("info")); //$NON-NLS-1$ + else { /* otherwise we have a boatload of options */ String subCmdString = nextToken(); int subCmd = infoCommandFor(subCmdString); - switch(subCmd) - { + switch (subCmd) { case INFO_ARGS_CMD: doInfoArgs(); break; @@ -1255,7 +1111,7 @@ public class DebugCLI implements Runnable, SourceLocator case INFO_SCOPECHAIN_CMD: doInfoScopeChain(); break; - + case INFO_SOURCES_CMD: doInfoSources(); break; @@ -1272,17 +1128,17 @@ public class DebugCLI implements Runnable, SourceLocator doInfoDisplay(); break; - case INFO_TARGETS_CMD: - doInfoTargets(); - break; + case INFO_TARGETS_CMD: + doInfoTargets(); + break; + + case INFO_SWFS_CMD: + doInfoSwfs(); + break; - case INFO_SWFS_CMD: - doInfoSwfs(); - break; - - case INFO_WORKERS_CMD: - doInfoWorkers(); - break; + case INFO_WORKERS_CMD: + doInfoWorkers(); + break; default: doUnknown("info", subCmdString); //$NON-NLS-1$ @@ -1290,9 +1146,8 @@ public class DebugCLI implements Runnable, SourceLocator } } } - - void doInfoWorkers() throws NotConnectedException, NotSupportedException, NotSuspendedException, NoResponseException - { + + void doInfoWorkers() throws NotConnectedException, NotSupportedException, NotSuspendedException, NoResponseException { // waitTilHalted(); Isolate[] isolates = m_session.getWorkers(); if (isolates == null || isolates.length == 0) { @@ -1312,8 +1167,7 @@ public class DebugCLI implements Runnable, SourceLocator sb.append(getLocalizationManager().getLocalizedTextString("mainThread")); //$NON-NLS-1$ sb.append(" "); //$NON-NLS-1$ sb.append(Isolate.DEFAULT_ID - 1); - } - else { + } else { HashMap<String, Object> workArgs = new HashMap<String, Object>(); workArgs.put("worker", (t.getId() - 1)); //$NON-NLS-1$ sb.append(getLocalizationManager().getLocalizedTextString("inWorker", workArgs)); //$NON-NLS-1$ @@ -1324,37 +1178,33 @@ public class DebugCLI implements Runnable, SourceLocator } - void doInfoStack() throws PlayerDebugException - { + void doInfoStack() throws PlayerDebugException { waitTilHalted(m_activeIsolate); StringBuilder sb = new StringBuilder(); Frame[] stack = m_session.getWorkerSession(m_activeIsolate).getFrames(); if (stack == null || stack.length == 0) sb.append(getLocalizationManager().getLocalizedTextString("noStackAvailable")); //$NON-NLS-1$ - else - { + else { boolean showThis = propertyGet(INFO_STACK_SHOW_THIS) == 1; - for(int i=0; i<stack.length; i++) - { + for (int i = 0; i < stack.length; i++) { // keep spitting out frames until we can't Frame frame = stack[i]; boolean valid = appendFrameInfo(sb, frame, i, showThis, true); sb.append(m_newline); - if (!valid) - break; + if (!valid) + break; } } /* dump it out */ out(sb.toString()); } - + /** - * Spit out frame information for a given frame number + * Spit out frame information for a given frame number */ - boolean appendFrameInfo(StringBuilder sb, Frame ctx, int frameNumber, boolean showThis, boolean showFileId) throws PlayerDebugException - { + boolean appendFrameInfo(StringBuilder sb, Frame ctx, int frameNumber, boolean showThis, boolean showFileId) throws PlayerDebugException { boolean validFrame = true; // some formatting properties @@ -1368,12 +1218,9 @@ public class DebugCLI implements Runnable, SourceLocator String func = extractFunctionName(sig); // file == null or line < 0 appears to be a terminator for stack info - if (file == null && line < 0) - { - validFrame = false; - } - else - { + if (file == null && line < 0) { + validFrame = false; + } else { Variable[] var = ctx.getArguments(m_session); Variable dis = ctx.getThis(m_session); boolean displayArgs = (func != null) || (var != null); @@ -1382,8 +1229,7 @@ public class DebugCLI implements Runnable, SourceLocator FieldFormat.formatLong(sb, i, 3); sb.append(' '); - if (showThis && dis != null) - { + if (showThis && dis != null) { m_exprCache.appendVariable(sb, dis, ctx.getIsolateId()); sb.append("."); //$NON-NLS-1$ } @@ -1391,16 +1237,14 @@ public class DebugCLI implements Runnable, SourceLocator if (func != null) sb.append(func); - if (displayArgs) - { + if (displayArgs) { sb.append('('); - for (int j=0; j<var.length; j++) - { + for (int j = 0; j < var.length; j++) { Variable v = var[j]; sb.append(v.getName()); sb.append('='); m_exprCache.appendVariableValue(sb, v.getValue(), ctx.getIsolateId()); - if ((j+1)<var.length) + if ((j + 1) < var.length) sb.append(", "); //$NON-NLS-1$ } sb.append(")"); //$NON-NLS-1$ @@ -1410,74 +1254,64 @@ public class DebugCLI implements Runnable, SourceLocator sb.append(name); // if this file is currently being filtered put the source file id after it - if (file != null && (showFileId || !m_fileInfo.inFileList(file))) - { + if (file != null && (showFileId || !m_fileInfo.inFileList(file))) { sb.append('#'); - sb.append( file.getId() ); + sb.append(file.getId()); } sb.append(':'); sb.append(line); } - return validFrame; + return validFrame; } /** extract the function name from a signature */ - public static String extractFunctionName(String sig) - { - // strip everything after the leading ( + public static String extractFunctionName(String sig) { + // strip everything after the leading ( int at = sig.indexOf('('); if (at > -1) sig = sig.substring(0, at); // trim the leading [object_name::] since it doesn't seem to add much if (sig != null && (at = sig.indexOf("::")) > -1) //$NON-NLS-1$ - sig = sig.substring(at+2); + sig = sig.substring(at + 2); return sig; } - void doInfoVariables() throws PlayerDebugException - { + void doInfoVariables() throws PlayerDebugException { waitTilHalted(m_activeIsolate); // dump a set of locals StringBuilder sb = new StringBuilder(); // use our expression cache formatting routine - try - { + try { Variable[] vars = m_session.getWorkerSession(m_activeIsolate).getVariableList(); - for(int i=0; i<vars.length; i++) - { + for (int i = 0; i < vars.length; i++) { Variable v = vars[i]; // all non-local and non-arg variables - if ( !v.isAttributeSet(VariableAttribute.IS_LOCAL) && - !v.isAttributeSet(VariableAttribute.IS_ARGUMENT) ) - { + if (!v.isAttributeSet(VariableAttribute.IS_LOCAL) && + !v.isAttributeSet(VariableAttribute.IS_ARGUMENT)) { m_exprCache.appendVariable(sb, vars[i], m_activeIsolate); sb.append(m_newline); } } - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { sb.append(getLocalizationManager().getLocalizedTextString("noVariables")); //$NON-NLS-1$ } out(sb.toString()); } - void doInfoDisplay() - { + void doInfoDisplay() { StringBuilder sb = new StringBuilder(); - sb.append("Num Enb Expression"+m_newline); //$NON-NLS-1$ + sb.append("Num Enb Expression" + m_newline); //$NON-NLS-1$ // our list of displays int count = displayCount(); - for(int i=0; i<count; i++) - { + for (int i = 0; i < count; i++) { DisplayAction b = displayAt(i); int num = b.getId(); String exp = b.getContent(); @@ -1497,145 +1331,115 @@ public class DebugCLI implements Runnable, SourceLocator out(sb.toString()); } - void doInfoArgs() throws PlayerDebugException - { + void doInfoArgs() throws PlayerDebugException { waitTilHalted(m_activeIsolate); // dump a set of locals StringBuilder sb = new StringBuilder(); // use our expression cache formatting routine - try - { + try { int num = propertyGet(DISPLAY_FRAME_NUMBER); Frame[] frames = m_session.getWorkerSession(m_activeIsolate).getFrames(); Variable[] vars = frames[num].getArguments(m_session); - for(int i=0; i<vars.length; i++) - { + for (int i = 0; i < vars.length; i++) { m_exprCache.appendVariable(sb, vars[i], m_activeIsolate); sb.append(m_newline); } - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { sb.append(getLocalizationManager().getLocalizedTextString("noArguments")); //$NON-NLS-1$ + } catch (ArrayIndexOutOfBoundsException aix) { + sb.append(getLocalizationManager().getLocalizedTextString("notInValidFrame")); //$NON-NLS-1$ } - catch(ArrayIndexOutOfBoundsException aix) - { - sb.append(getLocalizationManager().getLocalizedTextString("notInValidFrame")); //$NON-NLS-1$ - } out(sb.toString()); } - void doInfoLocals() throws PlayerDebugException - { + void doInfoLocals() throws PlayerDebugException { waitTilHalted(m_activeIsolate); // dump a set of locals StringBuilder sb = new StringBuilder(); // use our expression cache formatting routine - try - { + try { // get the variables from the requested frame int num = propertyGet(DISPLAY_FRAME_NUMBER); Frame[] ar = m_session.getWorkerSession(m_activeIsolate).getFrames(); Frame ctx = ar[num]; Variable[] vars = ctx.getLocals(m_session); - for(int i=0; i<vars.length; i++) - { + for (int i = 0; i < vars.length; i++) { Variable v = vars[i]; // see if variable is local - if ( v.isAttributeSet(VariableAttribute.IS_LOCAL) ) - { + if (v.isAttributeSet(VariableAttribute.IS_LOCAL)) { m_exprCache.appendVariable(sb, v, m_activeIsolate); sb.append(m_newline); } } - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { sb.append(getLocalizationManager().getLocalizedTextString("noLocals")); //$NON-NLS-1$ + } catch (ArrayIndexOutOfBoundsException aix) { + sb.append(getLocalizationManager().getLocalizedTextString("notInValidFrame")); //$NON-NLS-1$ } - catch(ArrayIndexOutOfBoundsException aix) - { - sb.append(getLocalizationManager().getLocalizedTextString("notInValidFrame")); //$NON-NLS-1$ - } out(sb.toString()); } - void doInfoScopeChain() throws PlayerDebugException - { + void doInfoScopeChain() throws PlayerDebugException { waitTilHalted(m_activeIsolate); // dump the scope chain StringBuilder sb = new StringBuilder(); // use our expression cache formatting routine - try - { + try { // get the scope chainfrom the requested frame int num = propertyGet(DISPLAY_FRAME_NUMBER); Frame[] ar = m_session.getWorkerSession(m_activeIsolate).getFrames(); Frame ctx = ar[num]; Variable[] scopes = ctx.getScopeChain(m_session); - for(int i=0; i<scopes.length; i++) - { + for (int i = 0; i < scopes.length; i++) { Variable scope = scopes[i]; m_exprCache.appendVariable(sb, scope, m_activeIsolate); sb.append(m_newline); } - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { sb.append(getLocalizationManager().getLocalizedTextString("noScopeChain")); //$NON-NLS-1$ + } catch (ArrayIndexOutOfBoundsException aix) { + sb.append(getLocalizationManager().getLocalizedTextString("notInValidFrame")); //$NON-NLS-1$ } - catch(ArrayIndexOutOfBoundsException aix) - { - sb.append(getLocalizationManager().getLocalizedTextString("notInValidFrame")); //$NON-NLS-1$ - } out(sb.toString()); } - - void doInfoTargets() - { - if (!haveConnection()) - { + + void doInfoTargets() { + if (!haveConnection()) { out(getLocalizationManager().getLocalizedTextString("noActiveSession")); //$NON-NLS-1$ - if (m_launchURI != null) - { + if (m_launchURI != null) { Map<String, Object> args = new HashMap<String, Object>(); args.put("uri", m_launchURI); //$NON-NLS-1$ out(getLocalizationManager().getLocalizedTextString("runWillLaunchUri", args)); //$NON-NLS-1$ } - } - else - { + } else { String uri = m_session.getURI(); if (uri == null || uri.length() < 1) err(getLocalizationManager().getLocalizedTextString("targetUnknown")); //$NON-NLS-1$ else out(uri); } - } + } /** * Dump some stats about our currently loaded swfs. */ - void doInfoSwfs() - { - try - { + void doInfoSwfs() { + try { StringBuilder sb = new StringBuilder(); SwfInfo[] swfs = m_fileInfo.getSwfs(m_activeIsolate); - for(int i=0; i<swfs.length; i++) - { + for (int i = 0; i < swfs.length; i++) { SwfInfo e = swfs[i]; if (e == null || e.isUnloaded()) continue; @@ -1644,8 +1448,7 @@ public class DebugCLI implements Runnable, SourceLocator args.put("swfName", FileInfoCache.nameOfSwf(e)); //$NON-NLS-1$ args.put("size", NumberFormat.getInstance().format(e.getSwfSize())); //$NON-NLS-1$ - try - { + try { int size = e.getSwdSize(m_session); // our swd is loaded so let's comb through our @@ -1653,8 +1456,7 @@ public class DebugCLI implements Runnable, SourceLocator SourceFile[] files = e.getSourceList(m_session); int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; - for(int j=0; j<files.length; j++) - { + for (int j = 0; j < files.length; j++) { SourceFile f = files[j]; int id = f.getId(); max = (id > max) ? id : max; @@ -1665,66 +1467,57 @@ public class DebugCLI implements Runnable, SourceLocator args.put("min", Integer.toString(min)); //$NON-NLS-1$ args.put("max", Integer.toString(max)); //$NON-NLS-1$ args.put("plus", (e.isProcessingComplete()) ? "+" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - args.put("moreInfo", (size==0) ? getLocalizationManager().getLocalizedTextString("remainingSourceBeingLoaded") : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - catch(InProgressException ipe) - { + args.put("moreInfo", (size == 0) ? getLocalizationManager().getLocalizedTextString("remainingSourceBeingLoaded") : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } catch (InProgressException ipe) { sb.append(getLocalizationManager().getLocalizedTextString("debugInfoBeingLoaded")); //$NON-NLS-1$ } args.put("url", e.getUrl()); //$NON-NLS-1$ sb.append(getLocalizationManager().getLocalizedTextString("swfInfo", args)); //$NON-NLS-1$ sb.append(m_newline); } - out( sb.toString() ); - } - catch(NullPointerException npe) - { + out(sb.toString()); + } catch (NullPointerException npe) { err(getLocalizationManager().getLocalizedTextString("noSWFs")); //$NON-NLS-1$ } - } + } - private static final int AUTHORED_FILE = 1; // a file that was created by the end user, e.g. MyApp.mxml - private static final int FRAMEWORK_FILE = 2; // a file from the Flex framework, e.g. mx.controls.Button.as, see FRAMEWORK_FILE_PACKAGES - private static final int SYNTHETIC_FILE = 3; // e.g. "<set up XML utilities.1>" - private static final int ACTIONS_FILE = 4; // e.g. "Actions for UIComponent: Frame 1 of Layer Name Layer 1" + private static final int AUTHORED_FILE = 1; // a file that was created by the end user, e.g. MyApp.mxml + private static final int FRAMEWORK_FILE = 2; // a file from the Flex framework, e.g. mx.controls.Button.as, see FRAMEWORK_FILE_PACKAGES + private static final int SYNTHETIC_FILE = 3; // e.g. "<set up XML utilities.1>" + private static final int ACTIONS_FILE = 4; // e.g. "Actions for UIComponent: Frame 1 of Layer Name Layer 1" - private static final String[] FRAMEWORK_FILE_PACKAGES // package prefixes that we consider FRAMEWORK_FILEs - = new String[] {"mx","flex","text"}; // 'text' is Vellum (temporary) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + private static final String[] FRAMEWORK_FILE_PACKAGES // package prefixes that we consider FRAMEWORK_FILEs + = new String[]{"mx", "flex", "text"}; // 'text' is Vellum (temporary) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ /** * Given a file, guesses what type it is -- e.g. a file created by the end user, * or a file from the Flex framework, etc. */ - private int getFileType(SourceFile sourceFile) - { + private int getFileType(SourceFile sourceFile) { String name = sourceFile.getName(); String pkg = sourceFile.getPackageName(); if (name.startsWith("<") && name.endsWith(">") || name.equals("GeneratedLocale")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return SYNTHETIC_FILE; - for (final String frameworkPkg : FRAMEWORK_FILE_PACKAGES ) - { - // look for packages starting with pkgName - if (pkg.startsWith(frameworkPkg + '\\') || - pkg.startsWith(frameworkPkg + '/') || - pkg.equals(frameworkPkg)) - { - return FRAMEWORK_FILE; - } - } - - if (name.startsWith("Actions for")) //$NON-NLS-1$ - return ACTIONS_FILE; - - return AUTHORED_FILE; -} + for (final String frameworkPkg : FRAMEWORK_FILE_PACKAGES) { + // look for packages starting with pkgName + if (pkg.startsWith(frameworkPkg + '\\') || + pkg.startsWith(frameworkPkg + '/') || + pkg.equals(frameworkPkg)) { + return FRAMEWORK_FILE; + } + } + + if (name.startsWith("Actions for")) //$NON-NLS-1$ + return ACTIONS_FILE; - void buildFileList(StringBuilder sb, boolean authoredFilesOnly) - { + return AUTHORED_FILE; + } + + void buildFileList(StringBuilder sb, boolean authoredFilesOnly) { SourceFile[] ar = m_fileInfo.getFileList(m_activeIsolate); - if (ar == null) - { + if (ar == null) { err(getLocalizationManager().getLocalizedTextString("noSourceFilesFound")); //$NON-NLS-1$ return; } @@ -1734,56 +1527,50 @@ public class DebugCLI implements Runnable, SourceLocator Vector<String> syntheticFiles = new Vector<String>(); Vector<String> actionsFiles = new Vector<String>(); - for (int i = 0; i < ar.length; i++) - { - SourceFile m = ar[i]; + for (int i = 0; i < ar.length; i++) { + SourceFile m = ar[i]; int fileType = getFileType(m); int id = m.getId(); // int fakeId = m_fileInfo.getFakeId(m); String entry = m.getName() + "#" + id; //$NON-NLS-1$ - switch (fileType) - { - case SYNTHETIC_FILE: - syntheticFiles.add(entry); - break; - case FRAMEWORK_FILE: - frameworkFiles.add(entry); - break; - case ACTIONS_FILE: - actionsFiles.add(entry); - break; - case AUTHORED_FILE: - authoredFiles.add(entry); - break; + switch (fileType) { + case SYNTHETIC_FILE: + syntheticFiles.add(entry); + break; + case FRAMEWORK_FILE: + frameworkFiles.add(entry); + break; + case ACTIONS_FILE: + actionsFiles.add(entry); + break; + case AUTHORED_FILE: + authoredFiles.add(entry); + break; } } int wrapAt = propertyGet(FILE_LIST_WRAP); - if (!authoredFilesOnly) - { - if (actionsFiles.size() > 0) - { - appendStrings(sb, actionsFiles, (actionsFiles.size() > wrapAt) ); + if (!authoredFilesOnly) { + if (actionsFiles.size() > 0) { + appendStrings(sb, actionsFiles, (actionsFiles.size() > wrapAt)); } - if (frameworkFiles.size() > 0) - { - sb.append("---"+m_newline); //$NON-NLS-1$ - appendStrings(sb, frameworkFiles, (frameworkFiles.size() > wrapAt) ); + if (frameworkFiles.size() > 0) { + sb.append("---" + m_newline); //$NON-NLS-1$ + appendStrings(sb, frameworkFiles, (frameworkFiles.size() > wrapAt)); } - if (syntheticFiles.size() > 0) - { - sb.append("---"+m_newline); //$NON-NLS-1$ - appendStrings(sb, syntheticFiles, (syntheticFiles.size() > wrapAt) ); + if (syntheticFiles.size() > 0) { + sb.append("---" + m_newline); //$NON-NLS-1$ + appendStrings(sb, syntheticFiles, (syntheticFiles.size() > wrapAt)); } - sb.append("---"+m_newline); //$NON-NLS-1$ + sb.append("---" + m_newline); //$NON-NLS-1$ } - appendStrings(sb, authoredFiles, (authoredFiles.size() > wrapAt) ); + appendStrings(sb, authoredFiles, (authoredFiles.size() > wrapAt)); } /** @@ -1791,30 +1578,24 @@ public class DebugCLI implements Runnable, SourceLocator * If flow is set then the strings are placed * on a single line and wrapped at $columnwidth */ - void appendStrings(StringBuilder sb, Vector<String> v, boolean flow) - { + void appendStrings(StringBuilder sb, Vector<String> v, boolean flow) { int count = v.size(); int width = 0; int maxCol = propertyGet(COLUMN_WIDTH); - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { String s = v.get(i); sb.append(s); // too many of them, then wrap according to columnwidth - if (flow) - { + if (flow) { width += (s.length() + 2); - if (width >= maxCol) - { + if (width >= maxCol) { sb.append(m_newline); width = 0; - } - else + } else sb.append(", "); //$NON-NLS-1$ - } - else + } else sb.append(m_newline); } @@ -1823,112 +1604,85 @@ public class DebugCLI implements Runnable, SourceLocator sb.append(m_newline); } - void doInfoFiles() - { - try - { + void doInfoFiles() { + try { StringBuilder sb = new StringBuilder(); - if (hasMoreTokens()) - { - String arg = nextToken(); - listFilesMatching(sb, arg); - } - else - { - buildFileList(sb, false); - } + if (hasMoreTokens()) { + String arg = nextToken(); + listFilesMatching(sb, arg); + } else { + buildFileList(sb, false); + } out(sb.toString()); - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { throw new IllegalStateException(); } } - void doInfoHandle() - { - if (hasMoreTokens()) - { + void doInfoHandle() { + if (hasMoreTokens()) { // user specified a fault String faultName = nextToken(); // make sure we know about this one - if (!m_faultTable.exists(faultName)) + if (!m_faultTable.exists(faultName)) err(getLocalizationManager().getLocalizedTextString("unrecognizedFault")); //$NON-NLS-1$ else listFault(faultName); - } - else - { + } else { // dump them all StringBuilder sb = new StringBuilder(); appendFaultTitles(sb); - Object names[] = m_faultTable.names(); + Object names[] = m_faultTable.names(); Arrays.sort(names); - for(int i=0; i<names.length; i++) - appendFault(sb, (String)names[i]); + for (int i = 0; i < names.length; i++) + appendFault(sb, (String) names[i]); - out ( sb.toString() ); + out(sb.toString()); } } - void doInfoFuncs() - { + void doInfoFuncs() { StringBuilder sb = new StringBuilder(); String arg = null; // we take an optional single arg which specifies a module - try - { - if (hasMoreTokens()) - { + try { + if (hasMoreTokens()) { arg = nextToken(); - int id = arg.equals(".") ? propertyGet(LIST_MODULE) : parseFileArg(m_activeIsolate, -1, arg); //$NON-NLS-1$ - + int id = arg.equals(".") ? propertyGet(LIST_MODULE) : parseFileArg(m_activeIsolate, -1, arg); //$NON-NLS-1$ + SourceFile m = m_fileInfo.getFile(id, m_activeIsolate); listFunctionsFor(sb, m); - } - else - { + } else { SourceFile[] ar = m_fileInfo.getFileList(m_activeIsolate); if (ar == null) err(getLocalizationManager().getLocalizedTextString("noSourceFilesFound")); //$NON-NLS-1$ - else - { - for(int i = 0; ar != null && i < ar.length; i++) - { - SourceFile m = ar[i]; - listFunctionsFor(sb, m); - } - } + else { + for (int i = 0; ar != null && i < ar.length; i++) { + SourceFile m = ar[i]; + listFunctionsFor(sb, m); + } + } } out(sb.toString()); - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { err(getLocalizationManager().getLocalizedTextString("noFunctionsFound")); //$NON-NLS-1$ - } - catch(ParseException pe) - { + } catch (ParseException pe) { err(pe.getMessage()); - } - catch(NoMatchException nme) - { + } catch (NoMatchException nme) { err(nme.getMessage()); - } - catch(AmbiguousException ae) - { + } catch (AmbiguousException ae) { err(ae.getMessage()); } } - void listFunctionsFor(StringBuilder sb, SourceFile m) - { + void listFunctionsFor(StringBuilder sb, SourceFile m) { String[] names = m.getFunctionNames(m_session); if (names == null) return; @@ -1940,8 +1694,7 @@ public class DebugCLI implements Runnable, SourceLocator sb.append(getLocalizationManager().getLocalizedTextString("functionsInSourceFile", args)); //$NON-NLS-1$ sb.append(m_newline); - for (int j = 0; j < names.length; j++) - { + for (int j = 0; j < names.length; j++) { String fname = names[j]; sb.append(' '); sb.append(fname); @@ -1951,51 +1704,44 @@ public class DebugCLI implements Runnable, SourceLocator } } - void listFilesMatching(StringBuilder sb, String match) - { - SourceFile[] sourceFiles = m_fileInfo.getFiles(match); + void listFilesMatching(StringBuilder sb, String match) { + SourceFile[] sourceFiles = m_fileInfo.getFiles(match); - for (int j = 0; j < sourceFiles.length; j++) - { - SourceFile sourceFile = sourceFiles[j]; - sb.append(sourceFile.getName()); + for (int j = 0; j < sourceFiles.length; j++) { + SourceFile sourceFile = sourceFiles[j]; + sb.append(sourceFile.getName()); sb.append('#'); sb.append(sourceFile.getId()); sb.append(m_newline); - } - } + } + } - void doInfoSources() - { - try - { + void doInfoSources() { + try { StringBuilder sb = new StringBuilder(); buildFileList(sb, true); out(sb.toString()); - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { throw new IllegalStateException(); } } - void doInfoBreak() throws NotConnectedException - { + void doInfoBreak() throws NotConnectedException { // waitTilHalted(); StringBuilder sb = new StringBuilder(); - sb.append("Num Type Disp Enb Address What"+m_newline); //$NON-NLS-1$ + sb.append("Num Type Disp Enb Address What" + m_newline); //$NON-NLS-1$ + // our list of breakpoints int count = breakpointCount(); - for(int i=0; i<count; i++) - { + for (int i = 0; i < count; i++) { BreakAction b = breakpointAt(i); int status = b.getStatus(); boolean isResolved = (status == BreakAction.RESOLVED); Location l = b.getLocation(); - final LocationCollection locations = b.getLocations(); - SourceFile file = (l != null) ? l.getFile() : null; - String funcName = (file == null) ? null : file.getFunctionNameForLine(m_session, l.getLine()) ; + final LocationCollection locations = b.getLocations(); + SourceFile file = (l != null) ? l.getFile() : null; + String funcName = (file == null) ? null : file.getFunctionNameForLine(m_session, l.getLine()); boolean singleSwf = b.isSingleSwf(); int cmdCount = b.getCommandCount(); int hits = b.getHits(); @@ -2023,74 +1769,65 @@ public class DebugCLI implements Runnable, SourceLocator FieldFormat.formatLongToHex(sb, offset, 8); sb.append(' '); - if (funcName != null) - { + if (funcName != null) { Map<String, Object> args = new HashMap<String, Object>(); args.put("functionName", funcName); //$NON-NLS-1$ sb.append(getLocalizationManager().getLocalizedTextString("inFunctionAt", args)); //$NON-NLS-1$ } - if (file != null) - { + if (file != null) { sb.append(file.getName()); - if (isResolved && singleSwf) - { + if (isResolved && singleSwf) { sb.append("#"); //$NON-NLS-1$ sb.append(file.getId()); } sb.append(':'); sb.append(l.getLine()); - } - else - { + } else { String expr = b.getBreakpointExpression(); if (expr != null) sb.append(expr); } - - final StringBuilder workerList = new StringBuilder(); - if (locations != null) { - for (Iterator<Location> iterator = locations.iterator(); iterator.hasNext(); ) { - Location location = iterator.next(); - workerList.append(location.getIsolateId() - 1); - if (iterator.hasNext()) - workerList.append(" / "); - } - } - + + final StringBuilder workerList = new StringBuilder(); + if (locations != null) { + for (Iterator<Location> iterator = locations.iterator(); iterator.hasNext(); ) { + Location location = iterator.next(); + workerList.append(location.getIsolateId() - 1); + if (iterator.hasNext()) + workerList.append(" / "); + } + } + + if (l != null) { - Map<String, Object> workerArgs = new HashMap<String, Object>(); - workerArgs.put("worker", workerList.toString()); //$NON-NLS-1$ - sb.append(" ("); - sb.append(getLocalizationManager().getLocalizedTextString("inWorker", workerArgs)); //$NON-NLS-1$ - sb.append(") "); - } - - switch (status) - { - case BreakAction.UNRESOLVED: - sb.append(getLocalizationManager().getLocalizedTextString("breakpointNotYetResolved")); //$NON-NLS-1$ - break; - case BreakAction.AMBIGUOUS: - sb.append(getLocalizationManager().getLocalizedTextString("breakpointAmbiguous")); //$NON-NLS-1$ - break; - case BreakAction.NOCODE: - sb.append(getLocalizationManager().getLocalizedTextString("breakpointNoCode")); //$NON-NLS-1$ - break; + Map<String, Object> workerArgs = new HashMap<String, Object>(); + workerArgs.put("worker", workerList.toString()); //$NON-NLS-1$ + sb.append(" ("); + sb.append(getLocalizationManager().getLocalizedTextString("inWorker", workerArgs)); //$NON-NLS-1$ + sb.append(") "); + } + + switch (status) { + case BreakAction.UNRESOLVED: + sb.append(getLocalizationManager().getLocalizedTextString("breakpointNotYetResolved")); //$NON-NLS-1$ + break; + case BreakAction.AMBIGUOUS: + sb.append(getLocalizationManager().getLocalizedTextString("breakpointAmbiguous")); //$NON-NLS-1$ + break; + case BreakAction.NOCODE: + sb.append(getLocalizationManager().getLocalizedTextString("breakpointNoCode")); //$NON-NLS-1$ + break; } // if a single swf break action then append more info - if (singleSwf && isResolved) - { - try - { + if (singleSwf && isResolved) { + try { SwfInfo info = m_fileInfo.swfForFile(file, l.getIsolateId()); Map<String, Object> swfArgs = new HashMap<String, Object>(); swfArgs.put("swf", FileInfoCache.nameOfSwf(info)); //$NON-NLS-1$ sb.append(getLocalizationManager().getLocalizedTextString("inSwf", swfArgs)); //$NON-NLS-1$ - } - catch(NullPointerException npe) - { + } catch (NullPointerException npe) { // can't find the swf sb.append(getLocalizationManager().getLocalizedTextString("nonRestorable")); //$NON-NLS-1$ } @@ -2100,18 +1837,16 @@ public class DebugCLI implements Runnable, SourceLocator final String INDENT = " "; //$NON-NLS-1$ // state our condition if we have one - if (cond != null && cond.length() > 0) - { + if (cond != null && cond.length() > 0) { sb.append(INDENT); Map<String, Object> args = new HashMap<String, Object>(); - args.put("breakpointCondition", cond ); //$NON-NLS-1$ + args.put("breakpointCondition", cond); //$NON-NLS-1$ sb.append(getLocalizationManager().getLocalizedTextString(getLocalizationManager().getLocalizedTextString("stopOnlyIfConditionMet", args))); //$NON-NLS-1$ sb.append(m_newline); } // now if its been hit, lets state the fact - if (hits > 0) - { + if (hits > 0) { sb.append(INDENT); Map<String, Object> args = new HashMap<String, Object>(); args.put("count", Integer.toString(hits)); //$NON-NLS-1$ @@ -2120,32 +1855,27 @@ public class DebugCLI implements Runnable, SourceLocator } // silent? - if (silent) - { + if (silent) { sb.append(INDENT); - sb.append(getLocalizationManager().getLocalizedTextString("silentBreakpoint")+m_newline); //$NON-NLS-1$ + sb.append(getLocalizationManager().getLocalizedTextString("silentBreakpoint") + m_newline); //$NON-NLS-1$ } // now if any commands are trailing then we pump them out - for(int j=0; j<cmdCount; j++) - { + for (int j = 0; j < cmdCount; j++) { sb.append(INDENT); sb.append(b.commandAt(j)); sb.append(m_newline); } } -// } int wcount = watchpointCount(); - for(int k = 0; k < wcount; k++) - { + for (int k = 0; k < wcount; k++) { WatchAction b = watchpointAt(k); int id = b.getId(); FieldFormat.formatLong(sb, id, 4); int flags = b.getKind(); - switch(flags) - { + switch (flags) { case WatchKind.READ: sb.append("rd watchpoint "); //$NON-NLS-1$ break; @@ -2166,8 +1896,7 @@ public class DebugCLI implements Runnable, SourceLocator } int ccount = catchpointCount(); - for (int k = 0; k < ccount; k++) - { + for (int k = 0; k < ccount; k++) { CatchAction c = catchpointAt(k); int id = c.getId(); FieldFormat.formatLong(sb, id, 4); @@ -2187,95 +1916,89 @@ public class DebugCLI implements Runnable, SourceLocator out(sb.toString()); } - /** - * Dump out the state of the execution, either the fact we are running - * or the breakpoint we hit. - */ - void dumpHaltState(boolean postStep) throws NotConnectedException, SuspendedException, NoResponseException, NotSupportedException, NotSuspendedException, IOException { - // spit out any event output, if we are to resume after a fault and we're not stepping then we're done. - processEvents(); + /** + * Dump out the state of the execution, either the fact we are running + * or the breakpoint we hit. + */ + void dumpHaltState(boolean postStep) throws NotConnectedException, SuspendedException, NoResponseException, NotSupportedException, NotSuspendedException, IOException { + // spit out any event output, if we are to resume after a fault and we're not stepping then we're done. + processEvents(); // System.out.println("processEvents = "+m_requestResume); - //if (m_requestResume && !postStep) - if (hasAnyPendingResumes() != -1 && !postStep) - return; - - if (!m_session.isConnected()) { - // session is kaput - out(getLocalizationManager().getLocalizedTextString("sessionTerminated")); //$NON-NLS-1$ - exitSession(); - } else { - if (!m_quietMode && hasAnythingSuspended()) { - // capture our break location / information - StringBuilder sbLine = new StringBuilder(); - dumpBreakLine(postStep, sbLine); - - // Process our breakpoints. - // Since we can have conditional breakpoints, which the - // player always breaks for, but we may not want to, the variable - // m_requestResume may be set after this call. Additionally, - // silent may be set for one of two reasons; 1) m_requestResume - // was set to true in the call or one or more breakpoints that - // hit contained the keyword silent in their command list. - // - StringBuilder sbBreak = new StringBuilder(); - boolean silent = processBreak(postStep, sbBreak, m_activeIsolate); - - StringBuilder sb = new StringBuilder(); - if (silent) { - // silent means we only spit out our current location - dumpBreakLine(postStep, sb); - } else { - // not silent means we append things like normal - sb.append(sbLine); - if (sbLine.length() > 0 && sbLine.charAt(sbLine.length() - 1) != '\n') - sb.append(m_newline); - sb.append(sbBreak); - } - - // output whatever was generated - if (sb.length() > 0) - out(sb.toString()); + //if (m_requestResume && !postStep) + if (hasAnyPendingResumes() != -1 && !postStep) + return; + + if (!m_session.isConnected()) { + // session is kaput + out(getLocalizationManager().getLocalizedTextString("sessionTerminated")); //$NON-NLS-1$ + exitSession(); + } else { + if (!m_quietMode && hasAnythingSuspended()) { + // capture our break location / information + StringBuilder sbLine = new StringBuilder(); + dumpBreakLine(postStep, sbLine); + + // Process our breakpoints. + // Since we can have conditional breakpoints, which the + // player always breaks for, but we may not want to, the variable + // m_requestResume may be set after this call. Additionally, + // silent may be set for one of two reasons; 1) m_requestResume + // was set to true in the call or one or more breakpoints that + // hit contained the keyword silent in their command list. + // + StringBuilder sbBreak = new StringBuilder(); + boolean silent = processBreak(postStep, sbBreak, m_activeIsolate); + + StringBuilder sb = new StringBuilder(); + if (silent) { + // silent means we only spit out our current location + dumpBreakLine(postStep, sb); + } else { + // not silent means we append things like normal + sb.append(sbLine); + if (sbLine.length() > 0 && sbLine.charAt(sbLine.length() - 1) != '\n') + sb.append(m_newline); + sb.append(sbBreak); + } + + // output whatever was generated + if (sb.length() > 0) + out(sb.toString()); // System.out.println("processbreak = "+m_requestResume+",silent="+silent+",reason="+m_session.suspendReason()); - } else if (!m_quietMode) { - // very bad, set stepping so that we don't trigger a continue on a breakpoint or fault - out(getLocalizationManager().getLocalizedTextString("playerDidNotStop")); //$NON-NLS-1$ - } - m_quietMode = false; - } - } - - Location getCurrentLocation() - { + } else if (!m_quietMode) { + // very bad, set stepping so that we don't trigger a continue on a breakpoint or fault + out(getLocalizationManager().getLocalizedTextString("playerDidNotStop")); //$NON-NLS-1$ + } + m_quietMode = false; + } + } + + Location getCurrentLocation() { return getCurrentLocationIsolate(Isolate.DEFAULT_ID); } - - Location getCurrentLocationIsolate(int isolateId) - { + + Location getCurrentLocationIsolate(int isolateId) { Location where = null; - try - <TRUNCATED>
