1 /* 2 * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef SHARED_IMAGE_H 6 #define SHARED_IMAGE_H 7 8 #include <image.h> 9 #include <OS.h> 10 #include <String.h> 11 12 #include "Referenceable.h" 13 14 15 class debug_symbol_iterator; 16 class debug_symbol_lookup_context; 17 class SharedImage; 18 19 20 class Symbol { 21 public: 22 Symbol(SharedImage* image, addr_t base, size_t size, const char* name) 23 : 24 image(image), 25 base(base), 26 size(size), 27 name(name) 28 { 29 } 30 31 const char* Name() const { return name.String(); } 32 33 SharedImage* image; 34 addr_t base; 35 size_t size; 36 BString name; 37 }; 38 39 40 struct SymbolComparator { 41 inline bool operator()(const Symbol* a, const Symbol* b) const 42 { 43 return a->base < b->base; 44 } 45 }; 46 47 48 class SharedImage : public BReferenceable { 49 public: 50 SharedImage(); 51 ~SharedImage(); 52 53 status_t Init(team_id owner, image_id imageID); 54 status_t Init(const char* path); 55 56 inline const char* Name() const; 57 inline const image_info& Info() const; 58 59 inline Symbol** Symbols() const; 60 inline int32 SymbolCount() const; 61 62 inline bool ContainsAddress(addr_t address) const; 63 int32 FindSymbol(addr_t address) const; 64 65 private: 66 status_t _Init(debug_symbol_iterator* iterator); 67 68 private: 69 image_info fInfo; 70 Symbol** fSymbols; 71 int32 fSymbolCount; 72 }; 73 74 75 // #pragma mark - 76 77 78 const char* 79 SharedImage::Name() const 80 { 81 return fInfo.name; 82 } 83 84 85 const image_info& 86 SharedImage::Info() const 87 { 88 return fInfo; 89 } 90 91 92 Symbol** 93 SharedImage::Symbols() const 94 { 95 return fSymbols; 96 } 97 98 99 int32 100 SharedImage::SymbolCount() const 101 { 102 return fSymbolCount; 103 } 104 105 106 bool 107 SharedImage::ContainsAddress(addr_t address) const 108 { 109 return (address >= (addr_t)fInfo.text && address < ((addr_t)fInfo.text + fInfo.text_size)) 110 || (address >= (addr_t)fInfo.data && address < ((addr_t)fInfo.data + fInfo.data_size)); 111 } 112 113 114 #endif // SHARED_IMAGE_H 115