CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/Debugger/SymbolMap.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <vector>20#include <set>21#include <map>22#include <string>23#include <mutex>2425#include "Common/CommonTypes.h"26#include "Common/File/Path.h"2728enum SymbolType {29ST_NONE = 0,30ST_FUNCTION = 1,31ST_DATA = 2,32ST_ALL = 3,33};3435struct SymbolInfo {36SymbolType type;37u32 address;38u32 size;39u32 moduleAddress;40};4142struct SymbolEntry {43std::string name;44u32 address;45u32 size;46};4748struct LoadedModuleInfo {49std::string name;50u32 address;51u32 size;52bool active;53};5455enum DataType {56DATATYPE_NONE, DATATYPE_BYTE, DATATYPE_HALFWORD, DATATYPE_WORD, DATATYPE_ASCII57};5859struct LabelDefinition;6061#ifdef _WIN3262struct HWND__;63typedef struct HWND__ *HWND;64#endif6566class SymbolMap {67public:68SymbolMap() {}69void Clear();70void SortSymbols();7172bool LoadSymbolMap(const Path &filename);73bool SaveSymbolMap(const Path &filename) const;74bool LoadNocashSym(const Path &filename);75void SaveNocashSym(const Path &filename) const;7677SymbolType GetSymbolType(u32 address);78bool GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask = ST_FUNCTION);79u32 GetNextSymbolAddress(u32 address, SymbolType symmask);80std::string GetDescription(unsigned int address);81std::vector<SymbolEntry> GetAllSymbols(SymbolType symmask);8283#ifdef _WIN3284void FillSymbolListBox(HWND listbox, SymbolType symType);85#endif86void GetLabels(std::vector<LabelDefinition> &dest);8788void AddModule(const char *name, u32 address, u32 size);89void UnloadModule(u32 address, u32 size);90u32 GetModuleRelativeAddr(u32 address, int moduleIndex = -1) const;91u32 GetModuleAbsoluteAddr(u32 relative, int moduleIndex) const;92int GetModuleIndex(u32 address) const;93bool IsModuleActive(int moduleIndex);94std::vector<LoadedModuleInfo> getAllModules() const;9596void AddFunction(const char* name, u32 address, u32 size, int moduleIndex = -1);97u32 GetFunctionStart(u32 address);98int GetFunctionNum(u32 address);99u32 GetFunctionSize(u32 startAddress);100u32 GetFunctionModuleAddress(u32 startAddress);101bool SetFunctionSize(u32 startAddress, u32 newSize);102bool RemoveFunction(u32 startAddress, bool removeName);103// Search for the first address their may be a function after address.104// Only valid for currently loaded modules. Not guaranteed there will be a function.105u32 FindPossibleFunctionAtAfter(u32 address);106107void AddLabel(const char* name, u32 address, int moduleIndex = -1);108std::string GetLabelString(u32 address);109void SetLabelName(const char* name, u32 address);110bool GetLabelValue(const char* name, u32& dest);111112void AddData(u32 address, u32 size, DataType type, int moduleIndex = -1);113u32 GetDataStart(u32 address);114u32 GetDataSize(u32 startAddress);115u32 GetDataModuleAddress(u32 startAddress);116DataType GetDataType(u32 startAddress);117118static const u32 INVALID_ADDRESS = (u32)-1;119120void UpdateActiveSymbols();121122private:123void AssignFunctionIndices();124const char *GetLabelName(u32 address);125const char *GetLabelNameRel(u32 relAddress, int moduleIndex) const;126127struct FunctionEntry {128u32 start;129u32 size;130int index;131int module;132};133134struct LabelEntry {135u32 addr;136int module;137char name[128];138};139140struct DataEntry {141DataType type;142u32 start;143u32 size;144int module;145};146147struct ModuleEntry {148// Note: this index is +1, 0 matches any for backwards-compat.149int index;150u32 start;151u32 size;152char name[128];153};154155// These are flattened, read-only copies of the actual data in active modules only.156std::map<u32, const FunctionEntry> activeFunctions;157std::map<u32, const LabelEntry> activeLabels;158std::map<u32, const DataEntry> activeData;159bool activeNeedUpdate_ = false;160161// This is indexed by the end address of the module.162std::map<u32, const ModuleEntry> activeModuleEnds;163164typedef std::pair<int, u32> SymbolKey;165166// These are indexed by the module id and relative address in the module.167std::map<SymbolKey, FunctionEntry> functions;168std::map<SymbolKey, LabelEntry> labels;169std::map<SymbolKey, DataEntry> data;170std::vector<ModuleEntry> modules;171172mutable std::recursive_mutex lock_;173bool sawUnknownModule = false;174};175176extern SymbolMap *g_symbolMap;177178179180