From d63594b684d7e65504b041fc70ddee85544a1058 Mon Sep 17 00:00:00 2001 From: Alexey Kozyatinskiy Date: Fri, 1 Sep 2017 10:27:11 -0700 Subject: [PATCH] [inspector] added url to Debugger.CallFrame Runtime.CallFrame has url already. It allows to show stack traces on pause without tacking all parsed scripts. R=alph@chromium.org,pfeldman@chromium.org Bug: chromium:762982 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: Ic4f096ade1cb6c9de42fec77280dcc3007c6a5cf Reviewed-on: https://chromium-review.googlesource.com/648068 Commit-Queue: Aleksey Kozyatinskiy Reviewed-by: Pavel Feldman Cr-Commit-Position: refs/heads/master@{#47895} --- src/inspector/js_protocol.json | 1 + src/inspector/v8-debugger-agent-impl.cc | 48 ++++++++++--------- .../debugger/call-frame-url-expected.txt | 15 ++++++ test/inspector/debugger/call-frame-url.js | 20 ++++++++ .../inspector/runtime/es6-module-expected.txt | 1 + 5 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 test/inspector/debugger/call-frame-url-expected.txt create mode 100644 test/inspector/debugger/call-frame-url.js diff --git a/src/inspector/js_protocol.json b/src/inspector/js_protocol.json index c08872831a..863be6a485 100644 --- a/src/inspector/js_protocol.json +++ b/src/inspector/js_protocol.json @@ -457,6 +457,7 @@ { "name": "functionName", "type": "string", "description": "Name of the JavaScript function called on this call frame." }, { "name": "functionLocation", "$ref": "Location", "optional": true, "experimental": true, "description": "Location in the source code." }, { "name": "location", "$ref": "Location", "description": "Location in the source code." }, + { "name": "url", "type": "string", "description": "JavaScript script name or url." }, { "name": "scopeChain", "type": "array", "items": { "$ref": "Scope" }, "description": "Scope chain for this call frame." }, { "name": "this", "$ref": "Runtime.RemoteObject", "description": "this object for this call frame." }, { "name": "returnValue", "$ref": "Runtime.RemoteObject", "optional": true, "description": "The value being returned, if the function is at return point." } diff --git a/src/inspector/v8-debugger-agent-impl.cc b/src/inspector/v8-debugger-agent-impl.cc index e78466c99f..2e47e4e778 100644 --- a/src/inspector/v8-debugger-agent-impl.cc +++ b/src/inspector/v8-debugger-agent-impl.cc @@ -64,19 +64,13 @@ static const intptr_t kBreakpointHintMaxSearchOffset = 80 * 10; namespace { -void TranslateWasmStackTraceLocations(Array* stackTrace, - WasmTranslation* wasmTranslation) { - for (size_t i = 0, e = stackTrace->length(); i != e; ++i) { - protocol::Debugger::Location* location = stackTrace->get(i)->getLocation(); - String16 scriptId = location->getScriptId(); - int lineNumber = location->getLineNumber(); - int columnNumber = location->getColumnNumber(-1); - - if (!wasmTranslation->TranslateWasmScriptLocationToProtocolLocation( - &scriptId, &lineNumber, &columnNumber)) { - continue; - } - +void TranslateLocation(protocol::Debugger::Location* location, + WasmTranslation* wasmTranslation) { + String16 scriptId = location->getScriptId(); + int lineNumber = location->getLineNumber(); + int columnNumber = location->getColumnNumber(-1); + if (wasmTranslation->TranslateWasmScriptLocationToProtocolLocation( + &scriptId, &lineNumber, &columnNumber)) { location->setScriptId(std::move(scriptId)); location->setLineNumber(lineNumber); location->setColumnNumber(columnNumber); @@ -1107,8 +1101,6 @@ Response V8DebuggerAgentImpl::currentCallFrames( String16 callFrameId = RemoteCallFrameId::serialize(contextId, frameOrdinal); - v8::Local script = iterator->GetScript(); - DCHECK(!script.IsEmpty()); v8::debug::Location loc = iterator->GetSourceLocation(); std::unique_ptr> scopes; @@ -1128,15 +1120,29 @@ Response V8DebuggerAgentImpl::currentCallFrames( .build(); } + v8::Local script = iterator->GetScript(); + DCHECK(!script.IsEmpty()); + std::unique_ptr location = + protocol::Debugger::Location::create() + .setScriptId(String16::fromInteger(script->Id())) + .setLineNumber(loc.GetLineNumber()) + .setColumnNumber(loc.GetColumnNumber()) + .build(); + TranslateLocation(location.get(), m_debugger->wasmTranslation()); + String16 scriptId = String16::fromInteger(script->Id()); + ScriptsMap::iterator scriptIterator = + m_scripts.find(location->getScriptId()); + String16 url; + if (scriptIterator != m_scripts.end()) { + url = scriptIterator->second->sourceURL(); + } + auto frame = CallFrame::create() .setCallFrameId(callFrameId) .setFunctionName(toProtocolString(iterator->GetFunctionName())) - .setLocation(protocol::Debugger::Location::create() - .setScriptId(String16::fromInteger(script->Id())) - .setLineNumber(loc.GetLineNumber()) - .setColumnNumber(loc.GetColumnNumber()) - .build()) + .setLocation(std::move(location)) + .setUrl(url) .setScopeChain(std::move(scopes)) .setThis(std::move(receiver)) .build(); @@ -1161,8 +1167,6 @@ Response V8DebuggerAgentImpl::currentCallFrames( } (*result)->addItem(std::move(frame)); } - TranslateWasmStackTraceLocations(result->get(), - m_debugger->wasmTranslation()); return Response::OK(); } diff --git a/test/inspector/debugger/call-frame-url-expected.txt b/test/inspector/debugger/call-frame-url-expected.txt new file mode 100644 index 0000000000..b27b40dd3d --- /dev/null +++ b/test/inspector/debugger/call-frame-url-expected.txt @@ -0,0 +1,15 @@ +Tests url in Debugger.CallFrame. +[ + [0] : { + url : + } + [1] : { + url : source-url.js + } + [2] : { + url : test.js + } + [3] : { + url : expr.js + } +] diff --git a/test/inspector/debugger/call-frame-url.js b/test/inspector/debugger/call-frame-url.js new file mode 100644 index 0000000000..af8e908ca5 --- /dev/null +++ b/test/inspector/debugger/call-frame-url.js @@ -0,0 +1,20 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +let {session, contextGroup, Protocol} = + InspectorTest.start('Tests url in Debugger.CallFrame.'); + +contextGroup.addScript(` +eval('function foo1() { debugger; }'); +eval('function foo2() { foo1() } //# sourceURL=source-url.js'); +function foo3() { foo2(); } +`, 0, 0, 'test.js'); + +(async function test() { + Protocol.Debugger.enable(); + Protocol.Runtime.evaluate({expression: 'foo3()//# sourceURL=expr.js'}); + let {params:{callFrames}} = await Protocol.Debugger.oncePaused(); + InspectorTest.logMessage(callFrames.map(frame => ({url: frame.url}))); + InspectorTest.completeTest(); +})(); diff --git a/test/inspector/runtime/es6-module-expected.txt b/test/inspector/runtime/es6-module-expected.txt index cbe63fe718..646fd018ea 100644 --- a/test/inspector/runtime/es6-module-expected.txt +++ b/test/inspector/runtime/es6-module-expected.txt @@ -117,6 +117,7 @@ console.log(239) this : { type : undefined } + url : module3 } ] hitBreakpoints : [