diff --git a/src/debug/debug-interface.cc b/src/debug/debug-interface.cc index 684347b0f09a05143c8d71b67fde6340d0c8322f..97ea9a822cfc1a646342c17cc2736194a4d6ee36 100644 --- a/src/debug/debug-interface.cc +++ b/src/debug/debug-interface.cc @@ -475,8 +475,8 @@ int Script::GetSourceOffset(const Location& location) const { i::Handle script = Utils::OpenHandle(this); #if V8_ENABLE_WEBASSEMBLY if (script->type() == i::Script::TYPE_WASM) { - DCHECK_EQ(0, location.GetLineNumber()); - return location.GetColumnNumber(); + return location.GetLineNumber() == 0 ? Just(location.GetColumnNumber()) + : Nothing(); } #endif // V8_ENABLE_WEBASSEMBLY diff --git a/test/inspector/inspector.status b/test/inspector/inspector.status index c74a09a3dee42f2716eff4840e6e421e75981804..54e9e5823c785bd060e4b125cf788ae5981446fc 100644 --- a/test/inspector/inspector.status +++ b/test/inspector/inspector.status @@ -58,6 +58,7 @@ 'debugger/wasm-*': [SKIP], 'cpu-profiler/console-profile-wasm': [SKIP], 'runtime/get-properties': [SKIP], + 'regress/regress-crbug-349248170': [SKIP], }], # not has_webassembly or variant == jitless ############################################################################## diff --git a/test/inspector/regress/regress-crbug-349248170-expected.txt b/test/inspector/regress/regress-crbug-349248170-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..72122506f5118d44ec0c27707cb55dc6666b6593 --- /dev/null +++ b/test/inspector/regress/regress-crbug-349248170-expected.txt @@ -0,0 +1,10 @@ +Don't crash when using non-zero line number to set WASM breakpoint +Waiting for wasm script to be parsed. +Setting breakpoint in wasm. +{ + error : { + code : -32000 + message : Could not resolve breakpoint + } + id : +} \ No newline at end of file diff --git a/test/inspector/regress/regress-crbug-349248170.js b/test/inspector/regress/regress-crbug-349248170.js new file mode 100644 index 0000000000000000000000000000000000000000..a043452e07b22a22228d5cd5dbfc2de7bf539996 --- /dev/null +++ b/test/inspector/regress/regress-crbug-349248170.js @@ -0,0 +1,52 @@ +// Copyright 2024 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. + +// Adapted test from 'inspector/debugger/wasm-externref-global.js' + +utils.load('test/inspector/wasm-inspector-test.js'); + +const {session, contextGroup, Protocol} = + InspectorTest.start('Don\'t crash when using non-zero line number to set WASM breakpoint'); + +(async () => { + let builder = new WasmModuleBuilder(); + builder.addImportedGlobal('m', 'global', kWasmExternRef, false); + let func = builder.addFunction('func', kSig_v_v) + .addBody([ + kExprGlobalGet, 0, // + kExprDrop, // + ]) + .exportAs('main'); + let moduleBytes = JSON.stringify(builder.toArray()); + + function test(moduleBytes) { + let module = new WebAssembly.Module((new Uint8Array(moduleBytes)).buffer); + let global = 'hello, world'; + instance = new WebAssembly.Instance(module, { m: { global } }); + } + + Protocol.Debugger.enable(); + Protocol.Runtime.evaluate({ + expression: ` + let instance; + ${test.toString()} + test(${moduleBytes});` + }); + + InspectorTest.log('Waiting for wasm script to be parsed.'); + let scriptId; + while (true) { + let msg = await Protocol.Debugger.onceScriptParsed(); + if (msg.params.url.startsWith('wasm://')) { + scriptId = msg.params.scriptId; + break; + } + } + + InspectorTest.log('Setting breakpoint in wasm.'); + InspectorTest.logMessage(await Protocol.Debugger.setBreakpoint( + { location: { scriptId, lineNumber: 42, columnNumber: func.body_offset } })); + + InspectorTest.completeTest(); +})(); \ No newline at end of file