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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 217 } |
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 #ifdef ENABLE_LOGGING_AND_PROFILING | 226 #ifdef ENABLE_LOGGING_AND_PROFILING |
227 static unsigned StringToLong(char* buffer) { | 227 static uintptr_t StringToULong(char* buffer) { |
228 return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT | 228 return strtoul(buffer, NULL, 16); // NOLINT |
229 } | 229 } |
230 #endif | 230 #endif |
231 | 231 |
232 | 232 |
233 void OS::LogSharedLibraryAddresses() { | 233 void OS::LogSharedLibraryAddresses() { |
234 #ifdef ENABLE_LOGGING_AND_PROFILING | 234 #ifdef ENABLE_LOGGING_AND_PROFILING |
235 static const int MAP_LENGTH = 1024; | 235 static const int MAP_LENGTH = 1024; |
236 int fd = open("/proc/self/maps", O_RDONLY); | 236 int fd = open("/proc/self/maps", O_RDONLY); |
237 if (fd < 0) return; | 237 if (fd < 0) return; |
238 while (true) { | 238 while (true) { |
239 char addr_buffer[11]; | 239 char addr_buffer[11]; |
240 addr_buffer[0] = '0'; | 240 addr_buffer[0] = '0'; |
241 addr_buffer[1] = 'x'; | 241 addr_buffer[1] = 'x'; |
242 addr_buffer[10] = 0; | 242 addr_buffer[10] = 0; |
243 int result = read(fd, addr_buffer + 2, 8); | 243 int result = read(fd, addr_buffer + 2, 8); |
244 if (result < 8) break; | 244 if (result < 8) break; |
245 unsigned start = StringToLong(addr_buffer); | 245 uintptr_t start = StringToULong(addr_buffer); |
246 result = read(fd, addr_buffer + 2, 1); | 246 result = read(fd, addr_buffer + 2, 1); |
247 if (result < 1) break; | 247 if (result < 1) break; |
248 if (addr_buffer[2] != '-') break; | 248 if (addr_buffer[2] != '-') break; |
249 result = read(fd, addr_buffer + 2, 8); | 249 result = read(fd, addr_buffer + 2, 8); |
250 if (result < 8) break; | 250 if (result < 8) break; |
251 unsigned end = StringToLong(addr_buffer); | 251 uintptr_t end = StringToULong(addr_buffer); |
252 char buffer[MAP_LENGTH]; | 252 char buffer[MAP_LENGTH]; |
253 int bytes_read = -1; | 253 int bytes_read = -1; |
254 do { | 254 do { |
255 bytes_read++; | 255 bytes_read++; |
256 if (bytes_read >= MAP_LENGTH - 1) | 256 if (bytes_read >= MAP_LENGTH - 1) |
257 break; | 257 break; |
258 result = read(fd, buffer + bytes_read, 1); | 258 result = read(fd, buffer + bytes_read, 1); |
259 if (result < 1) break; | 259 if (result < 1) break; |
260 } while (buffer[bytes_read] != '\n'); | 260 } while (buffer[bytes_read] != '\n'); |
261 buffer[bytes_read] = 0; | 261 buffer[bytes_read] = 0; |
262 // Ignore mappings that are not executable. | 262 // Ignore mappings that are not executable. |
263 if (buffer[3] != 'x') continue; | 263 if (buffer[3] != 'x') continue; |
264 char* start_of_path = index(buffer, '/'); | 264 char* start_of_path = index(buffer, '/'); |
265 // There may be no filename in this line. Skip to next. | 265 // If there is no filename for this line then log it as an anonymous |
266 if (start_of_path == NULL) continue; | 266 // mapping and use the address as its name. |
267 buffer[bytes_read] = 0; | 267 if (start_of_path == NULL) { |
268 LOG(SharedLibraryEvent(start_of_path, start, end)); | 268 // 40 is enough to print a 64 bit address range. |
| 269 ASSERT(sizeof(buffer) > 40); |
| 270 snprintf(buffer, |
| 271 sizeof(buffer), |
| 272 "%08" V8PRIxPTR "-%08" V8PRIxPTR, |
| 273 start, |
| 274 end); |
| 275 LOG(SharedLibraryEvent(buffer, start, end)); |
| 276 } else { |
| 277 buffer[bytes_read] = 0; |
| 278 LOG(SharedLibraryEvent(start_of_path, start, end)); |
| 279 } |
269 } | 280 } |
270 close(fd); | 281 close(fd); |
271 #endif | 282 #endif |
272 } | 283 } |
273 | 284 |
274 | 285 |
275 int OS::StackWalk(Vector<OS::StackFrame> frames) { | 286 int OS::StackWalk(Vector<OS::StackFrame> frames) { |
276 // backtrace is a glibc extension. | 287 // backtrace is a glibc extension. |
277 #ifdef __GLIBC__ | 288 #ifdef __GLIBC__ |
278 int frames_size = frames.length(); | 289 int frames_size = frames.length(); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } | 707 } |
697 | 708 |
698 // This sampler is no longer the active sampler. | 709 // This sampler is no longer the active sampler. |
699 active_sampler_ = NULL; | 710 active_sampler_ = NULL; |
700 active_ = false; | 711 active_ = false; |
701 } | 712 } |
702 | 713 |
703 #endif // ENABLE_LOGGING_AND_PROFILING | 714 #endif // ENABLE_LOGGING_AND_PROFILING |
704 | 715 |
705 } } // namespace v8::internal | 716 } } // namespace v8::internal |
OLD | NEW |