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 <elf_private.h>
12#include <image.h>
13#include <OS.h>
14
15#include <util/DoublyLinkedList.h>
16
17
18struct image_t;
19struct runtime_loader_debug_area;
20
21
22namespace BPrivate {
23namespace Debug {
24
25
26class Image : public DoublyLinkedListLinkImpl<Image> {
27public:
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 elf_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	virtual	status_t			GetSymbol(const char* name, int32 symbolType,
50									void** _symbolLocation, size_t* _symbolSize,
51									int32* _symbolType) const;
52
53protected:
54			image_info			fInfo;
55};
56
57
58class SymbolTableBasedImage : public Image {
59public:
60								SymbolTableBasedImage();
61	virtual						~SymbolTableBasedImage();
62
63	virtual	const elf_sym*		LookupSymbol(addr_t address,
64									addr_t* _baseAddress,
65									const char** _symbolName,
66									size_t *_symbolNameLen,
67									bool *_exactMatch) const;
68	virtual	status_t			NextSymbol(int32& iterator,
69									const char** _symbolName,
70									size_t* _symbolNameLen,
71									addr_t* _symbolAddress, size_t* _symbolSize,
72									int32* _symbolType) const;
73
74protected:
75			size_t				_SymbolNameLen(const char* symbolName) const;
76
77protected:
78			addr_t				fLoadDelta;
79			elf_sym*			fSymbolTable;
80			char*				fStringTable;
81			int32				fSymbolCount;
82			size_t				fStringTableSize;
83};
84
85
86class ImageFile : public SymbolTableBasedImage {
87public:
88								ImageFile();
89	virtual						~ImageFile();
90
91			status_t			Init(const image_info& info);
92			status_t			Init(const char* path);
93
94private:
95			status_t			_LoadFile(const char* path,
96									addr_t* _textAddress, size_t* _textSize,
97									addr_t* _dataAddress, size_t* _dataSize);
98
99			status_t			_FindTableInSection(elf_ehdr* elfHeader,
100									uint16 sectionType);
101
102private:
103			int					fFD;
104			off_t				fFileSize;
105			uint8*				fMappedFile;
106};
107
108
109class KernelImage : public SymbolTableBasedImage {
110public:
111								KernelImage();
112	virtual						~KernelImage();
113
114			status_t			Init(const image_info& info);
115};
116
117
118class CommPageImage : public SymbolTableBasedImage {
119public:
120								CommPageImage();
121	virtual						~CommPageImage();
122
123			status_t			Init(const image_info& info);
124};
125
126}	// namespace Debug
127}	// namespace BPrivate
128
129
130using BPrivate::Debug::ImageFile;
131
132
133#endif	// IMAGE_H
134