コード例 #1
0
        void UnhandledException(object sender, UnhandledExceptionEventArgs args)
        {
            // Dump global heap
            Log.WriteLine("\nGlobal Heap Map:");
            foreach (var sel in GlobalHeap.AllSelectors)
            {
                Log.WriteLine("0x{0:X4} len:0x{1:X4} - {2}",
                              sel.selector,
                              (sel.allocation == null || sel.allocation == null) ? 0 : sel.allocation.buffer.Length,
                              sel.name);
            }

            Log.WriteLine("\nCall Stack:");
            bool first = true;

            foreach (var e in StackWalker.WalkStack())
            {
                Log.WriteLine("{0} 0x{1:X4}:{2:X4} [stack={3:X4}] {4}", first ? "→" : " ",
                              e.csip.Hiword(), e.csip.Loword(), e.sp, e.name);
                first = false;
            }


            // Dump exception
            Log.WriteLine("\nUnhandled Exception:");
            Log.WriteLine(args.ExceptionObject.ToString());

            // Flush log
            Log.Flush();

            // Prevent re-entrancy while message box is shown
            IsStoppedInDebugger = true;

            // Unwrap useless exception wrapper
            var x = args.ExceptionObject as Exception;

            while (x is System.Reflection.TargetInvocationException)
            {
                x = x.InnerException;
            }

            User.MessageBox(IntPtr.Zero,
                            string.Format("An unrecoverable error has occurred:\n\n{0}", x.Message),
                            string.Format("{0} (via Win3mu)", System.IO.Path.GetFileName(ProgramHostPath)),
                            Win32.MB_OK | Win32.MB_ERROR | Win32.MB_TASKMODAL);

            // Kill the process
            System.Diagnostics.Process.GetCurrentProcess().Kill();
        }
コード例 #2
0
        public Machine()
        {
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += UnhandledException;
            }
            else
            {
                enableDebugger = true;
                logExecution   = true;
            }

            _pathMapper        = new PathMapper(this);
            _globalHeap        = new GlobalHeap(this);
            _stringHeap        = new StringHeap(this);
            _moduleManager     = new ModuleManager(this);
            _messaging         = new Messaging(this);
            _variableResolver  = new VariableResolver();
            _expressionContext = new ExpressionContext(this);
            _symbolResolver    = new SymbolResolver(this);
            _stackWalker       = new StackWalker(this);
            _expressionContext.PushSymbolScope(_symbolResolver);

            this.MemoryBus = _globalHeap;

            RegisterVariables();

            // Create system heaps
            _systemCodeSelector = _globalHeap.Alloc("System Thunks", 0, 0x10000);
            _globalHeap.SetSelectorAttributes(_systemCodeSelector, true, true);
            _systemDataHeap = _globalHeap.CreateLocalHeap("System Local Heap", 0);
            _globalHeap.SetSelectorAttributes(_systemDataHeap.GlobalHandle, false, false);

            // Initialise the system return thunk
            CreateSysRetThunk();

            // Creae DOS Api handler
            _dos = new DosApi(this, this);

            // Load standard modules
            _kernel = _moduleManager.LoadModule(new Kernel()) as Kernel;
            _user   = _moduleManager.LoadModule(new User()) as User;
            _moduleManager.LoadModule(new Gdi());
            _moduleManager.LoadModule(new MMSystem());
            _moduleManager.LoadModule(new Keyboard());
//            _moduleManager.LoadModule(new Shell());
            _moduleManager.LoadModule(new DdeML());
            _moduleManager.LoadModule(new Sound());

            _disassembler = new Disassembler(this);

            this.InstructionHook = () =>
            {
                if (logExecution)
                {
                    _disassembled = null;
                    Log.WriteLine(_variableResolver.ResolveTokenizedString(_logExecutionFormat));
                }
            };
        }