Beispiel #1
0
        public TargetMemoryArea[] GetMemoryMaps()
        {
            if (!is_coredump)
            {
                throw new InvalidOperationException();
            }

            ArrayList list = new ArrayList();

            read_sections();

            ArrayList all_sections = new ArrayList();

            all_sections.AddRange(sections);

            foreach (Section section in all_sections)
            {
                if ((section.flags & SectionFlags.Alloc) == 0)
                {
                    continue;
                }

                if (section.size == 0)
                {
                    continue;
                }

                TargetAddress start = new TargetAddress(
                    info.AddressDomain, section.vma);
                TargetAddress end = start + section.size;

                TargetMemoryFlags flags = 0;
                if ((section.flags & SectionFlags.ReadOnly) != 0)
                {
                    flags |= TargetMemoryFlags.ReadOnly;
                }

                if (list.Count > 0)
                {
                    TargetMemoryArea last = (TargetMemoryArea)list [list.Count - 1];

                    if ((last.Flags == flags) &&
                        ((last.End + 1 == start) || (last.End == start)))
                    {
                        list [list.Count - 1] = new TargetMemoryArea(
                            last.Start, end, last.Flags, last.Name);
                        continue;
                    }
                }

                string name = section.bfd.FileName;
                list.Add(new TargetMemoryArea(start, end, flags, name));
            }

            TargetMemoryArea[] maps = new TargetMemoryArea [list.Count];
            list.CopyTo(maps, 0);
            return(maps);
        }
Beispiel #2
0
        public TargetMemoryArea[] GetMemoryMaps()
        {
            // We cannot use System.IO to read this file because it is not
            // seekable.  Actually, the file is seekable, but it contains
            // "holes" and each line starts on a new 4096 bytes block.
            // So if you just read the first line from the file, the current
            // file position will be rounded up to the next 4096 bytes
            // boundary - it'll be different from what System.IO thinks is
            // the current file position and System.IO will try to "fix" this
            // by seeking back.
            string mapfile = String.Format ("/proc/{0}/maps", child_pid);
            string contents = GetFileContents (mapfile);

            if (contents == null)
                return null;

            ArrayList list = new ArrayList ();

            using (StringReader reader = new StringReader (contents)) {
                do {
                    string l = reader.ReadLine ();
                    if (l == null)
                        break;

                    bool is64bit;
                    if (l [8] == '-')
                        is64bit = false;
                    else if (l [16] == '-')
                        is64bit = true;
                    else
                        throw new InternalError ();

                    string sstart = is64bit ? l.Substring (0,16) : l.Substring (0,8);
                    string send = is64bit ? l.Substring (17,16) : l.Substring (9,8);
                    string sflags = is64bit ? l.Substring (34,4) : l.Substring (18,4);

                    long start = Int64.Parse (sstart, NumberStyles.HexNumber);
                    long end = Int64.Parse (send, NumberStyles.HexNumber);

                    string name;
                    if (is64bit)
                        name = (l.Length > 73) ? l.Substring (73) : "";
                    else
                        name = (l.Length > 49) ? l.Substring (49) : "";
                    name = name.TrimStart (' ').TrimEnd (' ');
                    if (name == "")
                        name = null;

                    TargetMemoryFlags flags = 0;
                    if (sflags [1] != 'w')
                        flags |= TargetMemoryFlags.ReadOnly;

                    TargetMemoryArea area = new TargetMemoryArea (
                        new TargetAddress (AddressDomain, start),
                        new TargetAddress (AddressDomain, end),
                        flags, name);
                    list.Add (area);
                } while (true);
            }

            TargetMemoryArea[] maps = new TargetMemoryArea [list.Count];
            list.CopyTo (maps, 0);
            return maps;
        }