Example #1
0
        //this constructor is private because it should only be used internally to create children
        private VariableInformation(TupleValue results, VariableInformation parent)
            : this(parent._ctx, parent._engine, parent.Client)
        {
            TypeName      = results.TryFindString("type");
            Value         = results.TryFindString("value");
            Name          = results.FindString("exp");
            CountChildren = results.FindUint("numchild");
            int index;

            if (!results.Contains("value") && (Name == TypeName || Name.Contains("::")))
            {
                // base classes show up with no value and exp==type
                // (sometimes underlying debugger does not follow this convention, when using typedefs in templated types so look for "::" in the field name too)
                Name             = "base";
                Value            = TypeName;
                VariableNodeType = NodeType.BaseClass;
            }
            else if (Int32.TryParse(this.Name, System.Globalization.NumberStyles.Integer, null, out index)) // array element
            {
                Name             = '[' + this.Name + ']';
                VariableNodeType = NodeType.ArrayElement;
            }
            else
            {
                _strippedName    = Name;
                VariableNodeType = NodeType.Field;
            }

            _internalName = results.FindString("name");
            IsChild       = true;
            _format       = parent._format; // inherit formatting
            _parent       = parent.VariableNodeType == NodeType.AccessQualifier ? parent._parent : parent;
        }
Example #2
0
        //this constructor is private because it should only be used internally to create children
        private VariableInformation(TupleValue results, VariableInformation parent, string name = null)
            : this(parent._ctx, parent._engine, parent.Client)
        {
            TypeName = results.TryFindString("type");
            Value    = results.TryFindString("value");
            Name     = name ?? results.FindString("exp");
            if (results.Contains("dynamic"))
            {
                CountChildren = 1;
            }
            else
            {
                CountChildren = results.FindUint("numchild");
            }
            if (results.Contains("displayhint"))
            {
                DisplayHint = results.FindString("displayhint");
            }
            if (results.Contains("attributes"))
            {
                if (results.FindString("attributes") == "noneditable")
                {
                    _isReadonly = true;
                }
                _attribsFetched = true;
            }

            int index;

            if (!results.Contains("value") && (Name == TypeName || Name.Contains("::")))
            {
                // base classes show up with no value and exp==type
                // (sometimes underlying debugger does not follow this convention, when using typedefs in templated types so look for "::" in the field name too)
                Name             = TypeName + " (base)";
                Value            = TypeName;
                VariableNodeType = NodeType.BaseClass;
            }
            else if (Int32.TryParse(this.Name, System.Globalization.NumberStyles.Integer, null, out index)) // array element
            {
                Name             = '[' + this.Name + ']';
                VariableNodeType = NodeType.ArrayElement;
            }
            else if (this.Name.Length > 2 && this.Name[0] == '[' && this.Name[this.Name.Length - 1] == ']')
            {
                VariableNodeType = NodeType.ArrayElement;
            }
            else
            {
                _strippedName    = Name;
                VariableNodeType = NodeType.Field;
            }

            _internalName          = results.FindString("name");
            IsChild                = true;
            _format                = parent._format; // inherit formatting
            _parent                = parent.VariableNodeType == NodeType.AccessQualifier ? parent._parent : parent;
            this.PropertyInfoFlags = parent.PropertyInfoFlags;
        }
        public static MITextPosition TryParse(TupleValue miTuple)
        {
            string filename = miTuple.TryFindString("fullname");

            if (string.IsNullOrEmpty(filename))
            {
                filename = miTuple.TryFindString("file");
            }
            if (!string.IsNullOrEmpty(filename))
            {
                filename = DebuggedProcess.UnixPathToWindowsPath(filename);
            }

            if (string.IsNullOrWhiteSpace(filename))
            {
                return(null);
            }

            uint?line = miTuple.TryFindUint("line");

            if (!line.HasValue || line.Value == 0)
            {
                return(null);
            }

            uint lineValue = line.Value;

            var startPosition = new TEXT_POSITION()
            {
                dwLine   = lineValue - 1,
                dwColumn = 0
            };

            uint?startColumn = miTuple.TryFindUint("col");

            if (startColumn > 0)
            {
                startPosition.dwColumn = startColumn.Value - 1;
            }

            TEXT_POSITION endPosition = startPosition;
            uint?         endLine     = miTuple.TryFindUint("end-line");

            if (endLine > 0)
            {
                endPosition.dwLine = endLine.Value - 1;

                uint?endCol = miTuple.TryFindUint("end-col");
                if (endCol > 0)
                {
                    endPosition.dwColumn = endCol.Value - 1;
                }
            }

            return(new MITextPosition(filename, startPosition, endPosition));
        }
Example #4
0
 internal BoundBreakpoint(PendingBreakpoint parent, TupleValue bindinfo)
 {
     // CLRDBG TODO: Support clr addresses for breakpoints
     this.Addr         = bindinfo.TryFindAddr("addr") ?? 0;
     this.FunctionName = bindinfo.TryFindString("func");
     this.Enabled      = bindinfo.TryFindString("enabled") == "n" ? false : true;
     this.HitCount     = 0;
     _parent           = parent;
     _textPosition     = MITextPosition.TryParse(bindinfo);
 }
Example #5
0
        private ThreadContext CreateContext(TupleValue frame)
        {
            ulong?         pc           = frame.TryFindAddr("addr");
            MITextPosition textPosition = MITextPosition.TryParse(this._debugger, frame);
            string         func         = frame.TryFindString("func");
            uint           level        = frame.FindUint("level");
            string         from         = frame.TryFindString("from");

            return(new ThreadContext(pc, textPosition, func, level, from));
        }
Example #6
0
        }                                                           // name as it appears in the debug symbols

        internal BoundBreakpoint(PendingBreakpoint parent, TupleValue bindinfo)
        {
            // CLRDBG TODO: Support clr addresses for breakpoints
            this.Addr             = bindinfo.TryFindAddr("addr") ?? 0;
            this.FunctionName     = bindinfo.TryFindString("func");
            this.Enabled          = bindinfo.TryFindString("enabled") == "n" ? false : true;
            this.HitCount         = 0;
            this.CompiledFileName = bindinfo.Contains("fullname") ? bindinfo.FindString("fullname") : bindinfo.TryFindString("file");
            _parent       = parent;
            _textPosition = MITextPosition.TryParse(parent.DebuggedProcess, bindinfo);
        }
Example #7
0
        /// <summary>
        /// Decode the mi results and create a bound breakpoint from it.
        /// </summary>
        /// <param name="bkpt">breakpoint description</param>
        /// <returns>null if breakpoint is pending</returns>
        private async Task <BoundBreakpoint> GetBoundBreakpoint(TupleValue bkpt)
        {
            string            addrString = bkpt.TryFindString("addr");
            MIBreakpointState state      = StringToBreakpointState(addrString);

            if (state == MIBreakpointState.Multiple)
            {
                // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit.
                // When the breakpoint is hit can rebind to actual address.
                bkpt.Content.RemoveAll((keyval) => { return(keyval.Name == "addr"); });
                bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0")));
            }
            else if (state == MIBreakpointState.Pending)
            {
                return(null);
            }
            else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS)
            {
                return(null);
            }

            var bbp = new BoundBreakpoint(this, bkpt);

            // On GDB, the returned line information is from the pending breakpoint instead of the bound breakpoint.
            // Check the address mapping to make sure the line info is correct.
            if (this.DebuggedProcess.MICommandFactory.Mode == MIMode.Gdb && !string.IsNullOrEmpty(bbp.CompiledFileName))
            {
                bbp.Line = await this.DebuggedProcess.LineForStartAddress(bbp.CompiledFileName, bbp.Addr);
            }

            return(bbp);
        }
Example #8
0
        public static MITextPosition TryParse(TupleValue miTuple)
        {
            string filename = miTuple.TryFindString("fullname");
            if (string.IsNullOrEmpty(filename))
            {
                filename = miTuple.TryFindString("file");
            }
            if (!string.IsNullOrEmpty(filename))
            {
                filename = DebuggedProcess.UnixPathToWindowsPath(filename);
            }

            if (string.IsNullOrWhiteSpace(filename))
                return null;

            uint? line = miTuple.TryFindUint("line");
            if (!line.HasValue || line.Value == 0)
                return null;

            uint lineValue = line.Value;

            Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION startPosition = new Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION();
            startPosition.dwLine = lineValue - 1;
            startPosition.dwColumn = 0;

            uint? startColumn = miTuple.TryFindUint("col");
            if (startColumn > 0)
            {
                startPosition.dwColumn = startColumn.Value - 1;
            }

            Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION endPosition = startPosition;
            uint? endLine = miTuple.TryFindUint("end-line");
            if (endLine > 0)
            {
                endPosition.dwLine = endLine.Value - 1;

                uint? endCol = miTuple.TryFindUint("end-col");
                if (endCol > 0)
                {
                    endPosition.dwColumn = endCol.Value - 1;
                }
            }

            return new MITextPosition(filename, startPosition, endPosition);
        }
Example #9
0
        internal BoundBreakpoint(PendingBreakpoint parent, ulong addr, /*optional*/ TupleValue frame)
        {
            Addr     = addr;
            HitCount = 0;
            _parent  = parent;

            if (frame != null)
            {
                this.FunctionName = frame.TryFindString("func");
                _textPosition     = MITextPosition.TryParse(frame);
            }
        }
Example #10
0
        private ThreadContext CreateContext(TupleValue frame)
        {
            ulong?pc = frame.TryFindAddr("addr");

            // don't report source line info for modules marked as IgnoreSource
            bool ignoreSource = false;

            if (pc != null)
            {
                var module = _debugger.FindModule(pc.Value);
                if (module != null && module.IgnoreSource)
                {
                    ignoreSource = true;
                }
            }
            MITextPosition textPosition = !ignoreSource?MITextPosition.TryParse(this._debugger, frame) : null;

            string func  = frame.TryFindString("func");
            uint   level = frame.FindUint("level");
            string from  = frame.TryFindString("from");

            return(new ThreadContext(pc, textPosition, func, level, from));
        }
Example #11
0
        internal BoundBreakpoint(PendingBreakpoint parent, ulong addr, /*optional*/ TupleValue frame, string bkptno)
        {
            Addr        = addr;
            HitCount    = 0;
            Enabled     = true;
            this.Number = bkptno;
            _parent     = parent;

            if (frame != null)
            {
                this.FunctionName = frame.TryFindString("func");
                _textPosition     = MITextPosition.TryParse(parent.DebuggedProcess, frame);
            }
        }
Example #12
0
        /// <summary>
        /// Decode the mi results and create a bound breakpoint from it.
        /// </summary>
        /// <param name="bkpt">breakpoint description</param>
        /// <returns>null if breakpoint is pending</returns>
        private BoundBreakpoint GetBoundBreakpoint(TupleValue bkpt)
        {
            string            addrString = bkpt.TryFindString("addr");
            MIBreakpointState state      = StringToBreakpointState(addrString);

            if (state == MIBreakpointState.Multiple)
            {
                // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit.
                // When the breakpoint is hit can rebind to actual address.
                bkpt.Content.RemoveAll((keyval) => { return(keyval.Name == "addr"); });
                bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0")));
            }
            else if (state == MIBreakpointState.Pending)
            {
                return(null);
            }
            else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS)
            {
                return(null);
            }

            return(new BoundBreakpoint(this, bkpt));
        }
Example #13
0
        /// <summary>
        /// Decode the mi results and create a bound breakpoint from it. 
        /// </summary>
        /// <param name="bkpt">breakpoint description</param>
        /// <returns>null if breakpoint is pending</returns>
        private BoundBreakpoint GetBoundBreakpoint(TupleValue bkpt)
        {
            string addrString = bkpt.TryFindString("addr");
            MIBreakpointState state = StringToBreakpointState(addrString);
            if (state == MIBreakpointState.Multiple)
            {
                // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit. 
                // When the breakpoint is hit can rebind to actual address.
                bkpt.Content.RemoveAll((keyval) => { return keyval.Name == "addr"; });
                bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0")));
            }
            else if (state == MIBreakpointState.Pending)
            {
                return null;
            }
            else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS)
            {
                return null;
            }

            return new BoundBreakpoint(this, bkpt);
        }
Example #14
0
        private ThreadContext CreateContext(TupleValue frame)
        {
            ulong? pc = frame.TryFindAddr("addr");
            MITextPosition textPosition = MITextPosition.TryParse(frame);
            string func = frame.TryFindString("func");
            uint level = frame.FindUint("level");
            string from = frame.TryFindString("from");

            return new ThreadContext(pc, textPosition, func, level, from);
        }
Example #15
0
        internal static async Task <BindResult> Bind(string documentName, uint line, uint column, DebuggedProcess process, string condition, AD7PendingBreakpoint pbreak)
        {
            string  basename   = System.IO.Path.GetFileName(documentName);  // get basename from Windows path
            Results bindResult = await process.MICommandFactory.BreakInsert(process.EscapePath(basename), line, condition, ResultClass.None);

            string errormsg = "Unknown error";

            if (bindResult.ResultClass == ResultClass.error)
            {
                if (bindResult.Contains("msg"))
                {
                    errormsg = bindResult.FindString("msg");
                }
                if (String.IsNullOrWhiteSpace(errormsg))
                {
                    errormsg = "Unknown error";
                }
                return(new BindResult(errormsg));
            }
            else if (bindResult.ResultClass != ResultClass.done)
            {
                return(new BindResult(errormsg));
            }
            TupleValue     bkpt = null;
            ValueListValue list = null;

            if (bindResult.Contains("bkpt"))
            {
                ResultValue b = bindResult.Find("bkpt");
                if (b is TupleValue)
                {
                    bkpt = b as TupleValue;
                }
                else if (b is ValueListValue)
                {
                    // "<MULTIPLE>" sometimes includes a list of bound breakpoints
                    list = b as ValueListValue;
                    bkpt = list.Content[0] as TupleValue;
                }
            }
            else
            {
                // If the source file is not found, "done" is the result without a binding
                // (the error is sent via an "&" string and hence lost)
                return(new BindResult(errormsg));
            }
            Debug.Assert(bkpt.FindString("type") == "breakpoint");

            string number = bkpt.FindString("number");
            string addr   = bkpt.TryFindString("addr");

            PendingBreakpoint bp = new PendingBreakpoint(pbreak, number, StringToBreakpointState(addr));

            if (list == null)   // single breakpoint
            {
                BoundBreakpoint bbp = bp.GetBoundBreakpoint(bkpt);

                if (bbp == null)
                {
                    return(new BindResult(bp, MICoreResources.Status_BreakpointPending));
                }
                return(new BindResult(bp, bbp));
            }
            else   // <MULTIPLE> with list of addresses
            {
                BindResult res = new BindResult(bp);
                for (int i = 1; i < list.Content.Length; ++i)
                {
                    BoundBreakpoint bbp = bp.GetBoundBreakpoint(list.Content[i] as TupleValue);
                    res.BoundBreakpoints.Add(bbp);
                }
                return(res);
            }
        }
Example #16
0
 internal BoundBreakpoint(PendingBreakpoint parent, TupleValue bindinfo)
 {
     // CLRDBG TODO: Support clr addresses for breakpoints
     this.Addr = bindinfo.TryFindAddr("addr") ?? 0;
     this.FunctionName = bindinfo.TryFindString("func");
     this.HitCount = 0;
     _parent = parent;
     _textPosition = MITextPosition.TryParse(bindinfo);
 }
Example #17
0
        internal BoundBreakpoint(PendingBreakpoint parent, ulong addr, /*optional*/ TupleValue frame)
        {
            Addr = addr;
            HitCount = 0;
            _parent = parent;

            if (frame != null)
            {
                this.FunctionName = frame.TryFindString("func");
                _textPosition = MITextPosition.TryParse(frame);
            }
        }
Example #18
0
        private static BindResult EvalBindResult(Results bindResult, AD7PendingBreakpoint pbreak)
        {
            string errormsg = "Unknown error";

            if (bindResult.ResultClass == ResultClass.error)
            {
                if (bindResult.Contains("msg"))
                {
                    errormsg = bindResult.FindString("msg");
                }
                if (String.IsNullOrWhiteSpace(errormsg))
                {
                    errormsg = "Unknown error";
                }
                return(new BindResult(errormsg));
            }
            else if (bindResult.ResultClass != ResultClass.done)
            {
                return(new BindResult(errormsg));
            }
            TupleValue     bkpt = null;
            ValueListValue list = null;

            if (bindResult.Contains("bkpt"))
            {
                ResultValue b = bindResult.Find("bkpt");
                if (b is TupleValue)
                {
                    bkpt = b as TupleValue;
                }
                else if (b is ValueListValue)
                {
                    // "<MULTIPLE>" sometimes includes a list of bound breakpoints
                    list = b as ValueListValue;
                    bkpt = list.Content[0] as TupleValue;
                }
            }
            else
            {
                // If the source file is not found, "done" is the result without a binding
                // (the error is sent via an "&" string and hence lost)
                return(new BindResult(errormsg));
            }
            Debug.Assert(bkpt.FindString("type") == "breakpoint");

            string number  = bkpt.FindString("number");
            string warning = bkpt.TryFindString("warning");
            string addr    = bkpt.TryFindString("addr");

            PendingBreakpoint bp;

            if (!string.IsNullOrEmpty(warning))
            {
                Debug.Assert(string.IsNullOrEmpty(addr));
                return(new BindResult(new PendingBreakpoint(pbreak, number, MIBreakpointState.Pending), warning));
            }
            bp = new PendingBreakpoint(pbreak, number, StringToBreakpointState(addr));
            if (list == null)   // single breakpoint
            {
                BoundBreakpoint bbp = bp.GetBoundBreakpoint(bkpt);

                if (bbp == null)
                {
                    return(new BindResult(bp, MICoreResources.Status_BreakpointPending));
                }
                return(new BindResult(bp, bbp));
            }
            else   // <MULTIPLE> with list of addresses
            {
                BindResult res = new BindResult(bp);
                for (int i = 1; i < list.Content.Length; ++i)
                {
                    BoundBreakpoint bbp = bp.GetBoundBreakpoint(list.Content[i] as TupleValue);
                    res.BoundBreakpoints.Add(bbp);
                }
                return(res);
            }
        }