| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 1 #include <errno.h> | 5 #include <errno.h> |
| 2 #include <fcntl.h> | 6 #include <fcntl.h> |
| 3 #include <iostream> | 7 #include <iostream> |
| 4 #include <linux/unistd.h> | 8 #include <linux/unistd.h> |
| 5 #include <signal.h> | 9 #include <signal.h> |
| 6 #include <stdarg.h> | 10 #include <stdarg.h> |
| 7 #include <stdlib.h> | 11 #include <stdlib.h> |
| 8 #include <sys/ptrace.h> | 12 #include <sys/ptrace.h> |
| 9 #include <sys/types.h> | 13 #include <sys/types.h> |
| 10 #include <sys/wait.h> | 14 #include <sys/wait.h> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 39 } |
| 36 } | 40 } |
| 37 char *ptr = buf; | 41 char *ptr = buf; |
| 38 if (!long_line) { | 42 if (!long_line) { |
| 39 long_line = true; | 43 long_line = true; |
| 40 unsigned long start = strtoul(ptr, &ptr, 16); | 44 unsigned long start = strtoul(ptr, &ptr, 16); |
| 41 unsigned long stop = strtoul(ptr + 1, &ptr, 16); | 45 unsigned long stop = strtoul(ptr + 1, &ptr, 16); |
| 42 while (*ptr == ' ' || *ptr == '\t') ++ptr; | 46 while (*ptr == ' ' || *ptr == '\t') ++ptr; |
| 43 char *perm_ptr = ptr; | 47 char *perm_ptr = ptr; |
| 44 while (*ptr && *ptr != ' ' && *ptr != '\t') ++ptr; | 48 while (*ptr && *ptr != ' ' && *ptr != '\t') ++ptr; |
| 45 std::string perm(perm_ptr, ptr - perm_ptr); | 49 string perm(perm_ptr, ptr - perm_ptr); |
| 46 unsigned long offset = strtoul(ptr, &ptr, 16); | 50 unsigned long offset = strtoul(ptr, &ptr, 16); |
| 47 while (*ptr == ' ' || *ptr == '\t') ++ptr; | 51 while (*ptr == ' ' || *ptr == '\t') ++ptr; |
| 48 char *id_ptr = ptr; | 52 char *id_ptr = ptr; |
| 49 while (*ptr && *ptr != ' ' && *ptr != '\t') ++ptr; | 53 while (*ptr && *ptr != ' ' && *ptr != '\t') ++ptr; |
| 50 while (*ptr == ' ' || *ptr == '\t') ++ptr; | 54 while (*ptr == ' ' || *ptr == '\t') ++ptr; |
| 51 while (*ptr && *ptr != ' ' && *ptr != '\t') ++ptr; | 55 while (*ptr && *ptr != ' ' && *ptr != '\t') ++ptr; |
| 52 std::string id(id_ptr, ptr - id_ptr); | 56 string id(id_ptr, ptr - id_ptr); |
| 53 while (*ptr == ' ' || *ptr == '\t') ++ptr; | 57 while (*ptr == ' ' || *ptr == '\t') ++ptr; |
| 54 char *library_ptr = ptr; | 58 char *library_ptr = ptr; |
| 55 while (*ptr && *ptr != ' ' && *ptr != '\t' && *ptr != '\n') ++ptr; | 59 while (*ptr && *ptr != ' ' && *ptr != '\t' && *ptr != '\n') ++ptr; |
| 56 std::string library(library_ptr, ptr - library_ptr); | 60 string library(library_ptr, ptr - library_ptr); |
| 57 bool isVDSO = false; | 61 bool isVDSO = false; |
| 58 if (library == "[vdso]") { | 62 if (library == "[vdso]") { |
| 59 // /proc/self/maps has a misleading file offset in the [vdso] entry. | 63 // /proc/self/maps has a misleading file offset in the [vdso] entry. |
| 60 // Override it with a sane value. | 64 // Override it with a sane value. |
| 61 offset = 0; | 65 offset = 0; |
| 62 isVDSO = true; | 66 isVDSO = true; |
| 63 } else if (library == "[vsyscall]") { | 67 } else if (library == "[vsyscall]") { |
| 64 vsyscall_ = reinterpret_cast<char *>(start); | 68 vsyscall_ = reinterpret_cast<char *>(start); |
| 65 } else if (library.empty() || library[0] == '[') { | 69 } else if (library.empty() || library[0] == '[') { |
| 66 goto skip_entry; | 70 goto skip_entry; |
| 67 } | 71 } |
| 68 int prot = 0; | 72 int prot = 0; |
| 69 if (perm.find('r') != std::string::npos) { | 73 if (perm.find('r') != string::npos) { |
| 70 prot |= PROT_READ; | 74 prot |= PROT_READ; |
| 71 } | 75 } |
| 72 if (perm.find('w') != std::string::npos) { | 76 if (perm.find('w') != string::npos) { |
| 73 prot |= PROT_WRITE; | 77 prot |= PROT_WRITE; |
| 74 } | 78 } |
| 75 if (perm.find('x') != std::string::npos) { | 79 if (perm.find('x') != string::npos) { |
| 76 prot |= PROT_EXEC; | 80 prot |= PROT_EXEC; |
| 77 } | 81 } |
| 78 if ((prot & (PROT_EXEC | PROT_READ)) == 0) { | 82 if ((prot & (PROT_EXEC | PROT_READ)) == 0) { |
| 79 goto skip_entry; | 83 goto skip_entry; |
| 80 } | 84 } |
| 81 Library* lib = &libs_[id + ' ' + library]; | 85 Library* lib = &libs_[id + ' ' + library]; |
| 82 lib->setLibraryInfo(this); | 86 lib->setLibraryInfo(this); |
| 83 lib->addMemoryRange(reinterpret_cast<void *>(start), | 87 lib->addMemoryRange(reinterpret_cast<void *>(start), |
| 84 reinterpret_cast<void *>(stop), | 88 reinterpret_cast<void *>(stop), |
| 85 Elf_Addr(offset), | 89 Elf_Addr(offset), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 143 } |
| 140 | 144 |
| 141 bool Maps::Iterator::operator==(const Maps::Iterator& iter) const { | 145 bool Maps::Iterator::operator==(const Maps::Iterator& iter) const { |
| 142 return getIterator().operator==(iter.getIterator()); | 146 return getIterator().operator==(iter.getIterator()); |
| 143 } | 147 } |
| 144 | 148 |
| 145 bool Maps::Iterator::operator!=(const Maps::Iterator& iter) const { | 149 bool Maps::Iterator::operator!=(const Maps::Iterator& iter) const { |
| 146 return !operator==(iter); | 150 return !operator==(iter); |
| 147 } | 151 } |
| 148 | 152 |
| 149 std::string Maps::Iterator::name() const { | 153 Maps::string Maps::Iterator::name() const { |
| 150 return getIterator()->first; | 154 return getIterator()->first; |
| 151 } | 155 } |
| 152 | 156 |
| 153 // Test whether a line ends with "[stack]"; used for identifying the | 157 // Test whether a line ends with "[stack]"; used for identifying the |
| 154 // stack entry of /proc/self/maps. | 158 // stack entry of /proc/self/maps. |
| 155 static bool isStackLine(char* buf, char* end) { | 159 static bool isStackLine(char* buf, char* end) { |
| 156 char* ptr = buf; | 160 char* ptr = buf; |
| 157 for ( ; *ptr != '\n' && ptr < end; ++ptr) | 161 for ( ; *ptr != '\n' && ptr < end; ++ptr) |
| 158 ; | 162 ; |
| 159 if (ptr < end && ptr - 7 > buf) { | 163 if (ptr < end && ptr - 7 > buf) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 break; | 256 break; |
| 253 } | 257 } |
| 254 } | 258 } |
| 255 } while (len || long_line); | 259 } while (len || long_line); |
| 256 new_addr = NULL; | 260 new_addr = NULL; |
| 257 done: | 261 done: |
| 258 return reinterpret_cast<char*>(new_addr); | 262 return reinterpret_cast<char*>(new_addr); |
| 259 } | 263 } |
| 260 | 264 |
| 261 } // namespace | 265 } // namespace |
| OLD | NEW |