Path: blob/master/src/jdk.hotspot.agent/linux/native/libsaproc/dwarf.hpp
41149 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020, NTT DATA.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#ifndef _DWARF_HPP_26#define _DWARF_HPP_2728#include "libproc_impl.h"2930/*31* from System V Application Binary Interface32* AMD64 Architecture Processor Supplement33* Figure 3.38: DWARF Register Number Mapping34* https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf35*/36enum DWARF_Register {37RAX,38RDX,39RCX,40RBX,41RSI,42RDI,43RBP,44RSP,45R8,46R9,47R10,48R11,49R12,50R13,51R14,52R15,53RA,54MAX_VALUE55};5657/*58* DwarfParser finds out CFA (Canonical Frame Address) from DWARF in ELF binary.59* Also Return Address (RA) and Base Pointer (BP) are calculated from CFA.60*/61class DwarfParser {62private:63const lib_info *_lib;64unsigned char *_buf;65unsigned char _encoding;66enum DWARF_Register _cfa_reg;67enum DWARF_Register _return_address_reg;68unsigned int _code_factor;69int _data_factor;7071uintptr_t _current_pc;72int _cfa_offset;73int _ra_cfa_offset;74int _bp_cfa_offset;75bool _bp_offset_available;7677uintptr_t read_leb(bool sign);78uint64_t get_entry_length();79bool process_cie(unsigned char *start_of_entry, uint32_t id);80void parse_dwarf_instructions(uintptr_t begin, uintptr_t pc, const unsigned char *end);81uint32_t get_decoded_value();82unsigned int get_pc_range();8384public:85DwarfParser(lib_info *lib) : _lib(lib),86_buf(NULL),87_encoding(0),88_cfa_reg(RSP),89_return_address_reg(RA),90_code_factor(0),91_data_factor(0),92_current_pc(0L),93_cfa_offset(0),94_ra_cfa_offset(0),95_bp_cfa_offset(0),96_bp_offset_available(false) {};9798~DwarfParser() {}99bool process_dwarf(const uintptr_t pc);100enum DWARF_Register get_cfa_register() { return _cfa_reg; }101int get_cfa_offset() { return _cfa_offset; }102int get_ra_cfa_offset() { return _ra_cfa_offset; }103int get_bp_cfa_offset() { return _bp_cfa_offset; }104bool is_bp_offset_available() { return _bp_offset_available; }105106bool is_in(long pc) {107return (_lib->exec_start <= pc) && (pc < _lib->exec_end);108}109110bool is_parseable() {111return _lib->eh_frame.data != NULL;112}113};114115#endif //_DWARF_HPP_116117118