Beispiel #1
0
        static CommandLine()
        {
            Root        = new RootCommand();
            ResumeEvent = new AutoResetEvent(false);

            try
            {
                LibEdit.Initialize();
            }
            catch (DllNotFoundException)
            {
                // Fall back to `Mono.Terminal.LineEditor`.
                _lineEditor = new LineEditor(null);
            }
        }
Beispiel #2
0
        static void Process(string cmd, bool rc)
        {
            if (!rc && _lineEditor == null)
            {
                LibEdit.AddHistory(cmd);
            }

            var args = cmd.Trim();

            if (args.Length == 0)
            {
                return;
            }

            try
            {
                Root.Process(args);
            }
            catch (Exception ex)
            {
                Log.Error("Command threw an exception:");
                Log.Error(ex.ToString());
            }
        }
Beispiel #3
0
        internal static void Run(Version ver, bool batch, bool rc,
                                 IEnumerable <string> commands,
                                 IEnumerable <string> files)
        {
            if (!Configuration.Read())
            {
                Configuration.Defaults();
            }

            Configuration.Apply();

            var dbFile = Configuration.Current.DefaultDatabaseFile;

            if (Configuration.Current.LoadDatabaseAutomatically &&
                !string.IsNullOrWhiteSpace(dbFile))
            {
                FileInfo file;

                try
                {
                    file = new FileInfo(dbFile);
                }
                catch (Exception ex)
                {
                    Log.Error("Could not open database file '{0}':", dbFile);
                    Log.Error(ex.ToString());

                    return;
                }

                Debugger.Read(file);
            }

            Log.Notice("Welcome to the Mono soft debugger (sdb {0})", ver);
            Log.Notice("Type 'help' for a list of commands or 'quit' to exit");
            Log.Info(string.Empty);

            Root.AddCommands(Plugins.LoadDefault());

            var rcFile = GetFilePath();

            if (rc && File.Exists(rcFile))
            {
                RunFile(rcFile, true);
            }

            foreach (var file in files)
            {
                if (File.Exists(file))
                {
                    RunFile(file, true);
                }
            }

            RunCommands(commands);

            while (!Stop)
            {
                // If the command caused the debuggee to start
                // or resume execution, wait for it to suspend.
                if (InferiorExecuting)
                {
                    ResumeEvent.WaitOne();
                    InferiorExecuting = false;
                }

                string cmd;

                // We use a queue here so that batch commands are
                // also subject to the suspension check above. It
                // also makes things easier since everything gets
                // executed in one thread.
                if (_queue.TryDequeue(out cmd))
                {
                    Process(cmd, true);
                }
                else if (batch)
                {
                    Stop = true;
                }
                else
                {
                    cmd = _lineEditor != null?
                          _lineEditor.Edit(GetPrompt(), string.Empty) :
                              LibEdit.ReadLine(GetPrompt());

                    // Did we get EOF?
                    if (cmd == null)
                    {
                        Log.Info(string.Empty);

                        if (Debugger.State != State.Exited)
                        {
                            Log.Error("An inferior process is active");
                        }
                        else
                        {
                            Stop = true;
                        }
                    }
                    else
                    {
                        Process(cmd, false);
                    }
                }
            }

            // Clean up just in case.
            UnsetControlCHandler();

            dbFile = Configuration.Current.DefaultDatabaseFile;

            if (Configuration.Current.SaveDatabaseAutomatically &&
                !string.IsNullOrWhiteSpace(dbFile))
            {
                FileInfo file;

                try
                {
                    file = new FileInfo(dbFile);
                }
                catch (Exception ex)
                {
                    Log.Error("Could not open database file '{0}':", dbFile);
                    Log.Error(ex.ToString());

                    return;
                }

                Debugger.Write(file);
            }

            // Let's not leave dead Mono processes behind...
            Debugger.Pause();
            Debugger.Kill();

            while (!Debugger.DebuggeeKilled)
            {
                Thread.Sleep(10);
            }

            Log.Notice("Bye");
        }