bfd_support.h revision cc2ee177dbb3befca43e36cfc56778b006c3d050
1/** 2 * @file bfd_support.h 3 * BFD muck we have to deal with. 4 * 5 * @remark Copyright 2005 OProfile authors 6 * @remark Read the file COPYING 7 * 8 * @author John Levon 9 */ 10 11#ifndef BFD_SUPPORT_H 12#define BFD_SUPPORT_H 13 14#include "utility.h" 15#include "op_types.h" 16 17#include <bfd.h> 18 19#include <string> 20 21class op_bfd_symbol; 22 23/// holder for BFD state we must keep 24struct bfd_info { 25 bfd_info() : abfd(0), nr_syms(0), synth_syms(0) {} 26 27 ~bfd_info(); 28 29 /// close the BFD, setting abfd to NULL 30 void close(); 31 32 /// return true if BFD is readable 33 bool valid() const { return abfd; } 34 35 /// return true if BFD has debug info 36 bool has_debug_info() const; 37 38 /// pick out the symbols from the bfd, if we can 39 void get_symbols(); 40 41 /// the actual BFD 42 bfd * abfd; 43 /// normal symbols (includes synthesized symbols) 44 scoped_array<asymbol *> syms; 45 /// nr. symbols 46 size_t nr_syms; 47 48private: 49 /** 50 * Acquire the synthetic symbols if we need to. 51 */ 52 bool get_synth_symbols(); 53 54 /** 55 * On PPC64, synth_syms points to an array of synthetic asymbol 56 * structs returned from bfd_get_synthetic_symtab. The syms 57 * member points into this array, so we have to keep it around 58 * until ~bfd_info time. 59 */ 60 asymbol * synth_syms; 61 62}; 63 64 65/* 66 * find_separate_debug_file - return true if a valid separate debug file found 67 * @param ibfd binary file 68 * @param dir_in directory holding the binary file 69 * @param global_in 70 * @param filename path to valid debug file 71 * 72 * Search order for debug file and use first one found: 73 * 1) dir_in directory 74 * 2) dir_in/.debug directory 75 * 3) global_in/dir_in directory 76 * 77 * Newer binutils and Linux distributions (e.g. Fedora) allow the 78 * creation of debug files that are separate from the binary. The 79 * debugging information is stripped out of the binary file, placed in 80 * this separate file, and a link to the new file is placed in the 81 * binary. The debug files hold the information needed by the debugger 82 * (and OProfile) to map machine instructions back to source code. 83 */ 84extern bool 85find_separate_debug_file(bfd * ibfd, 86 std::string const & dir_in, 87 std::string const & global_in, 88 std::string & filename); 89 90/// open the given BFD 91bfd * open_bfd(std::string const & file); 92 93/// open the given BFD from the fd 94bfd * fdopen_bfd(std::string const & file, int fd); 95 96/// Return true if the symbol is worth looking at 97bool interesting_symbol(asymbol * sym); 98 99/** 100 * return true if the first symbol is less interesting than the second symbol 101 * boring symbol are eliminated when multiple symbol exist at the same vma 102 */ 103bool boring_symbol(op_bfd_symbol const & first, op_bfd_symbol const & second); 104 105/// debug info for a given pc 106struct linenr_info { 107 /// did we find something? 108 bool found; 109 /// filename 110 std::string filename; 111 /// line number 112 unsigned int line; 113}; 114 115/** 116 * Attempt to locate a filename + line number for the given symbol and 117 * offset. 118 */ 119linenr_info const 120find_nearest_line(bfd_info const & ibfd, op_bfd_symbol const & sym, 121 unsigned int offset); 122 123#endif /* !BFD_SUPPORT_H */ 124