| 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..61624d601dae3776378326dc7e34bf3c5415838b 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* in_pc, char *out, int out_size, uint64_t *start_address) {
|
| + uint64_t pc = reinterpret_cast<uintptr_t>(in_pc);
|
| 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 <= pc && pc < 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) + 1) > out_size) { // +1 for '\0'.
|
| + return false; // Not enough room to write null-terminated 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 file_name[256];
|
| + if (!FindObjectFileNameContainingPcAndGetStartAddress(
|
| + pc, file_name, sizeof(file_name), &start_address)) {
|
| + return false;
|
| + }
|
| +
|
| + int object_fd = -1;
|
| + NO_INTR(object_fd = open(file_name, O_RDONLY));
|
| + if (object_fd < 0) {
|
| return false;
|
| }
|
| FileDescriptor wrapped_object_fd(object_fd);
|
|
|