173677f78SIngo Weinhold /* 273677f78SIngo Weinhold * Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 373677f78SIngo Weinhold * Distributed under the terms of the MIT License. 473677f78SIngo Weinhold */ 573677f78SIngo Weinhold 673677f78SIngo Weinhold #ifndef IMAGE_H 773677f78SIngo Weinhold #define IMAGE_H 873677f78SIngo Weinhold 973677f78SIngo Weinhold #include <stdio.h> 1073677f78SIngo Weinhold 1173677f78SIngo Weinhold #include <image.h> 1273677f78SIngo Weinhold #include <OS.h> 1373677f78SIngo Weinhold 1473677f78SIngo Weinhold #include <util/DoublyLinkedList.h> 1573677f78SIngo Weinhold 1673677f78SIngo Weinhold 1773677f78SIngo Weinhold struct image_t; 1873677f78SIngo Weinhold struct runtime_loader_debug_area; 1973677f78SIngo Weinhold struct Elf32_Sym; 2073677f78SIngo Weinhold 2173677f78SIngo Weinhold 2273677f78SIngo Weinhold namespace BPrivate { 2373677f78SIngo Weinhold namespace Debug { 2473677f78SIngo Weinhold 2573677f78SIngo Weinhold 2673677f78SIngo Weinhold class Image : public DoublyLinkedListLinkImpl<Image> { 2773677f78SIngo Weinhold public: 2873677f78SIngo Weinhold Image(); 2973677f78SIngo Weinhold virtual ~Image(); 3073677f78SIngo Weinhold 3173677f78SIngo Weinhold virtual image_id ID() const = 0; 3273677f78SIngo Weinhold virtual const char* Name() const = 0; 3373677f78SIngo Weinhold virtual addr_t TextAddress() const = 0; 3473677f78SIngo Weinhold virtual size_t TextSize() const = 0; 3573677f78SIngo Weinhold 3673677f78SIngo Weinhold virtual const Elf32_Sym* LookupSymbol(addr_t address, 3773677f78SIngo Weinhold addr_t* _baseAddress, 3873677f78SIngo Weinhold const char** _symbolName, 3973677f78SIngo Weinhold size_t *_symbolNameLen, 4073677f78SIngo Weinhold bool *_exactMatch) const = 0; 4173677f78SIngo Weinhold virtual status_t NextSymbol(int32& iterator, 4273677f78SIngo Weinhold const char** _symbolName, 4373677f78SIngo Weinhold size_t* _symbolNameLen, 4473677f78SIngo Weinhold addr_t* _symbolAddress, size_t* _symbolSize, 4573677f78SIngo Weinhold int32* _symbolType) const = 0; 4673677f78SIngo Weinhold }; 4773677f78SIngo Weinhold 4873677f78SIngo Weinhold 4973677f78SIngo Weinhold class SymbolTableBasedImage : public Image { 5073677f78SIngo Weinhold public: 5173677f78SIngo Weinhold SymbolTableBasedImage(); 5273677f78SIngo Weinhold virtual ~SymbolTableBasedImage(); 5373677f78SIngo Weinhold 5473677f78SIngo Weinhold virtual image_id ID() const ; 5573677f78SIngo Weinhold virtual const char* Name() const; 5673677f78SIngo Weinhold virtual addr_t TextAddress() const; 5773677f78SIngo Weinhold virtual size_t TextSize() const; 5873677f78SIngo Weinhold 5973677f78SIngo Weinhold virtual const Elf32_Sym* LookupSymbol(addr_t address, 6073677f78SIngo Weinhold addr_t* _baseAddress, 6173677f78SIngo Weinhold const char** _symbolName, 6273677f78SIngo Weinhold size_t *_symbolNameLen, 6373677f78SIngo Weinhold bool *_exactMatch) const; 6473677f78SIngo Weinhold virtual status_t NextSymbol(int32& iterator, 6573677f78SIngo Weinhold const char** _symbolName, 6673677f78SIngo Weinhold size_t* _symbolNameLen, 6773677f78SIngo Weinhold addr_t* _symbolAddress, size_t* _symbolSize, 6873677f78SIngo Weinhold int32* _symbolType) const; 6973677f78SIngo Weinhold 7073677f78SIngo Weinhold protected: 7173677f78SIngo Weinhold size_t _SymbolNameLen(const char* symbolName) const; 7273677f78SIngo Weinhold 7373677f78SIngo Weinhold protected: 7473677f78SIngo Weinhold image_info fInfo; 7573677f78SIngo Weinhold addr_t fLoadDelta; 7673677f78SIngo Weinhold Elf32_Sym* fSymbolTable; 7773677f78SIngo Weinhold char* fStringTable; 7873677f78SIngo Weinhold int32 fSymbolCount; 7973677f78SIngo Weinhold size_t fStringTableSize; 8073677f78SIngo Weinhold }; 8173677f78SIngo Weinhold 8273677f78SIngo Weinhold 8373677f78SIngo Weinhold class ImageFile : public SymbolTableBasedImage { 8473677f78SIngo Weinhold public: 8573677f78SIngo Weinhold ImageFile(); 8673677f78SIngo Weinhold virtual ~ImageFile(); 8773677f78SIngo Weinhold 8873677f78SIngo Weinhold status_t Init(const image_info& info); 89*e52c3559SIngo Weinhold status_t Init(const char* path); 90*e52c3559SIngo Weinhold 91*e52c3559SIngo Weinhold private: 92*e52c3559SIngo Weinhold status_t _LoadFile(const char* path, 93*e52c3559SIngo Weinhold addr_t* _textAddress, size_t* _textSize); 9473677f78SIngo Weinhold 9573677f78SIngo Weinhold private: 9673677f78SIngo Weinhold int fFD; 9773677f78SIngo Weinhold off_t fFileSize; 9873677f78SIngo Weinhold uint8* fMappedFile; 9973677f78SIngo Weinhold }; 10073677f78SIngo Weinhold 10173677f78SIngo Weinhold 10273677f78SIngo Weinhold class KernelImage : public SymbolTableBasedImage { 10373677f78SIngo Weinhold public: 10473677f78SIngo Weinhold KernelImage(); 10573677f78SIngo Weinhold virtual ~KernelImage(); 10673677f78SIngo Weinhold 10773677f78SIngo Weinhold status_t Init(const image_info& info); 10873677f78SIngo Weinhold }; 10973677f78SIngo Weinhold 11073677f78SIngo Weinhold } // namespace Debug 11173677f78SIngo Weinhold } // namespace BPrivate 11273677f78SIngo Weinhold 11373677f78SIngo Weinhold 11473677f78SIngo Weinhold using BPrivate::Debug::ImageFile; 11573677f78SIngo Weinhold 11673677f78SIngo Weinhold 11773677f78SIngo Weinhold #endif // IMAGE_H 118