OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 218 |
219 | 219 |
220 PosixMemoryMappedFile::~PosixMemoryMappedFile() { | 220 PosixMemoryMappedFile::~PosixMemoryMappedFile() { |
221 if (memory_) munmap(memory_, size_); | 221 if (memory_) munmap(memory_, size_); |
222 fclose(file_); | 222 fclose(file_); |
223 } | 223 } |
224 | 224 |
225 | 225 |
226 void OS::LogSharedLibraryAddresses() { | 226 void OS::LogSharedLibraryAddresses() { |
227 #ifdef ENABLE_LOGGING_AND_PROFILING | 227 #ifdef ENABLE_LOGGING_AND_PROFILING |
228 FILE *fp; | 228 // This function assumes that the layout of the file is as follows: |
229 fp = fopen("/proc/self/maps", "r"); | 229 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] |
| 230 // If we encounter an unexpected situation we abort scanning further entries. |
| 231 FILE *fp = fopen("/proc/self/maps", "r"); |
230 if (fp == NULL) return; | 232 if (fp == NULL) return; |
| 233 |
| 234 // Allocate enough room to be able to store a full file name. |
| 235 const int kLibNameLen = FILENAME_MAX + 1; |
| 236 char* lib_name = reinterpret_cast<char*>(malloc(kLibNameLen)); |
| 237 |
| 238 // This loop will terminate once the scanning hits an EOF. |
231 while (true) { | 239 while (true) { |
232 uintptr_t start, end; | 240 uintptr_t start, end; |
233 char attr_r, attr_w, attr_x, attr_p; | 241 char attr_r, attr_w, attr_x, attr_p; |
| 242 // Parse the addresses and permission bits at the beginning of the line. |
234 if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break; | 243 if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break; |
235 if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break; | 244 if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break; |
| 245 |
236 int c; | 246 int c; |
237 if (attr_r == 'r' && attr_x == 'x') { | 247 if (attr_r == 'r' && attr_x == 'x') { |
238 while (c = getc(fp), (c != EOF) && (c != '\n') && (c != '/')); | 248 // Found a readable and executable entry. Skip characters until we reach |
239 char lib_name[1024]; | 249 // the beginning of the filename or the end of the line. |
240 bool lib_has_name = false; | 250 do { |
| 251 c = getc(fp); |
| 252 } while ((c != EOF) && (c != '\n') && (c != '/')); |
| 253 if (c == EOF) break; // EOF: Was unexpected, just exit. |
| 254 |
| 255 // Process the filename if found. |
241 if (c == '/') { | 256 if (c == '/') { |
242 ungetc(c, fp); | 257 ungetc(c, fp); // Push the '/' back into the stream to be read below. |
243 lib_has_name = fgets(lib_name, sizeof(lib_name), fp) != NULL; | 258 |
244 } | 259 // Read to the end of the line. Exit if the read fails. |
245 if (lib_has_name && strlen(lib_name) > 0) { | 260 if (fgets(lib_name, kLibNameLen, fp) == NULL) break; |
| 261 |
| 262 // Drop the newline character read by fgets. We do not need to check |
| 263 // for a zero-length string because we know that we at least read the |
| 264 // '/' character. |
246 lib_name[strlen(lib_name) - 1] = '\0'; | 265 lib_name[strlen(lib_name) - 1] = '\0'; |
247 } else { | 266 } else { |
248 snprintf(lib_name, sizeof(lib_name), | 267 // No library name found, just record the raw address range. |
| 268 snprintf(lib_name, kLibNameLen, |
249 "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end); | 269 "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end); |
250 } | 270 } |
251 LOG(SharedLibraryEvent(lib_name, start, end)); | 271 LOG(SharedLibraryEvent(lib_name, start, end)); |
| 272 } else { |
| 273 // Entry not describing executable data. Skip to end of line to setup |
| 274 // reading the next entry. |
| 275 do { |
| 276 c = getc(fp); |
| 277 } while ((c != EOF) && (c != '\n')); |
| 278 if (c == EOF) break; |
252 } | 279 } |
253 while (c = getc(fp), (c != EOF) && (c != '\n')); | |
254 } | 280 } |
| 281 free(lib_name); |
255 fclose(fp); | 282 fclose(fp); |
256 #endif | 283 #endif |
257 } | 284 } |
258 | 285 |
259 | 286 |
260 int OS::StackWalk(Vector<OS::StackFrame> frames) { | 287 int OS::StackWalk(Vector<OS::StackFrame> frames) { |
261 // backtrace is a glibc extension. | 288 // backtrace is a glibc extension. |
262 #ifdef __GLIBC__ | 289 #ifdef __GLIBC__ |
263 int frames_size = frames.length(); | 290 int frames_size = frames.length(); |
264 void** addresses = NewArray<void*>(frames_size); | 291 void** addresses = NewArray<void*>(frames_size); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 } | 709 } |
683 | 710 |
684 // This sampler is no longer the active sampler. | 711 // This sampler is no longer the active sampler. |
685 active_sampler_ = NULL; | 712 active_sampler_ = NULL; |
686 active_ = false; | 713 active_ = false; |
687 } | 714 } |
688 | 715 |
689 #endif // ENABLE_LOGGING_AND_PROFILING | 716 #endif // ENABLE_LOGGING_AND_PROFILING |
690 | 717 |
691 } } // namespace v8::internal | 718 } } // namespace v8::internal |
OLD | NEW |