-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Please document the current debugging protocol between an IDE and Node.js (--inspect
)
#24025
Comments
How close comes https://chromedevtools.github.io/devtools-protocol/ to what you are looking for? It sounds like you’re interested more in the underlying message format for transport than the protocol itself? (I think the answer in that case would be pretty close to “WebSocket messages”, but I’m not sure.) |
Close to none? |
You can look at https://github.com/nodejs/node-inspect for a simple working debug client. https://github.com/nodejs/node/blob/98819dfa5853d7c8355d70aa1aa7783677c391e5/deps/v8/src/inspector/js_protocol.json describes the protocol. |
If we put a side the debugger client implementation language (in my case its C++).
So it goes something like this:
and on another terminal, I used
A connection is established successfully. Thanks! |
@eranif perhaps this guide is what you are looking for: https://nodejs.org/en/docs/guides/debugging-getting-started/ ? It has a section for |
@AyushG3112 thanks, this page is about how to debug your Node.js application. This is not what I am looking for. I am trying to implement a debugger interaface in my IDE (see my initial comment). |
@eranif VSCode is doing what you are looking for, debugging node js apps, so i guess he is using the new api. |
@eranif You are right in that we don't have a step by step guide for howto use the inspector protocol. We do have some direct examples in our test suite:
If you find this information useful, you could submit a PR, as I assume others will find it useful in the future. P.S. you could also use a MITM proxy and see how DevTools etc. talk to node. |
Ping @jkrems |
You can run
The code for the inspect protocol connection can be found here, including the websocket decoding: https://github.com/nodejs/node-inspect/blob/master/lib/internal/inspect_client.js#L60. The websocket code in the command line debugger is actually reverse engineered from its C++ counterpart here: https://github.com/nodejs/node/blob/8b4af64f50c5e41ce0155716f294c24ccdecad03/src/inspector_socket.cc |
Thank you! It's now just matter of replacing the old driver with the new one and I am good to go :) I will upload a working C++ example of how to connect to Node.js and execute a debug session for other people who might find it useful as I did. Here is the snippet that allows me to connect to the Node.js and initiate the debugging session (putting here for future / search references for other people): // No boost or other external libraries, just plain old good C++11
#define ASIO_STANDALONE 1
#define _WEBSOCKETPP_CPP11_THREAD_ 1
#include <websocketpp/client.hpp>
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <iostream>
#include <sstream>
typedef websocketpp::client<websocketpp::config::asio_client> client;
using websocketpp::lib::bind;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
// pull out the type of messages sent by our config
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
// This message handler will be invoked once for each incoming message
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg)
{
std::cout << "on_message called with hdl: " << hdl.lock().get() << " and message: " << msg->get_payload()
<< std::endl;
}
static void send_startup_command(client* c, websocketpp::connection_hdl hdl, const std::string& method)
{
static int i = 0;
std::stringstream ss;
ss << "{\"id\":" << (++i) << ",\"method\":\"" << method << "\"}";
websocketpp::lib::error_code ec;
c->send(hdl, ss.str(), websocketpp::frame::opcode::TEXT, ec);
}
void on_open_handler(client* c, websocketpp::connection_hdl hdl)
{
std::cout << "on_open_handler called" << std::endl;
// Send upgrade request
send_startup_command(c, hdl, "Runtime.enable");
send_startup_command(c, hdl, "Debugger.enable");
send_startup_command(c, hdl, "Runtime.runIfWaitingForDebugger");
}
int main(int argc, char* argv[])
{
// Create a client endpoint
client c;
if(argc < 2) {
std::cerr << "Usage: " << argv[0] << " <WebSocker URI>" << std::endl;
return 1;
}
std::string uri = argv[1];
try {
// Set logging to be pretty verbose (everything except message payloads)
c.set_access_channels(websocketpp::log::alevel::all);
c.clear_access_channels(websocketpp::log::alevel::frame_payload);
// Initialize ASIO
c.init_asio();
// Register our message handler
c.set_message_handler(bind(&on_message, &c, ::_1, ::_2));
c.set_open_handler(bind(&on_open_handler, &c, ::_1));
websocketpp::lib::error_code ec;
client::connection_ptr con = c.get_connection(uri, ec);
if(ec) {
std::cout << "could not create connection because: " << ec.message() << std::endl;
return 0;
}
// Note that connect here only requests a connection. No network messages are
// exchanged until the event loop starts running in the next line.
c.connect(con);
// Start the ASIO io_service run loop
// this will cause a single connection to be made to the server. c.run()
// will exit when this connection is closed.
c.run();
} catch(websocketpp::exception const& e) {
std::cout << e.what() << std::endl;
}
} |
HI! I agree that the DevTools Protocol View docs (https://chromedevtools.github.io/devtools-protocol/v8) leave much to be desired. Don't get me wrong, now that I've gotten over a few hurdles and have been using it, I'm mostly happy with the docs. But as a newbie, it was a challenge. First, an example use case of a web socket client showing how to connect and how to make a few of the basic methods would be good. Second, technical accuracy would be good. I've found some things are returned that aren't documented, and other times things are not returned that are documented. Finally, getting the variable values has not be clear. One would think there would be a dedicated method just to get the variable values associated with a stack. But it seems like I have to call a not-so-obvious Runtime domain method, parse a ton of json and then use some of the values from the json to make more Runtime domain calls. As I keep digging maybe I'll find something obvious. Anyway, I don't want to sound overly negative, overall the docs are good, but going forward more focus on details and accuracy would be good. |
Docs can always be better. :) Though I think that documenting it on the node side is dangerous because the protocol isn't controlled by node. It's a V8 protocol and/or a Chrome protocol. The good news is that you can use the same implementation to allow users to remotely debug a Chrome instance (and some other kinds of processes by now). The bad news is that we're "just" consumers of this protocol and node isn't really where the biggest experts can be found. :) In general issues with the documentation of the Chrome protocol could be filed here: https://github.com/ChromeDevTools/devtools-protocol/issues |
@hthomann I plan on writing a beginners document once I have my implementation done. About the variables: I am still not sure how to get list of all locals + function arguments, but once you have the variable name (or expression) it basically using 2 methods: |
HI! OK, I'm finding a spot where the docs are very much lacking. :) Take a call to Runtime.getProperties. This will return an array or PropertyDescriptor (PD). If we look at PD, it can contain a RemoteObject (RO), where the RO seems to be at the heart of the PD. BUT, RO is listed as optional. It would be nice to know under what conditions it might not exist, and if it does’t exist what we should look at instead. |
I think that improved documentation is always desirable, but this isn't Node.js's protocol to document. I'm going to close this. (A pull request putting some of the links above in appropriate places in our docs would be welcome.) |
(And even though this is closed, continued relevant comments and questions are fine. Not trying to shut down conversation about the protocol. Just trying to be realistic about whether or not Node.js is going to document it.) |
You can also use built in Protocol Monitor within DevTools while connecting to the NodeJS debugger. https://twitter.com/ChromeDevTools/status/983768645967818753 |
Is your feature request related to a problem? Please describe.
Yes. My name is Eran and I am the author of CodeLite IDE. Up until version ~7 we had a working Node.js debugger using the old API. Since the version 8.X (I think) the API was deprecated and it is recommended to use the new DevTools protocol :/
HOWEVER, for the love of god, I searched the web for 2 days and could not find an example of how to establish a connection to the Node.js or something that describes how the debug session is executed (flow of messages between Node.js and the IDE)
Describe the solution you'd like
Can you please provide such a document? or maybe a simple working example? (can be in any language you choose)
Here is for example, how the XDebug
DBGP
protocol is documented (using this protocol could have made Node.js Debuggable from many existing IDEs, thus providing a great choice of tools to your user base)https://xdebug.org/docs-dbgp.php#description
Thanks!
The text was updated successfully, but these errors were encountered: