Revert "Simplify debugger state."

This reverts r21346, it broke the layout tests.

R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/292713002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21351 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 327c016a
...@@ -2120,18 +2120,20 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) { ...@@ -2120,18 +2120,20 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
// Expose the debug global object in global if a name for it is specified. // Expose the debug global object in global if a name for it is specified.
if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) {
Debug* debug = isolate->debug();
// If loading fails we just bail out without installing the // If loading fails we just bail out without installing the
// debugger but without tanking the whole context. // debugger but without tanking the whole context.
Debug* debug = isolate->debug();
if (!debug->Load()) return true; if (!debug->Load()) return true;
Handle<Context> debug_context = debug->debug_context();
// Set the security token for the debugger context to the same as // Set the security token for the debugger context to the same as
// the shell native context to allow calling between these (otherwise // the shell native context to allow calling between these (otherwise
// exposing debug global object doesn't make much sense). // exposing debug global object doesn't make much sense).
debug_context->set_security_token(native_context->security_token()); debug->debug_context()->set_security_token(
native_context->security_token());
Handle<String> debug_string = Handle<String> debug_string =
factory->InternalizeUtf8String(FLAG_expose_debug_as); factory->InternalizeUtf8String(FLAG_expose_debug_as);
Handle<Object> global_proxy(debug_context->global_proxy(), isolate); Handle<Object> global_proxy(
debug->debug_context()->global_proxy(), isolate);
RETURN_ON_EXCEPTION_VALUE( RETURN_ON_EXCEPTION_VALUE(
isolate, isolate,
JSObject::SetLocalPropertyIgnoreAttributes( JSObject::SetLocalPropertyIgnoreAttributes(
......
...@@ -753,12 +753,11 @@ void Shell::InstallUtilityScript(Isolate* isolate) { ...@@ -753,12 +753,11 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
// Install the debugger object in the utility scope // Install the debugger object in the utility scope
i::Debug* debug = reinterpret_cast<i::Isolate*>(isolate)->debug(); i::Debug* debug = reinterpret_cast<i::Isolate*>(isolate)->debug();
debug->Load(); debug->Load();
i::Handle<i::Context> debug_context = debug->debug_context();
i::Handle<i::JSObject> js_debug i::Handle<i::JSObject> js_debug
= i::Handle<i::JSObject>(debug_context->global_object()); = i::Handle<i::JSObject>(debug->debug_context()->global_object());
utility_context->Global()->Set(String::NewFromUtf8(isolate, "$debug"), utility_context->Global()->Set(String::NewFromUtf8(isolate, "$debug"),
Utils::ToLocal(js_debug)); Utils::ToLocal(js_debug));
debug_context->set_security_token( debug->debug_context()->set_security_token(
reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value()); reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value());
// Run the d8 shell utility script in the utility context // Run the d8 shell utility script in the utility context
......
This diff is collapsed.
...@@ -490,6 +490,7 @@ class Debug { ...@@ -490,6 +490,7 @@ class Debug {
private: private:
explicit Debug(Isolate* isolate); explicit Debug(Isolate* isolate);
~Debug();
static bool CompileDebuggerScript(Isolate* isolate, int index); static bool CompileDebuggerScript(Isolate* isolate, int index);
void ClearOneShot(); void ClearOneShot();
...@@ -742,6 +743,25 @@ class LockingCommandMessageQueue BASE_EMBEDDED { ...@@ -742,6 +743,25 @@ class LockingCommandMessageQueue BASE_EMBEDDED {
class Debugger { class Debugger {
public: public:
~Debugger();
void DebugRequest(const uint16_t* json_request, int length);
MUST_USE_RESULT MaybeHandle<Object> MakeJSObject(
Vector<const char> constructor_name,
int argc,
Handle<Object> argv[]);
MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState();
MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent(
Handle<Object> break_points_hit);
MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent(
Handle<Object> exception,
bool uncaught,
Handle<Object> promise);
MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent(
Handle<Script> script, bool before);
MUST_USE_RESULT MaybeHandle<Object> MakeScriptCollectedEvent(int id);
void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue);
void OnException(Handle<Object> exception, bool uncaught); void OnException(Handle<Object> exception, bool uncaught);
void OnBeforeCompile(Handle<Script> script); void OnBeforeCompile(Handle<Script> script);
...@@ -753,7 +773,13 @@ class Debugger { ...@@ -753,7 +773,13 @@ class Debugger {
void OnAfterCompile(Handle<Script> script, void OnAfterCompile(Handle<Script> script,
AfterCompileFlags after_compile_flags); AfterCompileFlags after_compile_flags);
void OnScriptCollected(int id); void OnScriptCollected(int id);
void ProcessDebugEvent(v8::DebugEvent event,
Handle<JSObject> event_data,
bool auto_continue);
void NotifyMessageHandler(v8::DebugEvent event,
Handle<JSObject> exec_state,
Handle<JSObject> event_data,
bool auto_continue);
void SetEventListener(Handle<Object> callback, Handle<Object> data); void SetEventListener(Handle<Object> callback, Handle<Object> data);
void SetMessageHandler(v8::Debug::MessageHandler handler); void SetMessageHandler(v8::Debug::MessageHandler handler);
...@@ -772,13 +798,36 @@ class Debugger { ...@@ -772,13 +798,36 @@ class Debugger {
Handle<Context> GetDebugContext(); Handle<Context> GetDebugContext();
// Unload the debugger if possible. Only called when no debugger is currently
// active.
void UnloadDebugger();
friend void ForceUnloadDebugger(); // In test-debug.cc
inline bool EventActive() {
LockGuard<RecursiveMutex> lock_guard(&debugger_access_);
// Check whether the message handler was been cleared.
// TODO(yangguo): handle loading and unloading of the debugger differently.
if (debugger_unload_pending_) {
if (isolate_->debug()->debugger_entry() == NULL) {
UnloadDebugger();
}
}
// Currently argument event is not used.
return !ignore_debugger_ && is_active_;
}
bool ignore_debugger() const { return ignore_debugger_; } bool ignore_debugger() const { return ignore_debugger_; }
void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; } void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; }
bool live_edit_enabled() const { bool live_edit_enabled() const {
return FLAG_enable_liveedit && live_edit_enabled_ ; return FLAG_enable_liveedit && live_edit_enabled_ ;
} }
bool is_active() { return is_active_; } bool is_active() {
LockGuard<RecursiveMutex> lock_guard(&debugger_access_);
return is_active_;
}
class IgnoreScope { class IgnoreScope {
public: public:
...@@ -800,22 +849,6 @@ class Debugger { ...@@ -800,22 +849,6 @@ class Debugger {
private: private:
explicit Debugger(Isolate* isolate); explicit Debugger(Isolate* isolate);
~Debugger();
MUST_USE_RESULT MaybeHandle<Object> MakeJSObject(
Vector<const char> constructor_name,
int argc,
Handle<Object> argv[]);
MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState();
MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent(
Handle<Object> break_points_hit);
MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent(
Handle<Object> exception,
bool uncaught,
Handle<Object> promise);
MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent(
Handle<Script> script, bool before);
MUST_USE_RESULT MaybeHandle<Object> MakeScriptCollectedEvent(int id);
void CallEventCallback(v8::DebugEvent event, void CallEventCallback(v8::DebugEvent event,
Handle<Object> exec_state, Handle<Object> exec_state,
...@@ -828,31 +861,18 @@ class Debugger { ...@@ -828,31 +861,18 @@ class Debugger {
void CallJSEventCallback(v8::DebugEvent event, void CallJSEventCallback(v8::DebugEvent event,
Handle<Object> exec_state, Handle<Object> exec_state,
Handle<Object> event_data); Handle<Object> event_data);
void UpdateState(); void ListenersChanged();
void ProcessDebugEvent(v8::DebugEvent event,
Handle<JSObject> event_data,
bool auto_continue);
void NotifyMessageHandler(v8::DebugEvent event,
Handle<JSObject> exec_state,
Handle<JSObject> event_data,
bool auto_continue);
// Invoke the message handler function. // Invoke the message handler function.
void InvokeMessageHandler(MessageImpl message); void InvokeMessageHandler(MessageImpl message);
inline bool EventActive() { RecursiveMutex debugger_access_; // Mutex guarding debugger variables.
// Check whether the message handler was been cleared.
// TODO(yangguo): handle loading and unloading of the debugger differently.
// Currently argument event is not used.
return !ignore_debugger_ && is_active_;
}
Handle<Object> event_listener_; // Global handle to listener. Handle<Object> event_listener_; // Global handle to listener.
Handle<Object> event_listener_data_; Handle<Object> event_listener_data_;
bool is_active_; bool is_active_;
bool ignore_debugger_; // Are we temporarily ignoring the debugger? bool ignore_debugger_; // Are we temporarily ignoring the debugger?
bool live_edit_enabled_; // Enable LiveEdit. bool live_edit_enabled_; // Enable LiveEdit.
bool never_unload_debugger_; // Can we unload the debugger?
v8::Debug::MessageHandler message_handler_; v8::Debug::MessageHandler message_handler_;
bool debugger_unload_pending_; // Was message handler cleared? bool debugger_unload_pending_; // Was message handler cleared?
...@@ -891,7 +911,8 @@ class EnterDebugger BASE_EMBEDDED { ...@@ -891,7 +911,8 @@ class EnterDebugger BASE_EMBEDDED {
private: private:
Isolate* isolate_; Isolate* isolate_;
EnterDebugger* prev_; // Previous debugger entry if entered recursively. EnterDebugger* prev_; // Previous debugger entry if entered recursively.
bool has_js_frames_; // Were there any JavaScript frames? JavaScriptFrameIterator it_;
const bool has_js_frames_; // Were there any JavaScript frames?
StackFrame::Id break_frame_id_; // Previous break frame id. StackFrame::Id break_frame_id_; // Previous break frame id.
int break_id_; // Previous break id. int break_id_; // Previous break id.
bool load_failed_; // Did the debugger fail to load? bool load_failed_; // Did the debugger fail to load?
......
...@@ -714,6 +714,9 @@ void Execution::DebugBreakHelper(Isolate* isolate) { ...@@ -714,6 +714,9 @@ void Execution::DebugBreakHelper(Isolate* isolate) {
void Execution::ProcessDebugMessages(Isolate* isolate, void Execution::ProcessDebugMessages(Isolate* isolate,
bool debug_command_only) { bool debug_command_only) {
// Assert that we are on the main thread of the isolate.
ASSERT(ThreadId::Current().Equals(isolate->thread_id()));
isolate->stack_guard()->ClearDebugCommand(); isolate->stack_guard()->ClearDebugCommand();
StackLimitCheck check(isolate); StackLimitCheck check(isolate);
......
...@@ -1546,6 +1546,8 @@ void Isolate::Deinit() { ...@@ -1546,6 +1546,8 @@ void Isolate::Deinit() {
if (state_ == INITIALIZED) { if (state_ == INITIALIZED) {
TRACE_ISOLATE(deinit); TRACE_ISOLATE(deinit);
debugger()->UnloadDebugger();
if (concurrent_recompilation_enabled()) { if (concurrent_recompilation_enabled()) {
optimizing_compiler_thread_->Stop(); optimizing_compiler_thread_->Stop();
delete optimizing_compiler_thread_; delete optimizing_compiler_thread_;
......
...@@ -11044,9 +11044,8 @@ RUNTIME_FUNCTION(Runtime_DebugIndexedInterceptorElementValue) { ...@@ -11044,9 +11044,8 @@ RUNTIME_FUNCTION(Runtime_DebugIndexedInterceptorElementValue) {
static bool CheckExecutionState(Isolate* isolate, int break_id) { static bool CheckExecutionState(Isolate* isolate, int break_id) {
return !isolate->debug()->debug_context().is_null() && return (isolate->debug()->break_id() != 0 &&
isolate->debug()->break_id() != 0 && break_id == isolate->debug()->break_id());
isolate->debug()->break_id() == break_id;
} }
......
...@@ -98,11 +98,10 @@ class DebugLocalContext { ...@@ -98,11 +98,10 @@ class DebugLocalContext {
v8::internal::Isolate* isolate = v8::internal::Isolate* isolate =
reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate()); reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate());
v8::internal::Factory* factory = isolate->factory(); v8::internal::Factory* factory = isolate->factory();
v8::internal::Debug* debug = isolate->debug();
// Expose the debug context global object in the global object for testing. // Expose the debug context global object in the global object for testing.
CHECK(isolate->debug()->Load()); debug->Load();
Handle<v8::internal::Context> debug_context = debug->debug_context()->set_security_token(
isolate->debug()->debug_context();
debug_context->set_security_token(
v8::Utils::OpenHandle(*context_)->security_token()); v8::Utils::OpenHandle(*context_)->security_token());
Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast( Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast(
...@@ -110,7 +109,7 @@ class DebugLocalContext { ...@@ -110,7 +109,7 @@ class DebugLocalContext {
Handle<v8::internal::String> debug_string = Handle<v8::internal::String> debug_string =
factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug")); factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug"));
v8::internal::Runtime::SetObjectProperty(isolate, global, debug_string, v8::internal::Runtime::SetObjectProperty(isolate, global, debug_string,
Handle<Object>(debug_context->global_proxy(), isolate), Handle<Object>(debug->debug_context()->global_proxy(), isolate),
DONT_ENUM, DONT_ENUM,
::v8::internal::SLOPPY).Check(); ::v8::internal::SLOPPY).Check();
} }
...@@ -422,6 +421,12 @@ void CheckDebuggerUnloaded(bool check_functions) { ...@@ -422,6 +421,12 @@ void CheckDebuggerUnloaded(bool check_functions) {
} }
void ForceUnloadDebugger() {
CcTest::i_isolate()->debugger()->never_unload_debugger_ = false;
CcTest::i_isolate()->debugger()->UnloadDebugger();
}
} } // namespace v8::internal } } // namespace v8::internal
...@@ -5495,12 +5500,13 @@ static void CheckDataParameter( ...@@ -5495,12 +5500,13 @@ static void CheckDataParameter(
v8::String::NewFromUtf8(args.GetIsolate(), "Test"); v8::String::NewFromUtf8(args.GetIsolate(), "Test");
CHECK(v8::Debug::Call(debugger_call_with_data, data)->IsString()); CHECK(v8::Debug::Call(debugger_call_with_data, data)->IsString());
for (int i = 0; i < 3; i++) { CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
v8::TryCatch catcher; CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
CHECK(catcher.HasCaught()); v8::TryCatch catcher;
CHECK(catcher.Exception()->IsString()); v8::Debug::Call(debugger_call_with_data);
} CHECK(catcher.HasCaught());
CHECK(catcher.Exception()->IsString());
} }
...@@ -6866,11 +6872,9 @@ TEST(CallingContextIsNotDebugContext) { ...@@ -6866,11 +6872,9 @@ TEST(CallingContextIsNotDebugContext) {
TEST(DebugContextIsPreservedBetweenAccesses) { TEST(DebugContextIsPreservedBetweenAccesses) {
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext();
v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext();
CHECK_EQ(*context1, *context2); CHECK_EQ(*context1, *context2);
v8::Debug::SetDebugEventListener(NULL);
} }
......
...@@ -1888,7 +1888,7 @@ TEST(NoDebugObjectInSnapshot) { ...@@ -1888,7 +1888,7 @@ TEST(NoDebugObjectInSnapshot) {
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CHECK(CcTest::i_isolate()->debug()->Load()); CcTest::i_isolate()->debug()->Load();
CompileRun("foo = {};"); CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
......
...@@ -37,13 +37,12 @@ function TestCase(fun, frame_number) { ...@@ -37,13 +37,12 @@ function TestCase(fun, frame_number) {
var exception = false; var exception = false;
var codeSnippet = undefined; var codeSnippet = undefined;
var resultPositions = undefined; var resultPositions = undefined;
var step = 0;
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
try { try {
if (event == Debug.DebugEvent.Break || if (event == Debug.DebugEvent.Break ||
event == Debug.DebugEvent.Exception) { event == Debug.DebugEvent.Exception) {
if (step++ > 0) return; Debug.setListener(null);
assertHasLineMark(/pause/, exec_state.frame(0)); assertHasLineMark(/pause/, exec_state.frame(0));
assertHasLineMark(/positions/, exec_state.frame(frame_number)); assertHasLineMark(/positions/, exec_state.frame(frame_number));
var frame = exec_state.frame(frame_number); var frame = exec_state.frame(frame_number);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment