/*
Copyright (C) 2006 - 2009 Evan Teran
                   eteran@alum.rit.edu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef SYMBOLMANAGER_20060814_H_
#define SYMBOLMANAGER_20060814_H_

#include <QString>
#include <QMap>
#include <QList>
#include <QSet>
#include "Types.h"
#include "API.h"

class EDB_EXPORT SymbolManager {
public:
	SymbolManager() {}
public:
	void loadSymbols(const QString &symbolDirectory);
	void clear();

	struct Symbol {
		QString			file;
		QString			name;
		QString			name_no_prefix;
		edb::address_t	address;
		quint32			size;
		char			type;
		
		bool isCode() const { return type == 't' || type == 'T' || type == 'P'; }
		bool isData() const { return !isCode(); }
		bool isWeak() const { return type == 'W'; }
	};
	
	const Symbol *find(const QString &name) const;
	const Symbol *find(edb::address_t address) const;
	const Symbol *findNearSymbol(edb::address_t address) const;
	
	void loadSymbolFile(const QString &filename, edb::address_t base);
	
	const QList<Symbol> symbols() const;
	
private:
	bool processSymbolFile(const QString &f, edb::address_t base, const QString &libraryFilename);
	
private:
	QString									m_SymbolDirectory;
	QSet<QString>							m_SymbolFiles;
	QList<Symbol>							m_Symbols;
	QMap<edb::address_t, const Symbol *>	m_SymbolsByAddress;
	QMap<QString, const Symbol *>			m_SymbolsByName;
};

#endif

