コード例 #1
0
        public IEnumerable <MemoryRegionBase> IdentifyRegions(DbgEngDebugger debugger)
        {
            var NativeModules = new HashSet <string>();
            var is32bit       = debugger.TargetIs32Bit;

            foreach (var module in debugger.Modules)
            {
                //Skip Wow64 ntdll from 32-bit mode
                if (is32bit && module.BaseAddress > uint.MaxValue)
                {
                    break;
                }
                yield return(new NativeModuleRegion(module));

                NativeModules.Add(module.Name);
            }

            foreach (var runtime in debugger.GetCurrentTarget().ClrRuntimes)
            {
                foreach (var clrModule in runtime.Modules)
                {
                    if (clrModule.ImageBase > 0)
                    {
                        var region = new ClrModuleRegion(clrModule, is32bit);
                        if (!NativeModules.Contains(region.ModuleName) &&
                            !NativeModules.Contains(region.ModuleName.Replace('.', '_') + "_ni"))
                        {
                            yield return(region);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static bool TryCreateFunction(DbgEngDebugger debugger,
                                             DbgEngContext context,
                                             DEBUG_STACK_FRAME_EX nativeStackFrame,
                                             out DbgFunction function,
                                             out ulong displacement)
        {
            function     = null;
            displacement = 0;
            DbgSymbol sym = null;

            try
            {
                SymbolInfo si = DbgHelp.SymFromInlineContext(debugger.DebuggerInterface,
                                                             nativeStackFrame.InstructionOffset,
                                                             nativeStackFrame.InlineFrameContext,
                                                             out displacement);
                sym      = new DbgPublicSymbol(debugger, si, debugger.GetCurrentTarget());
                function = new DbgNativeFunction(debugger, context, sym);
                return(true);
            }
            catch (DbgProviderException dpe)
            {
                // Sometimes the debugger doesn't know. E.g., frame 'e' here (from ntsd):
                //    0:000> kn
                //    # Child-SP          RetAddr           Call Site
                //    00 00000000`0058dff8 00000000`76c02ef8 ntdll!NtRequestWaitReplyPort+0xa
                //    01 00000000`0058e000 00000000`76c352d1 kernel32!GetConsoleMode+0xf8
                //    02 00000000`0058e030 00000000`76c4a60c kernel32!VerifyConsoleIoHandle+0x281
                //    03 00000000`0058e180 000007fe`fae30fe1 kernel32!ReadConsoleW+0xbc
                //    04 00000000`0058e260 000007fe`fae1eb88 Microsoft_PowerShell_ConsoleHost_ni+0x70fe1
                //    05 00000000`0058e390 000007fe`fae2a7e2 Microsoft_PowerShell_ConsoleHost_ni+0x5eb88
                //    06 00000000`0058e410 000007fe`fae29fae Microsoft_PowerShell_ConsoleHost_ni+0x6a7e2
                //    07 00000000`0058e4c0 000007fe`fae32bd1 Microsoft_PowerShell_ConsoleHost_ni+0x69fae
                //    08 00000000`0058e5b0 000007fe`fae235c6 Microsoft_PowerShell_ConsoleHost_ni+0x72bd1
                //    09 00000000`0058e670 000007fe`fae23f27 Microsoft_PowerShell_ConsoleHost_ni+0x635c6
                //    0a 00000000`0058e6d0 000007fe`fade5006 Microsoft_PowerShell_ConsoleHost_ni+0x63f27
                //    0b 00000000`0058e760 000007fe`fade2c1a Microsoft_PowerShell_ConsoleHost_ni+0x25006
                //    0c 00000000`0058e7e0 000007fe`fae33588 Microsoft_PowerShell_ConsoleHost_ni+0x22c1a
                //    0d 00000000`0058e890 000007fe`97f805de Microsoft_PowerShell_ConsoleHost_ni+0x73588
                //    0e 00000000`0058e8f0 000007fe`f777dad3 0x000007fe`97f805de
                //    0f 00000000`0058ea80 000007fe`f777d7ae clr!PreBindAssemblyEx+0x13e07
                //    10 00000000`0058eac0 000007fe`f777d830 clr!PreBindAssemblyEx+0x13ae2
                //    11 00000000`0058eb00 000007fe`f76d0f3b clr!PreBindAssemblyEx+0x13b64
                //    12 00000000`0058ecb0 000007fe`f76a9e5a clr!GetHistoryFileDirectory+0x945b
                //    13 00000000`0058ee80 000007fe`f76a9d54 clr!InitializeFusion+0x8b12
                //    14 00000000`0058f170 000007fe`f76a98ce clr!InitializeFusion+0x8a0c
                //    15 00000000`0058f730 000007fe`f76a9826 clr!InitializeFusion+0x8586
                //    16 00000000`0058f7a0 000007fe`f76aa078 clr!InitializeFusion+0x84de
                //    17 00000000`0058f830 000007fe`f8247b95 clr!CorExeMain+0x14
                //    18 00000000`0058f870 000007fe`f82e5b21 mscoreei!CorExeMain+0x5d
                //    19 00000000`0058f8c0 00000000`76bf652d mscoree!CorExeMain+0x69
                //    1a 00000000`0058f8f0 00000000`772ec521 kernel32!BaseThreadInitThunk+0xd
                //    1b 00000000`0058f920 00000000`00000000 ntdll!RtlUserThreadStart+0x21
                LogManager.Trace("Could not get symbol for stack frame {0} on thread index {1}. Error: {2}",
                                 nativeStackFrame.FrameNumber,
                                 context.ThreadIndexOrAddress,
                                 Util.GetExceptionMessages(dpe));
            }
            return(false);
        } // end TryCreateFunction()
コード例 #3
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
コード例 #4
0
ファイル: ClrRegionProvider.cs プロジェクト: Zhentar/DbgShell
 public IEnumerable <MemoryRegionBase> IdentifyRegions(DbgEngDebugger debugger)
 {
     foreach (var runtime in debugger.GetCurrentTarget().ClrRuntimes)
     {
         //foreach( var segment in runtime.GetHeap().Segments)
         //{
         //    var startAddr = new Address( Util.RoundDownToVirtualAllocGranularity( segment.Start ), debugger );
         //    yield return new LeafRegion( startAddr , segment.ReservedEnd - startAddr, new ColorString( ConsoleColor.Yellow, "CLR Heap" ) );
         //}
         foreach (var region in runtime.EnumerateMemoryRegions())
         {
             var start = region.Address;
             var size  = region.Size;
             if (region.Type == Microsoft.Diagnostics.Runtime.ClrMemoryRegionType.GCSegment)
             {
                 start = Util.RoundDownToVirtualAllocGranularity(start);   //The first page of each heap segment doesn't get reported
                 size += region.Address - start;
             }
             yield return(new LeafRegion(new Address(start, debugger), size, new ColorString(ConsoleColor.Yellow, "CLR " + region.Type)));
         }
     }
 }