OLD | NEW |
---|---|
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 // 32 elements (to keep stack consumption low), otherwise we can | 289 // 32 elements (to keep stack consumption low), otherwise we can |
290 // have a 64 element Elf32_Sym array. | 290 // have a 64 element Elf32_Sym array. |
291 #if __WORDSIZE == 64 | 291 #if __WORDSIZE == 64 |
292 #define NUM_SYMBOLS 32 | 292 #define NUM_SYMBOLS 32 |
293 #else | 293 #else |
294 #define NUM_SYMBOLS 64 | 294 #define NUM_SYMBOLS 64 |
295 #endif | 295 #endif |
296 | 296 |
297 // Read at most NUM_SYMBOLS symbols at once to save read() calls. | 297 // Read at most NUM_SYMBOLS symbols at once to save read() calls. |
298 ElfW(Sym) buf[NUM_SYMBOLS]; | 298 ElfW(Sym) buf[NUM_SYMBOLS]; |
299 const ssize_t len = ReadFromOffset(fd, &buf, sizeof(buf), offset); | 299 int num_symbols_to_read = num_symbols - i; |
hamaji
2016/12/16 07:21:14
Use std::min?
| |
300 if (num_symbols_to_read > NUM_SYMBOLS) | |
301 num_symbols_to_read = NUM_SYMBOLS; | |
302 const ssize_t len = | |
303 ReadFromOffset(fd, &buf, sizeof(buf[0]) * num_symbols_to_read, offset); | |
300 SAFE_ASSERT(len % sizeof(buf[0]) == 0); | 304 SAFE_ASSERT(len % sizeof(buf[0]) == 0); |
301 const ssize_t num_symbols_in_buf = len / sizeof(buf[0]); | 305 const ssize_t num_symbols_in_buf = len / sizeof(buf[0]); |
302 SAFE_ASSERT(num_symbols_in_buf <= sizeof(buf)/sizeof(buf[0])); | 306 SAFE_ASSERT(num_symbols_in_buf <= num_symbols_to_read); |
303 for (int j = 0; j < num_symbols_in_buf; ++j) { | 307 for (int j = 0; j < num_symbols_in_buf; ++j) { |
304 const ElfW(Sym)& symbol = buf[j]; | 308 const ElfW(Sym)& symbol = buf[j]; |
305 uint64_t start_address = symbol.st_value; | 309 uint64_t start_address = symbol.st_value; |
306 start_address += symbol_offset; | 310 start_address += symbol_offset; |
307 uint64_t end_address = start_address + symbol.st_size; | 311 uint64_t end_address = start_address + symbol.st_size; |
308 if (symbol.st_value != 0 && // Skip null value symbols. | 312 if (symbol.st_value != 0 && // Skip null value symbols. |
309 symbol.st_shndx != 0 && // Skip undefined symbols. | 313 symbol.st_shndx != 0 && // Skip undefined symbols. |
310 start_address <= pc && pc < end_address) { | 314 start_address <= pc && pc < end_address) { |
311 ssize_t len1 = ReadFromOffset(fd, out, out_size, | 315 ssize_t len1 = ReadFromOffset(fd, out, out_size, |
312 strtab->sh_offset + symbol.st_name); | 316 strtab->sh_offset + symbol.st_name); |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 | 865 |
862 // TODO: Support other environments. | 866 // TODO: Support other environments. |
863 bool Symbolize(void *pc, char *out, int out_size) { | 867 bool Symbolize(void *pc, char *out, int out_size) { |
864 assert(0); | 868 assert(0); |
865 return false; | 869 return false; |
866 } | 870 } |
867 | 871 |
868 _END_GOOGLE_NAMESPACE_ | 872 _END_GOOGLE_NAMESPACE_ |
869 | 873 |
870 #endif | 874 #endif |
OLD | NEW |