author | naoto |
Tue, 09 Jul 2019 08:05:38 -0700 | |
changeset 55627 | 9c1885fb2a42 |
parent 51334 | cc2c79d22508 |
permissions | -rw-r--r-- |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
1 |
/* |
48975 | 2 |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
4 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
8 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
13 |
* accompanied this code). |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
14 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
18 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
21 |
* questions. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
22 |
* |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
23 |
*/ |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
24 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
26 |
|
10565 | 27 |
#if !defined(_WINDOWS) && !defined(__APPLE__) |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
28 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
29 |
#include "memory/allocation.inline.hpp" |
22857
2167396cfc83
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
13963
diff
changeset
|
30 |
#include "utilities/elfFuncDescTable.hpp" |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
31 |
#include "utilities/elfSymbolTable.hpp" |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
32 |
|
48975 | 33 |
ElfSymbolTable::ElfSymbolTable(FILE* const file, Elf_Shdr& shdr) : |
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
48975
diff
changeset
|
34 |
_next(NULL), _fd(file), _section(file, shdr) { |
48975 | 35 |
assert(file != NULL, "null file handle"); |
36 |
_status = _section.status(); |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
37 |
|
48975 | 38 |
if (_section.section_header()->sh_size % sizeof(Elf_Sym) != 0) { |
39 |
_status = NullDecoder::file_invalid; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
40 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
41 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
42 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
43 |
ElfSymbolTable::~ElfSymbolTable() { |
48975 | 44 |
if (_next != NULL) { |
45 |
delete _next; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
46 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
47 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
48 |
|
34641
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
49 |
bool ElfSymbolTable::compare(const Elf_Sym* sym, address addr, int* stringtableIndex, int* posIndex, int* offset, ElfFuncDescTable* funcDescTable) { |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
50 |
if (STT_FUNC == ELF_ST_TYPE(sym->st_info)) { |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
51 |
Elf_Word st_size = sym->st_size; |
48975 | 52 |
const Elf_Shdr* shdr = _section.section_header(); |
34641
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
53 |
address sym_addr; |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
54 |
if (funcDescTable != NULL && funcDescTable->get_index() == sym->st_shndx) { |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
55 |
// We need to go another step trough the function descriptor table (currently PPC64 only) |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
56 |
sym_addr = funcDescTable->lookup(sym->st_value); |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
57 |
} else { |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
58 |
sym_addr = (address)sym->st_value; |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
59 |
} |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
60 |
if (sym_addr <= addr && (Elf_Word)(addr - sym_addr) < st_size) { |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
61 |
*offset = (int)(addr - sym_addr); |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
62 |
*posIndex = sym->st_name; |
48975 | 63 |
*stringtableIndex = shdr->sh_link; |
34641
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
64 |
return true; |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
65 |
} |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
66 |
} |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
67 |
return false; |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
68 |
} |
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
69 |
|
22857
2167396cfc83
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
13963
diff
changeset
|
70 |
bool ElfSymbolTable::lookup(address addr, int* stringtableIndex, int* posIndex, int* offset, ElfFuncDescTable* funcDescTable) { |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
71 |
assert(stringtableIndex, "null string table index pointer"); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
72 |
assert(posIndex, "null string table offset pointer"); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
73 |
assert(offset, "null offset pointer"); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
74 |
|
48975 | 75 |
if (NullDecoder::is_error(get_status())) { |
11483 | 76 |
return false; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
77 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
78 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
79 |
size_t sym_size = sizeof(Elf_Sym); |
48975 | 80 |
int count = _section.section_header()->sh_size / sym_size; |
81 |
Elf_Sym* symbols = (Elf_Sym*)_section.section_data(); |
|
82 |
||
83 |
if (symbols != NULL) { |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
84 |
for (int index = 0; index < count; index ++) { |
48975 | 85 |
if (compare(&symbols[index], addr, stringtableIndex, posIndex, offset, funcDescTable)) { |
34641
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
86 |
return true; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
87 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
88 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
89 |
} else { |
48975 | 90 |
MarkedFileReader mfd(_fd); |
91 |
||
92 |
if (!mfd.has_mark() || !mfd.set_position(_section.section_header()->sh_offset)) { |
|
93 |
_status = NullDecoder::file_invalid; |
|
11483 | 94 |
return false; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
95 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
96 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
97 |
Elf_Sym sym; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
98 |
for (int index = 0; index < count; index ++) { |
48975 | 99 |
if (!mfd.read((void*)&sym, sizeof(sym))) { |
100 |
_status = NullDecoder::file_invalid; |
|
11483 | 101 |
return false; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
102 |
} |
48975 | 103 |
|
104 |
if (compare(&sym, addr, stringtableIndex, posIndex, offset, funcDescTable)) { |
|
105 |
return true; |
|
106 |
} |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
107 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
108 |
} |
34641
3755a5c95984
8144491: ElfSymbolTable::lookup returns bad value when the lookup has failed
iklam
parents:
22857
diff
changeset
|
109 |
return false; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
110 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
111 |
|
22857
2167396cfc83
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
13963
diff
changeset
|
112 |
#endif // !_WINDOWS && !__APPLE__ |