Issue 9096 in v8: Debugger.setScriptSource usage with Node.js does not work.

78 views
Skip to first unread message

jpahe… via monorail

unread,
Apr 5, 2019, 10:00:03 AM4/5/19
to v8-re...@googlegroups.com
Status: Untriaged
Owner: ----
Type: Bug

New issue 9096 by jpahe...@gmail.com: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096

Version: Node.js version 8
OS: Windows 10
Architecture: x86-64

In the following post Alexei Filippov requested that I open an issue here as I might have found a bug:

https://groups.google.com/forum/m/?utm_medium=email&utm_source=footer#!topic/chrome-debugging-protocol/KME12JMj3Ps

I should mention that I’m using Node.js version 8. I’m currently out of the office this week but on Monday I will verify the issue on Node.js version 10 as well. I should also mention that when I try my scenario from within Chrome Debugger all works fine. As I mention in my post things aren’t working from my client that is connected to Node.js via a web socket when it makes the call to Debugger.setScriptSource. I assume you have a client or unit tests that could do the same.

In the aforementioned post, I briefly describe the scenario I use to hit the issue. I will expand on those details here, but the issue doesn’t seem to be specific to one specific scenario. I’ve tried many ways to get Debugger.setScriptSource to work to no avail. I’ve had no success getting the updated source to be executed by the VM.

My scenario is pretty simple, which leads me to believe that I’m doing something wrong as opposed to a bug. :-) Anyway, here is what I do:

1. My Debugger client starts Node.js with --inspect-brk and connects to the websocket provided by node.
2. My client makes the necessary calls to Debugger and Runtime to enable them.
3. My client then sets a breakpoint on my application .js file.
4. My .js file is trivial and the details of it are not of any particular importance. Simple take a .js file with say 10 or so lines of console.logs (or any executable code) or such where a breakpoint has been set on say line 6 (or any line).
5. Once the “break on start” pause is hit send the resume command to node.
6. Once the breakpoint at line 6 is hit, edit the .js file to remove most, say 9, of the console.log entries. In other words remove all but the first line or two of executable code. You could even change the output printed by the console.log.
7. Save the source and send it to node by using Debugger.setScriptSource.
8. Notice the confirmation result message from node that the command worked.
9. Further verify things by calling Debugger.getScriptSource and notice the updated code sent in step #7. So far all works as expected!
10. Send the resume command to node which will allow it to run to completion.
11. Notice the console.log entries from line 6-10 are printed, NOT the updated source!

Am I missing something? In this case shouldn’t my one or two lines of updated code be executed, not lines 6-10 of the previous script source?

Please let me know if you need anything. I’d be more than happy to send you the logs from my client which shows exactly what I send to node and what I receive.

Thanks,

Heath Thomann

--
You received this message because:
1. The project was configured to send all issue notifications to this address

You may adjust your notification preferences at:
https://bugs.chromium.org/hosting/settings

a… via monorail

unread,
Apr 8, 2019, 3:05:30 PM4/8/19
to v8-re...@googlegroups.com
Updates:
Components: Inspector
Status: Available

Comment #1 on issue 9096 by al...@chromium.org: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c1

Hi Heath,

Thanks for the report. Can you please provide the exact JS source code you're live-editing. Provided the feature works in general, the issue is probably related to a specific JS usage in the code.

Ideally, we would like to end up with a test case like one here:
https://cs.chromium.org/chromium/src/v8/test/inspector/debugger/set-breakpoint-after-liveedit.js?dr=C&g=0

jpahe… via monorail

unread,
Apr 8, 2019, 7:37:15 PM4/8/19
to v8-re...@googlegroups.com

Comment #2 on issue 9096 by jpahe...@gmail.com: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c2

HI! Thanks for the response!! Unfortunately I am not at all familiar with the test case example and framework you pointed me to so there is no possible way I can create a test case similar to the one you suggest. I could give you general code that hopefully you could translate into something that fits you framework.

Before doing that, lets first answer one question: should live edit work on Node.js using the V8 inspector protocol (Chrome DevTools Protocol)? I know this might be a silly question but I’ve seen some stuff on the web that implies it might not work. Furthermore, my test is so simple that it should work, or I’m doing something wrong.

If the answer to this question is ‘yes’ (i.e. Node.js CAN be lived edited through V8 Inspector), then I’ll go forth with another post that provide some simple code. If 'no', then I guess we are done.

Sincerely,

Heath Thomann

dgoz… via monorail

unread,
Apr 8, 2019, 8:21:11 PM4/8/19
to v8-re...@googlegroups.com

Comment #3 on issue 9096 by dgo...@chromium.org: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c3

Node.js supports live edit starting with version 8. Versions 8, 9 and 10 contain the older live edit implementation, matching Chrome up to version 71. Versions 11 and higher have a newer live edit implementation, which supposedly works better in multiple cases.

jpahe… via monorail

unread,
Apr 9, 2019, 2:31:58 PM4/9/19
to v8-re...@googlegroups.com

Comment #4 on issue 9096 by jpahe...@gmail.com: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c4

HI! So, it looks maybe I’ve figured out things here and I think there were two things involved here: 1) My ignorance with the way the protocol works being an outsider and new to it and 2) THE VERY POORLY DOCUMENTED PROTOCOL!!!!!!!!! If you look here:

https://chromedevtools.github.io/devtools-protocol/v8/Debugger#method-setScriptSource

You’ll see that all it states is “Edits JavaScript source live.”. And it provides among others a “scriptSource” field. Great I thought initially, all I have to do is set the new source for a given script id. Easy. So, as an example if I have file x.js that does nothing other than:

console.log(‘hello’);

If I simply wanted to change ‘hello’ to ‘hello world’ I thought that all I had to do was call Debugger.setScriptSource passing the one line updated script source to ‘console.log(‘hello world’)’ using the script id for x.js. Doing this doesn’t give an error and doing a Debugger.getScriptSource returned my updated source. All seemed well! But during execution ‘hello’ was logged to the console, not ‘hello world’. I just figured out that if I sent the following as the new source:

(function (exports, require, module, __filename, __dirname) {
console.log(‘hello world’);
})

My updated source would be executed (i.e. I’d get ‘hello world’ logged as I hopped). Is this correct? Do we always have to add the ‘function’ line any time we update any source script? Anything else needed?
Finally, from the protocol documentation, how was I supposed to know this???? While creating my debugger I’ve had a really hard time figuring things out due to the fact that the Chrome DevTools provides so little doc details! Come on Google, I expect better!

Sincerely,

Heath Thomann

k… via monorail

unread,
Apr 9, 2019, 2:37:58 PM4/9/19
to v8-re...@googlegroups.com

Comment #5 on issue 9096 by ko...@chromium.org: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c5

It is very nice finding. DevTools frontend shows source without Node.js wrapper, I am not sure that we add this wrapper back before sending updated source to backend..

k… via monorail

unread,
Apr 9, 2019, 2:43:23 PM4/9/19
to v8-re...@googlegroups.com

Comment #6 on issue 9096 by ko...@chromium.org: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c6

When Node.js executed your script from x.js, it actually wraps content of script with module wrapper [1], so real script looks different from just x.js file content.
So it is better to get current script source using Debugger.getScriptSource first, edit it and then send edited version using Debugger.setScriptSource, in this case you definitely will use proper module wrapper.
[1] https://nodejs.org/api/modules.html#modules_the_module_wrapper

jpahe… via monorail

unread,
Apr 9, 2019, 3:05:44 PM4/9/19
to v8-re...@googlegroups.com

Comment #7 on issue 9096 by jpahe...@gmail.com: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c7

Thank you very much for you help and suggestions. For now, I think we can chalk this up to user error rather than bug. ;-)

dgoz… via monorail

unread,
Apr 15, 2019, 5:09:55 PM4/15/19
to v8-re...@googlegroups.com
Updates:
Status: WontFix

Comment #8 on issue 9096 by dgo...@chromium.org: Debugger.setScriptSource usage with Node.js does not work.
https://bugs.chromium.org/p/v8/issues/detail?id=9096#c8

Great, let me mark as WontFix then :)
Reply all
Reply to author
Forward
0 new messages