-
Notifications
You must be signed in to change notification settings - Fork 10
/
ld65dbg.h
139 lines (98 loc) · 2.68 KB
/
ld65dbg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// ld65dbg.h
//
#pragma once
#include <stdio.h>
#include <string>
#include <map>
namespace ld65
{
class database;
class segment
{
public:
static constexpr unsigned char READ = 0x01;
static constexpr unsigned char WRITE = 0x02;
segment( int id, const char *name = nullptr, int startAddr = 0, int size = 0, int ofs = -1, unsigned char type = READ );
const char *name(void){ return _name.c_str(); };
int addr(void){ return _startAddr; };
int ofs(void){ return _ofs; };
private:
std::string _name; // Segment Name
int _id; // Debug ID
int _startAddr; // Start Address CPU
int _size; // Memory region size
int _ofs; // ROM Offset
unsigned char _type; // ro or rw
friend class database;
};
class scope
{
public:
scope( int id, const char *name = nullptr, int size = 0, int parentID = -1);
const char *name(void){ return _name.c_str(); };
scope *getParent(void){ return _parent; };
void getFullName( std::string &out );
private:
std::string _name; // Scope Name
int _id; // Debug ID
int _parentID; // Parent ID
int _size;
scope *_parent;
friend class database;
};
class sym
{
public:
enum
{
IMPORT = 0,
LABEL,
EQU
};
sym( int id, const char *name = nullptr, int size = 0, int value = 0, int type = IMPORT);
int id(void){ return _id; };
const char *name(void){ return _name.c_str(); };
int size(void){ return _size; };
int value(void){ return _value; };
int type(void){ return _type; };
scope *getScope(void){ return _scope; };
segment *getSegment(void){ return _segment; };
private:
std::string _name; // Scope Name
int _id; // Debug ID
int _size;
int _value;
int _type;
scope *_scope;
segment *_segment;
friend class database;
};
class database
{
public:
database(void);
~database(void);
int dbgFileLoad( const char *dbgFilePath );
int iterateSymbols( void *userData, void (*cb)( void *userData, sym *s ) );
private:
std::map<int, scope*> scopeMap;
std::map<int, segment*> segmentMap;
std::map<int, sym*> symMap;
class dbgLine
{
public:
dbgLine(size_t bufferSize = 1024);
~dbgLine(void);
const char *readFromFile( FILE *fp );
const char *getLine(void){ return buf; };
int readToken( char *tk, size_t tkSize );
int readKeyValuePair( char *keyValueBuffer, size_t keyValueBufferSize );
static int splitKeyValuePair( char *keyValueBuffer, char **keyPtr, char **valuePtr );
private:
void allocBuffer(size_t bufferSize);
size_t readPtr;
size_t bufSize;
char *buf;
};
};
};