[wasm][debug] Fix OSR at stack check

Add missing source position for stack check, used by OSR to find the
correct return address.

R=clemensb@chromium.org

Bug: v8:10235
Change-Id: Ie26dd3b2079168e846f84b3a4ffe18b838649be7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2339625
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69309}
diff --git a/src/wasm/baseline/liftoff-compiler.cc b/src/wasm/baseline/liftoff-compiler.cc
index 97ef25b..f97c05f 100644
--- a/src/wasm/baseline/liftoff-compiler.cc
+++ b/src/wasm/baseline/liftoff-compiler.cc
@@ -728,7 +728,7 @@
     }
 
     source_position_table_builder_.AddPosition(
-        __ pc_offset(), SourcePosition(ool->position), true);
+        __ pc_offset(), SourcePosition(ool->position), false);
     __ CallRuntimeStub(ool->stub);
     DCHECK_EQ(!debug_sidetable_builder_, !ool->debug_sidetable_entry_builder);
     if (V8_UNLIKELY(ool->debug_sidetable_entry_builder)) {
@@ -738,10 +738,10 @@
     DCHECK_EQ(ool->continuation.get()->is_bound(), is_stack_check);
     if (!ool->regs_to_save.is_empty()) __ PopRegisters(ool->regs_to_save);
     if (is_stack_check) {
-      // TODO(thibaudm): If the top frame is OSR'ed during stack check,
-      // execution will resume at the next instruction, skipping the following
-      // register reloads.
       if (V8_UNLIKELY(ool->spilled_registers != nullptr)) {
+        DCHECK(for_debugging_);
+        source_position_table_builder_.AddPosition(
+            __ pc_offset(), SourcePosition(ool->position), true);
         for (auto& entry : ool->spilled_registers->entries) {
           __ Fill(entry.reg, entry.offset, entry.type);
         }
diff --git a/test/inspector/debugger/wasm-stack-check-expected.txt b/test/inspector/debugger/wasm-stack-check-expected.txt
index 6f8ce56..4868b3e 100644
--- a/test/inspector/debugger/wasm-stack-check-expected.txt
+++ b/test/inspector/debugger/wasm-stack-check-expected.txt
@@ -5,4 +5,8 @@
 Run
 Expecting to pause at 61
 Paused at offset 61; local: [12]; wasm-expression-stack: []
+Paused at offset 62; local: [12]; wasm-expression-stack: []
+Paused at offset 64; local: [12]; wasm-expression-stack: [12]
+Paused at offset 66; local: [12]; wasm-expression-stack: [12, 1]
+Paused at offset 67; local: [12]; wasm-expression-stack: [13]
 Finished!
diff --git a/test/inspector/debugger/wasm-stack-check.js b/test/inspector/debugger/wasm-stack-check.js
index 30af0a1..7963ab2 100644
--- a/test/inspector/debugger/wasm-stack-check.js
+++ b/test/inspector/debugger/wasm-stack-check.js
@@ -46,12 +46,11 @@
 
   InspectorTest.log('Run');
   Protocol.Runtime.evaluate({expression: 'instance.exports.main()'});
-  // TODO(thibaudm): Fix source position and OSR at stack checks.
   InspectorTest.log('Expecting to pause at ' + (f.body_offset - 1));
-  // await waitForPauseAndStep('stepInto');
-  // await waitForPauseAndStep('stepInto');
-  // await waitForPauseAndStep('stepInto');
-  // await waitForPauseAndStep('stepInto');
+  await waitForPauseAndStep('stepInto');
+  await waitForPauseAndStep('stepInto');
+  await waitForPauseAndStep('stepInto');
+  await waitForPauseAndStep('stepInto');
   await waitForPauseAndStep('resume');
   InspectorTest.log('Finished!');
   InspectorTest.completeTest();