public static CorDebugJITCompilerFlags MapDebugModeToJITCompilerFlags(DebugModeFlag debugMode) { CorDebugJITCompilerFlags jcf; switch (debugMode) { case DebugModeFlag.Optimized: jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT; // DEFAULT really means force optimized. break; case DebugModeFlag.Debug: jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION; break; case DebugModeFlag.Enc: jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_ENABLE_ENC; break; default: // we don't have mapping from default to "default", // therefore we'll use DISABLE_OPTIMIZATION. jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION; break; } return(jcf); }
////////////////////////////////////////////////////////////////////////////////// // // Controlling Commands // ////////////////////////////////////////////////////////////////////////////////// /// <summary> /// creates a new debugged process. /// </summary> /// <param name="commandLine">The command to run.</param> /// <param name="commandArguments">The arguments for the command.</param> /// <param name="debugMode">The debug mode to run with.</param> /// <param name="deeVersion">The version of debugging interfaces that should be used for /// debuging of the started program. If this value is null, the default (latest) version /// of interface is used. /// </param> /// <returns>The resulting MDbgProcess.</returns> public MDbgProcess CreateProcess(string commandLine, string commandArguments, DebugModeFlag debugMode, string deeVersion) { MDbgProcess p = m_processMgr.CreateLocalProcess(deeVersion); p.DebugMode = debugMode; p.CreateProcess(commandLine, commandArguments); return(p); }
////////////////////////////////////////////////////////////////////////////////// // // Controlling Commands // ////////////////////////////////////////////////////////////////////////////////// /// <summary> /// creates a new debugged process. /// </summary> /// <param name="commandLine">The command to run.</param> /// <param name="commandArguments">The arguments for the command.</param> /// <param name="debugMode">The debug mode to run with.</param> /// <param name="deeVersion">The version of debugging interfaces that should be used for /// debugging of the started program. If this value is null, the default (latest) version /// of interface is used. /// </param> /// <returns>The resulting MDbgProcess.</returns> public MDbgProcess CreateProcess(string commandLine, string commandArguments, DebugModeFlag debugMode, string deeVersion) { CorDebugger debugger; if (deeVersion == null) { debugger = new CorDebugger(CorDebugger.GetDefaultDebuggerVersion()); } else { debugger = new CorDebugger(deeVersion); } MDbgProcess p = m_processMgr.CreateLocalProcess(debugger); p.DebugMode = debugMode; p.CreateProcess(commandLine, commandArguments); return(p); }
// AssertOnErrors flag is used by mode ae command // to Enable/Disable stopping at the point of failure. // // The flag is defined here because it is used also by // recorder extension to stop at the point of failure during // replay of recorded scripts. /// <summary> /// Parses arguments for the run command, but does not provide direct access to the path to the /// program to run. /// </summary> /// <param name="arguments">Argument to the run and crun command</param> /// <param name="debugMode">Returns desired debugging mode. Returns internal /// default if not specified /// </param> /// <param name="debuggeeVersion">Returns the debugger interface version. /// Is null if the version cannot be determined. /// </param> /// <param name="programAndArgsToRun">Returns the command line for the program /// being run. Note that the program name may be quoted and may not contain /// a ".exe" extension. Rather than try to parse this, if you need the path to the binary /// being run, then use the 5 argument overload below.</param> public static void PreParseRunArguments(string arguments, out DebugModeFlag debugMode, out string debuggeeVersion, out string programAndArgsToRun) { string programToRun; string programArguments; PreParseRunArguments(arguments, out debugMode, out debuggeeVersion, out programToRun, out programArguments); // the binary name is included in the program arguments (as the 0th argument), so just use that if (programArguments == null) { programAndArgsToRun = String.Empty; } else { programAndArgsToRun = programArguments; } }
////////////////////////////////////////////////////////////////////////////////// // // Controlling Commands // ////////////////////////////////////////////////////////////////////////////////// /// <summary> /// creates a new debugged process. /// </summary> /// <param name="commandLine">The command to run.</param> /// <param name="commandArguments">The arguments for the command.</param> /// <param name="debugMode">The debug mode to run with.</param> /// <param name="deeVersion">The version of debugging interfaces that should be used for /// debugging of the started program. If this value is null, the default (latest) version /// of interface is used. /// </param> /// <returns>The resulting MDbgProcess.</returns> public MDbgProcess CreateProcess(string commandLine, string commandArguments, DebugModeFlag debugMode, string deeVersion) { CorDebugger debugger; if (deeVersion == null) { debugger = new CorDebugger(CorDebugger.GetDefaultDebuggerVersion()); } else { debugger = new CorDebugger(deeVersion); } MDbgProcess p = m_processMgr.CreateLocalProcess(debugger); p.DebugMode = debugMode; p.CreateProcess(commandLine, commandArguments); return p; }
////////////////////////////////////////////////////////////////////////////////// // // Controlling Commands // ////////////////////////////////////////////////////////////////////////////////// /// <summary> /// creates a new debugged process. /// </summary> /// <param name="commandLine">The command to run.</param> /// <param name="commandArguments">The arguments for the command.</param> /// <param name="debugMode">The debug mode to run with.</param> /// <param name="deeVersion">The version of debugging interfaces that should be used for /// debuging of the started program. If this value is null, the default (latest) version /// of interface is used. /// </param> /// <returns>The resulting MDbgProcess.</returns> public MDbgProcess CreateProcess(string commandLine, string commandArguments, DebugModeFlag debugMode, string deeVersion) { MDbgProcess p = m_processMgr.CreateLocalProcess(deeVersion); p.DebugMode = debugMode; p.CreateProcess(commandLine, commandArguments); return p; }
// helper function private static CorDebugJITCompilerFlags MapDebugModeToJITCompilerFlags(DebugModeFlag debugMode) { CorDebugJITCompilerFlags jcf; switch (debugMode) { case DebugModeFlag.Optimized: jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_DEFAULT; // DEFAULT really means force optimized. break; case DebugModeFlag.Debug: jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION; break; case DebugModeFlag.Enc: jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_ENABLE_ENC; break; default: Debug.Assert(false, "Invalid debugMode"); // we don't have mapping from default to "default", // therefore we'll use DISABLE_OPTIMIZATION. jcf = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION; break; } return jcf; }
private static bool DebugActiveSilverlightProcess(int processId, DebugModeFlag debugMode) { MDbgProcess p = null; string[] fullPaths; EventWaitHandle[] continueStartupEvents; bool bMatchFound = false; // some pre-condition checks if (processId <= 0) { throw new MDbgShellException("Invalid arguments passed in"); } // Get all funcs exported by the coreclr's dbg shim. Silverlight.InitSLApi(); // Enumerate all coreclr instances in the process Silverlight.EnumerateCLRs((uint)processId, out fullPaths, out continueStartupEvents); int nSilverlight = fullPaths.Length; if (fullPaths == null || nSilverlight == 0) { throw new MDbgShellException("Could not enumerate any CLRs in specifed Silverlight process"); } // for each coreclr instance found..... for (int i = 0; i < nSilverlight && !bMatchFound; i++) { // Attach to the first one WriteOutput("FOUND: " + fullPaths[i]); string slVersion = Silverlight.CreateVersionStringFromModule((uint)processId, fullPaths[i]); sVersionString = slVersion; // we'll get the required ICorDebug interface from dbgshim.dll ICorDebug cordbg = null; try { cordbg = Silverlight.CreateDebuggingInterfaceFromVersionEx(CorDebugInterfaceVersion.CorDebugLatestVersion, slVersion); } catch (COMException ce) { Console.WriteLine("CDIFVEx failed, will retry with CDIFV.\n" + ce.ToString()); } if (cordbg == null) { cordbg = Silverlight.CreateDebuggingInterfaceFromVersion(slVersion); } p = GetProcessFromCordb(cordbg); // specify JIT flages here p.DebugMode = debugMode; p.Attach((int)processId); bMatchFound = true; // signal the continue event if (!continueStartupEvents[i].SafeWaitHandle.IsInvalid) { continueStartupEvents[i].Set(); } if (null != p) { p.Go().WaitOne(); } } return bMatchFound; }
private static bool DebugActiveSilverlightProcess(int processId, DebugModeFlag debugMode) { MDbgProcess p = null; string[] fullPaths; EventWaitHandle[] continueStartupEvents; bool bMatchFound = false; // some pre-condition checks if (processId <= 0) { throw new MDbgShellException("Invalid arguments passed in"); } // Get all funcs exported by the coreclr's dbg shim. Silverlight.InitSLApi(); // Enumerate all coreclr instances in the process Silverlight.EnumerateCLRs((uint)processId, out fullPaths, out continueStartupEvents); int nSilverlight = fullPaths.Length; if (fullPaths == null || nSilverlight == 0) { throw new MDbgShellException("Could not enumerate any CLRs in specifed Silverlight process"); } // for each coreclr instance found..... for (int i = 0; i < nSilverlight && !bMatchFound; i++) { // Attach to the first one WriteOutput("FOUND: " + fullPaths[i]); string slVersion = Silverlight.CreateVersionStringFromModule((uint)processId, fullPaths[i]); sVersionString = slVersion; // we'll get the required ICorDebug interface from dbgshim.dll ICorDebug cordbg = null; try { cordbg = Silverlight.CreateDebuggingInterfaceFromVersionEx(CorDebugInterfaceVersion.CorDebugLatestVersion, slVersion); } catch (COMException ce) { Console.WriteLine("CDIFVEx failed, will retry with CDIFV.\n" + ce.ToString()); } if (cordbg == null) { cordbg = Silverlight.CreateDebuggingInterfaceFromVersion(slVersion); } p = GetProcessFromCordb(cordbg); // specify JIT flages here p.DebugMode = debugMode; p.Attach((int)processId); bMatchFound = true; // signal the continue event if (!continueStartupEvents[i].SafeWaitHandle.IsInvalid) { continueStartupEvents[i].Set(); } if (null != p) { p.Go().WaitOne(); } } return(bMatchFound); }
/// <summary> /// Helper function that parses inputs to run and crun commands. /// </summary> /// <param name="arguments">Argument to the run and crun command</param> /// <param name="debugMode">Returns desired debugging mode. Returns internal /// default if not specified /// </param> /// <param name="debuggeeVersion">Returns the debugger interface version. /// Is null if the version cannot be determined. /// </param> /// <param name="programToRun">Returns path of the program to execute.</param> /// <param name="programArguments">Returns arguments to pass to the program being /// run, including the binary name as the 0th argument</param> public static void PreParseRunArguments(string arguments, out DebugModeFlag debugMode, out string debuggeeVersion, out string programToRun, out string programArguments) { Debug.Assert(arguments != null); if (arguments == null) throw new ArgumentException("Parameter cannot be null.", "arguments"); debugMode = DebugModeFlag.Debug; // Is this the mode we want to always start in? int start, end; start = end = 0; // those flags are necessary so that people can run any program under debugger. // e.g to run program named '-debug.exe', they can write 'run -debug -debug' // // One obvious issue here is that if the binary name is same as the flag, then // user need to pass the flag to the run command so that the program name is not // interpreted as a flag. // bool debugModeFlagSet = false; bool versionFlagSet = false; debuggeeVersion = null; while (FindToken(arguments, ref start, ref end)) { Debug.Assert(start <= end); switch (arguments.Substring(start, end - start)) { case "-default": if (debugModeFlagSet) goto default; debugMode = DebugModeFlag.Default; debugModeFlagSet = true; break; case "-debug": case "-d": if (debugModeFlagSet) goto default; debugMode = DebugModeFlag.Debug; debugModeFlagSet = true; break; case "-optimize": case "-o": if (debugModeFlagSet) goto default; debugMode = DebugModeFlag.Optimized; debugModeFlagSet = true; break; case "-enc": if (debugModeFlagSet) goto default; debugMode = DebugModeFlag.Enc; debugModeFlagSet = true; break; case "-ver": if (versionFlagSet) goto default; if (!FindToken(arguments, ref start, ref end)) throw new MDbgShellException("missing argument to -ver option"); debuggeeVersion = arguments.Substring(start, end - start); versionFlagSet = true; break; default: // this means we have found some different token. // To keep comaptibility with cordbg, we assume that this is a program binary name. // Expand environment variables on the binary name so that we can use env vars in // the program path. Note that environment variables are not expanded in program // arguments so that we can pass in original strings. Programs can expand the environment // themselves if they wish so. string prog = Environment.ExpandEnvironmentVariables(arguments.Substring(start, end - start)); // program may be quoted, remove surrounding quotes // Note: ideally we'd have a general escapedPath format and escape/unescape methods to convert // but this is good enough for our purposes here. if (prog.Length >= 2 && prog.StartsWith("\"") && prog.EndsWith("\"")) prog = prog.Substring(1, prog.Length - 2); // may have omitted .exe extension, add it if necessary const string optExt = ".exe"; if (!prog.EndsWith(optExt, StringComparison.OrdinalIgnoreCase)) prog += optExt; // We're left with the program binary path programToRun = prog; // Use everything unmodified (including the possibly quoted binary path) as the run arguments programArguments = arguments.Substring(start); if (debuggeeVersion == null) { // user didn't specify, we need to guess it. try { debuggeeVersion = CorDebugger.GetDebuggerVersionFromFile(programToRun); } catch (COMException) { // we could not retrieve dee version. debuggeeVersion = null; } } // Rest of line processed, we're done. return; } } // we didn't find any token -- no other binary specified than options programToRun = null; programArguments = null; return; }
// AssertOnErrors flag is used by mode ae command // to Enable/Disable stopping at the point of failure. // // The flag is defined here because it is used also by // recorder extension to stop at the point of failure during // replay of recorded scripts. /// <summary> /// Parses arguments for the run command, but does not provide direct access to the path to the /// program to run. /// </summary> /// <param name="arguments">Argument to the run and crun command</param> /// <param name="debugMode">Returns desired debugging mode. Returns internal /// default if not specified /// </param> /// <param name="debuggeeVersion">Returns the debugger interface version. /// Is null if the version cannot be determined. /// </param> /// <param name="programAndArgsToRun">Returns the command line for the program /// being run. Note that the program name may be quoted and may not contain /// a ".exe" extension. Rather than try to parse this, if you need the path to the binary /// being run, then use the 5 argument overload below.</param> public static void PreParseRunArguments(string arguments, out DebugModeFlag debugMode, out string debuggeeVersion, out string programAndArgsToRun) { string programToRun; string programArguments; PreParseRunArguments(arguments, out debugMode, out debuggeeVersion, out programToRun, out programArguments); // the binary name is included in the program arguments (as the 0th argument), so just use that if (programArguments == null) programAndArgsToRun = String.Empty; else programAndArgsToRun = programArguments; }
/// <summary> /// Helper function that parses inputs to run and crun commands. /// </summary> /// <param name="arguments">Argument to the run and crun command</param> /// <param name="debugMode">Returns desired debugging mode. Returns internal /// default if not specified /// </param> /// <param name="debuggeeVersion">Returns the debugger interface version. /// Is null if the version cannot be determined. /// </param> /// <param name="programToRun">Returns path of the program to execute.</param> /// <param name="programArguments">Returns arguments to pass to the program being /// run, including the binary name as the 0th argument</param> public static void PreParseRunArguments(string arguments, out DebugModeFlag debugMode, out string debuggeeVersion, out string programToRun, out string programArguments) { Debug.Assert(arguments != null); if (arguments == null) { throw new ArgumentException("Parameter cannot be null.", "arguments"); } debugMode = DebugModeFlag.Debug; // Is this the mode we want to always start in? int start, end; start = end = 0; // those flags are necessary so that people can run any program under debugger. // e.g to run program named '-debug.exe', they can write 'run -debug -debug' // // One obvious issue here is that if the binary name is same as the flag, then // user need to pass the flag to the run command so that the program name is not // interpreted as a flag. // bool debugModeFlagSet = false; bool versionFlagSet = false; debuggeeVersion = null; while (FindToken(arguments, ref start, ref end)) { Debug.Assert(start <= end); switch (arguments.Substring(start, end - start)) { case "-default": if (debugModeFlagSet) { goto default; } debugMode = DebugModeFlag.Default; debugModeFlagSet = true; break; case "-debug": case "-d": if (debugModeFlagSet) { goto default; } debugMode = DebugModeFlag.Debug; debugModeFlagSet = true; break; case "-optimize": case "-o": if (debugModeFlagSet) { goto default; } debugMode = DebugModeFlag.Optimized; debugModeFlagSet = true; break; case "-enc": if (debugModeFlagSet) { goto default; } debugMode = DebugModeFlag.Enc; debugModeFlagSet = true; break; case "-ver": if (versionFlagSet) { goto default; } if (!FindToken(arguments, ref start, ref end)) { throw new MDbgShellException("missing argument to -ver option"); } debuggeeVersion = arguments.Substring(start, end - start); versionFlagSet = true; break; default: // this means we have found some different token. // To keep comaptibility with cordbg, we assume that this is a program binary name. // Expand environment variables on the binary name so that we can use env vars in // the program path. Note that environment variables are not expanded in program // arguments so that we can pass in original strings. Programs can expand the environment // themselves if they wish so. string prog = Environment.ExpandEnvironmentVariables(arguments.Substring(start, end - start)); // program may be quoted, remove surrounding quotes // Note: ideally we'd have a general escapedPath format and escape/unescape methods to convert // but this is good enough for our purposes here. if (prog.Length >= 2 && prog.StartsWith("\"") && prog.EndsWith("\"")) { prog = prog.Substring(1, prog.Length - 2); } // may have omitted .exe extension, add it if necessary const string optExt = ".exe"; if (!prog.EndsWith(optExt, StringComparison.OrdinalIgnoreCase)) { prog += optExt; } // We're left with the program binary path programToRun = prog; // Use everything unmodified (including the possibly quoted binary path) as the run arguments programArguments = arguments.Substring(start); if (debuggeeVersion == null) { // user didn't specify, we need to guess it. try { debuggeeVersion = CorDebugger.GetDebuggerVersionFromFile(programToRun); } catch (COMException) { // we could not retrieve dee version. debuggeeVersion = null; } } // Rest of line processed, we're done. return; } } // we didn't find any token -- no other binary specified than options programToRun = null; programArguments = null; return; }