rsp2elfu.cxx
3.31 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <symconst.h>
#include "rsp2elf.h"
extern symbol * symTable;
int source::containsAddr( unsigned long addr )
{
range * rp = rangeList;
while ( rp )
{
if ( rp->inrange( addr ) )
return 1;
rp = rp->next;
}
return 0;
}
void source::newRange( unsigned long addr, int sourceLine )
{
range * rp = rangeList;
unsigned long loc = addr;
while ( rp )
{
if ( loc == (rp->endOfRange() + 1) )
{
rp->extend( sourceLine );
return;
}
rp = rp->next;
}
// Could not find a range to extend, add a new one
rp = new range( addr, sourceLine );
if ( rangeList == 0 ) /* no ranges yet */
rangeList = rp;
else
rangeLast->next = rp;
rangeLast = rp;
}
void source::PrintProcs( void )
{
proc * pro = procList;
while ( pro )
{
pro->print();
pro = pro->next;
}
}
void source::PrintSymbols( void )
{
symbol * sym = symList;
if ( sym == 0 )
cout << " File had no orphan symbols" << endl;
else while ( sym )
{
sym->print();
sym = sym->pnext;
}
}
void source::AddProc( proc * p )
{
if ( procList ) /* new proc for file */
procLast->next = p;
else
procList = p;
procLast = p;
++procCount;
}
void source::AddLine( line * l )
{
if ( lineList == 0 ) /* first line for this file */
lineList = l;
else
lineLast->next = l;
lineLast = l;
++lineCount;
}
void source::AddSymbol( symbol * sym )
{
if ( symList )
symLast->pnext = sym;
else
symList = sym;
symLast = sym;
++labelCount;
}
void source::MakeProcForFile( void )
{
proc * newProc = new proc;
char c, * s, *d, *procName = (char *) malloc( strlen( fileName ) + 2 );
if ( !procName )
nospace();
d = procName;
*d++ = '_';
s = fileName;
while ( c = *s++ )
if ( isalnum( c ) )
*d++ = c;
else
*d++ = '_';
newProc->callMe( procName ); // copies it
newProc->newlow( rangeList->lowAddr, lineList->LineIs() );
newProc->newhigh( rangeLast->highAddr, lineLast );
newProc->InheritLines( lineList, lineLast );
newProc->InheritLabels( symList, symLast );
symList = symLast = 0;
lineList = lineLast = 0;
labelCount = 0;
lineCount = 0;
AddProc( newProc ); // should be only one
NewSymbol( procName, rangeList->lowAddr, stProc );
}
void proc::print( void ) {
symbol * s = symList;
line * l = lineList;
cout << " PROC " << procName << " range " << hex <<
lowAddr << ":" << highAddr << " lines " << dec <<
lowLine << ":" << highLine << " aux " << auxEntry << endl;
if ( !s )
cout << "(Proc had no symbols)" << endl;
else
while ( s )
{
s->print();
s = s->pnext;
}
if ( !l )
cout << " (Proc had no lines)" << endl;
else
{
cout << " LINES ";
while ( l )
{
l->print();
l = l->next;
}
cout << endl;
}
}
int proc::contains( unsigned long addr )
{
if ( addr >= lowAddr && addr <= highAddr )
return 1;
return 0;
}
void proc::AddLine( line * l )
{
if ( lineList == 0 ) /* first line for this proc */
lineList = l;
else
lineLast->next = l;
lineLast = l;
++lineCount;
}
void proc::AsgSymIndex( int index )
{
symbol * sym = symTable;
while ( sym )
{
if ( !strcmp( procName, sym->NameIs() ) ) // found it
{
sym->AsgSymIndex( index );
return;
}
sym = sym->next;
}
}
int range::inrange( unsigned long addr )
{
if ( addr >= lowAddr && addr <= highAddr )
return 1;
return 0;
}