Skip to content

Commit 0aadc8a

Browse files
committed
testing debug support
1 parent bef11bb commit 0aadc8a

File tree

9 files changed

+820
-276
lines changed

9 files changed

+820
-276
lines changed

JSCDebugger/JSCDebugger.cpp

Lines changed: 236 additions & 186 deletions
Large diffs are not rendered by default.

JSCDebugger/JSCDebuggerPrivate.h

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
class JSCDebuggerDelegate;
1717

1818
namespace JSCDebug {
19-
2019
inline String ustringToString(const JSC::UString& u)
2120
{
2221
return u.impl();
@@ -26,18 +25,49 @@ namespace JSCDebug {
2625
{
2726
return JSC::UString(s.impl());
2827
}
28+
29+
class JSSimpleAccessors
30+
{
31+
public:
32+
static JSC::JSValue getProperty(JSC::JSObject *obj, JSC::ExecState *state, const char *property);
33+
static void setProperty(JSC::JSObject *obj, const char *property, JSC::JSValue value);
34+
};
2935

3036
class JSCDebugger : public JSC::Debugger
3137
{
38+
protected:
39+
typedef HashMap<long, ScriptBreakpoint> LineToBreakpointMap;
40+
typedef HashMap<intptr_t, LineToBreakpointMap> SourceIdToBreakpointsMap;
41+
42+
JSCDebuggerDelegate* m_delegate;
43+
bool m_shouldPauseOnExceptions;
44+
bool m_pauseOnNextStatement;
45+
bool m_paused;
46+
bool m_breakpointsActivated;
47+
JavaScriptCallFrame* m_pauseOnCallFrame;
48+
WTF::HashMap<intptr_t,JSC::UString> m_sourceMap;
49+
RefPtr<JavaScriptCallFrame> m_currentCallFrame;
50+
SourceIdToBreakpointsMap m_sourceIdToBreakpoints;
51+
JSC::JSGlobalObject* m_currentGlobalObject;
52+
53+
void updateCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
54+
void createCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
55+
void pauseIfNeeded(JSC::JSGlobalObject* dynamicGlobalObject);
56+
bool hasBreakpoint(intptr_t sourceID, const TextPosition&) const;
3257
public:
3358
JSCDebugger();
3459

3560
void setDelegate(JSCDebuggerDelegate *delegate) { m_delegate = delegate; };
36-
void setShouldPause(bool shouldPause) { m_shouldPause = shouldPause; };
61+
void setShouldPause(bool shouldPause) { m_pauseOnNextStatement = shouldPause; };
3762
String setBreakpoint(const String& sourceID, const ScriptBreakpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber);
3863
void setBreakpointsActivated(bool activated);
39-
void evaluateInCurrentFrame(const char *script);
40-
64+
// control execution
65+
const unsigned char* evaluateInCurrentFrame(const unsigned char *scriptSource, unsigned *outLen);
66+
void continueProgram();
67+
void stepIntoStatement();
68+
void stepOverStatement();
69+
void stepOutOfFunction();
70+
4171
virtual void sourceParsed(JSC::ExecState*, JSC::SourceProvider* sourceProvider, int errorLineNumber, const JSC::UString& errorMessage);
4272
virtual void exception(const JSC::DebuggerCallFrame& debugFrame, intptr_t sourceID, int lineNumber, bool);
4373
virtual void atStatement(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
@@ -47,25 +77,6 @@ namespace JSCDebug {
4777
virtual void willExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
4878
virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
4979
virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
50-
51-
protected:
52-
typedef HashMap<long, ScriptBreakpoint> LineToBreakpointMap;
53-
typedef HashMap<intptr_t, LineToBreakpointMap> SourceIdToBreakpointsMap;
54-
55-
JSCDebuggerDelegate *m_delegate;
56-
bool m_shouldPause;
57-
bool m_shouldPauseOnExceptions;
58-
bool m_paused;
59-
bool m_breakpointsActivated;
60-
WTF::HashMap<intptr_t,JSC::UString> m_sourceMap;
61-
RefPtr<JavaScriptCallFrame> m_currentCallFrame;
62-
SourceIdToBreakpointsMap m_sourceIdToBreakpoints;
63-
64-
void updateCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
65-
void createCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
66-
void pauseIfNeeded(JSC::JSGlobalObject* dynamicGlobalObject);
67-
bool hasBreakpoint(intptr_t sourceID, const TextPosition&) const;
68-
6980
};
7081
}
7182

JSCDebugger/SimpleTCPServer.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
//
88

99
#include "config.h"
10-
#include <runtime/JSONObject.h>
11-
#include <runtime/LiteralParser.h>
12-
#include "SimpleTCPServer.h"
1310
#include <string>
11+
#include "SimpleTCPServer.h"
1412

1513
// auto-generated file with ragel
16-
#include "http_state.c"
14+
#include "simple_debug.c"
1715

1816
using namespace JSCDebug;
1917

@@ -51,43 +49,13 @@ SimpleTCPServer::~SimpleTCPServer()
5149
close(m_socket);
5250
}
5351

54-
void SimpleTCPServer::gotHeader(const char *name, const char *value)
55-
{
56-
std::string key(name);
57-
if (key.compare("Content-Length") == 0) {
58-
m_currentDataLength = atoi(value);
59-
}
60-
printf("got key: '%s' ~> '%s'\n", name, value);
61-
}
62-
63-
void SimpleTCPServer::finishedParsingHeaders()
64-
{
65-
printf("end of headers - body pending\n");
66-
}
67-
68-
void SimpleTCPServer::start()
52+
void SimpleTCPServer::start(JSCDebug::JSCDebugger *debugger)
6953
{
7054
listen(m_socket, 1);
7155
int t;
7256
while ((t = accept(m_socket, NULL, NULL)) > 0) {
7357
// we got something, process...
74-
int parsed = parseHeaders(t, this);
75-
if (parsed && m_currentDataLength) {
76-
// parsed headers and actually got a body length, now read that body
77-
unsigned char *buff = (unsigned char *)calloc(m_currentDataLength + 1, 1);
78-
int bytesRead = read(t, buff, m_currentDataLength);
79-
while (bytesRead < m_currentDataLength) {
80-
bytesRead = read(t, buff + bytesRead, m_currentDataLength - bytesRead);
81-
}
82-
parseRequest(buff, m_currentDataLength);
83-
}
58+
write(t, ">> ", 3);
59+
parseInput(t, debugger);
8460
}
8561
}
86-
87-
void SimpleTCPServer::jsonSend()
88-
{
89-
}
90-
91-
void SimpleTCPServer::jsonReceive()
92-
{
93-
}

JSCDebugger/SimpleTCPServer.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,25 @@
99
#ifndef JavaScriptCore_SimpleTCPServer_h
1010
#define JavaScriptCore_SimpleTCPServer_h
1111

12+
#include "JSCDebuggerPrivate.h"
1213
#include <sys/socket.h>
1314
#include <netinet/in.h>
1415
#include <netdb.h>
1516

16-
class ParserDelegate
17-
{
18-
public:
19-
virtual ~ParserDelegate() {};
20-
virtual void gotHeader(const char *headerName, const char *headerValue) = 0;
21-
virtual void finishedParsingHeaders() = 0;
22-
};
23-
2417
namespace JSCDebug {
25-
class SimpleTCPServer : public ParserDelegate
18+
class SimpleTCPServer
2619
{
2720
private:
2821
int m_socket;
2922
int m_currentDataLength;
30-
23+
24+
int parseLine(int socket);
25+
3126
public:
3227
SimpleTCPServer(int port);
3328
~SimpleTCPServer();
34-
35-
void start();
36-
void jsonSend();
37-
void jsonReceive();
38-
39-
// parser delegate
40-
virtual void gotHeader(const char *name, const char *value);
41-
virtual void finishedParsingHeaders();
29+
30+
void start(JSCDebug::JSCDebugger *delegate);
4231
};
4332
}
4433
#endif

JSCDebugger/http_state.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#include <sys/uio.h>
1616
#include <unistd.h>
1717

18-
class ParserDelegate
18+
class HTTPParserDelegate
1919
{
2020
public:
21-
virtual ~ParserDelegate() {};
21+
virtual ~HTTPParserDelegate() {};
2222
virtual void gotHeader(const char *headerName, const char *headerValue) = 0;
2323
virtual void finishedParsingHeaders() = 0;
2424
};
@@ -27,7 +27,7 @@ class ParserDelegate
2727

2828
extern "C" {
2929

30-
int parseHeaders(int file, ParserDelegate *delegate);
30+
int parseHeaders(int file, HTTPParserDelegate *delegate);
3131

3232

3333
#line 74 "http_state.rl"
@@ -100,7 +100,7 @@ static const int http_simple_en_main = 8;
100100

101101
#line 77 "http_state.rl"
102102

103-
int parseHeaders(int file, ParserDelegate *delegate)
103+
int parseHeaders(int file, HTTPParserDelegate *delegate)
104104
{
105105
// machine state
106106
int cs, act, done = 0;
@@ -120,7 +120,7 @@ int parseHeaders(int file, ParserDelegate *delegate)
120120

121121
#line 88 "http_state.rl"
122122

123-
#define READ_CHUNK_SIZE 2
123+
#define READ_CHUNK_SIZE 128
124124
int bufferSize = READ_CHUNK_SIZE;
125125
char *buffer = (char *)calloc(bufferSize + 1, 1);
126126
char *p = buffer;
@@ -310,7 +310,7 @@ int parseHeaders(int file, ParserDelegate *delegate)
310310

311311
#ifdef DEBUG_HTTP
312312

313-
class SomeDelegate : public ParserDelegate
313+
class SomeDelegate : public HTTPParserDelegate
314314
{
315315
void gotHeader(const char *name, const char *value)
316316
{

JSCDebugger/http_state.rl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#include <sys/uio.h>
1414
#include <unistd.h>
1515

16-
class ParserDelegate
16+
class HTTPParserDelegate
1717
{
1818
public:
19-
virtual ~ParserDelegate() {};
19+
virtual ~HTTPParserDelegate() {};
2020
virtual void gotHeader(const char *headerName, const char *headerValue) = 0;
2121
virtual void finishedParsingHeaders() = 0;
2222
};
@@ -25,7 +25,7 @@ public:
2525

2626
extern "C" {
2727

28-
int parseHeaders(int file, ParserDelegate *delegate);
28+
int parseHeaders(int file, HTTPParserDelegate *delegate);
2929

3030
%%{
3131
machine http_simple;
@@ -75,7 +75,7 @@ int parseHeaders(int file, ParserDelegate *delegate);
7575

7676
%% write data;
7777

78-
int parseHeaders(int file, ParserDelegate *delegate)
78+
int parseHeaders(int file, HTTPParserDelegate *delegate)
7979
{
8080
// machine state
8181
int cs, act, done = 0;
@@ -86,7 +86,7 @@ int parseHeaders(int file, ParserDelegate *delegate)
8686

8787
%% write init;
8888

89-
#define READ_CHUNK_SIZE 2
89+
#define READ_CHUNK_SIZE 128
9090
int bufferSize = READ_CHUNK_SIZE;
9191
char *buffer = (char *)calloc(bufferSize + 1, 1);
9292
char *p = buffer;
@@ -125,7 +125,7 @@ int parseHeaders(int file, ParserDelegate *delegate)
125125

126126
#ifdef DEBUG_HTTP
127127

128-
class SomeDelegate : public ParserDelegate
128+
class SomeDelegate : public HTTPParserDelegate
129129
{
130130
void gotHeader(const char *name, const char *value)
131131
{

0 commit comments

Comments
 (0)