コード例 #1
0
            } // end GetVersionInfo()

            public unsafe bool ReadMemory(ulong address, byte[] buffer, int bytesRequested, out int bytesRead)
            {
                _CheckClosed();
                if (null == buffer)
                {
                    throw new ArgumentNullException("buffer");
                }

                int  tmpBytesRead = 0;
                bool bResult      = m_umd.ExecuteOnDbgEngThread(() =>
                {
                    using (new DbgEngContextSaver(m_umd, m_target.Context))
                    {
                        fixed(byte *pBuf = buffer)
                        {
                            uint uiBytesRead;
                            int hr = m_umd.m_debugDataSpaces.ReadVirtualDirect(address,
                                                                               (uint)bytesRequested,
                                                                               pBuf,
                                                                               out uiBytesRead);
                            tmpBytesRead = (int)uiBytesRead;
                            return(hr == 0);
                        }
                    }     // end using( ctx )
                });

                bytesRead = tmpBytesRead;
                return(bResult);
            } // end ReadMemory()
コード例 #2
0
ファイル: DbgSymbolGroup.cs プロジェクト: zha0/DbgShell
        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
コード例 #3
0
ファイル: DbgTypeInfo.cs プロジェクト: zha0/DbgShell
        private static DbgTypeInfo _LoadTypeInfo(DbgEngDebugger debugger,
                                                 DbgModuleInfo module,
                                                 uint typeId,
                                                 SymTag symTag)
        {
            if (null == debugger)
            {
                throw new ArgumentNullException("debugger");
            }

            if (IsDbgGeneratedType(typeId) &&
                !DbgHelp.PeekSyntheticTypeExists(debugger.DebuggerInterface,
                                                 module.BaseAddress,
                                                 typeId))
            {
                return(new DbgGeneratedTypeInfo(debugger, module, typeId, symTag));
            }

            return(debugger.ExecuteOnDbgEngThread(() =>
            {
                if (((int)symTag) > sm_factories.Length)
                {
                    // In case they extend the SymTag enum and I don't get updated.
                    Util.Fail("Need to update SymTag enum.");
                    return _DefaultFactory(debugger, module, typeId, symTag);
                }

                return sm_factories[(int)symTag](debugger, module, typeId);
            }));
        } // end _LoadTypeInfo()
コード例 #4
0
ファイル: DbgTypeInfo.cs プロジェクト: zha0/DbgShell
        private static DbgTypeInfo _LoadTypeInfo(DbgEngDebugger debugger,
                                                 DbgModuleInfo module,
                                                 uint typeId)
        {
            if (null == debugger)
            {
                throw new ArgumentNullException("debugger");
            }

            if (IsDbgGeneratedType(typeId) &&
                !DbgHelp.PeekSyntheticTypeExists(debugger.DebuggerInterface,
                                                 module.BaseAddress,
                                                 typeId))
            {
                return(new DbgGeneratedTypeInfo(debugger, module, typeId));
            }

            return(debugger.ExecuteOnDbgEngThread(() =>
            {
                var symTag = DbgHelp.GetSymTag(debugger.DebuggerInterface,
                                               module.BaseAddress,
                                               typeId);
                return _LoadTypeInfo(debugger, module, typeId, symTag);
            }));
        }
コード例 #5
0
        } // end constructor

        public static DbgPseudoRegisterInfo GetDbgPsedoRegisterInfo(DbgEngDebugger debugger,
                                                                    string name)
        {
            return(debugger.ExecuteOnDbgEngThread(() =>
            {
                WDebugRegisters dr = (WDebugRegisters)debugger.DebuggerInterface;

                uint idx;
                StaticCheckHr(dr.GetPseudoIndexByNameWide(name, out idx));

                string tmpName;
                ulong typeMod;
                uint typeId;
                StaticCheckHr(dr.GetPseudoDescriptionWide(idx,
                                                          out tmpName,
                                                          out typeMod,
                                                          out typeId));

                DEBUG_VALUE[] dvs;
                StaticCheckHr(dr.GetPseudoValues(DEBUG_REGSRC.FRAME,
                                                 1,         // count
                                                 idx,       // start
                                                 out dvs));

                return new DbgPseudoRegisterInfo(debugger,
                                                 tmpName,
                                                 dvs[0],
                                                 typeMod,
                                                 typeId,
                                                 DEBUG_ANY_ID);
            }));
        } // end factory
コード例 #6
0
ファイル: AddressMap.cs プロジェクト: Zhentar/DbgShell
        public static AddressMap GetAddressMap(DbgEngDebugger debugger)
        {
            if (!sm_initDone)
            {
                debugger.SymbolStateChanged   += (_, __) => DumpAddressMapAtSlightestProvocation();
                debugger.DebuggeeStateChanged += (_, __) => DumpAddressMapAtSlightestProvocation();
                sm_initDone = true;
            }

            //TODO: thread through cancellation token!
            return(sm_cachedAddressMap ?? (sm_cachedAddressMap = debugger.ExecuteOnDbgEngThread(() => BuildAddressMap(debugger))));
        }
コード例 #7
0
        /// <summary>
        ///    Gets a DbgRegisterInfo object for a CV_HREG_e value (such as you might find
        ///    in a SYMBOL_INFO structure).
        /// </summary>
        public static DbgRegisterInfo GetDbgRegisterInfoFor_CV_HREG_e(DbgEngDebugger debugger,
                                                                      uint CV_HREG_e_val)
        {
            return(debugger.ExecuteOnDbgEngThread(() =>
            {
                var dc = (WDebugControl)debugger.DebuggerInterface;
                IMAGE_FILE_MACHINE effmach;
                StaticCheckHr(dc.GetEffectiveProcessorType(out effmach));
                if (CV_ALLREG_VFRAME == CV_HREG_e_val)
                {
                    // See MachineInfo::CvRegToMachine.
                    if (IMAGE_FILE_MACHINE.AMD64 == effmach)
                    {
                        CV_HREG_e_val = 335;     // CV_AMD64_RSP
                    }
                    else if (IMAGE_FILE_MACHINE.I386 == effmach)
                    {
                        // TODO: Drat... It /might/ be EBP, but likely not--it's likely some
                        // magical "virtual frame" value that I don't know how to get. I'll
                        // have to ask the debugger team for a way to get that.
                        //CV_HREG_e_val = 22; // CV_REG_EBP
                        throw new DbgProviderException("On x86, I don't know how to find the \"virtual frame\" value that corresponds to CV_ALLREG_VFRAME. Sorry. Use Get-DbgLocalSymbol instead of Get-Symbol.",
                                                       "CV_ALLREG_VFRAME_on_x86_notSupported",
                                                       System.Management.Automation.ErrorCategory.NotImplemented,
                                                       CV_HREG_e_val);
                    }
                    else
                    {
                        throw new NotSupportedException(Util.Sprintf("CV_ALLREG_VFRAME not supported for platform {0}",
                                                                     effmach));
                    }
                }

                uint dbgengRegIdx = CvRegMap.TryMapCvToDbgEngIndex(debugger,
                                                                   effmach,
                                                                   CV_HREG_e_val);

                if (dbgengRegIdx == DEBUG_ANY_ID)
                {
                    throw new NotSupportedException(Util.Sprintf("I don't know how to map this CV_HREG_e value '{0}' for platform '{1}'.",
                                                                 (CV_HREG_e)CV_HREG_e_val,
                                                                 effmach));
                }

                return GetDbgRegisterInfoForIndex(debugger, dbgengRegIdx);
            }));
        } // end factory
コード例 #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 constructor

        public static DbgRegisterInfo GetDbgRegisterInfoForIndex(DbgEngDebugger debugger,
                                                                 uint registerIndex)
        {
            return(debugger.ExecuteOnDbgEngThread(() =>
            {
                WDebugRegisters dr = (WDebugRegisters)debugger.DebuggerInterface;
                DEBUG_REGISTER_DESCRIPTION desc;

                string name;
                StaticCheckHr(dr.GetDescriptionWide(registerIndex,
                                                    out name,
                                                    out desc));

                // Don't use dr.GetValue, because it won't respect the context.
                DEBUG_VALUE[] dvs;
                StaticCheckHr(dr.GetValues2(DEBUG_REGSRC.FRAME,
                                            new uint[] { registerIndex },
                                            out dvs));
                return new DbgRegisterInfo(debugger, name, dvs[0], desc, registerIndex);
            }));
        } // end factory
コード例 #10
0
ファイル: DbgModuleInfo.cs プロジェクト: sayanmutd/DbgShell
        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()