// TODO:
        // [Parameter( Mandatory = true,
        //             Position = 0,
        //             ValueFromPipeline = true,
        //             ParameterSetName = c_FileParamSet )]
        // [ValidateNotNullOrEmpty]
        // public string File { get; set; }


        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!String.IsNullOrEmpty(TypeName))
            {
                string mod, template;
                ulong  dontCare;
                DbgProvider.ParseSymbolName(TypeName, out mod, out template, out dontCare);
                if (0 != dontCare)
                {
                    throw new ArgumentException("The TypeName parameter does not look like a type name.", "TypeName");
                }

                DbgValueConversionManager.RemoveEntries(mod, template, !AllMatching);
            }
            else
            {
                Util.Fail("impossible");
            }
            // else
            // {
            //     Util.Assert( !String.IsNullOrEmpty( File ) );
            //     string fullpath = GetUnresolvedProviderPathFromPSPath( File );
            //     DbgValueConversionManager.RemoveAllEntriesFromFile( fullpath, !AllMatching );
            // }
        } // end ProcessRecord()
Example #2
0
        /// <summary>
        ///    This method is "best effort"--it probably won't screen out all possible
        ///    invalid breakpoints. But it should hopefully catch some obviously bad ones.
        /// </summary>
        private void _TryValidateBp(ref DbgBreakpointInfo bp)
        {
            bool bpIsActuallyBogus = false;

            if (bp.IsEnabled)
            {
                if (bp.IsDeferred)
                {
                    try
                    {
                        Util.Assert(!String.IsNullOrEmpty(Expression));
                        // TODO: What if the expression is not a symbol??
                        string mod, bareSym;
                        ulong  offset;
                        DbgProvider.ParseSymbolName(Expression, out mod, out bareSym, out offset);

                        if ("*" == mod)
                        {
                            bpIsActuallyBogus = true;
                        }
                        else
                        {
                            var modInfos = Debugger.GetModuleByName(mod).ToArray();
                            if (modInfos.Length > 0)
                            {
                                // The module is loaded and yet the bp is deferred... the
                                // expression is no good.
                                //
                                // Or there is more than one module with that name.
                                bpIsActuallyBogus = true;
                            }
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        LogManager.Trace("Failed to parse expression as a symbol: {0}",
                                         Util.GetExceptionMessages(ae));
                    }
                } // end if( bp is deferred )
                else if (0 != bp.Offset)
                {
                    // The address shouldn't be invalid, because that would indicate the
                    // bp is deferred, but we already checked for that.
                    Util.Assert(bp.Offset != DebuggerObject.InvalidAddress);

                    MEMORY_BASIC_INFORMATION64 mbi;
                    int hr = Debugger.TryQueryVirtual(bp.Offset, out mbi);
                    if (hr != 0)
                    {
                        // iDNA targets don't yet handle QueryVirtual.
                        if (hr != DebuggerObject.E_NOTIMPL)
                        {
                            LogManager.Trace("_TryValidateBp: TryQueryVirtual failed: {0}", Util.FormatErrorCode(hr));
                            bpIsActuallyBogus = true;
                        }
                    }
                    else
                    {
                        if ((mbi.Protect != PAGE.EXECUTE) &&
                            (mbi.Protect != PAGE.EXECUTE_READ) &&      // <--
                            (mbi.Protect != PAGE.EXECUTE_READWRITE) && // <-- I don't actually know what these are
                            (mbi.Protect != PAGE.EXECUTE_WRITECOPY))   // <--
                        {
                            bpIsActuallyBogus = true;
                        }
                    }
                }
            } // end if( bp is enabled )

            if (bpIsActuallyBogus)
            {
                ulong addr = 0;
                if ((bp.Offset != 0) && (bp.Offset != DebuggerObject.InvalidAddress))
                {
                    addr = bp.Offset;
                }

                Debugger.RemoveBreakpoint(ref bp);
                var dpe = new DbgProviderException(Util.Sprintf("Failed to set breakpoint at {0}.",
                                                                addr != 0 ? DbgProvider.FormatAddress(addr, Debugger.TargetIs32Bit, true).ToString(false) : Expression),
                                                   "BpEnabledButDeferredAndOrBad",
                                                   ErrorCategory.InvalidArgument,
                                                   addr != 0 ? (object)addr : (object)Expression);
                try { throw dpe; } catch { } // give it a stack
                WriteError(dpe);
            }
        } // end _TryValidateBp()
Example #3
0
        } // end ProcessRecord()

        private IList <ulong> _TryResolveExpression()
        {
            // We need to parse this here for further examination of the modName and
            // so that we'll have the offset (which isn't returned from FindSymbol).
            string modName;
            string bareSym;
            ulong  offset;

            DbgProvider.ParseSymbolName(Expression, out modName, out bareSym, out offset);

            if (!WildcardPattern.ContainsWildcardCharacters(modName))
            {
                var mods = Debugger.GetModuleByName(modName, CancelTS.Token).ToArray();
                if (0 == mods.Length)
                {
                    // The module not loaded yet; it will have to become a deferred
                    // breakpoint if it's not obviously bad.

                    // DbgEng won't like wildcards for a deferred breakpoint.
                    if (WildcardPattern.ContainsWildcardCharacters(Expression))
                    {
                        var dpe = new DbgProviderException(Util.Sprintf("Can't use a wildcard for a deferred bp: {0}",
                                                                        Expression),
                                                           "BpNoWildcardsHere",
                                                           ErrorCategory.InvalidOperation,
                                                           Expression);
                        try { throw dpe; } catch { } // give it a stack
                        SafeWriteError(dpe);
                        return(null);
                    }

                    return(new ulong[0]);  // signals that we need a deferred breakpoint
                }
            }

            GlobalSymbolCategory category;

            if (_IsDataBreakpoint)
            {
                category = GlobalSymbolCategory.All;
            }
            else
            {
                category = GlobalSymbolCategory.Function;
            }

            var syms = Debugger.FindSymbol_Enum(Expression,
                                                category,
                                                CancelTS.Token).ToArray();

            if (0 == syms.Length)
            {
                var dpe = new DbgProviderException(Util.Sprintf("Could not resolve expression: {0}",
                                                                Expression),
                                                   "BpCouldNotFindSymbol",
                                                   ErrorCategory.ObjectNotFound,
                                                   Expression);
                try { throw dpe; } catch { } // give it a stack
                SafeWriteError(dpe);
                return(null);
            }

            if (syms.Length > 1)
            {
                //
                // Did the user obviously intend to have multiple breakpoints?
                //
                if (!WildcardPattern.ContainsWildcardCharacters(modName) &&
                    !WildcardPattern.ContainsWildcardCharacters(bareSym) &&
                    !Multiple)
                {
                    SafeWriteWarning("The expression matched multiple symbols. If this is intended, you can use -Multiple to suppress this warning.");
                }

                // If the user specified -Multiple, we'll assume they know what they are doing with an offset.
                if ((offset != 0) && !Multiple)
                {
                    SafeWriteWarning("Is it safe to use an offset with an expression that matches multiple symbols?");
                }
            }

            ulong[] addrs = new ulong[syms.Length];
            for (int i = 0; i < syms.Length; i++)
            {
                addrs[i] = syms[i].Address + offset;
            }

            return(addrs);
        } // end _TryResolveExpression()