Skip to content

Commit

Permalink
Merged: [inspector] improved V8Debugger::breakProgram method
Browse files Browse the repository at this point in the history
Revision: 835b71e

BUG=chromium:714819
LOG=N
NOTRY=true
NOPRESUBMIT=true
NOTREECHECKS=true
[email protected]

Change-Id: I4850e692cf5dd09c6dd8f5c9a1328c4d2a06999a
Reviewed-on: https://chromium-review.googlesource.com/502008
Reviewed-by: Aleksey Kozyatinskiy <[email protected]>
Commit-Queue: Aleksey Kozyatinskiy <[email protected]>
Cr-Commit-Position: refs/branch-heads/5.9@{crosswalk-project#43}
Cr-Branched-From: fe9bb7e-refs/heads/5.9.211@{crosswalk-project#1}
Cr-Branched-From: 70ad237-refs/heads/master@{#44591}
  • Loading branch information
alexkozy authored and Commit Bot committed May 10, 2017
1 parent ef88472 commit ffd3466
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/inspector/v8-debugger-agent-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ void V8DebuggerAgentImpl::breakProgram(
std::vector<BreakReason> currentScheduledReason;
currentScheduledReason.swap(m_breakReason);
pushBreakDetails(breakReason, std::move(data));
m_debugger->breakProgram();
if (!m_debugger->breakProgram(m_session->contextGroupId())) return;
popBreakDetails();
m_breakReason.swap(currentScheduledReason);
if (!m_breakReason.empty()) {
Expand Down
11 changes: 7 additions & 4 deletions src/inspector/v8-debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,14 @@ bool V8Debugger::canBreakProgram() {
return !v8::debug::AllFramesOnStackAreBlackboxed(m_isolate);
}

void V8Debugger::breakProgram() {
// Don't allow nested breaks.
if (isPaused()) return;
if (!canBreakProgram()) return;
bool V8Debugger::breakProgram(int targetContextGroupId) {
// Don't allow nested breaks.
if (isPaused()) return true;
if (!canBreakProgram()) return true;
DCHECK(targetContextGroupId);
m_targetContextGroupId = targetContextGroupId;
v8::debug::BreakRightNow(m_isolate);
return m_inspector->enabledDebuggerAgentForGroup(targetContextGroupId);
}

void V8Debugger::continueProgram() {
Expand Down
2 changes: 1 addition & 1 deletion src/inspector/v8-debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class V8Debugger : public v8::debug::DebugDelegate {
v8::debug::ExceptionBreakState getPauseOnExceptionsState();
void setPauseOnExceptionsState(v8::debug::ExceptionBreakState);
bool canBreakProgram();
void breakProgram();
bool breakProgram(int targetContextGroupId);
void continueProgram();

void setPauseOnNextStatement(bool, int targetContextGroupId);
Expand Down
25 changes: 20 additions & 5 deletions test/inspector/inspector-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,25 @@ class ConnectTask : public TaskRunner::Task {

class DisconnectTask : public TaskRunner::Task {
public:
explicit DisconnectTask(InspectorClientImpl* client) : client_(client) {}
explicit DisconnectTask(InspectorClientImpl* client, bool reset_inspector,
v8::base::Semaphore* ready_semaphore)
: client_(client),
reset_inspector_(reset_inspector),
ready_semaphore_(ready_semaphore) {}
virtual ~DisconnectTask() = default;

bool is_inspector_task() final { return true; }

void Run(v8::Isolate* isolate,
const v8::Global<v8::Context>& global_context) {
client_->disconnect();
client_->disconnect(reset_inspector_);
if (ready_semaphore_) ready_semaphore_->Signal();
}

private:
InspectorClientImpl* client_;
bool reset_inspector_;
v8::base::Semaphore* ready_semaphore_;
};

class CreateContextGroupTask : public TaskRunner::Task {
Expand Down Expand Up @@ -198,15 +205,23 @@ void InspectorClientImpl::connect(v8::Local<v8::Context> context) {

void InspectorClientImpl::scheduleReconnect(
v8::base::Semaphore* ready_semaphore) {
task_runner_->Append(new DisconnectTask(this));
task_runner_->Append(
new DisconnectTask(this, /* reset_inspector */ true, nullptr));
task_runner_->Append(new ConnectTask(this, ready_semaphore));
}

void InspectorClientImpl::disconnect() {
void InspectorClientImpl::scheduleDisconnect(
v8::base::Semaphore* ready_semaphore) {
task_runner_->Append(
new DisconnectTask(this, /* reset_inspector */ false, ready_semaphore));
}

void InspectorClientImpl::disconnect(bool reset_inspector) {
for (const auto& it : sessions_) {
states_[it.first] = it.second->stateJSON();
}
sessions_.clear();
if (reset_inspector) inspector_.reset();
}

void InspectorClientImpl::scheduleCreateContextGroup(
Expand Down Expand Up @@ -320,7 +335,7 @@ class SendMessageToBackendTask : public TaskRunner::Task {
->sessions_[context_group_id_]
.get();
}
CHECK(session);
if (!session) return;
}
v8_inspector::StringView message_view(message_.start(), message_.length());
session->dispatchProtocolMessage(message_view);
Expand Down
3 changes: 2 additions & 1 deletion test/inspector/inspector-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
virtual ~InspectorClientImpl();

void scheduleReconnect(v8::base::Semaphore* ready_semaphore);
void scheduleDisconnect(v8::base::Semaphore* ready_semaphore);
void scheduleCreateContextGroup(v8::ExtensionConfiguration* extensions,
v8::base::Semaphore* ready_semaphore,
int* context_group_id);
Expand Down Expand Up @@ -57,7 +58,7 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
friend class ConnectTask;
void connect(v8::Local<v8::Context> context);
friend class DisconnectTask;
void disconnect();
void disconnect(bool reset_inspector);
friend class CreateContextGroupTask;
int createContextGroup(v8::ExtensionConfiguration* extensions);

Expand Down
17 changes: 17 additions & 0 deletions test/inspector/inspector-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class UtilsExtension : public v8::Extension {
"native function schedulePauseOnNextStatement();"
"native function cancelPauseOnNextStatement();"
"native function reconnect();"
"native function disconnect();"
"native function createContextGroup();") {}
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) {
Expand Down Expand Up @@ -136,6 +137,12 @@ class UtilsExtension : public v8::Extension {
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(isolate, UtilsExtension::Reconnect);
} else if (name->Equals(context,
v8::String::NewFromUtf8(isolate, "disconnect",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(isolate, UtilsExtension::Disconnect);
} else if (name->Equals(context, v8::String::NewFromUtf8(
isolate, "createContextGroup",
v8::NewStringType::kNormal)
Expand Down Expand Up @@ -318,6 +325,16 @@ class UtilsExtension : public v8::Extension {
ready_semaphore.Wait();
}

static void Disconnect(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 0) {
fprintf(stderr, "Internal error: disconnect().");
Exit();
}
v8::base::Semaphore ready_semaphore(0);
inspector_client_->scheduleDisconnect(&ready_semaphore);
ready_semaphore.Wait();
}

static void CreateContextGroup(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 0) {
Expand Down
2 changes: 2 additions & 0 deletions test/inspector/protocol-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ var utils = {};
this.cancelPauseOnNextStatement = null;
utils.reconnect = reconnect;
this.reconnect = null;
utils.disconnect = disconnect;
this.disconnect = null;
utils.createContextGroup = createContextGroup;
this.createContextGroup = null;
})();
Expand Down

0 comments on commit ffd3466

Please sign in to comment.