op_bfd.h
Go to the documentation of this file.00001
00012 #ifndef OP_BFD_H
00013 #define OP_BFD_H
00014
00015 #include "config.h"
00016
00017 #include <vector>
00018 #include <string>
00019 #include <list>
00020 #include <map>
00021 #include <set>
00022
00023 #include "bfd_support.h"
00024 #include "locate_images.h"
00025 #include "utility.h"
00026 #include "cached_value.h"
00027 #include "op_types.h"
00028
00029 class op_bfd;
00030 class string_filter;
00031 class extra_images;
00032
00034 typedef size_t symbol_index_t;
00035
00041 class op_bfd_symbol {
00042 public:
00043
00045 op_bfd_symbol(asymbol const * a);
00046
00048 op_bfd_symbol(bfd_vma vma, size_t size, std::string const & name);
00049
00050 bfd_vma vma() const { return symb_value + section_vma; }
00051 unsigned long value() const { return symb_value; }
00052 unsigned long filepos() const { return symb_value + section_filepos; }
00053 unsigned long symbol_endpos(void) const;
00054 asection const * section(void) const { return bfd_symbol->section; }
00055 std::string const & name() const { return symb_name; }
00056 asymbol const * symbol() const { return bfd_symbol; }
00057 size_t size() const { return symb_size; }
00058 void size(size_t s) { symb_size = s; }
00059 bool hidden() const { return symb_hidden; }
00060 bool weak() const { return symb_weak; }
00061 bool artificial() const { return symb_artificial; }
00062
00064 bool operator<(op_bfd_symbol const & lhs) const;
00065
00066 private:
00069 asymbol const * bfd_symbol;
00072 unsigned long symb_value;
00074 unsigned long section_filepos;
00076 bfd_vma section_vma;
00078 size_t symb_size;
00080 std::string symb_name;
00082 bool symb_hidden;
00084 bool symb_weak;
00086 bool symb_artificial;
00088 std::string symb_bytes;
00089 };
00090
00097 class op_bfd {
00098 public:
00108 op_bfd(std::string const & filename,
00109 string_filter const & symbol_filter,
00110 extra_images const & extra_images,
00111 bool & ok);
00112
00117 op_bfd(uint64_t spu_offset,
00118 std::string const & filename,
00119 string_filter const & symbol_filter,
00120 extra_images const & extra_images,
00121 bool & ok);
00122
00123 std::string get_embedding_filename() const { return embedding_filename; }
00124
00126 ~op_bfd();
00127
00139 bool get_linenr(symbol_index_t sym_idx, bfd_vma offset,
00140 std::string & filename, unsigned int & linenr) const;
00141
00154 void get_symbol_range(symbol_index_t sym_idx,
00155 unsigned long long & start, unsigned long long & end) const;
00156
00163 void get_vma_range(bfd_vma & start, bfd_vma & end) const;
00164
00166 bfd_vma offset_to_pc(bfd_vma offset) const;
00167
00173 unsigned long get_start_offset(bfd_vma vma = 0) const;
00174
00180 std::string get_filename() const;
00181
00183 std::vector<op_bfd_symbol> syms;
00184
00188 size_t bfd_arch_bits_per_address() const;
00189
00191 bool has_debug_info() const;
00192
00208 bool symbol_has_contents(symbol_index_t sym_idx);
00209
00210 bool get_symbol_contents(symbol_index_t sym_index,
00211 unsigned char * contents) const;
00212
00213 bool valid() const { return ibfd.valid(); }
00214
00215 bfd_vma get_vma_adj(void) const { return vma_adj; }
00216
00217 private:
00219 typedef std::list<op_bfd_symbol> symbols_found_t;
00220
00230 void get_symbols(symbols_found_t & symbols);
00231
00236 void get_symbols_from_file(bfd_info & bfd, size_t start,
00237 op_bfd::symbols_found_t & symbols,
00238 bool debug_file);
00239
00244 void add_symbols(symbols_found_t & symbols,
00245 string_filter const & symbol_filter);
00246
00252 size_t symbol_size(op_bfd_symbol const & sym,
00253 op_bfd_symbol const * next) const;
00254
00256 op_bfd_symbol const create_artificial_symbol();
00257
00258
00259
00260
00261 uint process_symtab(bfd_info * bfd, uint start);
00262
00264 std::string filename;
00265
00267 std::string archive_path;
00268
00270 extra_images const & extra_found_images;
00271
00273 off_t file_size;
00274
00276 mutable std::string debug_filename;
00277
00279 mutable cached_value<bool> debug_info;
00280
00282 bfd_info ibfd;
00283
00284
00285 mutable bfd_info dbfd;
00286
00291 std::vector<asection const *> filtered_section;
00292
00293 typedef std::map<std::string, u32> filepos_map_t;
00294
00295 filepos_map_t filepos_map;
00296
00301 std::string embedding_filename;
00302
00303 bool anon_obj;
00304
00324 bfd_vma vma_adj;
00325
00326 };
00327
00328
00329 #endif