public static void RemapCmd(string args) { var ap = new ArgParser(args); if (!(Debugger.Processes.Active.StopReason is RemapOpportunityReachedStopReason)) { WriteError("Not stopped at RemapOpportunity breakpoint"); return; } var sr = (RemapOpportunityReachedStopReason)Debugger.Processes.Active.StopReason; if (!ap.Exists(0)) { // no arguments -- we just print content of last remap callback // we want to do remap. WriteOutput("Last FunctionRemapOpportunity Callback:"); WriteOutput("-----------------------------------------"); WriteOutput("AppDomain: " + sr.AppDomain.Name); WriteOutput("NewFunction: " + sr.NewFunction.Token); WriteOutput("OldFunction: " + sr.OldFunction.Token); WriteOutput("OldILOffset: " + sr.OldILOffset); WriteOutput("Thread Number: " + Debugger.Processes.Active.Threads.Lookup(sr.Thread).Number); } else { int newILOffset = ap.AsInt(0); sr.Thread.ActiveFrame.RemapFunction(newILOffset); Debugger.Processes.Active.Threads.RefreshStack(); WriteOutput("Remap successful."); } }
public static void Con(string args) { ArgParser ap = new ArgParser(args); if (ap.Exists(0)) { if (ap.AsString(0) == "close") { if (_console != null) { _console.Stop(); return; } else { throw new MDbgShellException("Console not started."); } } else { throw new MDbgShellException("invalid argument"); } } _console = new Screen(Shell); _console.Start(); }
// O2.Debugger.Mdbg.OriginalMdbgCode.mdbg.mdbgCommandsCustomizedForO2 // , O2Thread.FuncVoid<string> o2Callback) public static bool AttachCmd(string arguments, O2Thread.FuncVoidT1 <string> o2Callback) { try { var ap = new ArgParser(arguments); if (ap.Count > 1) { DI.log.error("in AttachCmd: Wrong # of arguments."); return(false); } if (!ap.Exists(0)) { DI.log.error("in AttachCmd: Please choose some process to attach"); MdbgCommands.ProcessEnumCmd(""); return(false); } int pid = ap.AsInt(0); if (Process.GetCurrentProcess().Id == pid) { DI.log.error("in AttachCmd: Cannot attach to myself!"); return(false); } MDbgProcess p = CommandBase.Debugger.Attach(pid); p.Go().WaitOne(); return(true); } catch (Exception ex) { DI.log.ex(ex, "in AttachCmd"); return(false); } }
public static void AttachCmd(string arguments) { ArgParser ap = new ArgParser(arguments); if (ap.Count > 1) { throw new MDbgShellException("Wrong # of arguments."); } if (!ap.Exists(0)) { throw new MDbgShellException("Wrong # of arguments."); } int pid = ap.AsInt(0); if (Process.GetCurrentProcess().Id == pid) { throw new MDbgShellException("Cannot attach to myself!"); } // time to attach, since the user isn't able to specify the DebugModeFlag for attach, use Debug which is the // default if (false == DebugActiveSilverlightProcess(pid, DebugModeFlag.Debug)) { throw new MDbgShellException("Could not find a match for *"); } }
public static void ShowCmd(string arguments, O2Thread.FuncVoidT1 <string> o2Callback) { MDbgSourcePosition pos = CommandBase.Debugger.Processes.Active.Threads.Active.CurrentSourcePosition; if (pos == null) { throw new MDbgShellException("No source location"); } string fileLoc = CommandBase.Shell.FileLocator.GetFileLocation(pos.Path); if (fileLoc == null) { throw new MDbgShellException(String.Format(CultureInfo.InvariantCulture, "Source file '{0}' not available.", pos.Path)); } IMDbgSourceFile file = CommandBase.Shell.SourceFileMgr.GetSourceFile(fileLoc); var ap = new ArgParser(arguments); if (ap.Count > 1) { throw new MDbgShellException("Wrong # of arguments."); } int around; if (ap.Exists(0)) { around = ap.AsInt(0); } else { around = 3; } int lo, hi; lo = pos.Line - around; if (lo < 1) { lo = 1; } hi = pos.Line + around; if (hi > file.Count) { hi = file.Count; } for (int i = lo; i < hi; i++) { CommandBase.WriteOutput(String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", i, i == pos.Line ? ":*" : " ", file[i])); } }
public static void ILDasmCmd(string args) { var ap = new ArgParser(args); if (ap.Count > 1) { WriteError("Wrong # of arguments."); return; } MDbgFrame functionFrame = null; MDbgFunction function = null; if (ap.Exists(0)) { function = Debugger.Processes.Active.ResolveFunctionNameFromScope(ap.AsString(0)); if (function == null) throw new MDbgShellException("no such function."); } else { functionFrame = Debugger.Processes.Active.Threads.Active.CurrentFrame; function = functionFrame.Function; } CorCode ilCode = function.CorFunction.ILCode; //CorMetadataImport importer = functionFrame.Function.Module.Importer; Debug.Assert(ilCode.IsIL); WriteOutput("code size: " + ilCode.Size); var doc = new ILVirtualDocument(function); int currentLine; if (functionFrame != null) { // we have frame and therefore we should show current location uint ip; CorDebugMappingResult mappingResult; functionFrame.CorFrame.GetIP(out ip, out mappingResult); WriteOutput("current IL-IP: " + ip); WriteOutput("mapping: " + mappingResult); WriteOutput("URL: " + doc.Path); currentLine = doc.Ip2LineNo((int) ip); } else { // no current IP. currentLine = -1; } for (int i = 0; i < doc.Count; i++) if (i == currentLine) WriteOutput("* " + doc[i]); else WriteOutput(" " + doc[i]); }
public static void Gui(string args) { // just do the check that gui is not already loaded, // strange things are happening else: var ap = new ArgParser(args); if (ap.Exists(0)) { if (ap.AsString(0) == "close") { if (m_mainForm != null) { m_mainForm.CloseGui(); Application.Exit(); // this line will cause the message pump on other thread to quit. return; } else { throw new MDbgShellException("GUI not started."); } } else { throw new MDbgShellException("invalid argument"); } } if (Shell.IO == m_mainForm) { WriteOutput("GUI already started. Cannot start second instance."); return; } WriteOutput("starting gui"); m_mainForm = new MainForm(Shell); var t = new Thread(RunMessageLoop); // Only MTA Threads can access CorDebug interfaces because mscordbi doesn't provide marshalling to make them accessable from STA Threads // However, UI thread must be STA. So we'll make cross-thread calls to a worker thread for all ICorDebug access. t.SetApartmentState(ApartmentState.STA); t.IsBackground = true; t.Start(); m_mainForm.InitComplete.WaitOne(); // wait till form is fully displayed. WriteOutput(MainForm.MetaInfoOutputConstant, "GUI: Simple Extension for Managed debugger (MDbg) started"); WriteOutput(MainForm.MetaInfoOutputConstant, "for information on how to use the extension select in menu bar help|about"); WriteOutput(MainForm.MetaInfoOutputConstant, "!!This is just a sample. It is not intended for Production purposes!!\n"); }
public static void Gui(string args) { // just do the check that gui is not already loaded, // strange things are happening else: var ap = new ArgParser(args); if (ap.Exists(0)) { if (ap.AsString(0) == "close") { if (m_mainForm != null) { m_mainForm.CloseGui(); Application.Exit(); // this line will cause the message pump on other thread to quit. return; } else throw new MDbgShellException("GUI not started."); } else throw new MDbgShellException("invalid argument"); } if (Shell.IO == m_mainForm) { WriteOutput("GUI already started. Cannot start second instance."); return; } WriteOutput("starting gui"); m_mainForm = new MainForm(Shell); var t = new Thread(RunMessageLoop); // Only MTA Threads can access CorDebug interfaces because mscordbi doesn't provide marshalling to make them accessable from STA Threads // However, UI thread must be STA. So we'll make cross-thread calls to a worker thread for all ICorDebug access. t.SetApartmentState(ApartmentState.STA); t.IsBackground = true; t.Start(); m_mainForm.InitComplete.WaitOne(); // wait till form is fully displayed. WriteOutput(MainForm.MetaInfoOutputConstant, "GUI: Simple Extension for Managed debugger (MDbg) started"); WriteOutput(MainForm.MetaInfoOutputConstant, "for information on how to use the extension select in menu bar help|about"); WriteOutput(MainForm.MetaInfoOutputConstant, "!!This is just a sample. It is not intended for Production purposes!!\n"); }
public static void Gui(string args) { //System.Diagnostics.Debug.Assert(false); if (nppDebugger == null) { nppDebugger = new DebuggerClient(Shell); } var ap = new ArgParser(args); if (ap.Exists(0)) { if (ap.AsString(0) == "close") { if (nppDebugger != null) { nppDebugger.Close(); Application.Exit(); // this line will cause the message pump on other thread to quit. return; } else { throw new MDbgShellException("NPP not started."); } } else { throw new MDbgShellException("invalid argument"); } } if (Shell.IO == nppDebugger) { WriteOutput("NPP already started. Cannot start second instance."); return; } WriteOutput("starting npp"); Shell.IO = nppDebugger; }
public static void EncCmd(string args) { var ap = new ArgParser(args); if (ap.Count == 0) { WriteOutput("Performed edits:"); foreach (MDbgModule module in Debugger.Processes.Active.Modules) { if (module.EditsCounter > 0) { WriteOutput(module.CorModule.Name); int edits = module.EditsCounter; for (int j = 1; j <= edits; j++) { string editFile = module.GetEditsSourceFile(j); WriteOutput(String.Format(CultureInfo.InvariantCulture, " {0}. - {1}", new Object[] { j, editFile == null ? "N/A" : editFile })); } } } return; } if (ap.Count < 1 && ap.Count > 3) { WriteError("Wrong amount of arguments!"); return; } string encModule = ap.AsString(0); MDbgModule m = Debugger.Processes.Active.Modules.Lookup(encModule); string modName = Path.DirectorySeparatorChar + Path.GetFileName(m.CorModule.Name); string pathToEncFiles = Path.GetDirectoryName(m.CorModule.Name); // defaults to location of the module string editSourceFile; if (ap.Exists(1)) { editSourceFile = ap.AsString(1); } else { editSourceFile = null; } string deltasBaseName; if (ap.Exists(2)) { deltasBaseName = ap.AsString(2); } else { deltasBaseName = pathToEncFiles + modName + ".1"; } string deltaPdbFile = deltasBaseName + ".pdb"; if (!File.Exists(deltaPdbFile)) { WriteOutput("Delta PDB file not found; debug symbols won't be updated."); deltaPdbFile = null; } m.ApplyEdit(deltasBaseName + ".dmeta", deltasBaseName + ".dil", deltaPdbFile, editSourceFile); WriteOutput("ENC successfully applied."); }
public static void ILDasmCmd(string args) { // Provides disassembly of IL opcodes. ArgParser ap = new ArgParser(args); if (ap.Count > 1) { WriteError("Wrong # of arguments."); return; } MDbgFrame functionFrame = null; MDbgFunction function = null; if (ap.Exists(0)) { function = Debugger.Processes.Active.ResolveFunctionNameFromScope(ap.AsString(0)); if (function == null) { throw new MDbgShellException("no such function."); } } else { functionFrame = Debugger.Processes.Active.Threads.Active.CurrentFrame; function = functionFrame.Function; } CorCode ilCode = function.CorFunction.ILCode; //CorMetadataImport importer = functionFrame.Function.Module.Importer; Debug.Assert(true == ilCode.IsIL); WriteOutput("code size: " + ilCode.Size); ILVirtualDocument doc = new ILVirtualDocument(function); int currentLine; if (functionFrame != null) { // we have frame and therefore we should show current location uint ip; CorDebugMappingResult mappingResult; functionFrame.CorFrame.GetIP(out ip, out mappingResult); WriteOutput("current IL-IP: " + ip); WriteOutput("mapping: " + mappingResult.ToString()); WriteOutput("URL: " + doc.Path); currentLine = doc.Ip2LineNo((int)ip); } else { // no current IP. currentLine = -1; } for (int i = 0; i < doc.Count; i++) { if (i == currentLine) { WriteOutput("* " + doc[i]); } else { WriteOutput(" " + doc[i]); } } }
public static void EncCmd(string args) { var ap = new ArgParser(args); if (ap.Count == 0) { WriteOutput("Performed edits:"); foreach (MDbgModule module in Debugger.Processes.Active.Modules) { if (module.EditsCounter > 0) { WriteOutput(module.CorModule.Name); int edits = module.EditsCounter; for (int j = 1; j <= edits; j++) { string editFile = module.GetEditsSourceFile(j); WriteOutput(String.Format(CultureInfo.InvariantCulture, " {0}. - {1}", new Object[] {j, editFile == null ? "N/A" : editFile})); } } } return; } if (ap.Count < 1 && ap.Count > 3) { WriteError("Wrong amount of arguments!"); return; } string encModule = ap.AsString(0); MDbgModule m = Debugger.Processes.Active.Modules.Lookup(encModule); string modName = Path.DirectorySeparatorChar + Path.GetFileName(m.CorModule.Name); string pathToEncFiles = Path.GetDirectoryName(m.CorModule.Name); // defaults to location of the module string editSourceFile; if (ap.Exists(1)) editSourceFile = ap.AsString(1); else editSourceFile = null; string deltasBaseName; if (ap.Exists(2)) deltasBaseName = ap.AsString(2); else deltasBaseName = pathToEncFiles + modName + ".1"; string deltaPdbFile = deltasBaseName + ".pdb"; if (!File.Exists(deltaPdbFile)) { WriteOutput("Delta PDB file not found; debug symbols won't be updated."); deltaPdbFile = null; } m.ApplyEdit(deltasBaseName + ".dmeta", deltasBaseName + ".dil", deltaPdbFile, editSourceFile); WriteOutput("ENC successfully applied."); }
public static void RemapCmd(string args) { var ap = new ArgParser(args); if (!(Debugger.Processes.Active.StopReason is RemapOpportunityReachedStopReason)) { WriteError("Not stopped at RemapOpportunity breakpoint"); return; } var sr = (RemapOpportunityReachedStopReason) Debugger.Processes.Active.StopReason; if (!ap.Exists(0)) { // no arguments -- we just print content of last remap callback // we want to do remap. WriteOutput("Last FunctionRemapOpportunity Callback:"); WriteOutput("-----------------------------------------"); WriteOutput("AppDomain: " + sr.AppDomain.Name); WriteOutput("NewFunction: " + sr.NewFunction.Token); WriteOutput("OldFunction: " + sr.OldFunction.Token); WriteOutput("OldILOffset: " + sr.OldILOffset); WriteOutput("Thread Number: " + Debugger.Processes.Active.Threads.Lookup(sr.Thread).Number); } else { int newILOffset = ap.AsInt(0); sr.Thread.ActiveFrame.RemapFunction(newILOffset); Debugger.Processes.Active.Threads.RefreshStack(); WriteOutput("Remap successful."); } }