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 15class debug_symbol_iterator; 16class debug_symbol_lookup_context; 17class SharedImage; 18 19 20class Symbol { 21public: 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 40struct SymbolComparator { 41 inline bool operator()(const Symbol* a, const Symbol* b) const 42 { 43 return a->base < b->base; 44 } 45}; 46 47 48class SharedImage : public BReferenceable { 49public: 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 65private: 66 status_t _Init(debug_symbol_iterator* iterator); 67 68private: 69 image_info fInfo; 70 Symbol** fSymbols; 71 int32 fSymbolCount; 72}; 73 74 75// #pragma mark - 76 77 78const char* 79SharedImage::Name() const 80{ 81 return fInfo.name; 82} 83 84 85const image_info& 86SharedImage::Info() const 87{ 88 return fInfo; 89} 90 91 92Symbol** 93SharedImage::Symbols() const 94{ 95 return fSymbols; 96} 97 98 99int32 100SharedImage::SymbolCount() const 101{ 102 return fSymbolCount; 103} 104 105 106bool 107SharedImage::ContainsAddress(addr_t address) const 108{ 109 return address >= (addr_t)fInfo.text 110 && address <= (addr_t)fInfo.data + fInfo.data_size - 1; 111} 112 113 114#endif // SHARED_IMAGE_H 115