Chromium Code Reviews| Index: base/third_party/symbolize/symbolize.cc |
| diff --git a/base/third_party/symbolize/symbolize.cc b/base/third_party/symbolize/symbolize.cc |
| index 21c0a078e92c8ce5ba25ed9e86403546ce18b49a..522df19f0304eb9fef92325e7e6d914d4b902513 100644 |
| --- a/base/third_party/symbolize/symbolize.cc |
| +++ b/base/third_party/symbolize/symbolize.cc |
| @@ -483,13 +483,9 @@ static char *GetHex(const char *start, const char *end, uint64_t *hex) { |
| return const_cast<char *>(p); |
| } |
| -// Search for the object file (from /proc/self/maps) that contains |
| -// the specified pc. If found, open this file and return the file handle, |
| -// and also set start_address to the start address of where this object |
| -// file is mapped to in memory. Otherwise, return -1. |
| -static ATTRIBUTE_NOINLINE int |
| -OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, |
| - uint64_t &start_address) { |
| +bool FindObjectFileNameContainingPcAndGetStartAddress( |
| + void* pc, char *out, int out_size, uint64_t *start_address) { |
| + uint64_t pc0 = reinterpret_cast<uintptr_t>(pc); |
|
satorux1
2013/06/13 01:58:10
pc0 looks a bit cryptic. maybe:
void *in_pc, ...)
scherkus (not reviewing)
2013/06/13 02:20:46
I was following SymbolizeAndDemangle() but agree i
|
| int object_fd; |
| // Open /proc/self/maps. |
| @@ -497,7 +493,7 @@ OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, |
| NO_INTR(maps_fd = open("/proc/self/maps", O_RDONLY)); |
| FileDescriptor wrapped_maps_fd(maps_fd); |
| if (wrapped_maps_fd.get() < 0) { |
| - return -1; |
| + return false; |
| } |
| // Iterate over maps and look for the map containing the pc. Then |
| @@ -508,7 +504,7 @@ OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, |
| const char *cursor; |
| const char *eol; |
| if (!reader.ReadLine(&cursor, &eol)) { // EOF or malformed line. |
| - return -1; |
| + return false; |
| } |
| // Start parsing line in /proc/self/maps. Here is an example: |
| @@ -519,9 +515,9 @@ OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, |
| // (r-xp) and file name (/bin/cat). |
| // Read start address. |
| - cursor = GetHex(cursor, eol, &start_address); |
| + cursor = GetHex(cursor, eol, start_address); |
| if (cursor == eol || *cursor != '-') { |
| - return -1; // Malformed line. |
| + return false; // Malformed line. |
| } |
| ++cursor; // Skip '-'. |
| @@ -529,12 +525,12 @@ OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, |
| uint64_t end_address; |
| cursor = GetHex(cursor, eol, &end_address); |
| if (cursor == eol || *cursor != ' ') { |
| - return -1; // Malformed line. |
| + return false; // Malformed line. |
| } |
| ++cursor; // Skip ' '. |
| // Check start and end addresses. |
| - if (!(start_address <= pc && pc < end_address)) { |
| + if (!(*start_address <= pc0 && pc0 < end_address)) { |
| continue; // We skip this map. PC isn't in this map. |
| } |
| @@ -545,7 +541,7 @@ OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, |
| } |
| // We expect at least four letters for flags (ex. "r-xp"). |
| if (cursor == eol || cursor < flags_start + 4) { |
| - return -1; // Malformed line. |
| + return false; // Malformed line. |
| } |
| // Check flags. We are only interested in "r-x" maps. |
| @@ -568,15 +564,16 @@ OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc, |
| ++cursor; |
| } |
| if (cursor == eol) { |
| - return -1; // Malformed line. |
| + return false; // Malformed line. |
| } |
| // Finally, "cursor" now points to file name of our interest. |
| - NO_INTR(object_fd = open(cursor, O_RDONLY)); |
| - if (object_fd < 0) { |
| - return -1; |
| + if (strlen(cursor) >= out_size) { |
|
satorux1
2013/06/13 01:58:10
maybe slightly easier to read:
if (stlren(cursor)
scherkus (not reviewing)
2013/06/13 02:20:46
Done + beefed up comment on next line
|
| + return false; // Not enough room to write file name. |
| } |
| - return object_fd; |
| + |
| + strcpy(out, cursor); |
| + return true; |
| } |
| } |
| @@ -593,9 +590,15 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out, |
| uint64_t pc0 = reinterpret_cast<uintptr_t>(pc); |
| uint64_t start_address = 0; |
| - int object_fd = OpenObjectFileContainingPcAndGetStartAddress(pc0, |
| - start_address); |
| - if (object_fd == -1) { |
| + char buf[256]; |
|
scherkus (not reviewing)
2013/06/13 01:27:44
this additional buffer allocation is a bit crummy
satorux1
2013/06/13 01:58:10
sounds reasonable. buf -> file_name?
|
| + if (!FindObjectFileNameContainingPcAndGetStartAddress( |
| + pc, buf, sizeof(buf), &start_address)) { |
| + return false; |
| + } |
| + |
| + int object_fd; |
|
satorux1
2013/06/13 01:58:10
object_fd = - 1;
to be extra defensive.
scherkus (not reviewing)
2013/06/13 02:20:46
Done.
|
| + NO_INTR(object_fd = open(buf, O_RDONLY)); |
| + if (object_fd < 0) { |
| return false; |
| } |
| FileDescriptor wrapped_object_fd(object_fd); |