Mercurial > hg > truffle
comparison src/share/vm/utilities/elfStringTable.cpp @ 4970:33df1aeaebbf
Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Mon, 27 Feb 2012 13:10:13 +0100 |
parents | d7e3846464d0 |
children | d2a62e0f25eb |
comparison
equal
deleted
inserted
replaced
4703:2cfb7fb2dce7 | 4970:33df1aeaebbf |
---|---|
36 assert(file, "null file handle"); | 36 assert(file, "null file handle"); |
37 m_table = NULL; | 37 m_table = NULL; |
38 m_index = index; | 38 m_index = index; |
39 m_next = NULL; | 39 m_next = NULL; |
40 m_file = file; | 40 m_file = file; |
41 m_status = Decoder::no_error; | 41 m_status = NullDecoder::no_error; |
42 | 42 |
43 // try to load the string table | 43 // try to load the string table |
44 long cur_offset = ftell(file); | 44 long cur_offset = ftell(file); |
45 m_table = (char*)os::malloc(sizeof(char) * shdr.sh_size); | 45 m_table = (char*)os::malloc(sizeof(char) * shdr.sh_size); |
46 if (m_table != NULL) { | 46 if (m_table != NULL) { |
47 // if there is an error, mark the error | 47 // if there is an error, mark the error |
48 if (fseek(file, shdr.sh_offset, SEEK_SET) || | 48 if (fseek(file, shdr.sh_offset, SEEK_SET) || |
49 fread((void*)m_table, shdr.sh_size, 1, file) != 1 || | 49 fread((void*)m_table, shdr.sh_size, 1, file) != 1 || |
50 fseek(file, cur_offset, SEEK_SET)) { | 50 fseek(file, cur_offset, SEEK_SET)) { |
51 m_status = Decoder::file_invalid; | 51 m_status = NullDecoder::file_invalid; |
52 os::free((void*)m_table); | 52 os::free((void*)m_table); |
53 m_table = NULL; | 53 m_table = NULL; |
54 } | 54 } |
55 } else { | 55 } else { |
56 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); | 56 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); |
65 if (m_next != NULL) { | 65 if (m_next != NULL) { |
66 delete m_next; | 66 delete m_next; |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 const char* ElfStringTable::string_at(int pos) { | 70 bool ElfStringTable::string_at(int pos, char* buf, int buflen) { |
71 if (m_status != Decoder::no_error) { | 71 if (NullDecoder::is_error(m_status)) { |
72 return NULL; | 72 return false; |
73 } | 73 } |
74 if (m_table != NULL) { | 74 if (m_table != NULL) { |
75 return (const char*)(m_table + pos); | 75 jio_snprintf(buf, buflen, "%s", (const char*)(m_table + pos)); |
76 return true; | |
76 } else { | 77 } else { |
77 long cur_pos = ftell(m_file); | 78 long cur_pos = ftell(m_file); |
78 if (cur_pos == -1 || | 79 if (cur_pos == -1 || |
79 fseek(m_file, m_shdr.sh_offset + pos, SEEK_SET) || | 80 fseek(m_file, m_shdr.sh_offset + pos, SEEK_SET) || |
80 fread(m_symbol, 1, MAX_SYMBOL_LEN, m_file) <= 0 || | 81 fread(buf, 1, buflen, m_file) <= 0 || |
81 fseek(m_file, cur_pos, SEEK_SET)) { | 82 fseek(m_file, cur_pos, SEEK_SET)) { |
82 m_status = Decoder::file_invalid; | 83 m_status = NullDecoder::file_invalid; |
83 return NULL; | 84 return false; |
84 } | 85 } |
85 return (const char*)m_symbol; | 86 return true; |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 #endif // _WINDOWS | 90 #endif // _WINDOWS |