xref: /haiku/src/kits/debug/Image.h (revision c302a243e15e640fae0f689e32cdf0c18749afee)
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 
1175c31ae2SSimon South #include <elf_private.h>
1273677f78SIngo Weinhold #include <image.h>
1373677f78SIngo Weinhold #include <OS.h>
1473677f78SIngo Weinhold 
1573677f78SIngo Weinhold #include <util/DoublyLinkedList.h>
1673677f78SIngo Weinhold 
1773677f78SIngo Weinhold 
1873677f78SIngo Weinhold struct image_t;
1973677f78SIngo Weinhold struct runtime_loader_debug_area;
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 
Info()3139df6341SIngo Weinhold 			const image_info&	Info() const		{ return fInfo; }
ID()3239df6341SIngo Weinhold 			image_id			ID() const			{ return fInfo.id; }
Name()3339df6341SIngo Weinhold 			const char*			Name() const		{ return fInfo.name; }
TextAddress()3439df6341SIngo Weinhold 			addr_t				TextAddress() const
3539df6341SIngo Weinhold 				{ return (addr_t)fInfo.text; }
TextSize()3639df6341SIngo Weinhold 			size_t				TextSize() const	{ return fInfo.text_size; }
3773677f78SIngo Weinhold 
38a731ad19SAlex Smith 	virtual	const elf_sym*		LookupSymbol(addr_t address,
3973677f78SIngo Weinhold 									addr_t* _baseAddress,
4073677f78SIngo Weinhold 									const char** _symbolName,
4173677f78SIngo Weinhold 									size_t *_symbolNameLen,
4273677f78SIngo Weinhold 									bool *_exactMatch) const = 0;
4373677f78SIngo Weinhold 	virtual	status_t			NextSymbol(int32& iterator,
4473677f78SIngo Weinhold 									const char** _symbolName,
4573677f78SIngo Weinhold 									size_t* _symbolNameLen,
4673677f78SIngo Weinhold 									addr_t* _symbolAddress, size_t* _symbolSize,
4773677f78SIngo Weinhold 									int32* _symbolType) const = 0;
4839df6341SIngo Weinhold 
499774f385SIngo Weinhold 	virtual	status_t			GetSymbol(const char* name, int32 symbolType,
509774f385SIngo Weinhold 									void** _symbolLocation, size_t* _symbolSize,
519774f385SIngo Weinhold 									int32* _symbolType) const;
529774f385SIngo Weinhold 
5339df6341SIngo Weinhold protected:
5439df6341SIngo Weinhold 			image_info			fInfo;
5573677f78SIngo Weinhold };
5673677f78SIngo Weinhold 
5773677f78SIngo Weinhold 
5873677f78SIngo Weinhold class SymbolTableBasedImage : public Image {
5973677f78SIngo Weinhold public:
6073677f78SIngo Weinhold 								SymbolTableBasedImage();
6173677f78SIngo Weinhold 	virtual						~SymbolTableBasedImage();
6273677f78SIngo Weinhold 
63a731ad19SAlex Smith 	virtual	const elf_sym*		LookupSymbol(addr_t address,
6473677f78SIngo Weinhold 									addr_t* _baseAddress,
6573677f78SIngo Weinhold 									const char** _symbolName,
6673677f78SIngo Weinhold 									size_t *_symbolNameLen,
6773677f78SIngo Weinhold 									bool *_exactMatch) const;
6873677f78SIngo Weinhold 	virtual	status_t			NextSymbol(int32& iterator,
6973677f78SIngo Weinhold 									const char** _symbolName,
7073677f78SIngo Weinhold 									size_t* _symbolNameLen,
7173677f78SIngo Weinhold 									addr_t* _symbolAddress, size_t* _symbolSize,
7273677f78SIngo Weinhold 									int32* _symbolType) const;
7373677f78SIngo Weinhold 
7473677f78SIngo Weinhold protected:
7573677f78SIngo Weinhold 			size_t				_SymbolNameLen(const char* symbolName) const;
7673677f78SIngo Weinhold 
7773677f78SIngo Weinhold protected:
7873677f78SIngo Weinhold 			addr_t				fLoadDelta;
79a731ad19SAlex Smith 			elf_sym*			fSymbolTable;
8073677f78SIngo Weinhold 			char*				fStringTable;
8173677f78SIngo Weinhold 			int32				fSymbolCount;
8273677f78SIngo Weinhold 			size_t				fStringTableSize;
8373677f78SIngo Weinhold };
8473677f78SIngo Weinhold 
8573677f78SIngo Weinhold 
8673677f78SIngo Weinhold class ImageFile : public SymbolTableBasedImage {
8773677f78SIngo Weinhold public:
8873677f78SIngo Weinhold 								ImageFile();
8973677f78SIngo Weinhold 	virtual						~ImageFile();
9073677f78SIngo Weinhold 
9173677f78SIngo Weinhold 			status_t			Init(const image_info& info);
92e52c3559SIngo Weinhold 			status_t			Init(const char* path);
93e52c3559SIngo Weinhold 
94e52c3559SIngo Weinhold private:
95e52c3559SIngo Weinhold 			status_t			_LoadFile(const char* path,
9639df6341SIngo Weinhold 									addr_t* _textAddress, size_t* _textSize,
9739df6341SIngo Weinhold 									addr_t* _dataAddress, size_t* _dataSize);
9873677f78SIngo Weinhold 
99*1bcd34c4SRene Gollent 			status_t			_FindTableInSection(elf_ehdr* elfHeader,
100*1bcd34c4SRene Gollent 									uint16 sectionType);
101*1bcd34c4SRene Gollent 
10273677f78SIngo Weinhold private:
10373677f78SIngo Weinhold 			int					fFD;
10473677f78SIngo Weinhold 			off_t				fFileSize;
10573677f78SIngo Weinhold 			uint8*				fMappedFile;
10673677f78SIngo Weinhold };
10773677f78SIngo Weinhold 
10873677f78SIngo Weinhold 
10973677f78SIngo Weinhold class KernelImage : public SymbolTableBasedImage {
11073677f78SIngo Weinhold public:
11173677f78SIngo Weinhold 								KernelImage();
11273677f78SIngo Weinhold 	virtual						~KernelImage();
11373677f78SIngo Weinhold 
11473677f78SIngo Weinhold 			status_t			Init(const image_info& info);
11573677f78SIngo Weinhold };
11673677f78SIngo Weinhold 
117ffbf0328SPawel Dziepak 
118ffbf0328SPawel Dziepak class CommPageImage : public SymbolTableBasedImage {
119ffbf0328SPawel Dziepak public:
120ffbf0328SPawel Dziepak 								CommPageImage();
121ffbf0328SPawel Dziepak 	virtual						~CommPageImage();
122ffbf0328SPawel Dziepak 
123ffbf0328SPawel Dziepak 			status_t			Init(const image_info& info);
124ffbf0328SPawel Dziepak };
125ffbf0328SPawel Dziepak 
12673677f78SIngo Weinhold }	// namespace Debug
12773677f78SIngo Weinhold }	// namespace BPrivate
12873677f78SIngo Weinhold 
12973677f78SIngo Weinhold 
13073677f78SIngo Weinhold using BPrivate::Debug::ImageFile;
13173677f78SIngo Weinhold 
13273677f78SIngo Weinhold 
13373677f78SIngo Weinhold #endif	// IMAGE_H
134