author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46560 | hotspot/src/share/vm/utilities/elfStringTable.cpp@388aa8d67c80 |
child 47765 | b7c7428eaab9 |
permissions | -rw-r--r-- |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
1 |
/* |
46560
388aa8d67c80
8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents:
22857
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, 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" |
46560
388aa8d67c80
8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents:
22857
diff
changeset
|
30 |
#include "prims/jvm.h" |
9403
6f3c6231c20a
7036747: 7017009 reappeared, problem with ElfStringTable
zgu
parents:
7447
diff
changeset
|
31 |
#include "runtime/os.hpp" |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
32 |
#include "utilities/elfStringTable.hpp" |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
33 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
34 |
// We will try to load whole string table into memory if we can. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
35 |
// Otherwise, fallback to more expensive file operation. |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
36 |
ElfStringTable::ElfStringTable(FILE* file, Elf_Shdr shdr, int index) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
37 |
assert(file, "null file handle"); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
38 |
m_table = NULL; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
39 |
m_index = index; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
40 |
m_next = NULL; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
41 |
m_file = file; |
11483 | 42 |
m_status = NullDecoder::no_error; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
43 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
44 |
// try to load the string table |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
45 |
long cur_offset = ftell(file); |
13195 | 46 |
m_table = (char*)os::malloc(sizeof(char) * shdr.sh_size, mtInternal); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
47 |
if (m_table != NULL) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
48 |
// if there is an error, mark the error |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
49 |
if (fseek(file, shdr.sh_offset, SEEK_SET) || |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
50 |
fread((void*)m_table, shdr.sh_size, 1, file) != 1 || |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
51 |
fseek(file, cur_offset, SEEK_SET)) { |
11483 | 52 |
m_status = NullDecoder::file_invalid; |
9403
6f3c6231c20a
7036747: 7017009 reappeared, problem with ElfStringTable
zgu
parents:
7447
diff
changeset
|
53 |
os::free((void*)m_table); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
54 |
m_table = NULL; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
55 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
56 |
} else { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
57 |
memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
58 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
59 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
60 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
61 |
ElfStringTable::~ElfStringTable() { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
62 |
if (m_table != NULL) { |
9403
6f3c6231c20a
7036747: 7017009 reappeared, problem with ElfStringTable
zgu
parents:
7447
diff
changeset
|
63 |
os::free((void*)m_table); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
64 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
65 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
66 |
if (m_next != NULL) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
67 |
delete m_next; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
68 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
69 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
70 |
|
11483 | 71 |
bool ElfStringTable::string_at(int pos, char* buf, int buflen) { |
72 |
if (NullDecoder::is_error(m_status)) { |
|
73 |
return false; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
74 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
75 |
if (m_table != NULL) { |
11483 | 76 |
jio_snprintf(buf, buflen, "%s", (const char*)(m_table + pos)); |
77 |
return true; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
78 |
} else { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
79 |
long cur_pos = ftell(m_file); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
80 |
if (cur_pos == -1 || |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
81 |
fseek(m_file, m_shdr.sh_offset + pos, SEEK_SET) || |
11483 | 82 |
fread(buf, 1, buflen, m_file) <= 0 || |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
83 |
fseek(m_file, cur_pos, SEEK_SET)) { |
11483 | 84 |
m_status = NullDecoder::file_invalid; |
85 |
return false; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
86 |
} |
11483 | 87 |
return true; |
7447
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 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
90 |
|
22857
2167396cfc83
8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
13963
diff
changeset
|
91 |
#endif // !_WINDOWS && !__APPLE__ |