Files
ppsspp/Core/Debugger/SymbolMap.h

180 lines
4.8 KiB
C
Raw Permalink Normal View History

2012-11-01 16:19:01 +01: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
// the Free Software Foundation, version 2.0 or later versions.
2012-11-01 16:19:01 +01: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>
#include <set>
#include <map>
#include <string>
#include <mutex>
#include "Common/CommonTypes.h"
#include "Common/File/Path.h"
enum SymbolType {
2013-12-02 15:30:03 +01:00
ST_NONE = 0,
ST_FUNCTION = 1,
ST_DATA = 2,
ST_ALL = 3,
2012-11-01 16:19:01 +01:00
};
struct SymbolInfo {
2013-11-27 13:33:30 +01:00
SymbolType type;
u32 address;
u32 size;
u32 moduleAddress;
};
2013-12-02 15:30:03 +01:00
struct SymbolEntry {
2013-11-27 15:06:41 +01:00
std::string name;
u32 address;
u32 size;
};
2014-01-27 00:35:16 +01:00
struct LoadedModuleInfo {
std::string name;
u32 address;
u32 size;
bool active;
};
2013-12-02 15:30:03 +01:00
enum DataType {
DATATYPE_NONE, DATATYPE_BYTE, DATATYPE_HALFWORD, DATATYPE_WORD, DATATYPE_ASCII
};
2013-11-27 13:33:30 +01:00
struct LabelDefinition;
2012-11-01 16:19:01 +01:00
#ifdef _WIN32
struct HWND__;
typedef struct HWND__ *HWND;
#endif
class SymbolMap {
2012-11-01 16:19:01 +01:00
public:
SymbolMap() {}
2013-11-27 13:33:30 +01:00
void Clear();
void SortSymbols();
bool LoadSymbolMap(const Path &filename);
bool SaveSymbolMap(const Path &filename) const;
bool LoadNocashSym(const Path &filename);
void SaveNocashSym(const Path &filename) const;
2013-12-02 15:30:03 +01:00
SymbolType GetSymbolType(u32 address);
bool GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask = ST_FUNCTION);
2013-11-27 13:33:30 +01:00
u32 GetNextSymbolAddress(u32 address, SymbolType symmask);
std::string GetDescription(unsigned int address);
2013-11-27 15:06:41 +01:00
std::vector<SymbolEntry> GetAllSymbols(SymbolType symmask);
2013-11-27 13:33:30 +01:00
2012-11-01 16:19:01 +01:00
#ifdef _WIN32
void FillSymbolListBox(HWND listbox, SymbolType symType);
2012-11-01 16:19:01 +01:00
#endif
void GetLabels(std::vector<LabelDefinition> &dest);
2012-11-01 16:19:01 +01: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);
2014-01-27 00:35:16 +01:00
std::vector<LoadedModuleInfo> getAllModules() const;
void AddFunction(const char* name, u32 address, u32 size, int moduleIndex = -1);
u32 GetFunctionStart(u32 address);
int GetFunctionNum(u32 address);
u32 GetFunctionSize(u32 startAddress);
u32 GetFunctionModuleAddress(u32 startAddress);
2013-11-27 13:33:30 +01:00
bool SetFunctionSize(u32 startAddress, u32 newSize);
bool RemoveFunction(u32 startAddress, bool removeName);
// 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);
2012-11-01 16:19:01 +01:00
void AddLabel(const char* name, u32 address, int moduleIndex = -1);
std::string GetLabelString(u32 address);
void SetLabelName(const char* name, u32 address);
bool GetLabelValue(const char* name, u32& dest);
2012-11-01 16:19:01 +01:00
void AddData(u32 address, u32 size, DataType type, int moduleIndex = -1);
u32 GetDataStart(u32 address);
u32 GetDataSize(u32 startAddress);
u32 GetDataModuleAddress(u32 startAddress);
DataType GetDataType(u32 startAddress);
2013-11-27 22:30:48 -08:00
static const u32 INVALID_ADDRESS = (u32)-1;
void UpdateActiveSymbols();
2013-11-27 13:33:30 +01:00
private:
void AssignFunctionIndices();
const char *GetLabelName(u32 address);
const char *GetLabelNameRel(u32 relAddress, int moduleIndex) const;
2013-11-27 13:33:30 +01:00
2013-12-02 15:30:03 +01:00
struct FunctionEntry {
u32 start;
2013-11-27 13:33:30 +01:00
u32 size;
int index;
int module;
};
2013-12-02 15:30:03 +01:00
struct LabelEntry {
u32 addr;
int module;
2013-11-26 00:23:17 +01:00
char name[128];
};
2013-12-02 15:30:03 +01:00
struct DataEntry {
2013-11-27 13:33:30 +01:00
DataType type;
u32 start;
2013-11-27 13:33:30 +01:00
u32 size;
int module;
2012-11-01 16:19:01 +01:00
};
2013-11-27 13:33:30 +01: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;
bool activeNeedUpdate_ = false;
// This is indexed by the end address of the module.
std::map<u32, const ModuleEntry> activeModuleEnds;
// Module ID, index
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 13:33:30 +01:00
mutable std::recursive_mutex lock_;
bool sawUnknownModule = false;
2012-11-01 16:19:01 +01:00
};
extern SymbolMap *g_symbolMap;
2013-12-02 15:30:03 +01:00