project64/Source/Project64/UserInterface/Debugger/Symbols.h

184 lines
3.9 KiB
C
Raw Normal View History

2017-08-18 05:08:22 +00:00
#pragma once
2019-12-25 00:41:20 +00:00
class CSymbol;
2022-09-26 02:31:54 +00:00
typedef enum
{
2019-12-25 00:41:20 +00:00
SYM_INVALID = -1,
SYM_CODE,
SYM_DATA,
SYM_U8,
SYM_U16,
SYM_U32,
SYM_U64,
SYM_S8,
SYM_S16,
SYM_S32,
SYM_S64,
SYM_FLOAT,
SYM_DOUBLE,
SYM_VECTOR2,
SYM_VECTOR3,
SYM_VECTOR4,
2019-12-25 00:41:20 +00:00
NUM_SYM_TYPES
} symbol_type_id_t;
typedef struct
{
2022-09-26 02:31:54 +00:00
symbol_type_id_t id;
const char * name;
int size;
2019-12-25 00:41:20 +00:00
} symbol_type_info_t;
2022-09-26 02:31:54 +00:00
typedef enum
{
2019-12-25 00:41:20 +00:00
ERR_SUCCESS,
ERR_INVALID_TYPE,
ERR_INVALID_ADDR,
ERR_INVALID_NAME,
ERR_MISSING_FIELDS,
} symbol_parse_error_t;
class CSymbolTable
2017-08-18 05:08:22 +00:00
{
public:
2022-09-26 02:31:54 +00:00
CSymbolTable(CDebuggerUI * debugger);
2019-12-25 00:41:20 +00:00
~CSymbolTable();
2017-08-18 05:08:22 +00:00
private:
2019-12-25 00:41:20 +00:00
CSymbolTable();
2022-09-26 02:31:54 +00:00
CDebuggerUI * m_Debugger;
2019-12-25 00:41:20 +00:00
CriticalSection m_CS;
std::vector<CSymbol> m_Symbols;
std::map<uint32_t, size_t> m_AddressMap; // address -> symbol index
2022-09-26 02:31:54 +00:00
int m_NextSymbolId;
2019-12-25 00:41:20 +00:00
2022-09-26 02:31:54 +00:00
CFile m_SymFileHandle;
char * m_SymFileBuffer;
2019-12-25 00:41:20 +00:00
size_t m_SymFileSize;
2022-09-26 02:31:54 +00:00
char * m_ParserToken;
2019-12-25 00:41:20 +00:00
size_t m_ParserTokenLength;
2022-09-26 02:31:54 +00:00
char * m_TokPos;
char m_ParserDelimeter;
char * m_SymFileParseBuffer;
bool m_bHaveFirstToken;
2019-12-25 00:41:20 +00:00
2022-09-26 02:31:54 +00:00
void ParserFetchToken(const char * delim);
2017-09-13 10:36:03 +00:00
void UpdateAddressMap();
2017-08-18 05:08:22 +00:00
public:
2019-12-25 00:41:20 +00:00
static symbol_type_info_t m_SymbolTypes[];
2022-09-26 02:31:54 +00:00
static const char * GetTypeName(int typeId);
2019-12-25 00:41:20 +00:00
static int GetTypeSize(int typeId);
2022-09-26 02:31:54 +00:00
static symbol_type_id_t GetTypeId(char * typeName);
static bool CmpSymbolAddresses(CSymbol & a, CSymbol & b);
2019-12-25 00:41:20 +00:00
2022-09-26 02:31:54 +00:00
void GetValueString(char * dst, CSymbol * symbol);
2019-12-25 00:41:20 +00:00
CPath GetSymFilePath();
void Load();
void Save();
2022-09-26 02:31:54 +00:00
void ParseErrorAlert(char * message, int lineNumber);
2019-12-25 00:41:20 +00:00
2022-09-26 02:31:54 +00:00
void AddSymbol(int type, uint32_t address, const char * name, const char * description = nullptr, bool bSortAfter = true);
2019-12-25 00:41:20 +00:00
void Reset();
2022-09-26 02:31:54 +00:00
int GetCount();
bool GetSymbolById(int id, CSymbol * symbol);
bool GetSymbolByIndex(size_t index, CSymbol * symbol);
bool GetSymbolByAddress(uint32_t address, CSymbol * symbol);
2019-12-25 00:41:20 +00:00
bool RemoveSymbolById(int id);
2017-08-18 05:08:22 +00:00
};
2022-09-26 02:31:54 +00:00
class CSymbol
{
2017-08-18 05:08:22 +00:00
public:
2022-09-26 02:31:54 +00:00
int m_Id;
int m_Type;
2017-09-13 10:36:03 +00:00
uint32_t m_Address;
2022-09-26 02:31:54 +00:00
char * m_Name;
char * m_Description;
2017-09-13 10:36:03 +00:00
2019-12-25 00:41:20 +00:00
CSymbol() :
m_Id(0),
m_Type(SYM_INVALID),
m_Address(0),
2021-04-12 11:35:39 +00:00
m_Name(nullptr),
m_Description(nullptr)
2019-12-25 00:41:20 +00:00
{
}
2022-09-26 02:31:54 +00:00
CSymbol(int id, int type, uint32_t address, const char * name, const char * description) :
2017-09-13 10:36:03 +00:00
m_Id(id),
m_Type(type),
2019-12-25 00:41:20 +00:00
m_Address(address),
2021-04-12 11:35:39 +00:00
m_Name(nullptr),
m_Description(nullptr)
2017-09-13 10:36:03 +00:00
{
2021-04-12 11:35:39 +00:00
if (name != nullptr)
2017-09-13 10:36:03 +00:00
{
2019-12-25 00:41:20 +00:00
m_Name = _strdup(name);
2017-09-13 10:36:03 +00:00
}
2021-04-12 11:35:39 +00:00
if (description != nullptr)
2017-09-13 10:36:03 +00:00
{
2019-12-25 00:41:20 +00:00
m_Description = _strdup(description);
2017-09-13 10:36:03 +00:00
}
}
2022-09-26 02:31:54 +00:00
CSymbol(const CSymbol & symbol) :
2019-12-25 00:41:20 +00:00
m_Id(symbol.m_Id),
m_Type(symbol.m_Type),
m_Address(symbol.m_Address),
2021-04-12 11:35:39 +00:00
m_Name(nullptr),
m_Description(nullptr)
2019-12-25 00:41:20 +00:00
{
2021-04-12 11:35:39 +00:00
m_Name = symbol.m_Name ? _strdup(symbol.m_Name) : nullptr;
m_Description = symbol.m_Description ? _strdup(symbol.m_Description) : nullptr;
2019-12-25 00:41:20 +00:00
}
2022-09-26 02:31:54 +00:00
CSymbol & operator=(const CSymbol & symbol)
2019-12-25 00:41:20 +00:00
{
2021-04-12 11:35:39 +00:00
if (m_Name != nullptr)
2019-12-25 00:41:20 +00:00
{
free(m_Name);
}
2021-04-12 11:35:39 +00:00
if (m_Description != nullptr)
2019-12-25 00:41:20 +00:00
{
free(m_Description);
}
m_Id = symbol.m_Id;
m_Type = symbol.m_Type;
m_Address = symbol.m_Address;
2021-04-12 11:35:39 +00:00
m_Name = symbol.m_Name ? _strdup(symbol.m_Name) : nullptr;
m_Description = symbol.m_Description ? _strdup(symbol.m_Description) : nullptr;
2019-12-25 00:41:20 +00:00
return *this;
}
~CSymbol()
2017-09-13 10:36:03 +00:00
{
2021-04-12 11:35:39 +00:00
if (m_Name != nullptr)
2017-09-13 10:36:03 +00:00
{
free(m_Name);
}
2019-12-25 00:41:20 +00:00
2021-04-12 11:35:39 +00:00
if (m_Description != nullptr)
2017-09-13 10:36:03 +00:00
{
free(m_Description);
}
}
2022-09-26 02:31:54 +00:00
const char * TypeName()
2017-09-13 10:36:03 +00:00
{
2019-12-25 00:41:20 +00:00
return CSymbolTable::GetTypeName(m_Type);
2017-09-13 10:36:03 +00:00
}
int TypeSize()
{
2019-12-25 00:41:20 +00:00
return CSymbolTable::GetTypeSize(m_Type);
2017-09-13 10:36:03 +00:00
}
2021-03-18 03:39:09 +00:00
};