OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/inspector/v8-debugger-script.h" | 5 #include "src/inspector/v8-debugger-script.h" |
6 | 6 |
7 #include "src/inspector/inspected-context.h" | 7 #include "src/inspector/inspected-context.h" |
8 #include "src/inspector/string-util.h" | 8 #include "src/inspector/string-util.h" |
9 #include "src/inspector/wasm-translation.h" | 9 #include "src/inspector/wasm-translation.h" |
10 | 10 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 return m_sourceMappingURL; | 148 return m_sourceMappingURL; |
149 } | 149 } |
150 | 150 |
151 void setSourceMappingURL(const String16& sourceMappingURL) override { | 151 void setSourceMappingURL(const String16& sourceMappingURL) override { |
152 m_sourceMappingURL = sourceMappingURL; | 152 m_sourceMappingURL = sourceMappingURL; |
153 } | 153 } |
154 | 154 |
155 bool getPossibleBreakpoints( | 155 bool getPossibleBreakpoints( |
156 const v8::debug::Location& start, const v8::debug::Location& end, | 156 const v8::debug::Location& start, const v8::debug::Location& end, |
157 bool restrictToFunction, | 157 bool restrictToFunction, |
158 std::vector<v8::debug::Location>* locations) override { | 158 std::vector<v8::debug::BreakLocation>* locations) override { |
159 v8::HandleScope scope(m_isolate); | 159 v8::HandleScope scope(m_isolate); |
160 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); | 160 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); |
161 return script->GetPossibleBreakpoints(start, end, restrictToFunction, | 161 std::vector<v8::debug::BreakLocation> allLocations; |
162 locations); | 162 if (!script->GetPossibleBreakpoints(start, end, restrictToFunction, |
| 163 &allLocations)) { |
| 164 return false; |
| 165 } |
| 166 if (!allLocations.size()) return true; |
| 167 v8::debug::BreakLocation current = allLocations[0]; |
| 168 for (size_t i = 1; i < allLocations.size(); ++i) { |
| 169 if (allLocations[i].GetLineNumber() == current.GetLineNumber() && |
| 170 allLocations[i].GetColumnNumber() == current.GetColumnNumber()) { |
| 171 if (allLocations[i].type() != v8::debug::kCommonBreakLocation) { |
| 172 DCHECK(allLocations[i].type() == v8::debug::kCallBreakLocation || |
| 173 allLocations[i].type() == v8::debug::kReturnBreakLocation); |
| 174 // debugger can returns more then one break location at the same |
| 175 // source location, e.g. foo() - in this case there are two break |
| 176 // locations before foo: for statement and for function call, we can |
| 177 // merge them for inspector and report only one with call type. |
| 178 current = allLocations[i]; |
| 179 } |
| 180 } else { |
| 181 // we assume that returned break locations are sorted. |
| 182 DCHECK( |
| 183 allLocations[i].GetLineNumber() > current.GetLineNumber() || |
| 184 (allLocations[i].GetColumnNumber() >= current.GetColumnNumber() && |
| 185 allLocations[i].GetLineNumber() == current.GetLineNumber())); |
| 186 locations->push_back(current); |
| 187 current = allLocations[i]; |
| 188 } |
| 189 } |
| 190 locations->push_back(current); |
| 191 return true; |
163 } | 192 } |
164 | 193 |
165 void resetBlackboxedStateCache() override { | 194 void resetBlackboxedStateCache() override { |
166 v8::HandleScope scope(m_isolate); | 195 v8::HandleScope scope(m_isolate); |
167 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); | 196 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); |
168 } | 197 } |
169 | 198 |
170 int offset(int lineNumber, int columnNumber) const override { | 199 int offset(int lineNumber, int columnNumber) const override { |
171 v8::HandleScope scope(m_isolate); | 200 v8::HandleScope scope(m_isolate); |
172 return m_script.Get(m_isolate)->GetSourceOffset( | 201 return m_script.Get(m_isolate)->GetSourceOffset( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 245 } |
217 | 246 |
218 const String16& sourceMappingURL() const override { return emptyString(); } | 247 const String16& sourceMappingURL() const override { return emptyString(); } |
219 bool isLiveEdit() const override { return false; } | 248 bool isLiveEdit() const override { return false; } |
220 bool isModule() const override { return false; } | 249 bool isModule() const override { return false; } |
221 void setSourceMappingURL(const String16&) override {} | 250 void setSourceMappingURL(const String16&) override {} |
222 | 251 |
223 bool getPossibleBreakpoints( | 252 bool getPossibleBreakpoints( |
224 const v8::debug::Location& start, const v8::debug::Location& end, | 253 const v8::debug::Location& start, const v8::debug::Location& end, |
225 bool restrictToFunction, | 254 bool restrictToFunction, |
226 std::vector<v8::debug::Location>* locations) override { | 255 std::vector<v8::debug::BreakLocation>* locations) override { |
227 v8::HandleScope scope(m_isolate); | 256 v8::HandleScope scope(m_isolate); |
228 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); | 257 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); |
229 String16 v8ScriptId = String16::fromInteger(script->Id()); | 258 String16 v8ScriptId = String16::fromInteger(script->Id()); |
230 | 259 |
231 v8::debug::Location translatedStart = start; | 260 v8::debug::Location translatedStart = start; |
232 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedStart, | 261 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedStart, |
233 scriptId(), v8ScriptId); | 262 scriptId(), v8ScriptId); |
234 | 263 |
235 v8::debug::Location translatedEnd = end; | 264 v8::debug::Location translatedEnd = end; |
236 if (translatedEnd.IsEmpty()) { | 265 if (translatedEnd.IsEmpty()) { |
237 // Stop before the start of the next function. | 266 // Stop before the start of the next function. |
238 translatedEnd = | 267 translatedEnd = |
239 v8::debug::Location(translatedStart.GetLineNumber() + 1, 0); | 268 v8::debug::Location(translatedStart.GetLineNumber() + 1, 0); |
240 } else { | 269 } else { |
241 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedEnd, | 270 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedEnd, |
242 scriptId(), v8ScriptId); | 271 scriptId(), v8ScriptId); |
243 } | 272 } |
244 | 273 |
245 bool success = script->GetPossibleBreakpoints( | 274 bool success = script->GetPossibleBreakpoints( |
246 translatedStart, translatedEnd, restrictToFunction, locations); | 275 translatedStart, translatedEnd, restrictToFunction, locations); |
247 for (v8::debug::Location& loc : *locations) { | 276 for (v8::debug::BreakLocation& loc : *locations) { |
248 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, | 277 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, |
249 scriptId()); | 278 scriptId()); |
250 } | 279 } |
251 return success; | 280 return success; |
252 } | 281 } |
253 | 282 |
254 void resetBlackboxedStateCache() override {} | 283 void resetBlackboxedStateCache() override {} |
255 | 284 |
256 int offset(int lineNumber, int columnNumber) const override { | 285 int offset(int lineNumber, int columnNumber) const override { |
257 return kNoOffset; | 286 return kNoOffset; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 if (m_hash.isEmpty()) m_hash = calculateHash(source()); | 332 if (m_hash.isEmpty()) m_hash = calculateHash(source()); |
304 DCHECK(!m_hash.isEmpty()); | 333 DCHECK(!m_hash.isEmpty()); |
305 return m_hash; | 334 return m_hash; |
306 } | 335 } |
307 | 336 |
308 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 337 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
309 m_sourceURL = sourceURL; | 338 m_sourceURL = sourceURL; |
310 } | 339 } |
311 | 340 |
312 } // namespace v8_inspector | 341 } // namespace v8_inspector |
OLD | NEW |