ld65 debug database loader in work.
This commit is contained in:
parent
0beac5d725
commit
e0aa5a71fa
|
@ -1,7 +1,10 @@
|
||||||
// ld65dbg.cpp
|
// ld65dbg.cpp
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
#include "ld65dbg.h"
|
#include "ld65dbg.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +22,7 @@ namespace ld65
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
sym::sym(int id, const char *name, int size)
|
sym::sym(int id, const char *name, int size)
|
||||||
: _name(name ? name : ""), _id(id), _size(size)
|
: _name(name ? name : ""), _id(id), _size(size), _scope(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
@ -27,6 +30,22 @@ namespace ld65
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
database::~database(void)
|
||||||
|
{
|
||||||
|
for (auto itSym = symMap.begin(); itSym != symMap.end(); itSym++)
|
||||||
|
{
|
||||||
|
delete itSym->second;
|
||||||
|
}
|
||||||
|
for (auto itScope = scopeMap.begin(); itScope != scopeMap.end(); itScope++)
|
||||||
|
{
|
||||||
|
delete itScope->second;
|
||||||
|
}
|
||||||
|
for (auto itSeg = segmentMap.begin(); itSeg != segmentMap.end(); itSeg++)
|
||||||
|
{
|
||||||
|
delete itSeg->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------
|
||||||
database::dbgLine::dbgLine(size_t bufferSize)
|
database::dbgLine::dbgLine(size_t bufferSize)
|
||||||
{
|
{
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
@ -164,9 +183,9 @@ namespace ld65
|
||||||
|
|
||||||
while (isspace(buf[i])) i++;
|
while (isspace(buf[i])) i++;
|
||||||
|
|
||||||
while ( (buf[i] != 0) )
|
while ( buf[i] != 0 )
|
||||||
{
|
{
|
||||||
if ( !isStringLiteral && buf[i] != ',' )
|
if ( !isStringLiteral && buf[i] == ',' )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -230,10 +249,11 @@ namespace ld65
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
int database::dbgFileLoad( const char *dbgFilePath )
|
int database::dbgFileLoad( const char *dbgFilePath )
|
||||||
{
|
{
|
||||||
|
static constexpr size_t lineSize = 4096;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
dbgLine line;
|
dbgLine line( lineSize );
|
||||||
char lineType[64];
|
char lineType[64];
|
||||||
char keyValueBuffer[1024];
|
fceuScopedPtr <char> keyValueBuffer( new char[ lineSize ], fceuScopedPtr<char>::NewArray );
|
||||||
|
|
||||||
fp = ::fopen( dbgFilePath, "r");
|
fp = ::fopen( dbgFilePath, "r");
|
||||||
|
|
||||||
|
@ -241,21 +261,80 @@ namespace ld65
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( line.readFromFile(fp) != NULL )
|
while ( line.readFromFile(fp) != NULL )
|
||||||
{
|
{
|
||||||
printf("%s", line.getLine());
|
printf("%s", line.getLine());
|
||||||
|
|
||||||
if ( line.readToken( lineType, sizeof(lineType) ) )
|
if ( line.readToken( lineType, sizeof(lineType) ) )
|
||||||
{
|
{
|
||||||
printf("%s\n", lineType);
|
int id = -1, size = 0, parentID = -1, scopeID = -1;
|
||||||
|
char name[256];
|
||||||
|
|
||||||
while ( line.readKeyValuePair( keyValueBuffer, sizeof(keyValueBuffer) ) )
|
name[0] = 0;
|
||||||
|
|
||||||
|
while ( line.readKeyValuePair( keyValueBuffer.get(), lineSize) )
|
||||||
{
|
{
|
||||||
char *key, *val;
|
char *key, *val;
|
||||||
|
|
||||||
line.splitKeyValuePair( keyValueBuffer, &key, &val );
|
line.splitKeyValuePair( keyValueBuffer.get(), &key, &val );
|
||||||
|
|
||||||
printf(" Key '%s' -> Value '%s' \n", key, val );
|
printf(" Key '%s' -> Value '%s' \n", key, val );
|
||||||
|
|
||||||
|
if ( strcmp( key, "id") == 0 )
|
||||||
|
{
|
||||||
|
id = strtol( val, nullptr, 0 );
|
||||||
|
}
|
||||||
|
else if ( strcmp( key, "name") == 0 )
|
||||||
|
{
|
||||||
|
strncpy( name, val, sizeof(name));
|
||||||
|
}
|
||||||
|
else if ( strcmp( key, "size") == 0 )
|
||||||
|
{
|
||||||
|
size = strtol( val, nullptr, 0 );
|
||||||
|
}
|
||||||
|
else if ( strcmp( key, "scope") == 0 )
|
||||||
|
{
|
||||||
|
scopeID = strtol( val, nullptr, 0 );
|
||||||
|
}
|
||||||
|
else if ( strcmp( key, "scope") == 0 )
|
||||||
|
{
|
||||||
|
parentID = strtol( val, nullptr, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strcmp( lineType, "scope" ) == 0 )
|
||||||
|
{
|
||||||
|
if ( id >= 0 )
|
||||||
|
{
|
||||||
|
scope *s = new scope( id, name, size, parentID );
|
||||||
|
|
||||||
|
scopeMap[id] = s;
|
||||||
|
|
||||||
|
auto it = scopeMap.find( parentID );
|
||||||
|
|
||||||
|
if ( it != scopeMap.end() )
|
||||||
|
{
|
||||||
|
printf("Found Parent:%i for %i\n", parentID, id );
|
||||||
|
s->_parent = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( strcmp( lineType, "sym") == 0 )
|
||||||
|
{
|
||||||
|
if ( id >= 0 )
|
||||||
|
{
|
||||||
|
sym *s = new sym( id, name, size );
|
||||||
|
|
||||||
|
auto it = scopeMap.find( scopeID );
|
||||||
|
|
||||||
|
if ( it != scopeMap.end() )
|
||||||
|
{
|
||||||
|
printf("Found Scope:%i for %s\n", scopeID, name );
|
||||||
|
s->_scope = it->second;
|
||||||
|
}
|
||||||
|
symMap[id] = s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,8 @@ namespace ld65
|
||||||
int _id; // Debug ID
|
int _id; // Debug ID
|
||||||
int _size;
|
int _size;
|
||||||
|
|
||||||
|
scope *_scope;
|
||||||
|
|
||||||
friend class database;
|
friend class database;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,12 +66,14 @@ namespace ld65
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
database(void);
|
database(void);
|
||||||
|
~database(void);
|
||||||
|
|
||||||
int dbgFileLoad( const char *dbgFilePath );
|
int dbgFileLoad( const char *dbgFilePath );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<int, scope*> scopeMap;
|
std::map<int, scope*> scopeMap;
|
||||||
std::map<int, segment*> segmentMap;
|
std::map<int, segment*> segmentMap;
|
||||||
|
std::map<int, sym*> symMap;
|
||||||
|
|
||||||
class dbgLine
|
class dbgLine
|
||||||
{
|
{
|
||||||
|
|
32
src/types.h
32
src/types.h
|
@ -22,6 +22,9 @@
|
||||||
#ifndef __FCEU_TYPES
|
#ifndef __FCEU_TYPES
|
||||||
#define __FCEU_TYPES
|
#define __FCEU_TYPES
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
//enables a hack designed for debugging dragon warrior 3 which treats BRK as a 3-byte opcode
|
//enables a hack designed for debugging dragon warrior 3 which treats BRK as a 3-byte opcode
|
||||||
//#define BRK_3BYTE_HACK
|
//#define BRK_3BYTE_HACK
|
||||||
|
|
||||||
|
@ -186,20 +189,23 @@ template <typename T>
|
||||||
class fceuScopedPtr
|
class fceuScopedPtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
fceuScopedPtr( T *ptrIn = nullptr )
|
enum
|
||||||
|
{
|
||||||
|
New = 0,
|
||||||
|
NewArray,
|
||||||
|
Malloc
|
||||||
|
};
|
||||||
|
fceuScopedPtr( T *ptrIn = nullptr, int allocType = New )
|
||||||
{
|
{
|
||||||
//printf("Scoped Pointer Constructor <%s>: %p\n", typeid(T).name(), ptrIn );
|
//printf("Scoped Pointer Constructor <%s>: %p\n", typeid(T).name(), ptrIn );
|
||||||
ptr = ptrIn;
|
ptr = ptrIn;
|
||||||
|
_allocType = allocType;
|
||||||
}
|
}
|
||||||
|
|
||||||
~fceuScopedPtr(void)
|
~fceuScopedPtr(void)
|
||||||
{
|
{
|
||||||
//printf("Scoped Pointer Destructor <%s>: %p\n", typeid(T).name(), ptr );
|
//printf("Scoped Pointer Destructor <%s>: %p\n", typeid(T).name(), ptr );
|
||||||
if (ptr)
|
Delete();
|
||||||
{
|
|
||||||
delete ptr;
|
|
||||||
ptr = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T* operator= (T *ptrIn)
|
T* operator= (T *ptrIn)
|
||||||
|
@ -217,13 +223,25 @@ class fceuScopedPtr
|
||||||
{
|
{
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
delete ptr;
|
if (_allocType == Malloc)
|
||||||
|
{
|
||||||
|
::free(ptr);
|
||||||
|
}
|
||||||
|
else if (_allocType == NewArray)
|
||||||
|
{
|
||||||
|
delete [] ptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
ptr = nullptr;
|
ptr = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T *ptr;
|
T *ptr;
|
||||||
|
int _allocType;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue