Tue, 25 Feb 2014 15:11:18 -0800
Merge
zgu@3430 | 1 | /* |
mikael@4153 | 2 | * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
zgu@3430 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
zgu@3430 | 4 | * |
zgu@3430 | 5 | * This code is free software; you can redistribute it and/or modify it |
zgu@3430 | 6 | * under the terms of the GNU General Public License version 2 only, as |
zgu@3430 | 7 | * published by the Free Software Foundation. |
zgu@3430 | 8 | * |
zgu@3430 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
zgu@3430 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
zgu@3430 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
zgu@3430 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
zgu@3430 | 13 | * accompanied this code). |
zgu@3430 | 14 | * |
zgu@3430 | 15 | * You should have received a copy of the GNU General Public License version |
zgu@3430 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
zgu@3430 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
zgu@3430 | 18 | * |
zgu@3430 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
zgu@3430 | 20 | * or visit www.oracle.com if you need additional information or have any |
zgu@3430 | 21 | * questions. |
zgu@3430 | 22 | * |
zgu@3430 | 23 | */ |
zgu@3430 | 24 | |
zgu@3430 | 25 | #include "precompiled.hpp" |
zgu@3430 | 26 | |
zgu@3430 | 27 | #if !defined(_WINDOWS) && !defined(__APPLE__) |
zgu@3430 | 28 | #include "decoder_elf.hpp" |
zgu@3430 | 29 | |
zgu@3430 | 30 | ElfDecoder::~ElfDecoder() { |
zgu@3430 | 31 | if (_opened_elf_files != NULL) { |
zgu@3430 | 32 | delete _opened_elf_files; |
zgu@3430 | 33 | _opened_elf_files = NULL; |
zgu@3430 | 34 | } |
zgu@3430 | 35 | } |
zgu@3430 | 36 | |
zgu@3430 | 37 | bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* filepath) { |
zgu@3430 | 38 | assert(filepath, "null file path"); |
zgu@3430 | 39 | assert(buf != NULL && buflen > 0, "Invalid buffer"); |
zgu@3430 | 40 | if (has_error()) return false; |
zgu@3430 | 41 | ElfFile* file = get_elf_file(filepath); |
zgu@3430 | 42 | if (file == NULL) { |
zgu@3430 | 43 | return false; |
zgu@3430 | 44 | } |
zgu@3430 | 45 | |
zgu@3430 | 46 | if (!file->decode(addr, buf, buflen, offset)) { |
zgu@3430 | 47 | return false; |
zgu@3430 | 48 | } |
zgu@3430 | 49 | if (buf[0] != '\0') { |
zgu@3430 | 50 | demangle(buf, buf, buflen); |
zgu@3430 | 51 | } |
zgu@3430 | 52 | return true; |
zgu@3430 | 53 | } |
zgu@3430 | 54 | |
zgu@3430 | 55 | ElfFile* ElfDecoder::get_elf_file(const char* filepath) { |
zgu@3430 | 56 | ElfFile* file; |
zgu@3430 | 57 | |
zgu@3430 | 58 | file = _opened_elf_files; |
zgu@3430 | 59 | while (file != NULL) { |
zgu@3430 | 60 | if (file->same_elf_file(filepath)) { |
zgu@3430 | 61 | return file; |
zgu@3430 | 62 | } |
zgu@3430 | 63 | file = file->next(); |
zgu@3430 | 64 | } |
zgu@3430 | 65 | |
zgu@3430 | 66 | file = new (std::nothrow)ElfFile(filepath); |
zgu@3430 | 67 | if (file != NULL) { |
zgu@3430 | 68 | if (_opened_elf_files != NULL) { |
zgu@3430 | 69 | file->set_next(_opened_elf_files); |
zgu@3430 | 70 | } |
zgu@3430 | 71 | _opened_elf_files = file; |
zgu@3430 | 72 | } |
zgu@3430 | 73 | |
zgu@3430 | 74 | return file; |
zgu@3430 | 75 | } |
simonis@6491 | 76 | #endif // !_WINDOWS && !__APPLE__ |