Exemple #1
0
        private void CreateClient(IDebugClient client)
        {
            DebuggerInterface = client;

            _spaces    = (IDebugDataSpaces)DebuggerInterface;
            _spacesPtr = (IDebugDataSpacesPtr)DebuggerInterface;
            _symbols   = (IDebugSymbols)DebuggerInterface;
            _control   = (IDebugControl2)DebuggerInterface;

            // These interfaces may not be present in older DbgEng dlls.
            _spaces2        = DebuggerInterface as IDebugDataSpaces2;
            _symbols3       = DebuggerInterface as IDebugSymbols3;
            _advanced       = DebuggerInterface as IDebugAdvanced;
            _systemObjects  = DebuggerInterface as IDebugSystemObjects;
            _systemObjects3 = DebuggerInterface as IDebugSystemObjects3;

            Interlocked.Increment(ref s_totalInstanceCount);

            if (_systemObjects3 == null && s_totalInstanceCount > 1)
            {
                throw new ClrDiagnosticsException("This version of DbgEng is too old to create multiple instances of DataTarget.", ClrDiagnosticsExceptionKind.DebuggerError);
            }

            if (_systemObjects3 != null)
            {
                _systemObjects3.GetCurrentSystemId(out _instance);
            }
        }
        // source location support, not implemented yet!
        //public string SourceFileName { get; set; }
        //public uint SourceLineNumber { get; set; }
        //public uint SourceLineNumberEnd { get; set; }
        //public uint SourceColumnNumber { get; set; }
        //public uint SourceColumnNumberEnd { get; set; }

        /// <summary>
        /// Constructor for native frame
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="debugSymbols"></param>
        public CombinedStackFrame(DEBUG_STACK_FRAME frame, IDebugSymbols3 debugSymbols)
        {
            Type = StackFrameType.Native;             //native frame
            InstructionPointer = frame.InstructionOffset;
            StackPointer       = frame.StackOffset;
            ReturnOffset       = frame.ReturnOffset;

            uint  moduleIndex;
            ulong dummy;

            //if no module is associated with this frame, the method is unknown, can happen with CLR-JIT code
            if (debugSymbols.GetModuleByOffset(InstructionPointer, 0, out moduleIndex, out dummy) != 0)
            {
                ModuleName = "UNKNOWN";
                MethodName = "UNKNOWN";
                return;                           //no more action needed
            }
            var   name = new StringBuilder(1024); //create buffer for storing method name
            ulong displacement;
            uint  nameSize;

            Utility.CheckHRESULT(debugSymbols.GetNameByOffset(InstructionPointer, name, name.Capacity, out nameSize, out displacement));
            OffsetInMethod = displacement;             //offset of InstructionPointer and base location of symbol, could be null

            //get module name and method name, example for name :
            string[] parts = name.ToString().Split('!');
            ModuleName = parts[0];             //module is the first part before '!'
            if (parts.Length > 1)
            {
                MethodName = parts[1];                 //second part, after the '!'
            }
            if (string.IsNullOrEmpty(ModuleName))
            {
                ModuleName = "UNKNOWN";
            }
            // check if method name was found or not
            if (string.IsNullOrEmpty(MethodName))
            {
                MethodName = "UNKNOWN";
            }

            // get source information
            uint line;
            var  fileBuffer = new StringBuilder(4 * 1024);
            uint fileSize;

            debugSymbols.GetLineByOffset(InstructionPointer, out line, fileBuffer, fileBuffer.Capacity, out fileSize, out displacement);
            if (fileSize > 0)
            {
                this.SourceInfo = new SDFileAndLineNumber {
                    File = fileBuffer.ToString(), Line = (int)line
                };
            }
        }
        public WindowsDebugEngine(string winDbgPath)
        {
            logger.Debug("WindowsDebugEngine");

            object obj   = null;
            Guid   clsid = CLSID(typeof(IDebugClient5));

            this.winDbgPath = winDbgPath;

            hDll  = LoadWin32Library(Path.Combine(winDbgPath, "dbgeng.dll"));
            hProc = GetProcAddress(hDll, "DebugCreate");
            DebugCreate debugCreate = (DebugCreate)Marshal.GetDelegateForFunctionPointer(hProc, typeof(DebugCreate));

            if (debugCreate(ref clsid, out obj) != 0)
            {
                Debugger.Break();
            }

            dbgClient        = (IDebugClient5)obj;
            dbgControl       = (IDebugControl4)obj;
            dbgSymbols       = (IDebugSymbols3)obj;
            dbgSystemObjects = (IDebugSystemObjects)obj;

            // Reset events
            loadModules.Reset();
            exitProcess.Reset();
            handlingException.Reset();
            handledException.Reset();
            exitDebugger.Reset();

            // Reset output
            output = new StringBuilder();

            dbgSymbols.SetSymbolPath(@"SRV*http://msdl.microsoft.com/download/symbols");

            dbgClient.SetOutputCallbacks(new OutputCallbacks(this));
            dbgClient.SetEventCallbacks(new EventCallbacks(this));
        }
Exemple #4
0
        public void Execute(CommandExecutionContext context)
        {
            if (!String.IsNullOrEmpty(SpecificModule))
            {
                var module = context.Runtime.Modules.FirstOrDefault(
                    m => String.Equals(Path.GetFileName(m.Name), SpecificModule, StringComparison.InvariantCultureIgnoreCase));
                if (module != null)
                {
                    var moduleInfo = context.Runtime.DataTarget.EnumerateModules().Single(
                        m => String.Equals(m.FileName, module.FileName, StringComparison.InvariantCultureIgnoreCase));
                    context.WriteLine("Module:     {0}", module.Name);
                    context.WriteLine("PDB name:   {0}", moduleInfo.Pdb.FileName);
                    context.WriteLine("Debug mode: {0}", module.DebuggingMode);
                }
                else
                {
                    // Couldn't find managed module, try to find native:
                    using (var target = context.CreateTemporaryDbgEngTarget())
                    {
                        var moduleInfo = context.Runtime.DataTarget.EnumerateModules().FirstOrDefault(
                            m => String.Equals(Path.GetFileName(m.FileName), SpecificModule, StringComparison.InvariantCultureIgnoreCase));
                        if (moduleInfo == null)
                        {
                            return;
                        }

                        IDebugSymbols3 debugSymbols = (IDebugSymbols3)target.DebuggerInterface;

                        uint loaded, unloaded;
                        if (0 != debugSymbols.GetNumberModules(out loaded, out unloaded))
                        {
                            return;
                        }

                        for (uint moduleIdx = 0; moduleIdx < loaded; ++moduleIdx)
                        {
                            StringBuilder name = new StringBuilder(2048);
                            uint          nameSize;
                            if (0 != debugSymbols.GetModuleNameString(DEBUG_MODNAME.IMAGE, moduleIdx, 0, name, (uint)name.Capacity, out nameSize))
                            {
                                continue;
                            }

                            if (!String.Equals(name.ToString(), moduleInfo.FileName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }

                            DEBUG_MODULE_PARAMETERS[] modInfo = new DEBUG_MODULE_PARAMETERS[1];
                            if (0 != debugSymbols.GetModuleParameters(1, null, moduleIdx, modInfo))
                            {
                                return;
                            }

                            name = new StringBuilder(2048);
                            debugSymbols.GetModuleNameString(DEBUG_MODNAME.SYMBOL_FILE, moduleIdx, 0, name, (uint)name.Capacity, out nameSize);

                            context.WriteLine("Module:     {0}", moduleInfo.FileName);
                            context.WriteLine("PDB loaded: {0}", modInfo[0].SymbolType == DEBUG_SYMTYPE.DIA || modInfo[0].SymbolType == DEBUG_SYMTYPE.PDB);
                            context.WriteLine("PDB name:   {0}", name.ToString());
                        }
                    }
                }
                return;
            }

            context.WriteLine("{0,-20:x16} {1,-10} {2,-20} {3}", "start", "size", "version", "filename");
            foreach (var module in context.Runtime.DataTarget.EnumerateModules())
            {
                context.WriteLine("{0,-20:x16} {1,-10:x} {2,-20} {3}",
                                  module.ImageBase, module.FileSize, module.Version, module.FileName);
            }
        }
Exemple #5
0
        private void CreateClient(IDebugClient client)
        {
            _client = client;

            _spaces = (IDebugDataSpaces)_client;
            _spacesPtr = (IDebugDataSpacesPtr)_client;
            _symbols = (IDebugSymbols)_client;
            _control = (IDebugControl2)_client;

            // These interfaces may not be present in older DbgEng dlls.
            _spaces2 = _client as IDebugDataSpaces2;
            _symbols3 = _client as IDebugSymbols3;
            _advanced = _client as IDebugAdvanced;
            _systemObjects = _client as IDebugSystemObjects;
            _systemObjects3 = _client as IDebugSystemObjects3;

            Interlocked.Increment(ref s_totalInstanceCount);

            if (_systemObjects3 == null && s_totalInstanceCount > 1)
                throw new ClrDiagnosticsException("This version of DbgEng is too old to create multiple instances of DataTarget.", ClrDiagnosticsException.HR.DebuggerError);

            if (_systemObjects3 != null)
                _systemObjects3.GetCurrentSystemId(out _instance);
        }
Exemple #6
0
 public Symbols(IDebugSymbols3 symbols)
 {
     _symbols = symbols;
 }
Exemple #7
0
 public SymbolsSearch(IDebugSymbols3 symbols, string pattern)
 {
     _symbols = symbols;
     _symbols.StartSymbolMatchWide(pattern, out _searchHandle);
 }