Skip to content

Commit 37dcd83

Browse files
alexkozyCommit Bot
authored andcommitted
[debug] remove debugger context
After liveedit removed - we do not need this context any more. [email protected] [email protected] Bug: v8:5530 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: Idb43d016d51b8048f6cd2ca590fd7510abcacb49 Reviewed-on: https://chromium-review.googlesource.com/1106802 Commit-Queue: Aleksey Kozyatinskiy <[email protected]> Reviewed-by: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#54273}
1 parent bb09758 commit 37dcd83

15 files changed

Lines changed: 22 additions & 381 deletions

src/api.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9627,9 +9627,7 @@ MaybeLocal<UnboundScript> debug::CompileInspectorScript(Isolate* v8_isolate,
96279627
void debug::SetDebugDelegate(Isolate* v8_isolate,
96289628
debug::DebugDelegate* delegate) {
96299629
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
9630-
// Might create the Debug context.
9631-
ENTER_V8_FOR_NEW_CONTEXT(isolate);
9632-
isolate->debug()->SetDebugDelegate(delegate, false);
9630+
isolate->debug()->SetDebugDelegate(delegate);
96339631
}
96349632

96359633
void debug::SetAsyncEventDelegate(Isolate* v8_isolate,

src/compiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
16291629
if (extension == nullptr) {
16301630
bool can_consume_code_cache =
16311631
compile_options == ScriptCompiler::kConsumeCodeCache &&
1632-
!isolate->debug()->is_loaded();
1632+
!isolate->debug()->is_active();
16331633
if (can_consume_code_cache) {
16341634
compile_timer.set_consuming_code_cache();
16351635
}
@@ -1720,7 +1720,7 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
17201720
MaybeHandle<SharedFunctionInfo> maybe_result;
17211721
bool can_consume_code_cache =
17221722
compile_options == ScriptCompiler::kConsumeCodeCache &&
1723-
!isolate->debug()->is_loaded();
1723+
!isolate->debug()->is_active();
17241724
if (can_consume_code_cache) {
17251725
compile_timer.set_consuming_code_cache();
17261726
// Then check cached code provided by embedder.

src/debug/debug.cc

Lines changed: 15 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ class Debug::TemporaryObjectsTracker : public HeapObjectAllocationTracker {
7979
};
8080

8181
Debug::Debug(Isolate* isolate)
82-
: debug_context_(Handle<Context>()),
83-
is_active_(false),
82+
: is_active_(false),
8483
hook_on_function_call_(false),
8584
is_suppressed_(false),
8685
break_disabled_(false),
@@ -392,60 +391,12 @@ DebugInfoListNode::~DebugInfoListNode() {
392391
debug_info_ = nullptr;
393392
}
394393

395-
396-
bool Debug::Load() {
397-
// Return if debugger is already loaded.
398-
if (is_loaded()) return true;
399-
400-
// Bail out if we're already in the process of compiling the native
401-
// JavaScript source code for the debugger.
402-
if (is_suppressed_) return false;
403-
SuppressDebug while_loading(this);
404-
405-
// Disable breakpoints and interrupts while compiling and running the
406-
// debugger scripts including the context creation code.
407-
DisableBreak disable(this);
408-
PostponeInterruptsScope postpone(isolate_);
409-
410-
// Create the debugger context.
411-
HandleScope scope(isolate_);
412-
ExtensionConfiguration no_extensions;
413-
// TODO(yangguo): we rely on the fact that first context snapshot is usable
414-
// as debug context. This dependency is gone once we remove
415-
// debug context completely.
416-
static const int kFirstContextSnapshotIndex = 0;
417-
Handle<Context> context = isolate_->bootstrapper()->CreateEnvironment(
418-
MaybeHandle<JSGlobalProxy>(), v8::Local<ObjectTemplate>(), &no_extensions,
419-
kFirstContextSnapshotIndex, v8::DeserializeEmbedderFieldsCallback(),
420-
DEBUG_CONTEXT);
421-
422-
// Fail if no context could be created.
423-
if (context.is_null()) return false;
424-
425-
debug_context_ = isolate_->global_handles()->Create(*context);
426-
GlobalHandles::AnnotateStrongRetainer(
427-
Handle<Object>::cast(debug_context_).location(),
428-
"v8::internal::Debug::debug_context_");
429-
430-
feature_tracker()->Track(DebugFeatureTracker::kActive);
431-
432-
return true;
433-
}
434-
435-
436394
void Debug::Unload() {
437395
ClearAllBreakPoints();
438396
ClearStepping();
439397
RemoveAllCoverageInfos();
440398
ClearAllDebuggerHints();
441-
RemoveDebugDelegate();
442-
443-
// Return debugger is not loaded.
444-
if (!is_loaded()) return;
445-
446-
// Clear debugger context global handle.
447-
GlobalHandles::Destroy(Handle<Object>::cast(debug_context_).location());
448-
debug_context_ = Handle<Context>();
399+
debug_delegate_ = nullptr;
449400
}
450401

451402
void Debug::Break(JavaScriptFrame* frame, Handle<JSFunction> break_target) {
@@ -457,7 +408,6 @@ void Debug::Break(JavaScriptFrame* frame, Handle<JSFunction> break_target) {
457408

458409
// Enter the debugger.
459410
DebugScope debug_scope(this);
460-
if (debug_scope.failed()) return;
461411

462412
// Postpone interrupt during breakpoint processing.
463413
PostponeInterruptsScope postpone(isolate_);
@@ -585,7 +535,6 @@ bool Debug::IsMutedAtCurrentLocation(JavaScriptFrame* frame) {
585535
Handle<DebugInfo> debug_info(function->shared()->GetDebugInfo(), isolate_);
586536
// Enter the debugger.
587537
DebugScope debug_scope(this);
588-
if (debug_scope.failed()) return false;
589538
std::vector<BreakLocation> break_locations;
590539
BreakLocation::AllAtCurrentStatement(debug_info, frame, &break_locations);
591540
bool has_break_points_at_all = false;
@@ -599,22 +548,6 @@ bool Debug::IsMutedAtCurrentLocation(JavaScriptFrame* frame) {
599548
return has_break_points_at_all;
600549
}
601550

602-
MaybeHandle<Object> Debug::CallFunction(const char* name, int argc,
603-
Handle<Object> args[],
604-
MaybeHandle<Object>* maybe_exception) {
605-
AllowJavascriptExecutionDebugOnly allow_script(isolate_);
606-
PostponeInterruptsScope no_interrupts(isolate_);
607-
AssertDebugContext();
608-
Handle<JSReceiver> holder =
609-
Handle<JSReceiver>::cast(isolate_->natives_utils_object());
610-
Handle<JSFunction> fun = Handle<JSFunction>::cast(
611-
JSReceiver::GetProperty(isolate_, holder, name).ToHandleChecked());
612-
Handle<Object> undefined = isolate_->factory()->undefined_value();
613-
return Execution::TryCall(isolate_, fun, undefined, argc, args,
614-
Execution::MessageHandling::kReport,
615-
maybe_exception);
616-
}
617-
618551
// Check whether a single break point object is triggered.
619552
bool Debug::CheckBreakPoint(Handle<BreakPoint> break_point,
620553
bool is_break_at_entry) {
@@ -1683,12 +1616,6 @@ void Debug::ScheduleFrameRestart(StackFrame* frame) {
16831616
}
16841617
}
16851618

1686-
1687-
bool Debug::IsDebugGlobal(JSGlobalObject* global) {
1688-
return is_loaded() && global == debug_context()->global_object();
1689-
}
1690-
1691-
16921619
Handle<FixedArray> Debug::GetLoadedScripts() {
16931620
isolate_->heap()->CollectAllGarbage(Heap::kFinalizeIncrementalMarkingMask,
16941621
GarbageCollectionReason::kDebugger);
@@ -1739,17 +1666,6 @@ void Debug::OnPromiseReject(Handle<Object> promise, Handle<Object> value) {
17391666
}
17401667
}
17411668

1742-
namespace {
1743-
v8::Local<v8::Context> GetDebugEventContext(Isolate* isolate) {
1744-
Handle<Context> context = handle(isolate->context(), isolate);
1745-
// Isolate::context() may have been nullptr when "script collected" event
1746-
// occurred.
1747-
if (context.is_null()) return v8::Local<v8::Context>();
1748-
Handle<Context> native_context(context->native_context(), isolate);
1749-
return v8::Utils::ToLocal(native_context);
1750-
}
1751-
} // anonymous namespace
1752-
17531669
bool Debug::IsExceptionBlackboxed(bool uncaught) {
17541670
// Uncaught exception is blackboxed if all current frames are blackboxed,
17551671
// caught exception if top frame is blackboxed.
@@ -1812,14 +1728,14 @@ void Debug::OnException(Handle<Object> exception, Handle<Object> promise) {
18121728
}
18131729

18141730
DebugScope debug_scope(this);
1815-
if (debug_scope.failed()) return;
18161731
HandleScope scope(isolate_);
18171732
PostponeInterruptsScope postpone(isolate_);
18181733
DisableBreak no_recursive_break(this);
18191734

1820-
debug_delegate_->ExceptionThrown(
1821-
GetDebugEventContext(isolate_),
1822-
v8::Utils::ToLocal(exception), v8::Utils::ToLocal(promise), uncaught);
1735+
Handle<Context> native_context(isolate_->native_context());
1736+
debug_delegate_->ExceptionThrown(v8::Utils::ToLocal(native_context),
1737+
v8::Utils::ToLocal(exception),
1738+
v8::Utils::ToLocal(promise), uncaught);
18231739
}
18241740

18251741
void Debug::OnDebugBreak(Handle<FixedArray> break_points_hit) {
@@ -1847,9 +1763,9 @@ void Debug::OnDebugBreak(Handle<FixedArray> break_points_hit) {
18471763
++inspector_break_points_count;
18481764
}
18491765

1850-
debug_delegate_->BreakProgramRequested(
1851-
GetDebugEventContext(isolate_),
1852-
inspector_break_points_hit);
1766+
Handle<Context> native_context(isolate_->native_context());
1767+
debug_delegate_->BreakProgramRequested(v8::Utils::ToLocal(native_context),
1768+
inspector_break_points_hit);
18531769
}
18541770

18551771
namespace {
@@ -1940,7 +1856,6 @@ void Debug::ProcessCompileEvent(bool has_compile_error, Handle<Script> script) {
19401856
if (!debug_delegate_) return;
19411857
SuppressDebug while_processing(this);
19421858
DebugScope debug_scope(this);
1943-
if (debug_scope.failed()) return;
19441859
HandleScope scope(isolate_);
19451860
PostponeInterruptsScope postpone(isolate_);
19461861
DisableBreak no_recursive_break(this);
@@ -1949,14 +1864,6 @@ void Debug::ProcessCompileEvent(bool has_compile_error, Handle<Script> script) {
19491864
running_live_edit_, has_compile_error);
19501865
}
19511866

1952-
Handle<Context> Debug::GetDebugContext() {
1953-
if (!is_loaded()) return Handle<Context>();
1954-
DebugScope debug_scope(this);
1955-
if (debug_scope.failed()) return Handle<Context>();
1956-
// The global handle may be destroyed soon after. Return it reboxed.
1957-
return handle(*debug_context(), isolate_);
1958-
}
1959-
19601867
int Debug::CurrentFrameCount() {
19611868
StackTraceFrameIterator it(isolate_);
19621869
if (break_frame_id() != StackFrame::NO_ID) {
@@ -1978,31 +1885,21 @@ int Debug::CurrentFrameCount() {
19781885
return counter;
19791886
}
19801887

1981-
void Debug::SetDebugDelegate(debug::DebugDelegate* delegate,
1982-
bool pass_ownership) {
1983-
RemoveDebugDelegate();
1888+
void Debug::SetDebugDelegate(debug::DebugDelegate* delegate) {
19841889
debug_delegate_ = delegate;
1985-
owns_debug_delegate_ = pass_ownership;
19861890
UpdateState();
19871891
}
19881892

1989-
void Debug::RemoveDebugDelegate() {
1990-
if (debug_delegate_ == nullptr) return;
1991-
if (owns_debug_delegate_) {
1992-
owns_debug_delegate_ = false;
1993-
delete debug_delegate_;
1994-
}
1995-
debug_delegate_ = nullptr;
1996-
}
1997-
19981893
void Debug::UpdateState() {
19991894
bool is_active = debug_delegate_ != nullptr;
2000-
if (is_active || in_debug_scope()) {
1895+
if (is_active == is_active_) return;
1896+
if (is_active) {
20011897
// Note that the debug context could have already been loaded to
20021898
// bootstrap test cases.
20031899
isolate_->compilation_cache()->Disable();
2004-
is_active = Load();
2005-
} else if (is_loaded()) {
1900+
is_active = true;
1901+
feature_tracker()->Track(DebugFeatureTracker::kActive);
1902+
} else {
20061903
isolate_->compilation_cache()->Enable();
20071904
Unload();
20081905
}
@@ -2045,9 +1942,6 @@ void Debug::HandleDebugBreak(IgnoreBreakMode ignore_break_mode) {
20451942
? IsBlackboxed(shared)
20461943
: AllFramesOnStackAreBlackboxed();
20471944
if (ignore_break) return;
2048-
JSGlobalObject* global = function->context()->global_object();
2049-
// Don't stop in debugger functions.
2050-
if (IsDebugGlobal(global)) return;
20511945
// Don't stop if the break location is muted.
20521946
if (IsMutedAtCurrentLocation(it.frame())) return;
20531947
}
@@ -2058,7 +1952,6 @@ void Debug::HandleDebugBreak(IgnoreBreakMode ignore_break_mode) {
20581952

20591953
HandleScope scope(isolate_);
20601954
DebugScope debug_scope(this);
2061-
if (debug_scope.failed()) return;
20621955

20631956
OnDebugBreak(isolate_->factory()->empty_fixed_array());
20641957
}
@@ -2125,9 +2018,6 @@ DebugScope::DebugScope(Debug* debug)
21252018
debug_->SetNextBreakId();
21262019

21272020
debug_->UpdateState();
2128-
// Make sure that debugger is loaded and enter the debugger context.
2129-
// The previous context is kept in save_.
2130-
failed_ = !debug_->is_loaded();
21312021
}
21322022

21332023

0 commit comments

Comments
 (0)