#include <op_bfd.h>
Public Member Functions | |
op_bfd (std::string const &filename, string_filter const &symbol_filter, extra_images const &extra_images, bool &ok) | |
op_bfd (uint64_t spu_offset, std::string const &filename, string_filter const &symbol_filter, extra_images const &extra_images, bool &ok) | |
std::string | get_embedding_filename () const |
~op_bfd () | |
close an opened bfd image and free all related resources | |
bool | get_linenr (symbol_index_t sym_idx, bfd_vma offset, std::string &filename, unsigned int &linenr) const |
void | get_symbol_range (symbol_index_t sym_idx, unsigned long long &start, unsigned long long &end) const |
void | get_vma_range (bfd_vma &start, bfd_vma &end) const |
bfd_vma | offset_to_pc (bfd_vma offset) const |
unsigned long | get_start_offset (bfd_vma vma=0) const |
std::string | get_filename () const |
size_t | bfd_arch_bits_per_address () const |
bool | has_debug_info () const |
return true if binary contain some debug information | |
bool | symbol_has_contents (symbol_index_t sym_idx) |
bool | get_symbol_contents (symbol_index_t sym_index, unsigned char *contents) const |
bool | valid () const |
bfd_vma | get_vma_adj (void) const |
Data Fields | |
std::vector< op_bfd_symbol > | syms |
sorted vector by vma of interesting symbol. | |
Private Types | |
typedef std::list< op_bfd_symbol > | symbols_found_t |
temporary container type for getting symbols | |
typedef std::map< std::string, u32 > | filepos_map_t |
Private Member Functions | |
void | get_symbols (symbols_found_t &symbols) |
void | get_symbols_from_file (bfd_info &bfd, size_t start, op_bfd::symbols_found_t &symbols, bool debug_file) |
void | add_symbols (symbols_found_t &symbols, string_filter const &symbol_filter) |
size_t | symbol_size (op_bfd_symbol const &sym, op_bfd_symbol const *next) const |
op_bfd_symbol const | create_artificial_symbol () |
create an artificial symbol for a symbolless binary | |
uint | process_symtab (bfd_info *bfd, uint start) |
Private Attributes | |
std::string | filename |
filename we open (not including archive path) | |
std::string | archive_path |
path to archive | |
extra_images const & | extra_found_images |
reference to extra_images | |
off_t | file_size |
file size in bytes | |
std::string | debug_filename |
corresponding debug file name | |
cached_value< bool > | debug_info |
true if at least one section has (flags & SEC_DEBUGGING) != 0 | |
bfd_info | ibfd |
our main bfd object: .bfd may be NULL | |
bfd_info | dbfd |
std::vector< asection const * > | filtered_section |
filepos_map_t | filepos_map |
std::string | embedding_filename |
bool | anon_obj |
bfd_vma | vma_adj |
Encapsulation of a bfd object. Simplifies open/close of bfd, enumerating symbols and retrieving informations for symbols or vma.
Use of this class relies on a std::ostream cverb
Definition at line 97 of file op_bfd.h.
typedef std::map<std::string, u32> op_bfd::filepos_map_t [private] |
typedef std::list<op_bfd_symbol> op_bfd::symbols_found_t [private] |
op_bfd::op_bfd | ( | std::string const & | filename, | |
string_filter const & | symbol_filter, | |||
extra_images const & | extra_images, | |||
bool & | ok | |||
) |
filename | the name of the image file | |
symbol_filter | filter to apply to symbols | |
extra_images | container where all extra candidate filenames are stored | |
ok | in-out parameter: on in, if not set, don't open the bfd (because it's not there or whatever). On out, it's set to false if the bfd couldn't be loaded. |
op_bfd::op_bfd | ( | uint64_t | spu_offset, | |
std::string const & | filename, | |||
string_filter const & | symbol_filter, | |||
extra_images const & | extra_images, | |||
bool & | ok | |||
) |
This constructor is used when processing an SPU profile where the SPU ELF is embedded within the PPE binary.
op_bfd::~op_bfd | ( | ) |
close an opened bfd image and free all related resources
Definition at line 190 of file op_bfd.cpp.
void op_bfd::add_symbols | ( | op_bfd::symbols_found_t & | symbols, | |
string_filter const & | symbol_filter | |||
) | [private] |
Add the symbols in the binary, applying filtering, and handling artificial symbols.
Definition at line 284 of file op_bfd.cpp.
References create_artificial_symbol(), cverb, syms, and vbfd.
size_t op_bfd::bfd_arch_bits_per_address | ( | ) | const |
return in bits the bfd_vma size for this binary. This is needed because gprof output depend on the bfd_vma for *this* binary and do not depend on sizeof(bfd_vma)
Definition at line 472 of file op_bfd.cpp.
References bfd_info::abfd, ibfd, and bfd_info::valid().
op_bfd_symbol const op_bfd::create_artificial_symbol | ( | ) | [private] |
create an artificial symbol for a symbolless binary
Definition at line 457 of file op_bfd.cpp.
References get_filename(), and get_vma_range().
Referenced by add_symbols().
std::string op_bfd::get_embedding_filename | ( | ) | const [inline] |
Definition at line 123 of file op_bfd.h.
References embedding_filename.
string op_bfd::get_filename | ( | ) | const |
Return the image name of the underlying binary image. For an archive, this returns the path *within* the archive, not the full path of the file.
Definition at line 466 of file op_bfd.cpp.
References filename.
Referenced by create_artificial_symbol(), and format_output::xml_formatter::get_bfd_object().
bool op_bfd::get_linenr | ( | symbol_index_t | sym_idx, | |
bfd_vma | offset, | |||
std::string & | filename, | |||
unsigned int & | linenr | |||
) | const |
sym_idx | index of the symbol | |
offset | fentry number | |
filename | output parameter to store filename | |
linenr | output parameter to store linenr. |
Retrieve the relevant finename:linenr information for the sym_idx at offset. If the lookup fails, return false. In some cases this function can retrieve the filename and return true but fail to retrieve the linenr and so can return zero in linenr
Referenced by profile_container::add_samples().
unsigned long op_bfd::get_start_offset | ( | bfd_vma | vma = 0 |
) | const |
If passed 0, return the file position of the .text section. Otherwise, return the filepos of a section with a matching vma.
Definition at line 195 of file op_bfd.cpp.
References filepos_map, ibfd, and bfd_info::valid().
Referenced by profile_t::set_offset().
bool op_bfd::get_symbol_contents | ( | symbol_index_t | sym_index, | |
unsigned char * | contents | |||
) | const |
Definition at line 331 of file op_bfd.cpp.
References bfd_info::abfd, ibfd, op_bfd_symbol::size(), op_bfd_symbol::symbol(), syms, and op_bfd_symbol::value().
void op_bfd::get_symbol_range | ( | symbol_index_t | sym_idx, | |
unsigned long long & | start, | |||
unsigned long long & | end | |||
) | const |
sym_idx | symbol index | |
start | reference to start var | |
end | reference to end var |
Calculates the range of sample file entries covered by sym. start and end will be filled in appropriately. If index is the last entry in symbol table, all entries up to the end of the sample file will be used. After calculating start and end they are sanitized
All errors are fatal.
Definition at line 410 of file op_bfd.cpp.
References anon_obj, cverb, op_bfd_symbol::filepos(), op_bfd_symbol::name(), op_bfd_symbol::size(), op_bfd_symbol::symbol(), syms, op_bfd_symbol::value(), vbfd, vlevel1, and op_bfd_symbol::vma().
void op_bfd::get_symbols | ( | op_bfd::symbols_found_t & | symbols | ) | [private] |
Parse and sort in ascending order all symbols in the file pointed to by abfd that reside in a SEC_CODE section.
The symbols are filtered through the interesting_symbol() predicate and sorted with op_bfd_symbol::operator<() comparator.
Definition at line 208 of file op_bfd.cpp.
References bfd_info::abfd, boring_symbol(), dbfd, filepos_map, filtered_section, bfd_info::get_symbols(), has_debug_info(), ibfd, interesting_symbol(), bfd_info::nr_syms, bfd_info::set_image_bfd_info(), op_bfd_symbol::size(), symbol_size(), bfd_info::syms, bfd_info::valid(), and vma_adj.
void op_bfd::get_symbols_from_file | ( | bfd_info & | bfd, | |
size_t | start, | |||
op_bfd::symbols_found_t & | symbols, | |||
bool | debug_file | |||
) | [private] |
Helper function for get_symbols. Populates bfd_syms and extracts the "interesting_symbol"s.
bfd_vma op_bfd::get_vma_adj | ( | void | ) | const [inline] |
void op_bfd::get_vma_range | ( | bfd_vma & | start, | |
bfd_vma & | end | |||
) | const |
start | reference to the start vma | |
end | reference to the end vma |
return in start, end the vma range for this binary object.
Definition at line 441 of file op_bfd.cpp.
References file_size, op_bfd_symbol::size(), syms, and op_bfd_symbol::vma().
Referenced by create_artificial_symbol().
bool op_bfd::has_debug_info | ( | ) | const |
return true if binary contain some debug information
Definition at line 344 of file op_bfd.cpp.
References bfd_info::abfd, cached_value< T >::cached(), cverb, dbfd, debug_filename, debug_info, extra_found_images, filename, find_separate_debug_file(), cached_value< T >::get(), bfd_info::has_debug_info(), ibfd, open_bfd(), cached_value< T >::reset(), bfd_info::valid(), and vbfd.
Referenced by get_symbols(), and populate_for_image().
bfd_vma op_bfd::offset_to_pc | ( | bfd_vma | offset | ) | const |
return the relocated PC value for the given file offset
Definition at line 305 of file op_bfd.cpp.
References bfd_info::abfd, and ibfd.
uint op_bfd::process_symtab | ( | bfd_info * | bfd, | |
uint | start | |||
) | [private] |
bool op_bfd::symbol_has_contents | ( | symbol_index_t | sym_idx | ) |
sym_idx | symbol index |
Return true or false, indicating whether or not the symbol referenced by the passed sym_idx has code available. Some symbols have no code associated with them; for example, artificial symbols created for anonymous memory samples or for stripped binaries with no symbol debug info. Additionally, if the bfd object associated with the symbol is not valid, this function will also return false.
NOTE: This call should be made prior to invoking get_symbol_contents to avoid unnecessarily allocating memory for the symbol contents.
Definition at line 320 of file op_bfd.cpp.
References op_bfd_symbol::artificial(), ibfd, op_bfd_symbol::name(), syms, and bfd_info::valid().
size_t op_bfd::symbol_size | ( | op_bfd_symbol const & | sym, | |
op_bfd_symbol const * | next | |||
) | const [private] |
symbol_size - return the size of a symbol
sym | symbol to get size | |
next | next symbol in vma order if any |
Definition at line 392 of file op_bfd.cpp.
References file_size, op_bfd_symbol::filepos(), op_bfd_symbol::section(), and op_bfd_symbol::symbol_endpos().
Referenced by get_symbols().
bool op_bfd::valid | ( | ) | const [inline] |
Definition at line 213 of file op_bfd.h.
References ibfd, and bfd_info::valid().
Referenced by profile_t::set_offset().
bool op_bfd::anon_obj [private] |
Definition at line 303 of file op_bfd.h.
Referenced by get_symbol_range().
std::string op_bfd::archive_path [private] |
bfd_info op_bfd::dbfd [mutable, private] |
Definition at line 285 of file op_bfd.h.
Referenced by get_symbols(), and has_debug_info().
std::string op_bfd::debug_filename [mutable, private] |
corresponding debug file name
Definition at line 276 of file op_bfd.h.
Referenced by has_debug_info().
cached_value<bool> op_bfd::debug_info [mutable, private] |
true if at least one section has (flags & SEC_DEBUGGING) != 0
Definition at line 279 of file op_bfd.h.
Referenced by has_debug_info().
std::string op_bfd::embedding_filename [private] |
If spu_offset is non-zero, embedding_filename is the file containing the embedded SPU image.
Definition at line 301 of file op_bfd.h.
Referenced by get_embedding_filename().
extra_images const& op_bfd::extra_found_images [private] |
off_t op_bfd::file_size [private] |
file size in bytes
Definition at line 273 of file op_bfd.h.
Referenced by get_vma_range(), and symbol_size().
std::string op_bfd::filename [private] |
filename we open (not including archive path)
Definition at line 264 of file op_bfd.h.
Referenced by get_filename(), and has_debug_info().
filepos_map_t op_bfd::filepos_map [private] |
Definition at line 295 of file op_bfd.h.
Referenced by get_start_offset(), and get_symbols().
std::vector<asection const *> op_bfd::filtered_section [private] |
sections we will avoid to use symbol from, this is needed because elf file allows sections with identical vma and we can't allow overlapping symbols. Such elf layout is used actually by kernel modules where all code section vma are set to 0.
Definition at line 291 of file op_bfd.h.
Referenced by get_symbols().
bfd_info op_bfd::ibfd [private] |
our main bfd object: .bfd may be NULL
Definition at line 282 of file op_bfd.h.
Referenced by bfd_arch_bits_per_address(), get_start_offset(), get_symbol_contents(), get_symbols(), has_debug_info(), offset_to_pc(), symbol_has_contents(), and valid().
std::vector<op_bfd_symbol> op_bfd::syms |
sorted vector by vma of interesting symbol.
Definition at line 183 of file op_bfd.h.
Referenced by profile_container::add_samples(), add_symbols(), get_symbol_contents(), get_symbol_range(), get_vma_range(), and symbol_has_contents().
bfd_vma op_bfd::vma_adj [private] |
If a runtime binary is prelinked, then its p_vaddr field in the first PT_LOAD segment will give the address where the binary will be loaded into memory. However, the corresponding debuginfo file may have a different p_vaddr value. In profile_container::add_samples, this difference is handled by adding the "base_vma" to the sample vma. However, if the runtime binary has no symbol information at all, then the "base_vma" is obtained from the debuginfo symbol information. For opreport, this works OK, since under such conditions, ALL symbol and debug data is then obtained from the debuginfo files, and the sample vma's should match up fine with the symbol vma's in the debuginfo file. But when doing 'opannoate --assembly', the real (runtime) image is used for annotation, and, thus, we may have a mis-match between real image p_vaddr and the impliled p_vaddr stored with the samples. To handle this case, we do the following: When a bfd_info is created for a debuginfo file, we set vma_adj to the difference between runtime load address and the p_vaddr of the first PT_LOAD segment of the debuginfo file, if and only if the real image has no symbol info; otherwise vma_adj is set to 0.
Definition at line 324 of file op_bfd.h.
Referenced by get_symbols(), and get_vma_adj().