Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/api/EscargotPublic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ class DebuggerC : public Debugger {
public:
virtual void init(const char* options, Context* context) override {}
virtual void parseCompleted(String* source, String* srcName, size_t originLineOffset, String* error = nullptr) override;
virtual void stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) override;
virtual bool stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) override;
virtual void byteCodeReleaseNotification(ByteCodeBlock* byteCodeBlock) override;
virtual void exceptionCaught(String* message, SavedStackTraceDataVector& exceptionTrace) override;
virtual void consoleOut(String* output) override;
Expand Down Expand Up @@ -2057,7 +2057,7 @@ static LexicalEnvironment* getFunctionLexEnv(ExecutionState* state)
return nullptr;
}

void DebuggerC::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
bool DebuggerC::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
{
DebuggerOperationsRef::BreakpointOperations operations(reinterpret_cast<DebuggerOperationsRef::WeakCodeRef*>(byteCodeBlock), toRef(state), offset);

Expand Down Expand Up @@ -2092,6 +2092,7 @@ void DebuggerC::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset,
break;
}
}
return false;
}

void DebuggerC::byteCodeReleaseNotification(ByteCodeBlock* byteCodeBlock)
Expand Down Expand Up @@ -3442,6 +3443,24 @@ bool ContextRef::isWaitBeforeExit()
#endif /* ESCARGOT_DEBUGGER */
}

bool ContextRef::isDebuggerRestartTrue()
{
#ifdef ESCARGOT_DEBUGGER
return isDebuggerRunning() && toImpl(this)->debugger()->getRestart();
#else /* !ESCARGOT_DEBUGGER */
return false;
#endif /* ESCARGOT_DEBUGGER */
}

void ContextRef::setDebuggerRestart()
{
#ifdef ESCARGOT_DEBUGGER
if (isDebuggerRunning()) {
toImpl(this)->debugger()->setRestart(false);
}
#endif /* ESCARGOT_DEBUGGER */
}

void ContextRef::printDebugger(StringRef* output)
{
#ifdef ESCARGOT_DEBUGGER
Expand Down
2 changes: 2 additions & 0 deletions src/api/EscargotPublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,11 @@ class ESCARGOT_EXPORT ContextRef {
bool initDebugger(const char* options);
bool isDebuggerRunning();
bool isWaitBeforeExit();
bool isDebuggerRestartTrue();
void printDebugger(StringRef* output);
void pumpDebuggerEvents();
void setAsAlwaysStopState();
void setDebuggerRestart();
StringRef* getClientSource(StringRef** sourceName);

typedef OptionalRef<ValueRef> (*VirtualIdentifierCallback)(ExecutionStateRef* state, ValueRef* name);
Expand Down
17 changes: 15 additions & 2 deletions src/debugger/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Debugger : public gc {
return m_activeSavedStackTrace;
}

inline void processDisabledBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
inline bool processDisabledBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
{
if (m_stopState != ESCARGOT_DEBUGGER_ALWAYS_STOP && m_stopState != state) {
m_delay--;
Expand All @@ -154,6 +154,8 @@ class Debugger : public gc {
if (m_stopState == ESCARGOT_DEBUGGER_ALWAYS_STOP || m_stopState == state) {
stopAtBreakpoint(byteCodeBlock, offset, state);
}

return m_restartDebugging;
}

static inline void updateStopState(Debugger* debugger, ExecutionState* state, ExecutionState* newState)
Expand Down Expand Up @@ -189,7 +191,7 @@ class Debugger : public gc {

virtual void init(const char* options, Context* context) = 0;
virtual void parseCompleted(String* source, String* srcName, size_t originLineOffset, String* error = nullptr) = 0;
virtual void stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) = 0;
virtual bool stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) = 0;
virtual void byteCodeReleaseNotification(ByteCodeBlock* byteCodeBlock) = 0;
virtual void exceptionCaught(String* message, SavedStackTraceDataVector& exceptionTrace) = 0;
virtual void consoleOut(String* output) = 0;
Expand All @@ -210,6 +212,16 @@ class Debugger : public gc {

Vector<Object*, GCUtil::gc_malloc_allocator<Object*>> m_activeObjects;

bool getRestart()
{
return m_restartDebugging;
}

void setRestart(bool b)
{
m_restartDebugging = b;
}

protected:
Debugger()
: m_delay(ESCARGOT_DEBUGGER_MESSAGE_PROCESS_DELAY)
Expand All @@ -234,6 +246,7 @@ class Debugger : public gc {
ExecutionState* m_stopState;
std::vector<BreakpointLocationsInfo*> m_breakpointLocationsVector;
Vector<uintptr_t, GCUtil::gc_malloc_atomic_allocator<uintptr_t>> m_releasedFunctions;
bool m_restartDebugging;

private:
Context* m_context;
Expand Down
8 changes: 5 additions & 3 deletions src/debugger/DebuggerDevtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ void DebuggerDevtools::sendPausedEvent(ByteCodeBlock* byteCodeBlock, const uint3
sendMessage(msg, msg.length());
}

void DebuggerDevtools::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
bool DebuggerDevtools::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
{
if (m_stopState == ESCARGOT_DEBUGGER_IN_EVAL_MODE) {
m_delay--;
if (m_delay == 0) {
processEvents(state, byteCodeBlock);
}
return;
return false;
}

sendPausedEvent(byteCodeBlock, offset, state, !m_startBreakpoint);
Expand All @@ -275,7 +275,7 @@ void DebuggerDevtools::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t o
}

if (!enabled()) {
return;
return false;
}

ASSERT(m_activeObjects.empty());
Expand All @@ -286,6 +286,8 @@ void DebuggerDevtools::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t o

m_activeObjects.clear();
m_delay = ESCARGOT_DEBUGGER_MESSAGE_PROCESS_DELAY;

return false;
}

void DebuggerDevtools::byteCodeReleaseNotification(ByteCodeBlock* byteCodeBlock)
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/DebuggerDevtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DebuggerDevtools : public DebuggerTcp {
bool skipSourceCode(String* srcName) const override;

void parseCompleted(String* source, String* srcName, size_t originLineOffset, String* error = nullptr) override;
void stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) override;
bool stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) override;
void byteCodeReleaseNotification(ByteCodeBlock* byteCodeBlock) override;
void exceptionCaught(String* message, SavedStackTraceDataVector& exceptionTrace) override;
void consoleOut(String* output) override;
Expand Down
12 changes: 9 additions & 3 deletions src/debugger/DebuggerEscargot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ void DebuggerEscargot::sendVariableObjectInfo(uint8_t subType, Object* object)
send(ESCARGOT_MESSAGE_VARIABLE, &variableObjectInfo, sizeof(VariableObjectInfo));
}

void DebuggerEscargot::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
bool DebuggerEscargot::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state)
{
if (m_stopState == ESCARGOT_DEBUGGER_IN_EVAL_MODE) {
m_delay--;
if (m_delay == 0) {
processEvents(state, byteCodeBlock);
}
return;
return m_restartDebugging;
}

BreakpointOffset breakpointOffset;
Expand All @@ -238,7 +238,7 @@ void DebuggerEscargot::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t o
send(ESCARGOT_MESSAGE_BREAKPOINT_HIT, &breakpointOffset, sizeof(BreakpointOffset));

if (!enabled()) {
return;
return m_restartDebugging;
}

ASSERT(m_activeObjects.size() == 0);
Expand All @@ -249,6 +249,8 @@ void DebuggerEscargot::stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t o

m_activeObjects.clear();
m_delay = ESCARGOT_DEBUGGER_MESSAGE_PROCESS_DELAY;

return m_restartDebugging;
}

void DebuggerEscargot::byteCodeReleaseNotification(ByteCodeBlock* byteCodeBlock)
Expand Down Expand Up @@ -899,6 +901,10 @@ bool DebuggerEscargot::processEvents(ExecutionState* state, Optional<ByteCodeBlo
m_stopState = stopState;
return false;
}
case ESCARGOT_MESSAGE_RESTART: {
setRestart(true);
return true;
}
case ESCARGOT_MESSAGE_WATCH_8BIT_START:
case ESCARGOT_MESSAGE_WATCH_16BIT_START:
case ESCARGOT_MESSAGE_EVAL_8BIT_START:
Expand Down
55 changes: 28 additions & 27 deletions src/debugger/DebuggerEscargot.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,36 +109,37 @@ class DebuggerEscargot : public DebuggerTcp {
ESCARGOT_MESSAGE_STEP = 3,
ESCARGOT_MESSAGE_NEXT = 4,
ESCARGOT_MESSAGE_FINISH = 5,
ESCARGOT_MESSAGE_RESTART = 6,
// These four must be in the same order.
ESCARGOT_MESSAGE_EVAL_8BIT_START = 6,
ESCARGOT_MESSAGE_EVAL_8BIT = 7,
ESCARGOT_MESSAGE_EVAL_16BIT_START = 8,
ESCARGOT_MESSAGE_EVAL_16BIT = 9,
ESCARGOT_MESSAGE_EVAL_8BIT_START = 7,
Comment thread
ksh8281 marked this conversation as resolved.
ESCARGOT_MESSAGE_EVAL_8BIT = 8,
ESCARGOT_MESSAGE_EVAL_16BIT_START = 9,
ESCARGOT_MESSAGE_EVAL_16BIT = 10,
// These four must be in the same order.
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_8BIT_START = 10,
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_8BIT = 11,
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_16BIT_START = 12,
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_16BIT = 13,
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_8BIT_START = 11,
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_8BIT = 12,
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_16BIT_START = 13,
ESCARGOT_MESSAGE_EVAL_WITHOUT_STOP_16BIT = 14,
// These four must be in the same order.
ESCARGOT_MESSAGE_WATCH_8BIT_START = 14,
ESCARGOT_MESSAGE_WATCH_8BIT = 15,
ESCARGOT_MESSAGE_WATCH_16BIT_START = 16,
ESCARGOT_MESSAGE_WATCH_16BIT = 17,
ESCARGOT_MESSAGE_GET_BACKTRACE = 18,
ESCARGOT_MESSAGE_GET_SCOPE_CHAIN = 19,
ESCARGOT_MESSAGE_GET_SCOPE_VARIABLES = 20,
ESCARGOT_MESSAGE_GET_OBJECT = 21,
ESCARGOT_MESSAGE_WATCH_8BIT_START = 15,
ESCARGOT_MESSAGE_WATCH_8BIT = 16,
ESCARGOT_MESSAGE_WATCH_16BIT_START = 17,
ESCARGOT_MESSAGE_WATCH_16BIT = 18,
ESCARGOT_MESSAGE_GET_BACKTRACE = 19,
ESCARGOT_MESSAGE_GET_SCOPE_CHAIN = 20,
ESCARGOT_MESSAGE_GET_SCOPE_VARIABLES = 21,
ESCARGOT_MESSAGE_GET_OBJECT = 22,
// These four must be in the same order.
ESCARGOT_DEBUGGER_CLIENT_SOURCE_8BIT_START = 22,
ESCARGOT_DEBUGGER_CLIENT_SOURCE_8BIT = 23,
ESCARGOT_DEBUGGER_CLIENT_SOURCE_16BIT_START = 24,
ESCARGOT_DEBUGGER_CLIENT_SOURCE_16BIT = 25,
ESCARGOT_DEBUGGER_THERE_WAS_NO_SOURCE = 26,
ESCARGOT_DEBUGGER_PENDING_CONFIG = 27,
ESCARGOT_DEBUGGER_PENDING_RESUME = 28,
ESCARGOT_DEBUGGER_WAIT_BEFORE_EXIT = 29,
ESCARGOT_DEBUGGER_TAKE_HEAP_SNAPSHOT = 30,
ESCARGOT_DEBUGGER_STOP = 31
ESCARGOT_DEBUGGER_CLIENT_SOURCE_8BIT_START = 23,
ESCARGOT_DEBUGGER_CLIENT_SOURCE_8BIT = 24,
ESCARGOT_DEBUGGER_CLIENT_SOURCE_16BIT_START = 25,
ESCARGOT_DEBUGGER_CLIENT_SOURCE_16BIT = 26,
ESCARGOT_DEBUGGER_THERE_WAS_NO_SOURCE = 27,
ESCARGOT_DEBUGGER_PENDING_CONFIG = 28,
ESCARGOT_DEBUGGER_PENDING_RESUME = 29,
ESCARGOT_DEBUGGER_WAIT_BEFORE_EXIT = 30,
ESCARGOT_DEBUGGER_TAKE_HEAP_SNAPSHOT = 31,
ESCARGOT_DEBUGGER_STOP = 32
};


Expand Down Expand Up @@ -190,7 +191,7 @@ class DebuggerEscargot : public DebuggerTcp {

void init(const char* options, Context* context) override;
void parseCompleted(String* source, String* srcName, size_t originLineOffset, String* error = nullptr) override;
void stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) override;
bool stopAtBreakpoint(ByteCodeBlock* byteCodeBlock, uint32_t offset, ExecutionState* state) override;
void byteCodeReleaseNotification(ByteCodeBlock* byteCodeBlock) override;
void exceptionCaught(String* message, SavedStackTraceDataVector& exceptionTrace) override;
void consoleOut(String* output) override;
Expand Down
18 changes: 16 additions & 2 deletions src/interpreter/ByteCodeInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,14 @@ Value Interpreter::interpret(ExecutionState* state, ByteCodeBlock* byteCodeBlock
// Return F.[[Call]](V, argumentsList).
registerFile[code->m_resultIndex] = callee.asPointerValue()->call(*state, Value(), code->m_argumentCount, &registerFile[code->m_argumentsStartIndex]);

#ifdef ESCARGOT_DEBUGGER
if (state->context()->debuggerEnabled()) {
if (state->context()->debugger()->getRestart()) {
return Value(true);
}
}
#endif /* ESCARGOT_DEBUGGER */

ADD_PROGRAM_COUNTER(Call);
NEXT_INSTRUCTION();
}
Expand Down Expand Up @@ -1715,7 +1723,10 @@ Value Interpreter::interpret(ExecutionState* state, ByteCodeBlock* byteCodeBlock
:
{
if (state->context()->debuggerEnabled()) {
state->context()->debugger()->processDisabledBreakpoint(byteCodeBlock, (uint32_t)(programCounter - (size_t)byteCodeBlock->m_code.data()), state);
bool restart = state->context()->debugger()->processDisabledBreakpoint(byteCodeBlock, (uint32_t)(programCounter - (size_t)byteCodeBlock->m_code.data()), state);
if (restart) {
return Value(true);
}
}

ADD_PROGRAM_COUNTER(BreakpointDisabled);
Expand All @@ -1726,7 +1737,10 @@ Value Interpreter::interpret(ExecutionState* state, ByteCodeBlock* byteCodeBlock
:
{
if (state->context()->debuggerEnabled()) {
state->context()->debugger()->stopAtBreakpoint(byteCodeBlock, (uint32_t)(programCounter - (size_t)byteCodeBlock->m_code.data()), state);
bool restart = state->context()->debugger()->stopAtBreakpoint(byteCodeBlock, (uint32_t)(programCounter - (size_t)byteCodeBlock->m_code.data()), state);
if (restart) {
return Value(true);
}
}

ADD_PROGRAM_COUNTER(BreakpointEnabled);
Expand Down
Loading
Loading