Skip to content

debugger: Reduce global variables and expose some APIs for the debugger. #6359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

deanm
Copy link
Contributor

@deanm deanm commented Apr 24, 2016

Checklist
  • tests and code linting passes
  • the commit message follows commit guidelines
Affected core subsystem(s)

Node embedding API / startup / command line handling.

Description of change

The debugger setup is a bit complicated because of all of the cross signal handler / thread / global state. While I didn't completely remove all of the global state, I think this patch at least improves it and takes a step towards a cleaner API. This is also exposes a few additional functions required to make the debugger work from an embedder of Node that does its own startup (not via node::Start).

Reduce the amount of global state relating to starting the debugger
to just the port number, which is needed by the SIGUSR1 handler.

Expose APIs so that embedders of Node can also have some control over
the debugger setup process. SetMainIsolate is required to set the
global Isolate variable that the debugger related handlers use.
Expose StartDebug and EnableDebug for controlling the debug agent.

Remove the debug agent flag from NodeInstanceData and instead track via a
separate DebugSettings struct and plumb that through as much as possible to
remove the majority of reliance on global settings.

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Apr 24, 2016
@Fishrock123 Fishrock123 added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 24, 2016
@reshnm
Copy link
Contributor

reshnm commented Apr 25, 2016

I like this one.
It would also be nice to have an API to stop the debugger.

@estliberitas estliberitas force-pushed the master branch 2 times, most recently from 7da4fd4 to c7066fb Compare April 26, 2016 05:23
@deanm
Copy link
Contributor Author

deanm commented Apr 26, 2016

@jasnell @indutny Mind having a look? Thanks!

src/node.cc Outdated
@@ -4256,11 +4260,14 @@ Environment* CreateEnvironment(Isolate* isolate,
return env;
}

bool SetMainIsolate(v8::Isolate* isolate) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I’d like to see a comment here saying what the return value means.

@addaleax
Copy link
Member

LGTM with a few nits

@jasnell
Copy link
Member

jasnell commented Apr 29, 2016

@deanm ... not my area of expertise. /cc @bnoordhuis

@deanm deanm force-pushed the debugger-settings branch from 54bed60 to 580ef35 Compare April 29, 2016 09:26
@deanm
Copy link
Contributor Author

deanm commented Apr 29, 2016

Thanks @addaleax for the comments, updated to address all of them.

Reduce the amount of global state relating to starting the debugger
to just the port number, which is needed by the SIGUSR1 handler.

Expose APIs so that embedders of Node can also have some control over
the debugger setup process.  SetMainIsolate is required to set the
global Isolate variable that the debugger related handlers use.
Expose StartDebug and EnableDebug for controlling the debug agent.

Remove the debug agent flag from NodeInstanceData and instead track via a
separate DebugSettings struct and plumb that through as much as possible to
remove the majority of reliance on global settings.
@addaleax
Copy link
Member

Thanks! @deanm You should try to keep your commit message formatted as mentioned in the guidlines, i.e. <= 50 characters for the first line and <= 72 characters for the subsequent ones.

And agreed, it would be nice to have someone comment on this who is more familiar with the code here. It only looks good to me because it’s just moving code around to reduce global state, which is almost always a good idea.

@addaleax
Copy link
Member

@deanm Sorry for the delays, but this needs to be rebased against master.

@@ -4256,11 +4260,16 @@ Environment* CreateEnvironment(Isolate* isolate,
return env;
}

// Returns true if the isolate field was previously null, otherwise returns
// false if there was another current main isolate value that was overwritten.
bool SetMainIsolate(v8::Isolate* isolate) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to qualify, v8::Isolate is imported at the top.

@bnoordhuis
Copy link
Member

I personally don't think it's a good idea to expose debugger details in src/node.h. The implementation is probably going to change quite a bit when multi-isolate support is added.

@deanm
Copy link
Contributor Author

deanm commented May 19, 2016

@bnoordhuis Do you have a suggestion for an alternative approach? Right now there are not so many details exposed, just start/stop, etc. Currently there is not a way to get the debugger working when embedding node.

@bnoordhuis
Copy link
Member

@deanm I think your best best for now is to float this patch. I'll be working on multi-isolate support this development cycle and I hope to get it into v7. I'll keep the embedder + debugger use case in mind.

@rvagg rvagg force-pushed the master branch 2 times, most recently from c133999 to 83c7a88 Compare October 18, 2016 17:01
@jkrems
Copy link
Contributor

jkrems commented Dec 13, 2016

Linking to node-inspect issue because this PR might be affected by the potential removal of the debugger code.

nodejs/diagnostics#67

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Jan 6, 2017
@jasnell
Copy link
Member

jasnell commented Jan 6, 2017

Is this something we'd do at all now given that the old debugger is being removed / deprecated?

@deanm
Copy link
Contributor Author

deanm commented Jan 6, 2017

I haven't had a chance to follow the debugger related changes, but saw that Node now integrates with Chrome's dev tools. Sorry for asking such a basic question, but is there sort of an overview discussion somewhere about all of the changes, and what that means for embedding Node?

@addaleax
Copy link
Member

addaleax commented Jan 6, 2017

@deanm It’s probably best to raise your questions/concerns at the https://github.com/nodejs/diagnostics issue tracker, I’d guess?

@deanm
Copy link
Contributor Author

deanm commented Jan 23, 2017

I had a look at some of the changes around the new inspect tools. I don't think that really eliminates the need for what this patch was trying to do. From what I can tell, even with the new inspect debugger functionality, you still have a similar process of parsing the command line arguments, decide if/when/how to start the debugger, etc.

For embedders of node, this functionality should still be exposed, there is still the process of startup (StartDebug, EnableDebug), shutdown (WaitForInspectorDisconnect), etc, which is currently not available outside of node's internal Start in node.cc.

When I wrote the original Node embedding APIs (f67e8f2), the intention was to allow an embedder the ability to write their own Start, meaning to run their own event loop (as it might need to integrate it with other things), etc.

An alternative would be to basically take the do/while event pump loop out of Start() and into a function that is passed in to start, allowing an embedder to supply an alternate main pump loop. I think either approach would be okay from my perspective, but it is essential that somehow embedding applications are able to implement a custom event loop.

I can draft up an example of passing a pump function through Start()...

@bnoordhuis
Copy link
Member

Making the event loop driver/pump configurable sounds like a decent idea.

@jasnell
Copy link
Member

jasnell commented Mar 1, 2017

should this remain open?

@bnoordhuis
Copy link
Member

The debugger changes probably can't land since we're phasing it out. Reshuffling to make embedding easier is still acceptable and a good idea but perhaps we can move that to a separate PR.

@Trott
Copy link
Member

Trott commented Aug 16, 2017

@deanm Should this remain open? Are you going to try to rework it for current Node.js? Can you rebase? Or is this something you're unlikely to come back to?

@bnoordhuis
Copy link
Member

I'll close this out because the debugger has been removed.

@deanm A PR to ease embedding is still welcome.

@bnoordhuis bnoordhuis closed this Aug 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. semver-minor PRs that contain new features and should be released in the next minor version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants