Esempio n. 1
0
    public void loadDataFromMapFile()
    {
        StreamReader strm =
            new StreamReader(m_symdumpFile, System.Text.Encoding.ASCII);
        String line;
        int    i;

        String[] RegExps;

        // Read the head of the symbol dump file and
        // determind the format of it.
        ReadMapHeader(strm);

        //
        // Scan through the symbol dump file looking
        // for the globals structure.
        //
        if (bIsWindowsMapfile)
        {
            RegExps = RegExps_WindowsMapfile;
        }
        else
        {
            RegExps = RegExps_UnixNmfile;
        }

        Console.WriteLine("It is a {0} file.", (bIsWindowsMapfile)?"Windows MAP":"Unix NM");

        Regex[] RegExs = new Regex[RegExps.Length];
        for (i = 0; i < RegExps.Length; i++)
        {
#if DACTABLEGEN_DEBUG
            Console.WriteLine("RegEx[{0}]: {1}", i, RegExps[i]);
#endif
            RegExs[i] = new Regex(RegExps[i]);
        }

        Match      match = null;
        SymbolInfo si;
        String     key;
        int        segment;
        UInt32     address;

        for (;;)
        {
            line = strm.ReadLine();

            if (line == null)
            {
                // No more to read.
                break;
            }

            // Console.WriteLine(">{0}", line);
            for (i = 0; i < RegExps.Length; i++)
            {
                match = RegExs[i].Match(line);
                if (match.Success)
                {
                    // Console.WriteLine(line);

                    segment = 0;
                    address = 0;
                    if (bIsWindowsMapfile)
                    {
                        switch ((WindowsSymbolTypes)i)
                        {
                        case WindowsSymbolTypes.ModuleNameClassNameFieldName:
                            key     = match.Groups["moduleName"].ToString() + "::" + match.Groups["className"].ToString() + "::" + match.Groups["fieldName"];
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.ClassNameFieldName:
                            key     = match.Groups["className"].ToString() + "::" + match.Groups["fieldName"];
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.GlobalVarName:
                        case WindowsSymbolTypes.GlobalVarName2:
                        case WindowsSymbolTypes.GlobalVarName3:
                            key     = match.Groups["globalVarName"].ToString();
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.SingleVtAddr:
                            key     = match.Groups["FunctionName"].ToString();
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.MultiVtAddr:
                            key = match.Groups["FunctionName"].ToString() +
                                  "__" +
                                  match.Groups["BaseName"].ToString();
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        default:
                            throw new ApplicationException("Unknown symbolType" + i);
                        }
                    }
                    else
                    {
                        switch ((UnixSymbolTypes)i)
                        {
                        case UnixSymbolTypes.ModuleNameClassNameFieldName:
                            key     = match.Groups["moduleName"].ToString() + "::" + match.Groups["className"].ToString() + "::" + match.Groups["fieldName"];
                            address = UInt32.Parse(match.Groups["address"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case UnixSymbolTypes.ClassNameFieldName:
                            key     = match.Groups["className"].ToString() + "::" + match.Groups["fieldName"];
                            address = UInt32.Parse(match.Groups["address"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case UnixSymbolTypes.GlobalVarName:
                            key     = match.Groups["globalVarName"].ToString();
                            address = UInt32.Parse(match.Groups["address"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case UnixSymbolTypes.JITHelpers1:
                        case UnixSymbolTypes.JITHelpers2:
                        case UnixSymbolTypes.VtAddr:
                        case UnixSymbolTypes.DACNotifyCompilationFinished:
                            key     = match.Groups["FunctionName"].ToString();
                            address = UInt32.Parse(match.Groups["address"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        default:
                            throw new ApplicationException("Unknown symbolType" + i);
                        }
                    }

                    si = (SymbolInfo)SymbolHash[key];
                    if (si != null)
                    {
#if DACTABLEGEN_DEBUG
                        Console.WriteLine("Warning: Key already exists: {0}", key);
#endif
                        si.dupFound = true;
                    }
                    else
                    {
                        si = new SymbolInfo(segment, address);
                        // Console.WriteLine("{0:x8} {1}", si.Segment, si.Address, key);
                        SymbolHash.Add(key, si);
                    }
                }
            }
        }

        strm.Close();
    }
Esempio n. 2
0
    public void loadDataFromMapFile()
    {
        StreamReader strm =
            new StreamReader(m_symdumpFile, System.Text.Encoding.ASCII);
        String line;
        int    i;

        String[] RegExps;

        // Read the head of the symbol dump file and
        // determind the format of it.
        ReadMapHeader(strm);

        //
        // Scan through the symbol dump file looking
        // for the globals structure.
        //
        if (bIsWindowsMapfile)
        {
            RegExps = RegExps_WindowsMapfile;
        }
        else
        {
            RegExps = RegExps_UnixNmfile;
        }

        Console.WriteLine("It is a {0} file.", (bIsWindowsMapfile)?"Windows MAP":"Unix NM");

        Regex[] RegExs = new Regex[RegExps.Length];
        for (i = 0; i < RegExps.Length; i++)
        {
#if DACTABLEGEN_DEBUG
            Console.WriteLine("RegEx[{0}]: {1}", i, RegExps[i]);
#endif
            RegExs[i] = new Regex(RegExps[i]);
        }

        Match      match = null;
        SymbolInfo si;
        String     key;
        int        segment;
        UInt32     address;

        for (;;)
        {
            line = strm.ReadLine();

            if (line == null)
            {
                // No more to read.
                break;
            }

            // Console.WriteLine(">{0}", line);
            for (i = 0; i < RegExps.Length; i++)
            {
                match = RegExs[i].Match(line);
                if (match.Success)
                {
                    // Console.WriteLine(line);

                    segment = 0;
                    address = 0;
                    if (bIsWindowsMapfile)
                    {
                        switch ((WindowsSymbolTypes)i)
                        {
                        case WindowsSymbolTypes.ModuleNameClassNameFieldName:
                            key     = match.Groups["moduleName"].ToString() + "::" + match.Groups["className"].ToString() + "::" + match.Groups["fieldName"];
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.ClassNameFieldName:
                            key     = match.Groups["className"].ToString() + "::" + match.Groups["fieldName"];
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.GlobalVarName:
                        case WindowsSymbolTypes.GlobalVarName2:
                        case WindowsSymbolTypes.GlobalVarName3:
                            key     = match.Groups["globalVarName"].ToString();
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.SingleVtAddr:
                            key     = match.Groups["FunctionName"].ToString();
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        case WindowsSymbolTypes.MultiVtAddr:
                            key = match.Groups["FunctionName"].ToString() +
                                  "__" +
                                  match.Groups["BaseName"].ToString();
                            segment = Int32.Parse(match.Groups["addrPart1"].ToString(), NumberStyles.AllowHexSpecifier);
                            address = UInt32.Parse(match.Groups["addrPart2"].ToString(), NumberStyles.AllowHexSpecifier);
                            break;

                        default:
                            throw new ApplicationException("Unknown symbolType" + i);
                        }
                    }
                    else
                    {
                        // We've got a UNIX nm file
                        // The full unmanaged symbol name is already included in the RegEx
                        // We could consider treating VTable's differently (a vt-specific key or different
                        // hash), but we want to be consistent with the windows map case here.

                        key     = match.Groups["symName"].ToString();
                        address = UInt32.Parse(match.Groups["address"].ToString(), NumberStyles.AllowHexSpecifier);

                        if (i == (int)UnixSymbolTypes.VtAddr)
                        {
                            // For VTables, what we really want is the vtAddr used at offset zero of objects.
                            // GCC has the vtAddr point to the 3rd slot of the VTable (in contrast to MSVC where
                            // the vtAddr points to the base of the VTable).
                            // Slot 0 appears to typically be NULL
                            // Slot 1 points to the run-time type info for the type
                            // Slot 2 is the first virtual method
                            // Fix up the symbol address here to match the value used in object headers.
                            // Note that we don't know a lot about the target here (eg. what platform it's
                            // running on), so it might be better to do this adjustment in DAC itself.  But
                            // for now doing it here is simpler and more reliable (only one place to update
                            // to make it consistent).
                            address += 2 * 4;   // assumes 32-bit
                        }
                    }

                    si = (SymbolInfo)SymbolHash[key];
                    if (si != null)
                    {
                        // Some duplicates are expected (eg. functions with overloads), but we should never
                        // actually care about the address of such symbols.  Record that this is a dup
                        // so that we can warn/fail if we try to use it.
                        si.dupFound = true;
                    }
                    else
                    {
                        si = new SymbolInfo(segment, address);
                        // Console.WriteLine("{0:x8} {1}", si.Segment, si.Address, key);
                        SymbolHash.Add(key, si);
                    }
                }
            }
        }

        strm.Close();
    }