} // end constructor public DbgFunctionTypeInfo(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId, string name, uint functionTypeTypeId, uint owningClassTypeId, uint numChildren, ulong address, ulong length, uint virtualBaseOffset, uint symIndex) : this(debugger, GetModBase(module), typeId, name, functionTypeTypeId, owningClassTypeId, numChildren, address, length, virtualBaseOffset, symIndex, module.Target) { __mod = module; } // end constructor
public DbgNativeFunction(DbgEngDebugger debugger, DbgEngContext context, DbgSymbol symbol) : base(debugger, context, symbol.Address, symbol.Name) { m_sym = symbol; } // end constructor()
/// <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
internal DbgStackFrameInfo(DbgEngDebugger debugger, DbgUModeThreadInfo thread, DEBUG_STACK_FRAME_EX nativeFrame, ClrStackFrame managedFrame) : this(debugger, thread, nativeFrame, managedFrame, true) { }
public DbgManagedFunction(DbgEngDebugger debugger, DbgEngContext context, ClrMethod method) : base(debugger, context, method.NativeCode, method.Name) { m_clrMethod = method; } // end constructor()
public static DbgUdtTypeInfo GetUdtTypeInfo(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId) { if (null == debugger) { throw new ArgumentNullException("debugger"); } if (null == module) { throw new ArgumentNullException("module"); } RawUdtInfo rui = DbgHelp.GetUdtInfo(debugger.DebuggerInterface, module.BaseAddress, typeId); return(new DbgUdtTypeInfo(debugger, module, typeId, rui.UdtKind, rui.SymName, rui.Size, rui.ChildrenCount, rui.ClassParentId, rui.VirtualTableShapeId)); } // end GetUdtTypeInfo()
} // end GetNullTypeInfo() protected DbgNullTypeInfo(DbgEngDebugger debugger, ulong moduleBase, uint typeId, DbgTarget target) : base(debugger, moduleBase, typeId, SymTag.Null, "void", 0, target) { } // end constructor
} // 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
} // end GetChildrenIds() private static DbgTypeInfo _DefaultFactory(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId, SymTag symTag) { return(new DbgTypeInfo(debugger, module, typeId, symTag)); }
} // end constructor public DbgVirtualBaseClassTypeInfo(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId, UdtKind kind, string name, ulong size, uint numChildren, uint classParentId, // could be 0? uint vtableShapeId, // could be 0? bool isVirtBaseClass, bool isIndirectVirtBaseClass, uint baseClassTypeId, uint virtualBaseDispIndex, uint virtualBasePointerOffset) : this(debugger, GetModBase(module), typeId, kind, name, size, numChildren, classParentId, vtableShapeId, isVirtBaseClass, isIndirectVirtBaseClass, baseClassTypeId, virtualBaseDispIndex, virtualBasePointerOffset, module.Target) { __mod = module; } // end constructor
public static MemoryRegionStack GetMemoryRegionsForAddress(DbgEngDebugger debugger, ulong address) { var results = new List <MemoryRegionBase>(); var map = GetAddressMap(debugger); foreach (var region in map.Regions) { if (region.BaseAddress <= address && region.BaseAddress + region.Size > address) { var currRegion = region; do { MemoryRegionBase nextRegion = null; results.Add(currRegion); foreach (var subRegion in currRegion.SubRegions) { if (subRegion.BaseAddress <= address && subRegion.BaseAddress + subRegion.Size > address) { nextRegion = subRegion; break; } } currRegion = nextRegion; } while(currRegion != null); } } return(new MemoryRegionStack(results)); }
} // end AggregateMembers() public DbgVirtualBaseClassTypeInfo(DbgEngDebugger debugger, ulong moduleBase, uint typeId, UdtKind kind, string name, ulong size, uint numChildren, uint classParentId, // could be 0? uint vtableShapeId, // could be 0? bool isVirtBaseClass, bool isIndirectVirtBaseClass, uint baseClassTypeId, uint virtualBaseDispIndex, uint virtualBasePointerOffset, DbgTarget target) : base(debugger, moduleBase, typeId, kind, name, size, numChildren, classParentId, vtableShapeId, isVirtBaseClass, isIndirectVirtBaseClass, baseClassTypeId, target) { VirtualBaseDispIndex = virtualBaseDispIndex; VirtualBasePointerOffset = virtualBasePointerOffset; } // end constructor
protected DbgBaseClassTypeInfoBase(DbgEngDebugger debugger, ulong moduleBase, uint typeId, UdtKind kind, string name, ulong size, uint numChildren, uint classParentId, // could be 0? uint vtableShapeId, // could be 0? bool isVirtBaseClass, bool isIndirectVirtBaseClass, uint baseClassTypeId, DbgTarget target) : base(debugger, moduleBase, typeId, kind, name, size, numChildren, classParentId, vtableShapeId, target) { IsVirtualBaseClass = isVirtBaseClass; IsIndirectVirtualBaseClass = isIndirectVirtBaseClass; BaseClassTypeId = baseClassTypeId; } // end constructor
} // end constructor protected DbgBaseClassTypeInfoBase(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId, UdtKind kind, string name, ulong size, uint numChildren, uint classParentId, // could be 0? uint vtableShapeId, // could be 0? bool isVirtBaseClass, bool isIndirectVirtBaseClass, uint baseClassTypeId) : this(debugger, GetModBase(module), typeId, kind, name, size, numChildren, classParentId, vtableShapeId, isVirtBaseClass, isIndirectVirtBaseClass, baseClassTypeId, module.Target) { __mod = module; } // end constructor
private DbgSimpleSymbol(DbgEngDebugger debugger, string name, DbgNamedTypeInfo type) : base(debugger, name, _GetTargetFromType(type)) { m_type = type; } // end constructor
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); })); }
protected override void ProcessRecord() { // Support relative paths in PS. string dumpFileResolved = SessionState.Path.GetUnresolvedProviderPathFromPSPath(DumpFile); // TODO: don't check this here... catch and write instead if (!File.Exists(dumpFileResolved)) { // It could be wildcarded... unfortunately attaching to multiple dumps // doesn't seem to work. But if it only resolves to one file... let's // allow it. ProviderInfo dontCare; var multi = SessionState.Path.GetResolvedProviderPathFromPSPath(DumpFile, out dontCare); if ((null == multi) || (0 == multi.Count)) { ThrowTerminatingError(new FileNotFoundException(), "NoSuchDumpFile", ErrorCategory.ObjectNotFound, DumpFile); return; } else if (multi.Count > 1) { ThrowTerminatingError(new NotSupportedException("Attaching to multiple dump files does not really work."), "AttachToMultipleDumpsNotsupported", ErrorCategory.OpenError, DumpFile); return; } else { dumpFileResolved = multi[0]; } } if (String.IsNullOrEmpty(TargetName)) { TargetName = Path.GetFileNameWithoutExtension(dumpFileResolved); } if (DbgProvider.IsTargetNameInUse(TargetName)) { ThrowTerminatingError(new ArgumentException(Util.Sprintf("The target name '{0}' is already in use. Please use -TargetName to specify a different target name.", TargetName), "TargetName"), "TargetNameInUse", ErrorCategory.ResourceExists, TargetName); } Debugger = DbgEngDebugger.NewDebugger(); using (Debugger.SetCurrentCmdlet(this)) { Debugger.LoadCrashDump(dumpFileResolved, TargetName); base.ProcessRecord(true); } // end using( psPipe ) } // end ProcessRecord()
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()
public DbgGeneratedTypeInfo(DbgEngDebugger debugger, ulong moduleBase, uint typeId, DbgTarget target) : this(debugger, moduleBase, typeId, SymTag.Null, target) { }
} // end _EnsureIsNamed() public static DbgNamedTypeInfo GetNamedTypeInfo(DbgEngDebugger debugger, ulong moduleBase, uint typeId, DbgTarget target) { return(_EnsureIsNamed(GetTypeInfo(debugger, moduleBase, typeId, target))); }
} // end GetColorName() public static DbgFunctionTypeTypeInfo GetFunctionTypeTypeInfo(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId) { if (null == debugger) { throw new ArgumentNullException("debugger"); } if (null == module) { throw new ArgumentNullException("module"); } var rfti = DbgHelp.GetFuncTypeInfo(debugger.DebuggerInterface, module.BaseAddress, typeId); return(new DbgFunctionTypeTypeInfo(debugger, module, typeId, rfti.ReturnTypeId, rfti.ClassParentId, rfti.ThisAdjust, rfti.CallingConvention, rfti.Arguments)); } // end GetUdtTypeInfo()
public static DbgNamedTypeInfo GetNamedTypeInfo(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId, SymTag symTag) { return(_EnsureIsNamed(GetTypeInfo(debugger, module, typeId, symTag))); }
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); } } } } }
} // end _BuildRemoteParams() protected override void ProcessRecord() { if (String.IsNullOrEmpty(TargetName)) { TargetName = _GenerateTargetName(); } string remoteParams = _BuildRemoteParams(); // TODO: if (null == Password) { LogManager.Trace("Connecting to remote with parameters: {0}", remoteParams); } else { LogManager.Trace("Connecting to remote with parameters: <TODO need to take password out>"); } using (var psPipe = GetPipelineCallback()) { Debugger = DbgEngDebugger.ConnectToServer(remoteParams, psPipe); // TODO: This is a temp workaround to pre-fetch filter info. The // problem is that when connected to a remote debugger, we're going // over RPC, and when the event callbacks are being dispatched, RPC // doesn't like us to try to call back in to the dbgeng API--and one // place where we normally do that is to decide if we need to output // an event or not. So we'll pre-fetch here. Debugger.GetSpecificEventFilters(); // This will call Debugger.WaitForEvent(), if necessary base.ProcessRecord(); } // end using( psPipe ) } // end ProcessRecord()
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()
} // end _EnsureInitialized() public static bool TryFindPossibleOffsetFromDerivedClass(DbgEngDebugger debugger, ulong vtableAddr, ulong firstSlotPtr, DbgUdtTypeInfo derivedType, DbgUdtTypeInfo baseType, out int offset) { _EnsureInitialized(); foreach (var plugin in sm_dtdPlugins) { using (var logger = new LogAdapter(plugin.Name)) { if (plugin.TryFindPossibleOffsetFromDerivedClass(debugger, logger, vtableAddr, firstSlotPtr, derivedType, baseType, out offset)) { LogManager.Trace("Possible offset from derived class ({0}{1:x}) found by plugin: {2}", offset > 0 ? "0x" : "", offset, plugin.Name); return(true); } } } // end foreach( plugin ) // No plugin could figure it out. offset = 0; return(false); } // end TryFindPossibleOffsetFromDerivedClass()
} // end GetImplicitThreadLocalStorageForThread() internal DbgModuleInfo(DbgEngDebugger debugger, DEBUG_MODULE_PARAMETERS nativeParams, DbgTarget target) : base(debugger) { if (null == target) { throw new ArgumentNullException("target"); } Target = target; m_params = nativeParams; if (0 == nativeParams.Base) { throw new ArgumentException("Invalid DEBUG_MODULE_PARAMETERS: no base address.", "nativeParams"); } if (UInt64.MaxValue == nativeParams.Base) // (DEBUG_INVALID_OFFSET) { throw new ArgumentException("Invalid DEBUG_MODULE_PARAMETERS: base address indicates the structure is empty. Guess: Don't pass a base address buffer to GetModuleParameters.", "nativeParams"); } // TODO: more validation? } // end constructor
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
public DbgMemory(ulong address, byte[] bytes, bool is32bit, DbgEngDebugger debugger) : this(address, bytes, is32bit, false, (x) => _DefaultSymLookup(debugger, x)) { }
} // end property IsAbstract public static DbgFunctionTypeInfo GetFunctionTypeInfo(DbgEngDebugger debugger, DbgModuleInfo module, uint typeId) { if (null == debugger) { throw new ArgumentNullException("debugger"); } if (null == module) { throw new ArgumentNullException("module"); } RawFuncInfo rfi = DbgHelp.GetFuncInfo(debugger.DebuggerInterface, module.BaseAddress, typeId); return(new DbgFunctionTypeInfo(debugger, module, typeId, rfi.FuncName, rfi.FunctionTypeTypeId, rfi.OwningClassTypeId, rfi.ChildrenCount, rfi.Address, rfi.Length, rfi.VirtualBaseOffset, rfi.SymIndex)); } // end GetFunctionTypeInfo()