Commit cf49b6e3 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Reland "Simplify debugger state."

R=ulan@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21378 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c8ad96d7
......@@ -2169,20 +2169,18 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
// 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) {
Debug* debug = isolate->debug();
// If loading fails we just bail out without installing the
// debugger but without tanking the whole context.
Debug* debug = isolate->debug();
if (!debug->Load()) return true;
Handle<Context> debug_context = debug->debug_context();
// Set the security token for the debugger context to the same as
// the shell native context to allow calling between these (otherwise
// exposing debug global object doesn't make much sense).
debug->debug_context()->set_security_token(
native_context->security_token());
debug_context->set_security_token(native_context->security_token());
Handle<String> debug_string =
factory->InternalizeUtf8String(FLAG_expose_debug_as);
Handle<Object> global_proxy(
debug->debug_context()->global_proxy(), isolate);
Handle<Object> global_proxy(debug_context->global_proxy(), isolate);
RETURN_ON_EXCEPTION_VALUE(
isolate,
JSObject::SetLocalPropertyIgnoreAttributes(
......
......@@ -753,11 +753,12 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
// Install the debugger object in the utility scope
i::Debug* debug = reinterpret_cast<i::Isolate*>(isolate)->debug();
debug->Load();
i::Handle<i::Context> debug_context = debug->debug_context();
i::Handle<i::JSObject> js_debug
= i::Handle<i::JSObject>(debug->debug_context()->global_object());
= i::Handle<i::JSObject>(debug_context->global_object());
utility_context->Global()->Set(String::NewFromUtf8(isolate, "$debug"),
Utils::ToLocal(js_debug));
debug->debug_context()->set_security_token(
debug_context->set_security_token(
reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value());
// Run the d8 shell utility script in the utility context
......
This diff is collapsed.
......@@ -490,7 +490,6 @@ class Debug {
private:
explicit Debug(Isolate* isolate);
~Debug();
static bool CompileDebuggerScript(Isolate* isolate, int index);
void ClearOneShot();
......@@ -743,25 +742,6 @@ class LockingCommandMessageQueue BASE_EMBEDDED {
class Debugger {
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 OnException(Handle<Object> exception, bool uncaught);
void OnBeforeCompile(Handle<Script> script);
......@@ -773,13 +753,7 @@ class Debugger {
void OnAfterCompile(Handle<Script> script,
AfterCompileFlags after_compile_flags);
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 SetMessageHandler(v8::Debug::MessageHandler handler);
......@@ -798,36 +772,13 @@ class Debugger {
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_; }
void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; }
bool live_edit_enabled() const {
return FLAG_enable_liveedit && live_edit_enabled_ ;
}
bool is_active() {
LockGuard<RecursiveMutex> lock_guard(&debugger_access_);
return is_active_;
}
bool is_active() { return is_active_; }
class IgnoreScope {
public:
......@@ -849,6 +800,22 @@ class Debugger {
private:
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,
Handle<Object> exec_state,
......@@ -861,18 +828,31 @@ class Debugger {
void CallJSEventCallback(v8::DebugEvent event,
Handle<Object> exec_state,
Handle<Object> event_data);
void ListenersChanged();
void UpdateState();
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.
void InvokeMessageHandler(MessageImpl message);
RecursiveMutex debugger_access_; // Mutex guarding debugger variables.
inline bool EventActive() {
// 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_data_;
bool is_active_;
bool ignore_debugger_; // Are we temporarily ignoring the debugger?
bool live_edit_enabled_; // Enable LiveEdit.
bool never_unload_debugger_; // Can we unload the debugger?
v8::Debug::MessageHandler message_handler_;
bool debugger_unload_pending_; // Was message handler cleared?
......@@ -911,8 +891,7 @@ class EnterDebugger BASE_EMBEDDED {
private:
Isolate* isolate_;
EnterDebugger* prev_; // Previous debugger entry if entered recursively.
JavaScriptFrameIterator it_;
const bool has_js_frames_; // Were there any JavaScript frames?
bool has_js_frames_; // Were there any JavaScript frames?
StackFrame::Id break_frame_id_; // Previous break frame id.
int break_id_; // Previous break id.
bool load_failed_; // Did the debugger fail to load?
......
......@@ -692,9 +692,6 @@ void Execution::DebugBreakHelper(Isolate* isolate) {
void Execution::ProcessDebugMessages(Isolate* isolate,
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();
StackLimitCheck check(isolate);
......
......@@ -1558,8 +1558,6 @@ void Isolate::Deinit() {
if (state_ == INITIALIZED) {
TRACE_ISOLATE(deinit);
debugger()->UnloadDebugger();
if (concurrent_recompilation_enabled()) {
optimizing_compiler_thread_->Stop();
delete optimizing_compiler_thread_;
......
......@@ -11044,8 +11044,9 @@ RUNTIME_FUNCTION(Runtime_DebugIndexedInterceptorElementValue) {
static bool CheckExecutionState(Isolate* isolate, int break_id) {
return (isolate->debug()->break_id() != 0 &&
break_id == isolate->debug()->break_id());
return !isolate->debug()->debug_context().is_null() &&
isolate->debug()->break_id() != 0 &&
isolate->debug()->break_id() == break_id;
}
......
......@@ -98,10 +98,11 @@ class DebugLocalContext {
v8::internal::Isolate* isolate =
reinterpret_cast<v8::internal::Isolate*>(context_->GetIsolate());
v8::internal::Factory* factory = isolate->factory();
v8::internal::Debug* debug = isolate->debug();
// Expose the debug context global object in the global object for testing.
debug->Load();
debug->debug_context()->set_security_token(
CHECK(isolate->debug()->Load());
Handle<v8::internal::Context> debug_context =
isolate->debug()->debug_context();
debug_context->set_security_token(
v8::Utils::OpenHandle(*context_)->security_token());
Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast(
......@@ -109,7 +110,7 @@ class DebugLocalContext {
Handle<v8::internal::String> debug_string =
factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug"));
v8::internal::Runtime::SetObjectProperty(isolate, global, debug_string,
Handle<Object>(debug->debug_context()->global_proxy(), isolate),
Handle<Object>(debug_context->global_proxy(), isolate),
DONT_ENUM,
::v8::internal::SLOPPY).Check();
}
......@@ -421,12 +422,6 @@ void CheckDebuggerUnloaded(bool check_functions) {
}
void ForceUnloadDebugger() {
CcTest::i_isolate()->debugger()->never_unload_debugger_ = false;
CcTest::i_isolate()->debugger()->UnloadDebugger();
}
} } // namespace v8::internal
......@@ -5500,13 +5495,12 @@ static void CheckDataParameter(
v8::String::NewFromUtf8(args.GetIsolate(), "Test");
CHECK(v8::Debug::Call(debugger_call_with_data, data)->IsString());
CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
v8::TryCatch catcher;
v8::Debug::Call(debugger_call_with_data);
CHECK(catcher.HasCaught());
CHECK(catcher.Exception()->IsString());
for (int i = 0; i < 3; i++) {
v8::TryCatch catcher;
CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty());
CHECK(catcher.HasCaught());
CHECK(catcher.Exception()->IsString());
}
}
......@@ -6872,9 +6866,12 @@ TEST(CallingContextIsNotDebugContext) {
TEST(DebugContextIsPreservedBetweenAccesses) {
v8::HandleScope scope(CcTest::isolate());
v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount);
v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext();
v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext();
CHECK_EQ(*context1, *context2);
CHECK(v8::Utils::OpenHandle(*context1).is_identical_to(
v8::Utils::OpenHandle(*context2)));
v8::Debug::SetDebugEventListener(NULL);
}
......
......@@ -1888,7 +1888,7 @@ TEST(NoDebugObjectInSnapshot) {
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CcTest::i_isolate()->debug()->Load();
CHECK(CcTest::i_isolate()->debug()->Load());
CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
......
......@@ -37,12 +37,13 @@ function TestCase(fun, frame_number) {
var exception = false;
var codeSnippet = undefined;
var resultPositions = undefined;
var step = 0;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break ||
event == Debug.DebugEvent.Exception) {
Debug.setListener(null);
if (step++ > 0) return;
assertHasLineMark(/pause/, exec_state.frame(0));
assertHasLineMark(/positions/, 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