예제 #1
0
        /// <summary>
        ///    This constructor is used by the modload event.
        /// </summary>
        internal DbgModuleInfo(DbgEngDebugger debugger,
                               WDebugSymbols ds,
                               //ulong imageFileHandle, <-- is there any [straightforward] way to get this besides the modload event? Is it useful?
                               ulong baseOffset,
                               uint moduleSize,
                               string moduleName,
                               string imageName,
                               uint checkSum,
                               uint timeDateStamp,
                               DbgTarget target)
            : base(debugger)
        {
            Util.Assert(0 != baseOffset);
            m_ds            = ds;
            m_baseAddr      = baseOffset;
            m_size          = moduleSize;
            m_name          = moduleName;
            m_imgName       = imageName;
            m_checkSum      = checkSum;
            m_timeDateStamp = timeDateStamp;

            // We can't always get the current target context--like when we are trying to raise
            // a "module loaded" event, which happens from a dbgeng callback, where we don't know
            // the current context.
            //   if( null == target )
            //       throw new ArgumentNullException( "target" );

            Target = target;
        } // end constructor
예제 #2
0
        } // end GetSymbolByAddress()

        public ulong GetOffsetByName(string symbolName)
        {
            return(Debugger.ExecuteOnDbgEngThread(() =>
            {
                ulong offset;
                WDebugSymbols ds = (WDebugSymbols)Debugger.DebuggerInterface;
                int hr = ds.GetOffsetByNameWide(symbolName, out offset);
                if (S_FALSE == hr)
                {
                    // The symbolName was ambiguous.
                    var matches = Debugger.FindSymbol_Enum(symbolName).ToArray();
                    Util.Assert((matches != null) && (matches.Length > 1));
                    throw new DbgProviderException(Util.Sprintf("Ambiguous symbol error at: '{0}'.",
                                                                symbolName),
                                                   "AmbiguousSymbol",
                                                   System.Management.Automation.ErrorCategory.InvalidArgument,
                                                   matches);
                }
                else
                {
                    CheckHr(hr);
                }
                return offset;
            }));
        } // end GetOffsetByName()
예제 #3
0
        } // end GetNameByOffset()

        /// <summary>
        ///    Gets the symbol name for the specified address. Do not use for getting
        ///    stack frame stuff; this won't get inline frame info. Also consider using
        ///    FindSymbolForAddress
        /// </summary>
        public bool TryGetNameByOffset(ulong offset, out string name, out ulong displacement)
        {
            name = null;
            bool   itWorked        = false;
            string tmpName         = null;
            ulong  tmpDisplacement = 0xffffffffffffffff;

            Debugger.ExecuteOnDbgEngThread(() =>
            {
                WDebugSymbols ds = (WDebugSymbols)Debugger.DebuggerInterface;

                int hr = ds.GetNameByOffsetWide(offset, out tmpName, out tmpDisplacement);
                if (0 == hr)
                {
                    itWorked = true;
                }
            });

            displacement = tmpDisplacement;
            if (itWorked)
            {
                name = tmpName;
            }

            return(itWorked);
        } // end TryGetNameByOffset()
예제 #4
0
        } // end TryGetNameByOffset()

        // TODO: Why is this method here? Belongs in DbgEngDebugger, methinks.
        /// <summary>
        ///    Gets the symbol name for the specified address. Do not use for getting
        ///    stack frame stuff; this won't get inline frame info.
        /// </summary>
        public string GetNearNameByOffset(ulong offset, int delta, out long displacement)
        {
            string tmpName         = null;
            ulong  tmpDisplacement = 0xffffffffffffffff;

            Debugger.ExecuteOnDbgEngThread(() =>
            {
                WDebugSymbols ds = (WDebugSymbols)Debugger.DebuggerInterface;

                int hr = ds.GetNearNameByOffsetWide(offset, delta, out tmpName, out tmpDisplacement);
                if (E_NOINTERFACE != hr)
                {
                    CheckHr(hr);
                }
            });

            displacement = (long)tmpDisplacement;
            // N.B. The displacement is an unsigned value. So if we asked for a negative
            // delta, we are to understand that the displacement is also negative. Best
            // to just encode that for our caller by using a signed value instead.
            //
            // 0 also will result in a negative displacement, because if we are asking for
            // a delta of 0 and the displacement is not zero, the symbol we've got is
            // 'displacement' bytes /after/ the address we asked about (the next symbol).
            //
            // (displacement of 0 means that GetNearNameByOffsetWide will behave the same
            // as GetNameByOffset, which means "get me the symbol that is at this address,
            // or this first one that comes after it")
            if (delta <= 0)
            {
                displacement = -displacement;
            }

            return(tmpName);
        } // end GetNearNameByOffset()
예제 #5
0
        public DbgSymbolGroup(DbgEngDebugger debugger,
                              DEBUG_SCOPE_GROUP scope,
                              DbgStackFrameInfo frame,
                              DbgEngContext context)
            : base(debugger)
        {
            if (null == context)
            {
                context = debugger.GetCurrentDbgEngContext();
            }

            if (null == frame)
            {
                frame = debugger.GetCurrentScopeFrame();
            }

            Context = context;
            Frame   = frame;

            using (new DbgEngContextSaver(debugger, context))
            {
                debugger.ExecuteOnDbgEngThread(() =>
                {
                    WDebugSymbols ds5 = (WDebugSymbols)debugger.DebuggerInterface;
                    WDebugSymbolGroup symGroup;
                    CheckHr(ds5.GetScopeSymbolGroup2(scope, null, out symGroup));
                    m_symGroup = symGroup;
                    Target     = debugger.GetCurrentTarget();
                });
            }
        } // end constructor
예제 #6
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            PathInfo pi       = this.CurrentProviderLocation(DbgProvider.ProviderId);
            var      debugger = DbgProvider.GetDebugger(pi.ProviderPath);

            debugger.SetContextByPath(pi.ProviderPath);
            WDebugSymbols ds = (WDebugSymbols)debugger.DebuggerInterface;
        } // end ProcessRecord()
예제 #7
0
        } // end StaticCheckHr()

        public string GetNameByInlineContext(ulong address, uint inlineContext, out ulong displacement)
        {
            string name            = null;
            ulong  tmpDisplacement = 0xffffffffffffffff;

            Debugger.ExecuteOnDbgEngThread(() =>
            {
                WDebugSymbols ds = (WDebugSymbols)Debugger.DebuggerInterface;

                CheckHr(ds.GetNameByInlineContextWide(address, inlineContext, out name, out tmpDisplacement));
            });
            displacement = tmpDisplacement;
            return(name);
        } // end GetNameByInlineContext()
예제 #8
0
        private static DEBUG_MODULE_PARAMETERS _GetModParamsByAddress(DbgEngDebugger debugger,
                                                                      DbgEngContext ctx,
                                                                      WDebugSymbols ds,
                                                                      ulong addressInModule)
        {
            if (null == debugger)
            {
                throw new ArgumentNullException("debugger");
            }

            if (0 == addressInModule)
            {
                throw new ArgumentException("You must supply a non-zero address.", "addressInModule");
            }

            return(debugger.ExecuteOnDbgEngThread(() =>
            {
                using (new DbgEngContextSaver(debugger, ctx))
                {
                    if (null == ds)
                    {
                        ds = (WDebugSymbols)debugger.DebuggerInterface;
                    }

                    uint index;
                    ulong baseAddr;

                    // TODO: If it's a managed module, this will fail. We could use
                    // ClrMd to synthesize this DbgModule instead.
                    // https://github.com/Microsoft/DbgShell/issues/35
                    StaticCheckHr(ds.GetModuleByOffset2(addressInModule,
                                                        0,       // start index
                                                        DEBUG_GETMOD.DEFAULT,
                                                        out index,
                                                        out baseAddr));
                    DEBUG_MODULE_PARAMETERS[] modParams;
                    StaticCheckHr(ds.GetModuleParameters(1, null, index, out modParams));
                    Util.Assert(1 == modParams.Length);
                    return modParams[0];
                }
            }));
        } // end _GetModParamsByAddress()
예제 #9
0
        } // end GetNameByInlineContext()

        public string TryGetNameByInlineContext(ulong address, uint inlineContext, out ulong displacement)
        {
            string localName         = null;
            ulong  localDisplacement = 0xffffffffffffffff;

            Debugger.ExecuteOnDbgEngThread(() =>
            {
                WDebugSymbols ds = (WDebugSymbols)Debugger.DebuggerInterface;

                string tmpName        = null;
                ulong tmpDisplacement = 0;
                int hr = ds.GetNameByInlineContextWide(address, inlineContext, out tmpName, out tmpDisplacement);
                if (S_OK == hr)
                {
                    localName         = tmpName;
                    localDisplacement = tmpDisplacement;
                }
            });
            displacement = localDisplacement;
            return(localName);
        } // end GetNameByInlineContext()
예제 #10
0
        private static DEBUG_MODULE_PARAMETERS _GetModParamsByAddress(DbgEngDebugger debugger,
                                                                      DbgEngContext ctx,
                                                                      WDebugSymbols ds,
                                                                      ulong addressInModule)
        {
            if (null == debugger)
            {
                throw new ArgumentNullException("debugger");
            }

            if (0 == addressInModule)
            {
                throw new ArgumentException("You must supply a non-zero address.", "addressInModule");
            }

            return(debugger.ExecuteOnDbgEngThread(() =>
            {
                using (new DbgEngContextSaver(debugger, ctx))
                {
                    if (null == ds)
                    {
                        ds = (WDebugSymbols)debugger.DebuggerInterface;
                    }

                    uint index;
                    ulong baseAddr;
                    StaticCheckHr(ds.GetModuleByOffset2(addressInModule,
                                                        0,       // start index
                                                        DEBUG_GETMOD.DEFAULT,
                                                        out index,
                                                        out baseAddr));
                    DEBUG_MODULE_PARAMETERS[] modParams;
                    StaticCheckHr(ds.GetModuleParameters(1, null, index, out modParams));
                    Util.Assert(1 == modParams.Length);
                    return modParams[0];
                }
            }));
        } // end _GetModParamsByAddress()
예제 #11
0
        internal DbgPublicSymbol(DbgEngDebugger debugger,
                                 SymbolInfo symbolInfo,
                                 DbgTarget target)
            : base(debugger, _VerifySymInfo(symbolInfo), target)
        {
            m_debugSymbols = (WDebugSymbols)debugger.DebuggerInterface;
            m_symInfo      = symbolInfo;
            var typeSymTag = DbgHelp.GetSymTag(debugger.DebuggerInterface,
                                               symbolInfo.ModBase,
                                               symbolInfo.TypeIndex);

            m_type = (DbgNamedTypeInfo)DbgTypeInfo.GetTypeInfo(debugger,
                                                               symbolInfo.ModBase,
                                                               symbolInfo.TypeIndex,
                                                               typeSymTag,
                                                               target);

            m_dmai = new DEBUG_MODULE_AND_ID()
            {
                Id         = symbolInfo.Index,
                ModuleBase = symbolInfo.ModBase
            };
        } // end constructor
예제 #12
0
        protected DbgRegisterSetBase(DbgEngDebugger debugger,
                                     DbgStackFrameInfo stackFrame,
                                     DbgRegisterSetBase baseline)
            : base(debugger)
        {
            if (null == stackFrame)
            {
                throw new ArgumentNullException("stackFrame");
            }

            StackFrame = stackFrame;

            Debugger.ExecuteOnDbgEngThread(() =>
            {
                m_debugSymbols   = (WDebugSymbols)Debugger.DebuggerInterface;
                m_debugRegisters = (WDebugRegisters)Debugger.DebuggerInterface;
                m_debugControl   = (WDebugControl)Debugger.DebuggerInterface;
            });

            Baseline = baseline;
            // We used to lazily retrieve values, but that's no good when the context
            // changes (such as when stepping through code).
            _GetRegisterInfo();
        } // end constructor