예제 #1
0
        private void SerializeArguments(CallStackEntry callStackEntry)
        {
            var methodInfo = callStackEntry.BreakpointMetadata.Details.MethodInfo;

            shell.WriteLine("Captured arguments for {0}", callStackEntry.BreakpointMetadata.Details.Method.name);
            var path = Path.Combine(GetWorkingDirectory(), string.Format("{0}.{1}-{2}-{3}-arguments.txt", methodInfo.DeclaringType.FullName, methodInfo.Name, methodInfo.MetadataToken, callStackEntry.Identifier));

            parameterSerializer.Serialize(path, GetArguments());
        }
예제 #2
0
        private void WaitForBreakpointHit(Stack <CallStackEntry> bpStack)
        {
            while (true)
            {
                try
                {
                    shell.Debugger.Processes.Active.Go().WaitOne();

                    if (shell.Debugger.Processes.Active.StopReason is BreakpointHitStopReason)
                    {
                        var bp = ((BreakpointHitStopReason)shell.Debugger.Processes.Active.StopReason).Breakpoint;
                        var breakpointMetadata = breakpointMetadataList[bp];
                        var languageUtil       = shell.GetLanguageUtil(breakpointMetadata.Details.Method.assembly.language);

                        CallStackEntry stackItem;
                        switch (breakpointMetadata.Reason)
                        {
                        case BreakpointReason.MethodEntry:
                            stackItem = new CallStackEntry {
                                BreakpointMetadata = breakpointMetadata
                            };
                            bpStack.Push(stackItem);
                            breakpointMetadata.Details.HitCount++;
                            SerializeArguments(stackItem);
                            break;

                        case BreakpointReason.MethodExit:
                            stackItem = bpStack.Pop();
                            IEnumerable <MDbgValue> locals = GetActiveLocalVariables();
                            string resultFieldName         = string.IsNullOrEmpty(breakpointMetadata.Details.Method.resultField) ? languageUtil.GuessResultFieldName() : breakpointMetadata.Details.Method.resultField;
                            var    result = locals.Where(l => l.Name == resultFieldName).FirstOrDefault();
                            if (result != null)
                            {
                                SerializeReturnValue(result, stackItem);
                            }

                            //Write out the method info
                            if (breakpointMetadata.Details.HitCount == breakpointMetadata.Details.Method.maxCaptures)
                            {
                                var removables = breakpointMetadataList.Where(p => p.Value.Details.Method == breakpointMetadata.Details.Method).ToList();
                                foreach (var r in removables)
                                {
                                    r.Key.Delete();
                                    breakpointMetadataList.Remove(r.Key);

                                    //No more breakpoints left. Exit.
                                    if (breakpointMetadataList.Count == 0)
                                    {
                                        shell.WriteLine("Finished capturing. Debugger can now detach.");
                                        return;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    shell.WriteLine(ex.ToString());
                    return;
                }
            }
        }
예제 #3
0
        private void SerializeReturnValue(Microsoft.Samples.Debugging.MdbgEngine.MDbgValue value, CallStackEntry callStackEntry)
        {
            var methodInfo = callStackEntry.BreakpointMetadata.Details.MethodInfo;

            shell.WriteLine("Captured return value for {0}", methodInfo.Name);
            var path = Path.Combine(GetWorkingDirectory(), string.Format("{0}.{1}-{2}-{3}-returnvalue.txt", methodInfo.DeclaringType.FullName, methodInfo.Name, methodInfo.MetadataToken, callStackEntry.Identifier));

            parameterSerializer.Serialize(path, new MDbgValue[] { value });
        }
예제 #4
0
        private void WaitForBreakpointHit(Stack<CallStackEntry> bpStack)
        {
            while (true)
            {
                try
                {
                    shell.Debugger.Processes.Active.Go().WaitOne();

                    if (shell.Debugger.Processes.Active.StopReason is BreakpointHitStopReason)
                    {
                        var bp = ((BreakpointHitStopReason)shell.Debugger.Processes.Active.StopReason).Breakpoint;
                        var breakpointMetadata = breakpointMetadataList[bp];
                        var languageUtil = shell.GetLanguageUtil(breakpointMetadata.Details.Method.assembly.language);

                        CallStackEntry stackItem;
                        switch (breakpointMetadata.Reason)
                        {
                            case BreakpointReason.MethodEntry:
                                stackItem = new CallStackEntry { BreakpointMetadata = breakpointMetadata };
                                bpStack.Push(stackItem);
                                breakpointMetadata.Details.HitCount++;
                                SerializeArguments(stackItem);
                                break;

                            case BreakpointReason.MethodExit:
                                stackItem = bpStack.Pop();
                                IEnumerable<MDbgValue> locals = GetActiveLocalVariables();
                                string resultFieldName = string.IsNullOrEmpty(breakpointMetadata.Details.Method.resultField) ? languageUtil.GuessResultFieldName() : breakpointMetadata.Details.Method.resultField;
                                var result = locals.Where(l => l.Name == resultFieldName).FirstOrDefault();
                                if (result != null)
                                    SerializeReturnValue(result, stackItem);

                                //Write out the method info
                                if (breakpointMetadata.Details.HitCount == breakpointMetadata.Details.Method.maxCaptures)
                                {
                                    var removables = breakpointMetadataList.Where(p => p.Value.Details.Method == breakpointMetadata.Details.Method).ToList();
                                    foreach (var r in removables)
                                    {
                                        r.Key.Delete();
                                        breakpointMetadataList.Remove(r.Key);

                                        //No more breakpoints left. Exit.
                                        if (breakpointMetadataList.Count == 0)
                                        {
                                            shell.WriteLine("Finished capturing. Debugger can now detach.");
                                            return;
                                        }
                                    }
                                }
                                break;
                        }
                    }
                }
                catch(Exception ex)
                {
                    shell.WriteLine(ex.ToString());
                    return;
                }
            }
        }
예제 #5
0
 private void SerializeReturnValue(Microsoft.Samples.Debugging.MdbgEngine.MDbgValue value, CallStackEntry callStackEntry)
 {
     var methodInfo = callStackEntry.BreakpointMetadata.Details.MethodInfo;
     shell.WriteLine("Captured return value for {0}", methodInfo.Name);
     var path = Path.Combine(GetWorkingDirectory(), string.Format("{0}.{1}-{2}-{3}-returnvalue.txt", methodInfo.DeclaringType.FullName, methodInfo.Name, methodInfo.MetadataToken, callStackEntry.Identifier));
     parameterSerializer.Serialize(path, new MDbgValue[] { value });
 }
예제 #6
0
 private void SerializeArguments(CallStackEntry callStackEntry)
 {
     var methodInfo = callStackEntry.BreakpointMetadata.Details.MethodInfo;
     shell.WriteLine("Captured arguments for {0}", callStackEntry.BreakpointMetadata.Details.Method.name);
     var path = Path.Combine(GetWorkingDirectory(), string.Format("{0}.{1}-{2}-{3}-arguments.txt", methodInfo.DeclaringType.FullName, methodInfo.Name, methodInfo.MetadataToken, callStackEntry.Identifier));
     parameterSerializer.Serialize(path, GetArguments());
 }