Commit 764371bc authored by clemensh's avatar clemensh Committed by Commit bot

[inspector] Change ScriptBreakpoint to include scriptId

The ScriptBreakpoint struct was before just holding line, column and
condition. It now additionally holds the scriptId.
This encapsulates information nicer, and allows for easier translation
of wasm locations, since one struct now holds all information needed
for the translation.

BUG=chromium:659715
R=yangguo@chromium.org, kozyatinskiy@chromium.org

Review-Url: https://codereview.chromium.org/2491133003
Cr-Commit-Position: refs/heads/master@{#41044}
parent 72c3732f
...@@ -35,15 +35,18 @@ ...@@ -35,15 +35,18 @@
namespace v8_inspector { namespace v8_inspector {
struct ScriptBreakpoint { struct ScriptBreakpoint {
ScriptBreakpoint() : ScriptBreakpoint(0, 0, String16()) {} ScriptBreakpoint() {}
ScriptBreakpoint(int lineNumber, int columnNumber, const String16& condition) ScriptBreakpoint(String16 script_id, int line_number, int column_number,
: lineNumber(lineNumber), String16 condition)
columnNumber(columnNumber), : script_id(std::move(script_id)),
condition(condition) {} line_number(line_number),
column_number(column_number),
int lineNumber; condition(std::move(condition)) {}
int columnNumber;
String16 script_id;
int line_number = 0;
int column_number = 0;
String16 condition; String16 condition;
}; };
......
...@@ -74,14 +74,14 @@ static String16 breakpointIdSuffix( ...@@ -74,14 +74,14 @@ static String16 breakpointIdSuffix(
} }
static String16 generateBreakpointId( static String16 generateBreakpointId(
const String16& scriptId, int lineNumber, int columnNumber, const ScriptBreakpoint& breakpoint,
V8DebuggerAgentImpl::BreakpointSource source) { V8DebuggerAgentImpl::BreakpointSource source) {
String16Builder builder; String16Builder builder;
builder.append(scriptId); builder.append(breakpoint.script_id);
builder.append(':'); builder.append(':');
builder.appendNumber(lineNumber); builder.appendNumber(breakpoint.line_number);
builder.append(':'); builder.append(':');
builder.appendNumber(columnNumber); builder.appendNumber(breakpoint.column_number);
builder.append(breakpointIdSuffix(source)); builder.append(breakpointIdSuffix(source));
return builder.toString(); return builder.toString();
} }
...@@ -291,12 +291,13 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl( ...@@ -291,12 +291,13 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl(
breakpointId, buildObjectForBreakpointCookie( breakpointId, buildObjectForBreakpointCookie(
url, lineNumber, columnNumber, condition, isRegex)); url, lineNumber, columnNumber, condition, isRegex));
ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); ScriptBreakpoint breakpoint(String16(), lineNumber, columnNumber, condition);
for (const auto& script : m_scripts) { for (const auto& script : m_scripts) {
if (!matches(m_inspector, script.second->sourceURL(), url, isRegex)) if (!matches(m_inspector, script.second->sourceURL(), url, isRegex))
continue; continue;
std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoint( breakpoint.script_id = script.first;
breakpointId, script.first, breakpoint, UserBreakpointSource); std::unique_ptr<protocol::Debugger::Location> location =
resolveBreakpoint(breakpointId, breakpoint, UserBreakpointSource);
if (location) (*locations)->addItem(std::move(location)); if (location) (*locations)->addItem(std::move(location));
} }
...@@ -308,21 +309,18 @@ Response V8DebuggerAgentImpl::setBreakpoint( ...@@ -308,21 +309,18 @@ Response V8DebuggerAgentImpl::setBreakpoint(
std::unique_ptr<protocol::Debugger::Location> location, std::unique_ptr<protocol::Debugger::Location> location,
Maybe<String16> optionalCondition, String16* outBreakpointId, Maybe<String16> optionalCondition, String16* outBreakpointId,
std::unique_ptr<protocol::Debugger::Location>* actualLocation) { std::unique_ptr<protocol::Debugger::Location>* actualLocation) {
String16 scriptId = location->getScriptId(); ScriptBreakpoint breakpoint(
int lineNumber = location->getLineNumber(); location->getScriptId(), location->getLineNumber(),
int columnNumber = location->getColumnNumber(0); location->getColumnNumber(0), optionalCondition.fromMaybe(String16()));
String16 condition = optionalCondition.fromMaybe(""); String16 breakpointId =
generateBreakpointId(breakpoint, UserBreakpointSource);
String16 breakpointId = generateBreakpointId(
scriptId, lineNumber, columnNumber, UserBreakpointSource);
if (m_breakpointIdToDebuggerBreakpointIds.find(breakpointId) != if (m_breakpointIdToDebuggerBreakpointIds.find(breakpointId) !=
m_breakpointIdToDebuggerBreakpointIds.end()) { m_breakpointIdToDebuggerBreakpointIds.end()) {
return Response::Error("Breakpoint at specified location already exists."); return Response::Error("Breakpoint at specified location already exists.");
} }
ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); *actualLocation =
*actualLocation = resolveBreakpoint(breakpointId, scriptId, breakpoint, resolveBreakpoint(breakpointId, breakpoint, UserBreakpointSource);
UserBreakpointSource);
if (!*actualLocation) return Response::Error("Could not resolve breakpoint"); if (!*actualLocation) return Response::Error("Could not resolve breakpoint");
*outBreakpointId = breakpointId; *outBreakpointId = breakpointId;
return Response::OK(); return Response::OK();
...@@ -405,13 +403,13 @@ Response V8DebuggerAgentImpl::continueToLocation( ...@@ -405,13 +403,13 @@ Response V8DebuggerAgentImpl::continueToLocation(
m_continueToLocationBreakpointId = ""; m_continueToLocationBreakpointId = "";
} }
String16 scriptId = location->getScriptId(); ScriptBreakpoint breakpoint(location->getScriptId(),
int lineNumber = location->getLineNumber(); location->getLineNumber(),
int columnNumber = location->getColumnNumber(0); location->getColumnNumber(0), String16());
ScriptBreakpoint breakpoint(lineNumber, columnNumber, "");
m_continueToLocationBreakpointId = m_debugger->setBreakpoint( m_continueToLocationBreakpointId = m_debugger->setBreakpoint(
scriptId, breakpoint, &lineNumber, &columnNumber); breakpoint, &breakpoint.line_number, &breakpoint.column_number);
// TODO(kozyatinskiy): Return actual line and column number.
return resume(); return resume();
} }
...@@ -493,23 +491,22 @@ V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipStepPause( ...@@ -493,23 +491,22 @@ V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipStepPause(
std::unique_ptr<protocol::Debugger::Location> std::unique_ptr<protocol::Debugger::Location>
V8DebuggerAgentImpl::resolveBreakpoint(const String16& breakpointId, V8DebuggerAgentImpl::resolveBreakpoint(const String16& breakpointId,
const String16& scriptId,
const ScriptBreakpoint& breakpoint, const ScriptBreakpoint& breakpoint,
BreakpointSource source) { BreakpointSource source) {
DCHECK(enabled()); DCHECK(enabled());
// FIXME: remove these checks once crbug.com/520702 is resolved. // FIXME: remove these checks once crbug.com/520702 is resolved.
CHECK(!breakpointId.isEmpty()); CHECK(!breakpointId.isEmpty());
CHECK(!scriptId.isEmpty()); CHECK(!breakpoint.script_id.isEmpty());
ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId); ScriptsMap::iterator scriptIterator = m_scripts.find(breakpoint.script_id);
if (scriptIterator == m_scripts.end()) return nullptr; if (scriptIterator == m_scripts.end()) return nullptr;
if (breakpoint.lineNumber < scriptIterator->second->startLine() || if (breakpoint.line_number < scriptIterator->second->startLine() ||
scriptIterator->second->endLine() < breakpoint.lineNumber) scriptIterator->second->endLine() < breakpoint.line_number)
return nullptr; return nullptr;
int actualLineNumber; int actualLineNumber;
int actualColumnNumber; int actualColumnNumber;
String16 debuggerBreakpointId = m_debugger->setBreakpoint( String16 debuggerBreakpointId = m_debugger->setBreakpoint(
scriptId, breakpoint, &actualLineNumber, &actualColumnNumber); breakpoint, &actualLineNumber, &actualColumnNumber);
if (debuggerBreakpointId.isEmpty()) return nullptr; if (debuggerBreakpointId.isEmpty()) return nullptr;
m_serverBreakpoints[debuggerBreakpointId] = m_serverBreakpoints[debuggerBreakpointId] =
...@@ -518,7 +515,8 @@ V8DebuggerAgentImpl::resolveBreakpoint(const String16& breakpointId, ...@@ -518,7 +515,8 @@ V8DebuggerAgentImpl::resolveBreakpoint(const String16& breakpointId,
m_breakpointIdToDebuggerBreakpointIds[breakpointId].push_back( m_breakpointIdToDebuggerBreakpointIds[breakpointId].push_back(
debuggerBreakpointId); debuggerBreakpointId);
return buildProtocolLocation(scriptId, actualLineNumber, actualColumnNumber); return buildProtocolLocation(breakpoint.script_id, actualLineNumber,
actualColumnNumber);
} }
Response V8DebuggerAgentImpl::searchInContent( Response V8DebuggerAgentImpl::searchInContent(
...@@ -1075,14 +1073,15 @@ void V8DebuggerAgentImpl::didParseSource( ...@@ -1075,14 +1073,15 @@ void V8DebuggerAgentImpl::didParseSource(
breakpointObject->getString(DebuggerAgentState::url, &url); breakpointObject->getString(DebuggerAgentState::url, &url);
if (!matches(m_inspector, scriptURL, url, isRegex)) continue; if (!matches(m_inspector, scriptURL, url, isRegex)) continue;
ScriptBreakpoint breakpoint; ScriptBreakpoint breakpoint;
breakpoint.script_id = scriptId;
breakpointObject->getInteger(DebuggerAgentState::lineNumber, breakpointObject->getInteger(DebuggerAgentState::lineNumber,
&breakpoint.lineNumber); &breakpoint.line_number);
breakpointObject->getInteger(DebuggerAgentState::columnNumber, breakpointObject->getInteger(DebuggerAgentState::columnNumber,
&breakpoint.columnNumber); &breakpoint.column_number);
breakpointObject->getString(DebuggerAgentState::condition, breakpointObject->getString(DebuggerAgentState::condition,
&breakpoint.condition); &breakpoint.condition);
std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoint( std::unique_ptr<protocol::Debugger::Location> location =
cookie.first, scriptId, breakpoint, UserBreakpointSource); resolveBreakpoint(cookie.first, breakpoint, UserBreakpointSource);
if (location) if (location)
m_frontend.breakpointResolved(cookie.first, std::move(location)); m_frontend.breakpointResolved(cookie.first, std::move(location));
} }
...@@ -1221,17 +1220,17 @@ void V8DebuggerAgentImpl::setBreakpointAt(const String16& scriptId, ...@@ -1221,17 +1220,17 @@ void V8DebuggerAgentImpl::setBreakpointAt(const String16& scriptId,
int lineNumber, int columnNumber, int lineNumber, int columnNumber,
BreakpointSource source, BreakpointSource source,
const String16& condition) { const String16& condition) {
String16 breakpointId = ScriptBreakpoint breakpoint(scriptId, lineNumber, columnNumber, condition);
generateBreakpointId(scriptId, lineNumber, columnNumber, source); String16 breakpointId = generateBreakpointId(breakpoint, source);
ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); resolveBreakpoint(breakpointId, breakpoint, source);
resolveBreakpoint(breakpointId, scriptId, breakpoint, source);
} }
void V8DebuggerAgentImpl::removeBreakpointAt(const String16& scriptId, void V8DebuggerAgentImpl::removeBreakpointAt(const String16& scriptId,
int lineNumber, int columnNumber, int lineNumber, int columnNumber,
BreakpointSource source) { BreakpointSource source) {
removeBreakpointImpl( removeBreakpointImpl(generateBreakpointId(
generateBreakpointId(scriptId, lineNumber, columnNumber, source)); ScriptBreakpoint(scriptId, lineNumber, columnNumber, String16()),
source));
} }
void V8DebuggerAgentImpl::reset() { void V8DebuggerAgentImpl::reset() {
......
...@@ -162,8 +162,7 @@ class V8DebuggerAgentImpl : public protocol::Debugger::Backend { ...@@ -162,8 +162,7 @@ class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
void setPauseOnExceptionsImpl(int); void setPauseOnExceptionsImpl(int);
std::unique_ptr<protocol::Debugger::Location> resolveBreakpoint( std::unique_ptr<protocol::Debugger::Location> resolveBreakpoint(
const String16& breakpointId, const String16& scriptId, const String16& breakpointId, const ScriptBreakpoint&, BreakpointSource);
const ScriptBreakpoint&, BreakpointSource);
void removeBreakpointImpl(const String16& breakpointId); void removeBreakpointImpl(const String16& breakpointId);
void clearBreakDetails(); void clearBreakDetails();
......
...@@ -135,8 +135,7 @@ void V8Debugger::getCompiledScripts( ...@@ -135,8 +135,7 @@ void V8Debugger::getCompiledScripts(
} }
} }
String16 V8Debugger::setBreakpoint(const String16& sourceID, String16 V8Debugger::setBreakpoint(const ScriptBreakpoint& breakpoint,
const ScriptBreakpoint& scriptBreakpoint,
int* actualLineNumber, int* actualLineNumber,
int* actualColumnNumber) { int* actualColumnNumber) {
v8::HandleScope scope(m_isolate); v8::HandleScope scope(m_isolate);
...@@ -146,20 +145,20 @@ String16 V8Debugger::setBreakpoint(const String16& sourceID, ...@@ -146,20 +145,20 @@ String16 V8Debugger::setBreakpoint(const String16& sourceID,
v8::Local<v8::Object> info = v8::Object::New(m_isolate); v8::Local<v8::Object> info = v8::Object::New(m_isolate);
bool success = false; bool success = false;
success = info->Set(context, toV8StringInternalized(m_isolate, "sourceID"), success = info->Set(context, toV8StringInternalized(m_isolate, "sourceID"),
toV8String(m_isolate, sourceID)) toV8String(m_isolate, breakpoint.script_id))
.FromMaybe(false); .FromMaybe(false);
DCHECK(success); DCHECK(success);
success = info->Set(context, toV8StringInternalized(m_isolate, "lineNumber"), success = info->Set(context, toV8StringInternalized(m_isolate, "lineNumber"),
v8::Integer::New(m_isolate, scriptBreakpoint.lineNumber)) v8::Integer::New(m_isolate, breakpoint.line_number))
.FromMaybe(false); .FromMaybe(false);
DCHECK(success); DCHECK(success);
success = success =
info->Set(context, toV8StringInternalized(m_isolate, "columnNumber"), info->Set(context, toV8StringInternalized(m_isolate, "columnNumber"),
v8::Integer::New(m_isolate, scriptBreakpoint.columnNumber)) v8::Integer::New(m_isolate, breakpoint.column_number))
.FromMaybe(false); .FromMaybe(false);
DCHECK(success); DCHECK(success);
success = info->Set(context, toV8StringInternalized(m_isolate, "condition"), success = info->Set(context, toV8StringInternalized(m_isolate, "condition"),
toV8String(m_isolate, scriptBreakpoint.condition)) toV8String(m_isolate, breakpoint.condition))
.FromMaybe(false); .FromMaybe(false);
DCHECK(success); DCHECK(success);
......
...@@ -36,8 +36,8 @@ class V8Debugger { ...@@ -36,8 +36,8 @@ class V8Debugger {
bool enabled() const; bool enabled() const;
String16 setBreakpoint(const String16& sourceID, const ScriptBreakpoint&, String16 setBreakpoint(const ScriptBreakpoint&, int* actualLineNumber,
int* actualLineNumber, int* actualColumnNumber); int* actualColumnNumber);
void removeBreakpoint(const String16& breakpointId); void removeBreakpoint(const String16& breakpointId);
void setBreakpointsActivated(bool); void setBreakpointsActivated(bool);
bool breakpointsActivated() const { return m_breakpointsActivated; } bool breakpointsActivated() const { return m_breakpointsActivated; }
......
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