2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// 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
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
2013-06-30 16:42:31 +00:00
|
|
|
#include <set>
|
2013-07-06 23:58:17 +00:00
|
|
|
#include <map>
|
2013-12-30 09:49:05 +00:00
|
|
|
#include <string>
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-12-30 09:17:11 +00:00
|
|
|
#include "native/base/mutex.h"
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2014-11-21 23:11:28 +00:00
|
|
|
#include "ext/armips/Core/Assembler.h"
|
|
|
|
|
2013-10-18 12:31:08 +00:00
|
|
|
enum SymbolType {
|
2013-12-02 14:30:03 +00:00
|
|
|
ST_NONE = 0,
|
|
|
|
ST_FUNCTION = 1,
|
|
|
|
ST_DATA = 2,
|
|
|
|
ST_ALL = 3,
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
2013-10-18 12:31:08 +00:00
|
|
|
struct SymbolInfo {
|
2013-11-27 12:33:30 +00:00
|
|
|
SymbolType type;
|
2013-07-06 23:58:17 +00:00
|
|
|
u32 address;
|
|
|
|
u32 size;
|
2014-05-04 08:24:18 +00:00
|
|
|
u32 moduleAddress;
|
2013-07-06 23:58:17 +00:00
|
|
|
};
|
|
|
|
|
2013-12-02 14:30:03 +00:00
|
|
|
struct SymbolEntry {
|
2013-11-27 14:06:41 +00:00
|
|
|
std::string name;
|
|
|
|
u32 address;
|
|
|
|
u32 size;
|
|
|
|
};
|
|
|
|
|
2014-01-26 23:35:16 +00:00
|
|
|
struct LoadedModuleInfo {
|
|
|
|
std::string name;
|
|
|
|
u32 address;
|
|
|
|
u32 size;
|
|
|
|
bool active;
|
|
|
|
};
|
|
|
|
|
2013-12-02 14:30:03 +00:00
|
|
|
enum DataType {
|
|
|
|
DATATYPE_NONE, DATATYPE_BYTE, DATATYPE_HALFWORD, DATATYPE_WORD, DATATYPE_ASCII
|
|
|
|
};
|
2013-11-27 12:33:30 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
struct HWND__;
|
|
|
|
typedef struct HWND__ *HWND;
|
|
|
|
#endif
|
|
|
|
|
2013-10-18 12:31:08 +00:00
|
|
|
class SymbolMap {
|
2012-11-01 15:19:01 +00:00
|
|
|
public:
|
2014-02-15 06:07:39 +00:00
|
|
|
SymbolMap() : sawUnknownModule(false) {}
|
2013-11-27 12:33:30 +00:00
|
|
|
void Clear();
|
|
|
|
void SortSymbols();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
bool LoadSymbolMap(const char *filename);
|
2013-06-30 16:42:31 +00:00
|
|
|
void SaveSymbolMap(const char *filename) const;
|
2013-07-29 11:06:01 +00:00
|
|
|
bool LoadNocashSym(const char *ilename);
|
2014-06-29 22:02:22 +00:00
|
|
|
void SaveNocashSym(const char *filename) const;
|
2013-12-02 14:30:03 +00:00
|
|
|
|
2013-11-27 12:33:30 +00:00
|
|
|
SymbolType GetSymbolType(u32 address) const;
|
2013-07-06 23:58:17 +00:00
|
|
|
bool GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask = ST_FUNCTION) const;
|
2013-11-27 12:33:30 +00:00
|
|
|
u32 GetNextSymbolAddress(u32 address, SymbolType symmask);
|
2014-01-26 05:40:23 +00:00
|
|
|
std::string GetDescription(unsigned int address) const;
|
2013-11-27 14:06:41 +00:00
|
|
|
std::vector<SymbolEntry> GetAllSymbols(SymbolType symmask);
|
2013-11-27 12:33:30 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#ifdef _WIN32
|
2013-11-27 12:33:30 +00:00
|
|
|
void FillSymbolListBox(HWND listbox, SymbolType symType) const;
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif
|
2014-12-07 23:20:34 +00:00
|
|
|
void GetLabels(std::vector<LabelDefinition> &dest) const;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-01-26 04:59:14 +00:00
|
|
|
void AddModule(const char *name, u32 address, u32 size);
|
|
|
|
void UnloadModule(u32 address, u32 size);
|
|
|
|
u32 GetModuleRelativeAddr(u32 address, int moduleIndex = -1) const;
|
|
|
|
u32 GetModuleAbsoluteAddr(u32 relative, int moduleIndex) const;
|
|
|
|
int GetModuleIndex(u32 address) const;
|
|
|
|
bool IsModuleActive(int moduleIndex) const;
|
2014-01-26 23:35:16 +00:00
|
|
|
std::vector<LoadedModuleInfo> getAllModules() const;
|
2014-01-26 04:59:14 +00:00
|
|
|
|
|
|
|
void AddFunction(const char* name, u32 address, u32 size, int moduleIndex = -1);
|
2013-11-27 12:33:30 +00:00
|
|
|
u32 GetFunctionStart(u32 address) const;
|
|
|
|
int GetFunctionNum(u32 address) const;
|
|
|
|
u32 GetFunctionSize(u32 startAddress) const;
|
2014-05-04 08:24:18 +00:00
|
|
|
u32 GetFunctionModuleAddress(u32 startAddress) const;
|
2013-11-27 12:33:30 +00:00
|
|
|
bool SetFunctionSize(u32 startAddress, u32 newSize);
|
|
|
|
bool RemoveFunction(u32 startAddress, bool removeName);
|
2014-02-15 06:26:35 +00:00
|
|
|
// Search for the first address their may be a function after address.
|
|
|
|
// Only valid for currently loaded modules. Not guaranteed there will be a function.
|
|
|
|
u32 FindPossibleFunctionAtAfter(u32 address) const;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-01-26 04:59:14 +00:00
|
|
|
void AddLabel(const char* name, u32 address, int moduleIndex = -1);
|
2014-01-26 05:40:23 +00:00
|
|
|
std::string GetLabelString(u32 address) const;
|
2014-02-15 05:49:20 +00:00
|
|
|
void SetLabelName(const char* name, u32 address);
|
2013-11-25 23:43:31 +00:00
|
|
|
bool GetLabelValue(const char* name, u32& dest);
|
2013-11-27 12:33:30 +00:00
|
|
|
|
2014-01-26 04:59:14 +00:00
|
|
|
void AddData(u32 address, u32 size, DataType type, int moduleIndex = -1);
|
2013-11-27 12:33:30 +00:00
|
|
|
u32 GetDataStart(u32 address) const;
|
|
|
|
u32 GetDataSize(u32 startAddress) const;
|
2014-05-04 08:24:18 +00:00
|
|
|
u32 GetDataModuleAddress(u32 startAddress) const;
|
2013-11-27 12:33:30 +00:00
|
|
|
DataType GetDataType(u32 startAddress) const;
|
2013-11-28 06:30:48 +00:00
|
|
|
|
|
|
|
static const u32 INVALID_ADDRESS = (u32)-1;
|
2013-11-30 19:57:44 +00:00
|
|
|
|
2014-02-11 10:21:56 +00:00
|
|
|
void UpdateActiveSymbols();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
private:
|
2013-11-27 12:33:30 +00:00
|
|
|
void AssignFunctionIndices();
|
2014-01-26 05:40:23 +00:00
|
|
|
const char *GetLabelName(u32 address) const;
|
|
|
|
const char *GetLabelNameRel(u32 relAddress, int moduleIndex) const;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-12-02 14:30:03 +00:00
|
|
|
struct FunctionEntry {
|
2014-01-26 04:59:14 +00:00
|
|
|
u32 start;
|
2013-11-27 12:33:30 +00:00
|
|
|
u32 size;
|
|
|
|
int index;
|
2014-01-26 04:59:14 +00:00
|
|
|
int module;
|
2013-06-30 16:42:31 +00:00
|
|
|
};
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-12-02 14:30:03 +00:00
|
|
|
struct LabelEntry {
|
2014-01-26 04:59:14 +00:00
|
|
|
u32 addr;
|
|
|
|
int module;
|
2013-11-25 23:23:17 +00:00
|
|
|
char name[128];
|
|
|
|
};
|
|
|
|
|
2013-12-02 14:30:03 +00:00
|
|
|
struct DataEntry {
|
2013-11-27 12:33:30 +00:00
|
|
|
DataType type;
|
2014-01-26 04:59:14 +00:00
|
|
|
u32 start;
|
2013-11-27 12:33:30 +00:00
|
|
|
u32 size;
|
2014-01-26 04:59:14 +00:00
|
|
|
int module;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
2013-11-27 12:33:30 +00:00
|
|
|
|
2014-01-26 04:59:14 +00:00
|
|
|
struct ModuleEntry {
|
|
|
|
// Note: this index is +1, 0 matches any for backwards-compat.
|
|
|
|
int index;
|
|
|
|
u32 start;
|
|
|
|
u32 size;
|
|
|
|
char name[128];
|
|
|
|
};
|
|
|
|
|
|
|
|
// These are flattened, read-only copies of the actual data in active modules only.
|
|
|
|
std::map<u32, const FunctionEntry> activeFunctions;
|
|
|
|
std::map<u32, const LabelEntry> activeLabels;
|
|
|
|
std::map<u32, const DataEntry> activeData;
|
|
|
|
|
|
|
|
// This is indexed by the end address of the module.
|
|
|
|
std::map<u32, const ModuleEntry> activeModuleEnds;
|
|
|
|
|
|
|
|
typedef std::pair<int, u32> SymbolKey;
|
|
|
|
|
|
|
|
// These are indexed by the module id and relative address in the module.
|
|
|
|
std::map<SymbolKey, FunctionEntry> functions;
|
|
|
|
std::map<SymbolKey, LabelEntry> labels;
|
|
|
|
std::map<SymbolKey, DataEntry> data;
|
|
|
|
std::vector<ModuleEntry> modules;
|
2013-11-27 12:33:30 +00:00
|
|
|
|
2013-08-11 03:54:55 +00:00
|
|
|
mutable recursive_mutex lock_;
|
2014-02-15 06:07:39 +00:00
|
|
|
bool sawUnknownModule;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern SymbolMap symbolMap;
|
2013-12-02 14:30:03 +00:00
|
|
|
|