zgu@2364: /* zgu@2364: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. zgu@2364: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. zgu@2364: * zgu@2364: * This code is free software; you can redistribute it and/or modify it zgu@2364: * under the terms of the GNU General Public License version 2 only, as zgu@2364: * published by the Free Software Foundation. zgu@2364: * zgu@2364: * This code is distributed in the hope that it will be useful, but WITHOUT zgu@2364: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or zgu@2364: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License zgu@2364: * version 2 for more details (a copy is included in the LICENSE file that zgu@2364: * accompanied this code). zgu@2364: * zgu@2364: * You should have received a copy of the GNU General Public License version zgu@2364: * 2 along with this work; if not, write to the Free Software Foundation, zgu@2364: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. zgu@2364: * zgu@2364: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA zgu@2364: * or visit www.oracle.com if you need additional information or have any zgu@2364: * questions. zgu@2364: * zgu@2364: */ zgu@2364: zgu@2364: #include "precompiled.hpp" zgu@2364: #include "prims/jvm.h" zgu@2364: #include "utilities/decoder.hpp" zgu@2364: zgu@2364: Decoder::decoder_status Decoder::_decoder_status = Decoder::no_error; zgu@2364: bool Decoder::_initialized = false; zgu@2364: zgu@2364: #ifndef _WINDOWS zgu@2364: zgu@2364: // Implementation of common functionalities among Solaris and Linux zgu@2364: #include "utilities/elfFile.hpp" zgu@2364: zgu@2364: ElfFile* Decoder::_opened_elf_files = NULL; zgu@2364: zgu@2364: bool Decoder::can_decode_C_frame_in_vm() { zgu@2364: return true; zgu@2364: } zgu@2364: zgu@2364: void Decoder::initialize() { zgu@2364: _initialized = true; zgu@2364: } zgu@2364: zgu@2364: void Decoder::uninitialize() { zgu@2364: if (_opened_elf_files != NULL) { zgu@2364: delete _opened_elf_files; zgu@2364: _opened_elf_files = NULL; zgu@2364: } zgu@2364: _initialized = false; zgu@2364: } zgu@2364: zgu@2364: Decoder::decoder_status Decoder::decode(address addr, const char* filepath, char *buf, int buflen, int *offset) { zgu@2364: if (_decoder_status != no_error) { zgu@2364: return _decoder_status; zgu@2364: } zgu@2364: zgu@2364: ElfFile* file = get_elf_file(filepath); zgu@2364: if (_decoder_status != no_error) { zgu@2364: return _decoder_status; zgu@2364: } zgu@2364: zgu@2364: const char* symbol = file->decode(addr, offset); zgu@2364: if (file->get_status() == out_of_memory) { zgu@2364: _decoder_status = out_of_memory; zgu@2364: return _decoder_status; zgu@2364: } else if (symbol != NULL) { zgu@2364: if (!demangle(symbol, buf, buflen)) { zgu@2364: jio_snprintf(buf, buflen, "%s", symbol); zgu@2364: } zgu@2364: return no_error; zgu@2364: } else { zgu@2364: return symbol_not_found; zgu@2364: } zgu@2364: } zgu@2364: zgu@2364: ElfFile* Decoder::get_elf_file(const char* filepath) { zgu@2364: if (_decoder_status != no_error) { zgu@2364: return NULL; zgu@2364: } zgu@2364: ElfFile* file = _opened_elf_files; zgu@2364: while (file != NULL) { zgu@2364: if (file->same_elf_file(filepath)) { zgu@2364: return file; zgu@2364: } zgu@2364: file = file->m_next; zgu@2364: } zgu@2364: zgu@2364: file = new ElfFile(filepath); zgu@2364: if (file == NULL) { zgu@2364: _decoder_status = out_of_memory; zgu@2364: } zgu@2364: if (_opened_elf_files != NULL) { zgu@2364: file->m_next = _opened_elf_files; zgu@2364: } zgu@2364: zgu@2364: _opened_elf_files = file; zgu@2364: return file; zgu@2364: } zgu@2364: zgu@2364: #endif zgu@2364: