From e4c3b10c4b92037f6bca9628dffe5b0d0b069ea1 Mon Sep 17 00:00:00 2001 From: zhangsizheng Date: Sun, 22 Sep 2024 17:01:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCVE349248170?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangsizheng --- src/debug/debug-interface.cc | 4 +- test/inspector/inspector.status | 1 + .../regress-crbug-349248170-expected.txt | 10 ++++ .../regress/regress-crbug-349248170.js | 52 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 test/inspector/regress/regress-crbug-349248170-expected.txt create mode 100644 test/inspector/regress/regress-crbug-349248170.js diff --git a/src/debug/debug-interface.cc b/src/debug/debug-interface.cc index 684347b0f..97ea9a822 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 c74a09a3d..54e9e5823 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 000000000..72122506f --- /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 000000000..a043452e0 --- /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 -- Gitee