internal PdbSynchronizationPoint(BitAccess bits, System.Compiler.Metadata.Reader reader)
 {
     this.reader = reader;
     bits.ReadUInt32(out this.synchronizeOffset);
     bits.ReadUInt32(out this.continuationMethodToken);
     bits.ReadUInt32(out this.continuationOffset);
     //this.continuationMethod = reader.pdbInfo.GetMethodFromPdbToken(continuationMethodToken);
 }
        private void MapTokens(PdbSynchronizationPoint[] syncPoints, uint[] ridMap, System.Compiler.Metadata.Reader reader)
        {
            if (syncPoints == null)
            {
                return;
            }

            for (int i = 0; i < syncPoints.Length; i++)
            {
                MapTokens(syncPoints[i], ridMap, reader);
            }
        }
        internal PdbSynchronizationInformation(Method moveNext, BitAccess bits, System.Compiler.Metadata.Reader reader)
        {
            this.reader = reader;
            uint asyncStepInfoCount;

            bits.ReadUInt32(out this.kickoffMethodToken);
            bits.ReadUInt32(out this.generatedCatchHandlerIlOffset);
            bits.ReadUInt32(out asyncStepInfoCount);
            this.synchronizationPoints = new PdbSynchronizationPoint[asyncStepInfoCount];
            for (uint i = 0; i < asyncStepInfoCount; i += 1)
            {
                this.synchronizationPoints[i] = new PdbSynchronizationPoint(bits, reader);
            }
            // this.asyncMethod = reader.pdbInfo.GetMethodFromPdbToken(kickoffMethodToken);
            this.moveNextMethod = moveNext;
        }
Example #4
0
        static void LoadFuncsFromDbiModule(BitAccess bits,
                                           DbiModuleInfo info,
                                           IntHashTable names,
                                           ArrayList funcList,
                                           bool readStrings,
                                           MsfDirectory dir,
                                           Dictionary <string, int> nameIndex,
                                           PdbReader reader,
                                           System.Compiler.Metadata.Reader ilreader,
                                           Dictionary <string, PdbSource> sourceCache
                                           )
        {
            PdbFunction[] funcs = null;

            bits.Position = 0;
            int sig;

            bits.ReadInt32(out sig);
            if (sig != 4)
            {
                throw new PdbDebugException("Invalid signature. (sig={0})", sig);
            }

            bits.Position = 4;
            // Console.WriteLine("{0}:", info.moduleName);
            funcs = PdbFunction.LoadManagedFunctions(/*info.moduleName,*/
                bits, (uint)info.cbSyms,
                readStrings, ilreader);
            if (funcs != null)
            {
                bits.Position = info.cbSyms + info.cbOldLines;
                LoadManagedLines(funcs, names, bits, dir, nameIndex, reader,
                                 (uint)(info.cbSyms + info.cbOldLines + info.cbLines),
                                 sourceCache);

                for (int i = 0; i < funcs.Length; i++)
                {
                    funcList.Add(funcs[i]);
                }
            }
        }
Example #5
0
        internal static Dictionary <uint, PdbFunction> LoadFunctionMap(FileStream inputStream, out Dictionary <uint, PdbTokenLine> tokenToSourceMapping, out string sourceServerData, System.Compiler.Metadata.Reader reader)
        {
            var funcs  = LoadFunctions(inputStream, out tokenToSourceMapping, out sourceServerData, reader);
            var result = new Dictionary <uint, PdbFunction>(funcs.Length + 10);

            foreach (PdbFunction pdbFunction in funcs)
            {
                result[pdbFunction.token] = pdbFunction;
            }

            return(result);
        }
Example #6
0
        internal static PdbFunction[] LoadFunctions(Stream read, out Dictionary <uint, PdbTokenLine> tokenToSourceMapping, out string sourceServerData,
                                                    System.Compiler.Metadata.Reader ilreader)
        {
            tokenToSourceMapping = new Dictionary <uint, PdbTokenLine>();
            BitAccess     bits   = new BitAccess(512 * 1024);
            PdbFileHeader head   = new PdbFileHeader(read, bits);
            PdbReader     reader = new PdbReader(read, head.pageSize);
            MsfDirectory  dir    = new MsfDirectory(reader, head, bits);

            DbiModuleInfo[] modules = null;
            DbiDbgHdr       header;
            Dictionary <string, PdbSource> sourceCache = new Dictionary <string, PdbSource>();

            dir.streams[1].Read(reader, bits);
            Dictionary <string, int> nameIndex = LoadNameIndex(bits);
            int nameStream;

            if (!nameIndex.TryGetValue("/NAMES", out nameStream))
            {
                throw new PdbDebugException("No `name' stream");
            }
            dir.streams[nameStream].Read(reader, bits);
            IntHashTable names = LoadNameStream(bits);

            int srcsrvStream;

            if (!nameIndex.TryGetValue("SRCSRV", out srcsrvStream))
            {
                sourceServerData = string.Empty;
            }
            else
            {
                DataStream dataStream = dir.streams[srcsrvStream];
                byte[]     bytes      = new byte[dataStream.contentSize];
                dataStream.Read(reader, bits);
                sourceServerData = bits.ReadBString(bytes.Length);
            }

            dir.streams[3].Read(reader, bits);
            LoadDbiStream(bits, out modules, out header, true);

            ArrayList funcList = new ArrayList();

            if (modules != null)
            {
                for (int m = 0; m < modules.Length; m++)
                {
                    var module = modules[m];
                    if (module.stream > 0)
                    {
                        dir.streams[module.stream].Read(reader, bits);
                        if (module.moduleName == "TokenSourceLineInfo")
                        {
                            LoadTokenToSourceInfo(bits, module, names, dir, nameIndex, reader, tokenToSourceMapping, sourceCache);
                            continue;
                        }
                        LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader, ilreader, sourceCache);
                    }
                }
            }

            PdbFunction[] funcs = (PdbFunction[])funcList.ToArray(typeof(PdbFunction));

            // After reading the functions, apply the token remapping table if it exists.
            if (header.snTokenRidMap != 0 && header.snTokenRidMap != 0xffff)
            {
                uint[] ridMap = new uint[dir.streams[header.snTokenRidMap].Length / 4];
                dir.streams[header.snTokenRidMap].Read(reader, bits);
                bits.ReadUInt32(ridMap);

                foreach (PdbFunction func in funcs)
                {
                    func.MapTokens(ridMap, ilreader);
                }
            }
            else
            {
                foreach (PdbFunction func in funcs)
                {
                    func.MapTokens(null, ilreader);
                }
            }
            //
            Array.Sort(funcs, PdbFunction.byAddressAndToken);
            //Array.Sort(funcs, PdbFunction.byToken);
            return(funcs);
        }
        internal static PdbFunction[] LoadManagedFunctions(/*string module,*/
            BitAccess bits, uint limit,
            bool readStrings,
            System.Compiler.Metadata.Reader reader
            )
        {
            //string mod = StripNamespace(module);
            int begin = bits.Position;
            int count = 0;

            while (bits.Position < limit)
            {
                ushort siz;
                ushort rec;

                bits.ReadUInt16(out siz);
                int star = bits.Position;
                int stop = bits.Position + siz;
                bits.Position = star;
                bits.ReadUInt16(out rec);

                switch ((SYM)rec)
                {
                case SYM.S_GMANPROC:
                case SYM.S_LMANPROC:
                    ManProcSym proc;
                    bits.ReadUInt32(out proc.parent);
                    bits.ReadUInt32(out proc.end);
                    bits.Position = (int)proc.end;
                    count++;
                    break;

                case SYM.S_END:
                    bits.Position = stop;
                    break;

                default:
                    //Console.WriteLine("{0,6}: {1:x2} {2}",
                    //                  bits.Position, rec, (SYM)rec);
                    bits.Position = stop;
                    break;
                }
            }
            if (count == 0)
            {
                return(null);
            }

            bits.Position = begin;
            PdbFunction[] funcs = new PdbFunction[count];
            int           func  = 0;

            while (bits.Position < limit)
            {
                ushort siz;
                ushort rec;

                bits.ReadUInt16(out siz);
                int star = bits.Position;
                int stop = bits.Position + siz;
                bits.ReadUInt16(out rec);

                switch ((SYM)rec)
                {
                case SYM.S_GMANPROC:
                case SYM.S_LMANPROC:
                    ManProcSym proc;
                    //int offset = bits.Position;

                    bits.ReadUInt32(out proc.parent);
                    bits.ReadUInt32(out proc.end);
                    bits.ReadUInt32(out proc.next);
                    bits.ReadUInt32(out proc.len);
                    bits.ReadUInt32(out proc.dbgStart);
                    bits.ReadUInt32(out proc.dbgEnd);
                    bits.ReadUInt32(out proc.token);
                    bits.ReadUInt32(out proc.off);
                    bits.ReadUInt16(out proc.seg);
                    bits.ReadUInt8(out proc.flags);
                    bits.ReadUInt16(out proc.retReg);
                    if (readStrings)
                    {
                        bits.ReadCString(out proc.name);
                    }
                    else
                    {
                        bits.SkipCString(out proc.name);
                    }
                    //Console.WriteLine("token={0:X8} [{1}::{2}]", proc.token, module, proc.name);

                    bits.Position = stop;

                    funcs[func++] = new PdbFunction(/*module,*/ proc, bits, reader);
                    break;

                default:
                {
                    //throw new PdbDebugException("Unknown SYMREC {0}", (SYM)rec);
                    bits.Position = stop;
                    break;
                }
                }
            }
            return(funcs);
        }
 private void MapTokens(PdbSynchronizationPoint syncpoint, uint[] ridMap, System.Compiler.Metadata.Reader reader)
 {
     MapToken(ref syncpoint.continuationMethodToken, ridMap);
 }
        private void MapTokens(PdbSynchronizationInformation pdbSynchronizationInformation, uint[] ridMap, System.Compiler.Metadata.Reader reader)
        {
            if (pdbSynchronizationInformation == null)
            {
                return;
            }

            MapToken(ref pdbSynchronizationInformation.kickoffMethodToken, ridMap);

            MapTokens(pdbSynchronizationInformation.synchronizationPoints, ridMap, reader);
        }
        internal void MapTokens(uint[] ridMap, System.Compiler.Metadata.Reader reader)
        {
            MapToken(ref this.token, ridMap);

            MapTokens(this.synchronizationInformation, ridMap, reader);
        }
        internal PdbFunction(/*string module, */ ManProcSym proc, BitAccess bits, System.Compiler.Metadata.Reader reader)
        {
            this.token         = proc.token;
            this.unmappedToken = proc.token;
            //this.module = module;
            this.name = proc.name;
            //this.flags = proc.flags;
            this.segment = proc.seg;
            this.address = proc.off;
            //this.length = proc.len;

            if (proc.seg != 1)
            {
                throw new PdbDebugException("Segment is {0}, not 1.", proc.seg);
            }
            if (proc.parent != 0 || proc.next != 0)
            {
                throw new PdbDebugException("Warning parent={0}, next={1}",
                                            proc.parent, proc.next);
            }
            //if (proc.dbgStart != 0 || proc.dbgEnd != 0) {
            //  throw new PdbDebugException("Warning DBG start={0}, end={1}",
            //                              proc.dbgStart, proc.dbgEnd);
            //}

            int constantCount;
            int scopeCount;
            int slotCount;
            int usedNamespacesCount;

            CountScopesAndSlots(bits, proc.end, out constantCount, out scopeCount, out slotCount, out usedNamespacesCount);
            int scope    = constantCount > 0 || slotCount > 0 || usedNamespacesCount > 0 ? 1 : 0;
            int slot     = 0;
            int constant = 0;
            int usedNs   = 0;

            scopes         = new PdbScope[scopeCount + scope];
            slots          = new PdbSlot[slotCount];
            constants      = new PdbConstant[constantCount];
            usedNamespaces = new string[usedNamespacesCount];

            if (scope > 0)
            {
                scopes[0] = new PdbScope(this.address, proc.len, slots, constants, usedNamespaces);
            }

            while (bits.Position < proc.end)
            {
                ushort siz;
                ushort rec;

                bits.ReadUInt16(out siz);
                int star = bits.Position;
                int stop = bits.Position + siz;
                bits.Position = star;
                bits.ReadUInt16(out rec);

                switch ((SYM)rec)
                {
                case SYM.S_OEM:
                {      // 0x0404
                    OemSymbol oem;

                    bits.ReadGuid(out oem.idOem);
                    bits.ReadUInt32(out oem.typind);
                    // internal byte[]   rgl;        // user data, force 4-byte alignment

                    if (oem.idOem == msilMetaData)
                    {
                        string name = bits.ReadString();
                        if (name == "MD2")
                        {
                            byte version;
                            bits.ReadUInt8(out version);
                            if (version == 4)
                            {
                                byte count;
                                bits.ReadUInt8(out count);
                                bits.Align(4);
                                while (count-- > 0)
                                {
                                    this.ReadCustomMetadata(bits);
                                }
                            }
                        }
                        else if (name == "asyncMethodInfo")
                        {
                            this.synchronizationInformation = new PdbSynchronizationInformation(method, bits, reader);
                        }
                        bits.Position = stop;
                        break;
                    }
                    else
                    {
                        throw new PdbDebugException("OEM section: guid={0} ti={1}",
                                                    oem.idOem, oem.typind);
                        // bits.Position = stop;
                    }
                }

                case SYM.S_BLOCK32:
                {
                    BlockSym32 block = new BlockSym32();

                    bits.ReadUInt32(out block.parent);
                    bits.ReadUInt32(out block.end);
                    bits.ReadUInt32(out block.len);
                    bits.ReadUInt32(out block.off);
                    bits.ReadUInt16(out block.seg);
                    bits.SkipCString(out block.name);
                    bits.Position = stop;

                    scopes[scope++] = new PdbScope(this.address, block, bits, out slotToken);
                    bits.Position   = (int)block.end;
                    break;
                }

                case SYM.S_MANSLOT:
                    slots[slot++] = new PdbSlot(bits);
                    bits.Position = stop;
                    break;

                case SYM.S_MANCONSTANT:
                    constants[constant++] = new PdbConstant(bits);
                    bits.Position         = stop;
                    break;

                case SYM.S_UNAMESPACE:
                    bits.ReadCString(out usedNamespaces[usedNs++]);
                    bits.Position = stop;
                    break;

                case SYM.S_END:
                    bits.Position = stop;
                    break;

                default:
                {
                    //throw new PdbDebugException("Unknown SYM: {0}", (SYM)rec);
                    bits.Position = stop;
                    break;
                }
                }
            }

            if (bits.Position != proc.end)
            {
                throw new PdbDebugException("Not at S_END");
            }

            ushort esiz;
            ushort erec;

            bits.ReadUInt16(out esiz);
            bits.ReadUInt16(out erec);

            if (erec != (ushort)SYM.S_END)
            {
                throw new PdbDebugException("Missing S_END");
            }
        }
Example #12
0
 internal PdbSynchronizationPoint(BitAccess bits, System.Compiler.Metadata.Reader reader)
 {
   this.reader = reader;
   bits.ReadUInt32(out this.synchronizeOffset);
   bits.ReadUInt32(out this.continuationMethodToken);
   bits.ReadUInt32(out this.continuationOffset);
   //this.continuationMethod = reader.pdbInfo.GetMethodFromPdbToken(continuationMethodToken);
 }
Example #13
0
 internal PdbSynchronizationInformation(Method moveNext, BitAccess bits, System.Compiler.Metadata.Reader reader)
 {
   this.reader = reader;
   uint asyncStepInfoCount;
   bits.ReadUInt32(out this.kickoffMethodToken);
   bits.ReadUInt32(out this.generatedCatchHandlerIlOffset);
   bits.ReadUInt32(out asyncStepInfoCount);
   this.synchronizationPoints = new PdbSynchronizationPoint[asyncStepInfoCount];
   for (uint i = 0; i < asyncStepInfoCount; i += 1)
   {
     this.synchronizationPoints[i] = new PdbSynchronizationPoint(bits, reader);
   }
   // this.asyncMethod = reader.pdbInfo.GetMethodFromPdbToken(kickoffMethodToken);
   this.moveNextMethod = moveNext;
 }