public void dump_global_heap(DebuggerCore debugger)
 {
     foreach (var sel in _machine.GlobalHeap.AllSelectors)
     {
         debugger.WriteLine("0x{0:X4} - {1}", sel.selector, sel.name);
     }
 }
Пример #2
0
        public override bool ShouldBreak(DebuggerCore debugger)
        {
            bool t = _tripped;

            _tripped = false;
            return(t);
        }
        public void dump_module(DebuggerCore debugger, string modulename)
        {
            // Get the module
            var m = _machine.ModuleManager.GetModule(modulename);

            if (m == null)
            {
                debugger.WriteLine("Module '{0}' not found", modulename);
                return;
            }

            debugger.WriteLine("0x{0:X4} {1} {2}", m.hModule, m is Module32 ? "[32]" : "[16]", m.GetModuleName());

            // Dump related selectors
            debugger.WriteLine("\nSelectors:");
            var prefix = string.Format("Module '{0}'", modulename);

            foreach (var sel in _machine.GlobalHeap.AllSelectors.Where(x => x.name.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)))
            {
                debugger.WriteLine("0x{0:X4} - {1}", sel.selector, sel.name);
            }

            debugger.WriteLine("\nExports:");
            foreach (var ord in m.GetExports())
            {
                uint procAddress = m.GetProcAddress(ord);
                debugger.WriteLine("{0:X4} 0x{1:X4}:{2:X4} {3}", ord, procAddress.Hiword(), procAddress.Loword(), m.GetNameFromOrdinal(ord));
            }
        }
 public void dump_modules(DebuggerCore debugger)
 {
     foreach (var m in _machine.ModuleManager.AllModules)
     {
         debugger.WriteLine("0x{0:X4} {1} {2}", m.hModule, m is Module32 ? "[32]" : "[16]", m.GetModuleName());
     }
 }
 public void dump_file_handles(DebuggerCore debugger)
 {
     foreach (var file in _machine.Dos.OpenFiles)
     {
         debugger.WriteLine("#{0} @{1} mode:{2} access:{3} share:{4} - {5} ({6})",
                            file.handle,
                            file.mode,
                            file.access,
                            file.share,
                            file.guestFilename,
                            file.hostFilename);
     }
 }
        public void dump_call_stack(DebuggerCore debugger)
        {
            bool first = true;

            foreach (var e in _machine.StackWalker.WalkStack())
            {
                if (first)
                {
                    debugger.Write("→");
                    first = false;
                }
                else
                {
                    debugger.Write(" ");
                }
                debugger.WriteLine("  0x{0:X4}:{1:X4} [stack={2:X4}] {3}", e.csip.Hiword(), e.csip.Loword(), e.sp, e.name);
            }
        }
        public void file_source(DebuggerCore debugger, FarPointer address)
        {
            // Get the selector
            var sel = _machine.GlobalHeap.GetSelector(address.Segment);

            if (sel == null || sel.allocation == null || sel.allocation.filename == null)
            {
                debugger.WriteLine("No associated source file");
                return;
            }

            uint offset = (uint)(((address.Segment >> 3) - sel.selectorIndex) << 16 | address.Offset);

            if (offset > sel.allocation.buffer.Length)
            {
                debugger.WriteLine("Address is past end of allocation");
                return;
            }

            debugger.WriteLine("VM address 0x{0:X4}:{1:X4} => {2}:{3:X8}",
                               address.Segment, address.Offset,
                               System.IO.Path.GetFileName(sel.allocation.filename), sel.allocation.fileoffset + offset);
        }
 public void bp_wndproc(DebuggerCore debugger)
 {
     debugger.AddBreakPoint(new WndProcBreakPoint());
 }
Пример #9
0
        public int RunProgram(string programName, string[] commandArgs, int nCmdShow)
        {
            try
            {
                var cl = new Utils.CommandLine(commandArgs);

                // Store the program path
                ProgramHostPath = System.IO.Path.GetFullPath(programName);

                // Work out base name for the program (we'll use this to merge program specific configuration settings)
                var baseProgramName = System.IO.Path.GetFileNameWithoutExtension(programName).ToLowerInvariant();

                // Create merged config
                var config = new Dictionary <string, object>();
                MergeConfig(cl.Config, baseProgramName, config, VariableResolver.Resolve("$(Win3muFolder)\\config.json"));
                MergeConfig(cl.Config, baseProgramName, config, VariableResolver.Resolve("$(AppData)\\Win3mu\\config.json"));
                MergeConfig(cl.Config, baseProgramName, config, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(programName), "config.json"));
                MergeConfig(cl.Config, baseProgramName, config, System.IO.Path.ChangeExtension(programName, ".json"));
                Json.ReparseInto(this, config);

                // Need console?
                if (enableDebugger || consoleLogger)
                {
                    ConsoleHelper.CreateConsole();
                }

                // Initialize logging
                Log.Init(consoleLogger, VariableResolver.Resolve(fileLogger));
                _pathMapper.Prepare(mountPoints);
                _dos.EnableApiLogging  = logApiCalls;
                _dos.EnableFileLogging = logFileOperations;

                // Log configuration
                Log.WriteLine("Configuration:");
                Log.WriteLine(Json.Format(config));
                Log.WriteLine("");

                // Connect debugger?
                if (enableDebugger)
                {
                    // Connect debugger
                    _debugger     = new Debugging.Win3muDebugger(this);
                    _debugger.CPU = this;
                    _debugger.ExpressionContext = ExpressionContext;
                    _debugger.CommandDispatcher.RegisterCommandHandler(new Win3muCore.Debugging.DebuggerCommandExtensions(this));
                    _debugger.SettingsFile = VariableResolver.Resolve(DebuggerSettingsFile);

                    if (DebuggerCommands != null)
                    {
                        foreach (var cmd in DebuggerCommands)
                        {
                            _debugger.CommandDispatcher.EnqueueCommand(cmd);
                        }
                    }

                    // Break immediately?
                    if (cl.Break || breakOnLoad || DebuggerCommands != null && DebuggerCommands.Count > 0)
                    {
                        _debugger.Break();
                    }
                }

                // Setup execution logging
                _logExecutionFormat = VariableResolver.TokenizeString(logExecutionFormat);

                // Map the program name to 8.3 name
                var programName16 = _pathMapper.MapHostToGuest(programName, false);

                // Set the current directory
                _dos.WorkingDirectory = System.IO.Path.GetDirectoryName(programName16);

                // Look for unqualified dll paths in same folder as the program
                _moduleManager.SetProcessPath(System.IO.Path.GetDirectoryName(programName16));

                // Load the executable module
                ProcessModule = _moduleManager.LoadModule(programName16) as Module16;
                ProcessModule.PrepareRun(this, cl.CommandTail16, nCmdShow);

                Log.WriteLine("Starting program...");

                _stackWalker.EnterTransition("WinMain");

                try
                {
                    // Run until finished
                    while (!_finished)
                    {
                        Run(1000000);
                    }
                }
                finally
                {
                    _stackWalker.LeaveTransition();
                }

                Log.WriteLine("Program finished with exit code {0}.", _exitCode);

                ProcessModule = null;

                Log.Flush();

                return(_exitCode);
            }
            catch (Exception x)
            {
                Log.WriteLine(x.Message);
                Log.Flush();
                throw;
            }
        }