1 /* 2 * Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef IMAGE_H 7 #define IMAGE_H 8 9 #include <stdio.h> 10 11 #include <image.h> 12 #include <OS.h> 13 14 #include <util/DoublyLinkedList.h> 15 16 17 struct image_t; 18 struct runtime_loader_debug_area; 19 struct Elf32_Sym; 20 21 22 namespace BPrivate { 23 namespace Debug { 24 25 26 class Image : public DoublyLinkedListLinkImpl<Image> { 27 public: 28 Image(); 29 virtual ~Image(); 30 31 const image_info& Info() const { return fInfo; } 32 image_id ID() const { return fInfo.id; } 33 const char* Name() const { return fInfo.name; } 34 addr_t TextAddress() const 35 { return (addr_t)fInfo.text; } 36 size_t TextSize() const { return fInfo.text_size; } 37 38 virtual const Elf32_Sym* LookupSymbol(addr_t address, 39 addr_t* _baseAddress, 40 const char** _symbolName, 41 size_t *_symbolNameLen, 42 bool *_exactMatch) const = 0; 43 virtual status_t NextSymbol(int32& iterator, 44 const char** _symbolName, 45 size_t* _symbolNameLen, 46 addr_t* _symbolAddress, size_t* _symbolSize, 47 int32* _symbolType) const = 0; 48 49 protected: 50 image_info fInfo; 51 }; 52 53 54 class SymbolTableBasedImage : public Image { 55 public: 56 SymbolTableBasedImage(); 57 virtual ~SymbolTableBasedImage(); 58 59 virtual const Elf32_Sym* LookupSymbol(addr_t address, 60 addr_t* _baseAddress, 61 const char** _symbolName, 62 size_t *_symbolNameLen, 63 bool *_exactMatch) const; 64 virtual status_t NextSymbol(int32& iterator, 65 const char** _symbolName, 66 size_t* _symbolNameLen, 67 addr_t* _symbolAddress, size_t* _symbolSize, 68 int32* _symbolType) const; 69 70 protected: 71 size_t _SymbolNameLen(const char* symbolName) const; 72 73 protected: 74 addr_t fLoadDelta; 75 Elf32_Sym* fSymbolTable; 76 char* fStringTable; 77 int32 fSymbolCount; 78 size_t fStringTableSize; 79 }; 80 81 82 class ImageFile : public SymbolTableBasedImage { 83 public: 84 ImageFile(); 85 virtual ~ImageFile(); 86 87 status_t Init(const image_info& info); 88 status_t Init(const char* path); 89 90 private: 91 status_t _LoadFile(const char* path, 92 addr_t* _textAddress, size_t* _textSize, 93 addr_t* _dataAddress, size_t* _dataSize); 94 95 private: 96 int fFD; 97 off_t fFileSize; 98 uint8* fMappedFile; 99 }; 100 101 102 class KernelImage : public SymbolTableBasedImage { 103 public: 104 KernelImage(); 105 virtual ~KernelImage(); 106 107 status_t Init(const image_info& info); 108 }; 109 110 } // namespace Debug 111 } // namespace BPrivate 112 113 114 using BPrivate::Debug::ImageFile; 115 116 117 #endif // IMAGE_H 118