Skip to content

Commit 882ff2f

Browse files
committed
really simple debugger working
breaks on exceptions, can eval on current stack, can continue
1 parent 0aadc8a commit 882ff2f

File tree

5 files changed

+91
-73
lines changed

5 files changed

+91
-73
lines changed

JSCDebugger/JSCDebuggerPrivate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ namespace JSCDebug {
5656
bool hasBreakpoint(intptr_t sourceID, const TextPosition&) const;
5757
public:
5858
JSCDebugger();
59-
59+
60+
bool isPaused() { return m_paused; };
6061
void setDelegate(JSCDebuggerDelegate *delegate) { m_delegate = delegate; };
6162
void setShouldPause(bool shouldPause) { m_pauseOnNextStatement = shouldPause; };
6263
String setBreakpoint(const String& sourceID, const ScriptBreakpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber);

JSCDebugger/SimpleTCPServer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ void SimpleTCPServer::start(JSCDebug::JSCDebugger *debugger)
5353
{
5454
listen(m_socket, 1);
5555
int t;
56-
while ((t = accept(m_socket, NULL, NULL)) > 0) {
56+
bool keepListening = true;
57+
while (keepListening && (t = accept(m_socket, NULL, NULL)) > 0) {
5758
// we got something, process...
5859
write(t, ">> ", 3);
59-
parseInput(t, debugger);
60+
if (parseInput(t, debugger) == 0)
61+
keepListening = false;
62+
close(t);
6063
}
6164
}

JSCDebugger/simple_debug.c

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -46,87 +46,91 @@ enum {
4646

4747
void performAction(int command, char **args, JSCDebug::JSCDebugger *debugger, int socket);
4848
int parseInput(int file, JSCDebug::JSCDebugger *debugger);
49+
static bool shouldExit = false;
4950

5051

51-
#line 78 "simple_debug.rl"
52+
#line 80 "simple_debug.rl"
5253

5354

5455

55-
#line 56 "simple_debug.c"
56+
#line 57 "simple_debug.c"
5657
static const char _simple_debug_actions[] = {
5758
0, 1, 0, 1, 2, 1, 3, 1,
58-
4, 1, 5, 2, 1, 6
59+
4, 1, 5, 1, 7, 2, 1, 6
60+
5961
};
6062

6163
static const char _simple_debug_key_offsets[] = {
62-
0, 0, 2, 3, 4, 5, 6, 7,
63-
8, 9, 11, 12, 13, 14, 15, 16,
64-
17, 19, 20, 21
64+
0, 0, 2, 4, 5, 6, 8, 9,
65+
10, 11, 12, 14, 15, 16, 17, 18,
66+
19, 20, 22, 23, 24
6567
};
6668

6769
static const char _simple_debug_trans_keys[] = {
68-
10, 111, 110, 116, 105, 110, 117, 101,
69-
10, 32, 118, 10, 10, 97, 108, 32,
70-
10, 10, 116, 101, 112, 99, 101, 110,
71-
115, 0
70+
10, 32, 10, 111, 110, 116, 10, 105,
71+
110, 117, 101, 10, 32, 118, 10, 10,
72+
97, 108, 32, 10, 10, 116, 101, 112,
73+
10, 32, 99, 101, 110, 115, 0
7274
};
7375

7476
static const char _simple_debug_single_lengths[] = {
75-
0, 2, 1, 1, 1, 1, 1, 1,
76-
1, 2, 1, 1, 1, 1, 1, 1,
77-
2, 1, 1, 4
77+
0, 2, 2, 1, 1, 2, 1, 1,
78+
1, 1, 2, 1, 1, 1, 1, 1,
79+
1, 2, 1, 1, 6
7880
};
7981

8082
static const char _simple_debug_range_lengths[] = {
8183
0, 0, 0, 0, 0, 0, 0, 0,
8284
0, 0, 0, 0, 0, 0, 0, 0,
83-
0, 0, 0, 0
85+
0, 0, 0, 0, 0
8486
};
8587

8688
static const char _simple_debug_index_offsets[] = {
87-
0, 0, 3, 5, 7, 9, 11, 13,
88-
15, 17, 20, 22, 24, 26, 28, 30,
89-
32, 35, 37, 39
89+
0, 0, 3, 6, 8, 10, 13, 15,
90+
17, 19, 21, 24, 26, 28, 30, 32,
91+
34, 36, 39, 41, 43
9092
};
9193

9294
static const char _simple_debug_trans_targs[] = {
93-
19, 2, 0, 3, 0, 4, 0, 5,
94-
0, 6, 0, 7, 0, 8, 0, 19,
95-
0, 10, 12, 0, 0, 11, 19, 11,
96-
13, 0, 14, 0, 10, 0, 19, 0,
97-
19, 17, 0, 18, 0, 15, 0, 1,
98-
9, 15, 16, 0, 0
95+
20, 1, 0, 20, 3, 0, 4, 0,
96+
5, 0, 20, 6, 0, 7, 0, 8,
97+
0, 9, 0, 20, 0, 11, 13, 0,
98+
0, 12, 20, 12, 14, 0, 15, 0,
99+
11, 0, 20, 0, 20, 18, 0, 19,
100+
0, 16, 0, 20, 1, 2, 10, 16,
101+
17, 0, 0
99102
};
100103

101104
static const char _simple_debug_trans_actions[] = {
102-
9, 0, 0, 0, 0, 0, 0, 0,
103-
0, 0, 0, 0, 0, 0, 0, 9,
104-
0, 0, 0, 0, 0, 1, 11, 0,
105-
0, 0, 0, 0, 0, 0, 7, 0,
106-
7, 0, 0, 0, 0, 0, 0, 0,
107-
0, 0, 0, 0, 0
105+
11, 0, 0, 9, 0, 0, 0, 0,
106+
0, 0, 9, 0, 0, 0, 0, 0,
107+
0, 0, 0, 9, 0, 0, 0, 0,
108+
0, 1, 13, 0, 0, 0, 0, 0,
109+
0, 0, 7, 0, 7, 0, 0, 0,
110+
0, 0, 0, 11, 0, 0, 0, 0,
111+
0, 0, 0
108112
};
109113

110114
static const char _simple_debug_to_state_actions[] = {
111115
0, 0, 0, 0, 0, 0, 0, 0,
112116
0, 0, 0, 0, 0, 0, 0, 0,
113-
0, 0, 0, 3
117+
0, 0, 0, 0, 3
114118
};
115119

116120
static const char _simple_debug_from_state_actions[] = {
117121
0, 0, 0, 0, 0, 0, 0, 0,
118122
0, 0, 0, 0, 0, 0, 0, 0,
119-
0, 0, 0, 5
123+
0, 0, 0, 0, 5
120124
};
121125

122-
static const int simple_debug_start = 19;
123-
static const int simple_debug_first_final = 19;
126+
static const int simple_debug_start = 20;
127+
static const int simple_debug_first_final = 20;
124128
static const int simple_debug_error = 0;
125129

126-
static const int simple_debug_en_main = 19;
130+
static const int simple_debug_en_main = 20;
127131

128132

129-
#line 81 "simple_debug.rl"
133+
#line 83 "simple_debug.rl"
130134

131135
void performAction(int command, char **args, JSCDebug::JSCDebugger *debugger, int socket)
132136
{
@@ -141,12 +145,14 @@ void performAction(int command, char **args, JSCDebug::JSCDebugger *debugger, in
141145
break;
142146
case kContinueCommand:
143147
debugger->continueProgram();
148+
shouldExit = true;
144149
break;
145150
case kEvalCommand:
146151
printf("eval: '%s'\n", *args);
147152
unsigned outLen;
148153
const unsigned char *result = debugger->evaluateInCurrentFrame((unsigned char *)*args, &outLen);
149154
write(socket, result, outLen);
155+
write(socket, "\n>> ", 4);
150156
free(*args); *args = NULL;
151157
break;
152158
}
@@ -164,22 +170,22 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger)
164170
char *args = NULL, *argsBegin = NULL;
165171

166172

167-
#line 168 "simple_debug.c"
173+
#line 174 "simple_debug.c"
168174
{
169175
cs = simple_debug_start;
170176
ts = 0;
171177
te = 0;
172178
act = 0;
173179
}
174180

175-
#line 118 "simple_debug.rl"
181+
#line 122 "simple_debug.rl"
176182
ssize_t readBytes;
177-
while ((readBytes = read(file, buff, BUF_SIZE))) {
183+
while (!shouldExit && (readBytes = read(file, buff, BUF_SIZE))) {
178184
char *p = buff, *eof = buff + readBytes;
179185
char *pe = eof;
180186

181187

182-
#line 183 "simple_debug.c"
188+
#line 189 "simple_debug.c"
183189
{
184190
int _klen;
185191
unsigned int _trans;
@@ -200,7 +206,7 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger)
200206
#line 1 "NONE"
201207
{ts = p;}
202208
break;
203-
#line 204 "simple_debug.c"
209+
#line 210 "simple_debug.c"
204210
}
205211
}
206212

@@ -265,13 +271,13 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger)
265271
switch ( *_acts++ )
266272
{
267273
case 0:
268-
#line 61 "simple_debug.rl"
274+
#line 62 "simple_debug.rl"
269275
{
270276
argsBegin = p;
271277
}
272278
break;
273279
case 1:
274-
#line 64 "simple_debug.rl"
280+
#line 65 "simple_debug.rl"
275281
{
276282
if (args) {
277283
free(args);
@@ -282,18 +288,22 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger)
282288
}
283289
break;
284290
case 4:
285-
#line 74 "simple_debug.rl"
291+
#line 75 "simple_debug.rl"
286292
{te = p+1;{ performAction(kNextCommand, NULL, debugger, file); }}
287293
break;
288294
case 5:
289-
#line 75 "simple_debug.rl"
290-
{te = p+1;{ performAction(kContinueCommand, NULL, debugger, file); }}
295+
#line 76 "simple_debug.rl"
296+
{te = p+1;{ performAction(kContinueCommand, NULL, debugger, file); {p++; goto _out; } }}
291297
break;
292298
case 6:
293-
#line 76 "simple_debug.rl"
299+
#line 77 "simple_debug.rl"
294300
{te = p+1;{ performAction(kEvalCommand, &args, debugger, file); }}
295301
break;
296-
#line 297 "simple_debug.c"
302+
case 7:
303+
#line 78 "simple_debug.rl"
304+
{te = p+1;}
305+
break;
306+
#line 307 "simple_debug.c"
297307
}
298308
}
299309

@@ -306,7 +316,7 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger)
306316
#line 1 "NONE"
307317
{ts = 0;}
308318
break;
309-
#line 310 "simple_debug.c"
319+
#line 320 "simple_debug.c"
310320
}
311321
}
312322

@@ -318,10 +328,10 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger)
318328
_out: {}
319329
}
320330

321-
#line 124 "simple_debug.rl"
331+
#line 128 "simple_debug.rl"
322332

323333
if (cs == simple_debug_error) {
324-
printf("parser error @ '%s'", p);
334+
printf("parser error @ '%s'\n", p);
325335
return -1;
326336
}
327337
}

JSCDebugger/simple_debug.rl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ enum {
4444

4545
void performAction(int command, char **args, JSCDebug::JSCDebugger *debugger, int socket);
4646
int parseInput(int file, JSCDebug::JSCDebugger *debugger);
47+
static bool shouldExit = false;
4748

4849
%%{
4950
machine simple_debug;
5051

5152
# commands
5253
step = ('s' | 'step' | 'n');
53-
cont = ('c' | 'continue');
54+
cont = ('c' | 'continue' | 'cont');
5455
breakpoint = ('b' | 'breakpoint');
5556
step_into = ('si');
5657
backtrace = ('bt' | 'backtrace');
@@ -72,8 +73,9 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger);
7273

7374
main := |*
7475
step newline => { performAction(kNextCommand, NULL, debugger, file); };
75-
cont newline => { performAction(kContinueCommand, NULL, debugger, file); };
76+
cont newline => { performAction(kContinueCommand, NULL, debugger, file); fbreak; };
7677
eval ' ' (any - newline)+ > markArgsBegin % markArgsEnd newline => { performAction(kEvalCommand, &args, debugger, file); };
78+
[ ]* newline;
7779
*|;
7880
}%%
7981

@@ -92,12 +94,14 @@ void performAction(int command, char **args, JSCDebug::JSCDebugger *debugger, in
9294
break;
9395
case kContinueCommand:
9496
debugger->continueProgram();
97+
shouldExit = true;
9598
break;
9699
case kEvalCommand:
97100
printf("eval: '%s'\n", *args);
98101
unsigned outLen;
99102
const unsigned char *result = debugger->evaluateInCurrentFrame((unsigned char *)*args, &outLen);
100103
write(socket, result, outLen);
104+
write(socket, "\n>> ", 4);
101105
free(*args); *args = NULL;
102106
break;
103107
}
@@ -116,14 +120,14 @@ int parseInput(int file, JSCDebug::JSCDebugger *debugger)
116120

117121
%% write init;
118122
ssize_t readBytes;
119-
while ((readBytes = read(file, buff, BUF_SIZE))) {
123+
while (!shouldExit && (readBytes = read(file, buff, BUF_SIZE))) {
120124
char *p = buff, *eof = buff + readBytes;
121125
char *pe = eof;
122126

123127
%% write exec;
124128

125129
if (cs == simple_debug_error) {
126-
printf("parser error @ '%s'", p);
130+
printf("parser error @ '%s'\n", p);
127131
return -1;
128132
}
129133
}

0 commit comments

Comments
 (0)