private void symbolParser_DbgIDRSDSTraceData(DbgIDRSDSData obj)
        {
            string pdbFile = obj.PdbFileName;
            Guid   pdbGuid = obj.GuidSig;

            if (!symbolFiles.ContainsKey(pdbFile))
            {
                // unsafe, but OK to do for now,
                // other options is to Marshal.AllocHGlobal.
                // other option is to use fixed in unsafe code
                // other option ....?1

                GCHandle handle = GCHandle.Alloc(pdbGuid, GCHandleType.Pinned);

                IntPtr guidPtr = handle.AddrOfPinnedObject();

                //
                StringBuilder pdbFullPath = new StringBuilder(1024);
                // Try To locate the symbol file.

                //tmm.pdbWith Guid2d244915-4bd6-4d74-a496-8877396f5510
                bool foundPDB = TraceEventNativeMethods.SymFindFileInPathW(contextInfo.currentProcessHandle,
                                                                           null,
                                                                           pdbFile,
                                                                           guidPtr,
                                                                           (int)obj.Age,
                                                                           0,
                                                                           TraceEventNativeMethods.SSRVOPT_GUIDPTR,
                                                                           pdbFullPath,
                                                                           null,
                                                                           IntPtr.Zero);
                int lastError = Marshal.GetLastWin32Error();
                if (lastError == 0x2) // path not found
                {
                    Console.WriteLine("Can't find symbol for " + pdbFile);
                    Console.WriteLine("are you sure _NT_SYMBOL_PATH is set?"); // check if _NT_SYMBOL_PATH is set
                }

                if (foundPDB)
                {
                    PDBInfo info = new PDBInfo()
                    {
                        pdbFullPath = pdbFullPath.ToString(), pdbImageBase = (ulong)obj.ImageBase
                    };
                    symbolFiles.Add(pdbFile, info);
                }
                else
                {
                    symbolFiles.Add(pdbFile, null);
                }
                handle.Free();
            }
        }
        public unsafe ulong LoadSymModule(string moduleName, ulong moduleBase)
        {
            // given a module file name *.exe  or .dll, we will try to find a matching .PDB symbol and load it.
            Console.WriteLine("Trying to load symbol for file" + moduleName);
            // lookup the image name
            string moduleFileName = System.IO.Path.GetFileName(moduleName);
            string pdbFileName    = System.IO.Path.ChangeExtension(moduleFileName, ".pdb");

            if (symbolFiles.ContainsKey(pdbFileName))
            {
                PDBInfo info = symbolFiles[pdbFileName];
                if (info != null)
                {
                    return(TraceEventNativeMethods.SymLoadModuleExW(contextInfo.currentProcessHandle,
                                                                    IntPtr.Zero, info.pdbFullPath, null, info.pdbImageBase, (uint)0x10000000, null, (uint)0));
                }
            }
            return(0);
        }
Esempio n. 3
0
        private void symbolParser_DbgIDRSDSTraceData(DbgIDRSDSData obj)
        {
            string pdbFile = obj.PdbFileName;
            Guid pdbGuid = obj.GuidSig;

            if (!symbolFiles.ContainsKey(pdbFile))
            {
                // unsafe, but OK to do for now,
                // other options is to Marshal.AllocHGlobal.
                // other option is to use fixed in unsafe code
                // other option ....?1

                GCHandle handle = GCHandle.Alloc(pdbGuid, GCHandleType.Pinned);

                IntPtr guidPtr = handle.AddrOfPinnedObject();

                //
                StringBuilder pdbFullPath = new StringBuilder(1024);
                // Try To locate the symbol file.

                //tmm.pdbWith Guid2d244915-4bd6-4d74-a496-8877396f5510
                bool foundPDB = TraceEventNativeMethods.SymFindFileInPathW(contextInfo.currentProcessHandle,
                    null,
                    pdbFile,
                    guidPtr,
                    (int)obj.Age,
                    0,
                    TraceEventNativeMethods.SSRVOPT_GUIDPTR,
                    pdbFullPath,
                    null,
                    IntPtr.Zero);
                int lastError = Marshal.GetLastWin32Error();
                if (lastError == 0x2) // path not found
                {
                    Console.WriteLine("Can't find symbol for " + pdbFile);
                    Console.WriteLine("are you sure _NT_SYMBOL_PATH is set?"); // check if _NT_SYMBOL_PATH is set
                }

                if (foundPDB)
                {
                    // Lookup in _NT_SYMBOL_PATH failed, try to get one from the path.
                    // TODO: check this
                    // TODO: enable Symbol Cache,  so that we optimize in the future.
                    //  pdbFullPath = pdbStrFullPath.ToString();
                    // Console.WriteLine("Found A PDB file @ " + pdbFullPath);
                    //Console.WriteLine("Found a PDB file for "  + pdbFile);
                    PDBInfo info = new PDBInfo() { pdbFullPath = pdbFullPath.ToString(), pdbImageBase = (ulong)obj.ImageBase };
                    symbolFiles.Add(pdbFile, info);

                    // Try to load the symbol file here.
                    unsafe
                    {
                        //ulong symHandle = TraceEventNativeMethods.SymLoadModuleExW(this.currentProcessHandle,
                        //                               IntPtr.Zero, pdbFullPath.ToString(),
                        //                             null, (ulong)obj.ImageBase,
                        //                           0x1000000, null, 0);

                        // let us enumerate all the symbols.. just to check out if this is working.

                        //TraceEventNativeMethods.SymEnumSymbolsW(currentProcessHandle, symHandle, "*", this.SymEnumSymbolsProc, IntPtr.Zero);

                        // unload
                        //TraceEventNativeMethods.SymUnloadModule64(currentProcessHandle, symHandle);
                    }
                }
                else
                {
                    symbolFiles.Add(pdbFile, null);
                }
                handle.Free();
            }
        }