Exemplo n.º 1
0
        protected override object DoExecute(ScriptingContext context)
        {
            Event handle;

            if (!address.IsNull)
            {
                handle = context.Interpreter.Session.InsertBreakpoint(
                    context.CurrentThread, tgroup, address);
                context.Print("Breakpoint {0} at {1}", handle.Index, address);
            }
            else if (location != null)
            {
                // line breakpoints use this method!
                handle = context.Interpreter.Session.InsertBreakpoint(
                    tgroup, location);
                context.Print("Breakpoint {0} at {1}", handle.Index, location.Name);
            }
            else
            {
                handle = context.Interpreter.Session.InsertBreakpoint(
                    tgroup, type, Argument);
                context.Print("Breakpoint {0} at {1}", handle.Index, Argument);
            }

            if (!context.Interpreter.HasTarget)
            {
                EmonicInterpreter.breakpointNumber = handle.Index;
                EmonicInterpreter.breakpointSem.Release();
                return(handle.Index);
            }

            try {
                handle.Activate(context.Interpreter.CurrentThread);
            } catch {
                if (!lazy)
                {
                    EmonicInterpreter.breakpointNumber = -1;
                    EmonicInterpreter.breakpointSem.Release();
                    throw;
                }
            }

            EmonicInterpreter.breakpointNumber = handle.Index;
            EmonicInterpreter.breakpointSem.Release();

            return(handle.Index);
        }
Exemplo n.º 2
0
        protected override string Execute(ScriptingContext context,
                                          Expression expression, DisplayFormat format)
        {
            // try-catch block for whole method: if an exception occurs, we are able to
            // release the semaphore waiting for the command answer
            try {
                TargetType type = expression.EvaluateType(context);

                string fieldNames           = "";
                string fieldNamesStaticOnly = "";
                if (type.Kind == TargetObjectKind.Class || type.Kind == TargetObjectKind.Struct)
                {
                    TargetClassType stype = (TargetClassType)type;
                    foreach (TargetFieldInfo field in stype.Fields)
                    {
                        fieldNames += field.Name;
                        fieldNames += " ";
                        if (field.IsStatic)
                        {
                            fieldNamesStaticOnly += field.Name;
                            fieldNamesStaticOnly += " ";
                        }
                    }
                    fieldNames           = fieldNames.Trim();
                    fieldNamesStaticOnly = fieldNamesStaticOnly.Trim();
                }
                string text = context.FormatType(type);
                context.Print(text);

                EmonicInterpreter.ptypeOutput           = fieldNames;
                EmonicInterpreter.ptypeOutputStaticOnly = fieldNamesStaticOnly;
                EmonicInterpreter.ptypeSem.Release();

                return(text);
            } catch {
                EmonicInterpreter.ptypeOutput           = "--";
                EmonicInterpreter.ptypeOutputStaticOnly = "--";
                EmonicInterpreter.ptypeSem.Release();
                throw;
            }
        }
Exemplo n.º 3
0
            protected override object DoExecute(ScriptingContext context)
            {
                int current_id = -1;

                if (context.Interpreter.HasCurrentThread)
                {
                    current_id = context.Interpreter.CurrentThread.ID;
                }

                bool printed_something = false;

                Process[] processes = context.Interpreter.Processes;
                for (int i = 0; i < processes.Length; i++)
                {
                    context.Print("Process {0}:",
                                  context.Interpreter.PrintProcess(processes[i]));

                    Mono.Debugger.Thread[] threads = processes[i].GetThreads();
                    for (int j = 0; j < threads.Length; j++)
                    {
                        string prefix = threads[j].ID == current_id ? "(*)" : "   ";
                        context.Print("{0} {1} ({2}:{3:x}) {4}", prefix, threads[j],
                                      threads[j].PID, threads[j].TID, threads[j].State);
                        printed_something = true;

                        EmonicInterpreter.threadData td = new EmonicInterpreter.threadData();
                        td.processNumber  = processes[i].ID;
                        td.PID            = processes[i].MainThread.PID;
                        td.processCmdLine = context.Interpreter.PrintCommandLineArgs(processes[i]);
                        td.threadNumber   = threads[j].ID;
                        if ((threads[j].ThreadFlags & Mono.Debugger.Thread.Flags.Daemon) != 0)
                        {
                            td.daemonThread = true;
                        }
                        else
                        {
                            td.daemonThread = false;
                        }
                        td.threadState   = threads[j].State != Mono.Debugger.TargetState.Stopped;
                        td.currentThread = threads[j].ID == current_id;
                        td.TID           = threads[j].PID;               // we take the PID of the thread here, not really the TID
                        td.moreData      = j + 1 < threads.Length || i + 1 < processes.Length;

                        EmonicInterpreter.threadList.Add(td);
                    }
                }

                if (!printed_something)
                {
                    context.Print("No target.");

                    // generate an invalid response
                    EmonicInterpreter.threadData td = new EmonicInterpreter.threadData();
                    td.processNumber  = -1;
                    td.PID            = -1;
                    td.processCmdLine = "";
                    td.threadNumber   = -1;
                    td.daemonThread   = false;
                    td.threadState    = false;
                    td.currentThread  = false;
                    td.TID            = -1;
                    td.moreData       = false;
                    EmonicInterpreter.threadList.Add(td);
                }
                return(null);
            }
Exemplo n.º 4
0
        protected override object DoExecute(ScriptingContext context)
        {
            Backtrace backtrace = null;

            if ((mode == Backtrace.Mode.Default) && (max_frames == -1))
            {
                backtrace = CurrentThread.CurrentBacktrace;
            }

            if (backtrace == null)
            {
                backtrace = CurrentThread.GetBacktrace(mode, max_frames);
            }

            for (int i = 0; i < backtrace.Count; i++)
            {
                string prefix = i == backtrace.CurrentFrameIndex ? "(*)" : "   ";
                context.Print("{0} {1}", prefix, backtrace [i]);

                EmonicInterpreter.backtraceData bt = new EmonicInterpreter.backtraceData();
                bt.frameNumber  = backtrace[i].Level;
                bt.currentFrame = i == backtrace.CurrentFrameIndex;
                if (backtrace[i].Method != null)
                {
                    bt.method = backtrace[i].Method.Name;
                    if (bt.method == null)
                    {
                        bt.method = "";
                    }
                }
                else
                {
                    if (backtrace[i].Name == null)
                    {
                        bt.method = "";
                    }
                    else
                    {
                        bt.method = backtrace[i].Name.ToString();
                        if (bt.method == null)
                        {
                            bt.method = "";
                        }
                    }
                }
                if (backtrace[i].SourceAddress != null && backtrace[i].SourceAddress.SourceFile != null)
                {
                    bt.file = backtrace[i].SourceAddress.SourceFile.FileName;
                }
                else
                {
                    bt.file = "";
                }
                if (backtrace[i].SourceAddress != null)
                {
                    bt.lineNumber = backtrace[i].SourceAddress.Row;
                }
                else
                {
                    bt.lineNumber = -1;
                }
                if (i + 1 < backtrace.Count)
                {
                    bt.moreData = true;
                }
                else
                {
                    bt.moreData = false;
                }
                EmonicInterpreter.backtraceList.Add(bt);
            }

            return(backtrace);
        }
Exemplo n.º 5
0
        protected override string Execute(ScriptingContext context,
                                          Expression expression, DisplayFormat format)
        {
            try {
                if (expression is TypeExpression)
                {
                    throw new ScriptingException(
                              "`{0}' is a type, not a variable.", expression.Name);
                }
                object retval = expression.Evaluate(context);

                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type     = "";
                output.varValue = "";
                output.varNames = "";

                if (retval != null)
                {
                    output.type = ((TargetObject)retval).TypeName;
                    if (output.type == null)
                    {
                        output.type = "";
                    }

                    switch (((TargetObject)retval).Kind)
                    {
                    case TargetObjectKind.Fundamental:
                        // we send the value of the fundamental type
                        TargetFundamentalObject tfo = retval as TargetFundamentalObject;
                        if (tfo == null)
                        {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        output.varValue = tfo.GetObject(context.CurrentThread).ToString();
                        if (output.varValue == null)
                        {
                            output.varValue = "";
                        }
                        break;

                    case TargetObjectKind.Array:
                        // we send back the number of array elements
                        TargetArrayObject tao = retval as TargetArrayObject;
                        if (tao == null)
                        {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        int lower = tao.GetLowerBound(context.CurrentThread, 0);
                        int upper = tao.GetUpperBound(context.CurrentThread, 0);
                        output.varNames = (upper - lower).ToString();
                        break;

                    // same for struct and class
                    case TargetObjectKind.Struct:
                    case TargetObjectKind.Class:
                        // we send back the member's names
                        // NOTE! we also show static and constant fields
                        TargetObject obj = retval as TargetObject;
                        if (obj.HasAddress && obj.GetAddress(context.CurrentThread).IsNull)
                        {
                            output.varValue = "<null>";
                            break;
                        }
                        Mono.Debugger.Thread thread = context.CurrentThread;
                        TargetClass          tc     = ((TargetClassObject)retval).Type.GetClass(thread);
                        if (tc == null)
                        {
                            break;
                        }
                        TargetFieldInfo[] tfi = tc.GetFields(thread);
                        if (tfi == null)
                        {
                            break;
                        }
                        output.varNames = "";
                        for (int i = 0; i < tfi.Length; i++)
                        {
                            if (tfi[i].IsStatic)                             // do not show static fields, they're not accessible via the instance!
                            {
                                continue;
                            }
                            output.varNames += tfi[i].Name;
                            output.varNames += " ";
                        }
                        output.varNames = output.varNames.Trim();
                        break;

                    case TargetObjectKind.Object:
                    case TargetObjectKind.Pointer:
                    case TargetObjectKind.Unknown:
                    case TargetObjectKind.Function:
                    case TargetObjectKind.Alias:
                    case TargetObjectKind.Enum:
                        context.Print("ERROR: Print Command will return no values because of an implementation error");
                        break;
                    }
                }
                string text = context.FormatObject(retval, format);
                context.Print(text);

                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();

                return(text);
            } catch {
                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type     = "";
                output.varValue = "";
                output.varNames = "";
                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();
                throw;
            }
        }