Tuesday 23 February 2016

Core dumps are the most important way to debug a crashing program. Why aren't they supported in Node?

I'm an embedded developer using Node for my next app. One thing that absolutely terrifies me is the lack of decent post-mortem debugging options, especially since my code runs on offline/isolated machines.Explanation of core dumps for those that don't know You know how when you're using Node Inspector and put a debugger breakpoint, you can see (and navigate) the stack, as well as see the value of all the local variables in the current scope? A core file is a debugger breakpoint that's automatically generated for you when your application crashes, at the exact line where it crashed. I can't think of anything more easy to debug than "the program crashed at this exact line, and here's a debugger breakpoint and all the info you need to fix it, including backtrace and locals". This makes all but the worst bugs trivial to fix. When writing native code, using core dumps is trivial: on Linux, enable them with "ulimit -c unlimited", let the app crash and generate a core file, then load the core file in your debugger. End explanationI can still do this for Node, by adding a handler to process' uncaughtException' event which calls process.abort(), or dumping a core file on-demand. However, the generated core file is a V8 program, and I don't know how to turn that into something relevant to me as a Node dev. I don't care about the V8 backtrace/locals, I care about the Node backtrace/locals.I'm surprised Node lacks official support for something this useful, i.e. a way to turn that V8 dump into a Node dump. A mere printing of the backtrace is not enough, it just points you in the general direction of the problem. It requires you to look up functions manually, and usually to write lots of logging statements to trace values and such. It's just a big painful question mark when a bug is hard to reproduce. Compare that to the automatic magic of core dumps.I know the Linux+Native ecosystem is a lot more evolved than Node's, and that's why I have that free magic. It's just disappointing that debugging is now harder for me in a more productive high-level language. I fear once I've shipped my first app, I'll have to deal with rough bugs that will take more time to solve than I saved by using Node.

Submitted February 23, 2016 at 08:41PM by MachinTrucChose

No comments:

Post a Comment