Ejemplo n.º 1
0
        public void Execute(CommandArguments args)
        {
            var hasArgs = args.HasArguments;
            var lowerOffset = 0;
            var upperOffset = 0;

            if (hasArgs)
            {
                lowerOffset = args.NextInt32();
                upperOffset = args.NextInt32();

                if (upperOffset < 0)
                {
                    Logger.WriteErrorLine("Invalid line count.");
                    return;
                }
            }

            var backtrace = SoftDebugger.Backtrace;

            if (backtrace == null)
            {
                Logger.WriteErrorLine("No backtrace available.");
                return;
            }

            var frame = backtrace.CurrentStackFrame;

            if (frame == null)
            {
                Logger.WriteErrorLine("No stack frame available.");
                return;
            }

            if (hasArgs)
                upperOffset += System.Math.Abs(lowerOffset);

            var disasm = frame.Disassemble(hasArgs ? lowerOffset : -10, hasArgs ? upperOffset + 1 : 20);

            foreach (var line in disasm)
            {
                if (line.IsOutOfRange)
                    continue;

                var str = string.Format("{0}:\t{1}", line.Address.ToString(Environment.Is64BitProcess ? "X8" : "X4"), line.Code);

                if (line.Address == frame.Address)
                    Logger.WriteEmphasisLine("{0}", str);
                else
                    Logger.WriteInfoLine("{0}", str);
            }
        }
Ejemplo n.º 2
0
        public void Execute(CommandArguments args)
        {
            var op = args.NextString(string.Empty);

            if (SoftDebugger.State == DebuggerState.Null)
            {
                Logger.WriteErrorLine("No session active.");
                return;
            }

            var session = SoftDebugger.Session;

            switch (op.ToLower())
            {
                case "add":
                    var file = args.NextString();
                    var line = args.NextInt32();

                    if (line < 1)
                    {
                        Logger.WriteErrorLine("Invalid line number.");
                        return;
                    }

                    session.Breakpoints.Add(file, line, true);

                    Logger.WriteInfoLine("Added breakpoint: {0}:{1}", file, line);
                    return;
                case "set":
                    var frame = args.NextInt32();
                    var setLine = args.NextInt32();

                    var bt = SoftDebugger.Backtrace;

                    if (bt == null)
                    {
                        Logger.WriteErrorLine("No backtrace available.");
                        return;
                    }

                    if (frame < 0 || frame > bt.CurrentBacktrace.Count - 1)
                    {
                        Logger.WriteErrorLine("Invalid stack frame.");
                        return;
                    }

                    if (setLine < 1)
                    {
                        Logger.WriteErrorLine("Invalid line number.");
                        return;
                    }

                    var fileName = bt.CurrentBacktrace[frame].SourceLocation.FileName;
                    session.Breakpoints.Add(fileName, setLine);

                    Logger.WriteInfoLine("Set breakpoint: {0}:{1}");
                    return;
                case "del":
                    var delFile = args.NextString();
                    var delLine = args.NextInt32();

                    if (delLine < 1)
                    {
                        Logger.WriteErrorLine("Invalid line number.");
                        return;
                    }

                    session.Breakpoints.Remove(delFile, delLine);

                    Logger.WriteInfoLine("Deleted breakpoint: {0}:{1}", delFile, delLine);
                    return;
                case "clear":
                    session.Breakpoints.ClearBreakpoints();

                    Logger.WriteInfoLine("Cleared all breakpoints.");
                    return;
                case "":
                    Logger.WriteInfoLine("Breakpoints:");

                    foreach (var bp in session.Breakpoints.GetBreakpoints())
                        Logger.WriteInfoLine("{0}:{1}", bp.FileName, bp.Line);
                    return;
            }

            Logger.WriteErrorLine("Unknown breakpoint operation: {0}", op);
        }
Ejemplo n.º 3
0
        public void Execute(CommandArguments args)
        {
            var hasArgs = args.HasArguments;
            var lowerOffset = 0;
            var upperOffset = 0;

            if (hasArgs)
            {
                lowerOffset = args.NextInt32();
                upperOffset = args.NextInt32();

                if (upperOffset < 0)
                {
                    Logger.WriteErrorLine("Invalid line count.");
                    return;
                }
            }

            var backtrace = SoftDebugger.Backtrace;

            if (backtrace == null)
            {
                Logger.WriteErrorLine("No backtrace available.");
                return;
            }

            var frame = backtrace.CurrentStackFrame;

            if (frame == null)
            {
                Logger.WriteErrorLine("No stack frame available.");
                return;
            }

            var loc = frame.SourceLocation;

            if (loc.HasSource())
            {
                var fileName = loc.FileName;
                var line = loc.Line;
                var reader = SoftDebugger.Session.GetSourceReader(fileName);

                if (reader != null)
                {
                    if (File.GetLastWriteTime(fileName) > SoftDebugger.CurrentExecutable.LastWriteTime)
                        Logger.WriteWarningLine("Source file {0} is newer than the debugged executable!", fileName);

                    var start = hasArgs ? line + lowerOffset : line - 5;

                    if (start < 0)
                        start = 0;

                    var end = (hasArgs ? line + upperOffset : start + 10) + 1;

                    for (var i = 0; i < end - 1; i++)
                    {
                        var src = reader.ReadLine();

                        if (i < start - 1)
                            continue;

                        if (i == line - 1)
                            Logger.WriteEmphasisLine("{0}", src);
                        else
                            Logger.WriteInfoLine("{0}", src);

                        if (reader.EndOfStream)
                            break;
                    }
                }
                else
                    Logger.WriteErrorLine("Could not locate source code file: {0}", fileName);
            }
            else
                Logger.WriteErrorLine("Source code not available.");
        }