© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	
Node.js post-mortem
debugging with mdb and
SmartOS
1
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Node.js
var http = require('http');	
http.createServer(function (req, res) {	
res.writeHead(200, {'Content-Type': 'text/plain'});	
res.end('Hello Worldn');	
}).listen(4242, '127.0.0.1');
Platform built on top of Chrome's JavaScript runtime for easily
building fast, scalable network applications.
2
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Debugging challenge
3
“My application crashes
randomly every few days,
what’s going on?”
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Common debugging tools
• Live debuggers
• How to reproduce the bug in a timely manner?

• Application cannot restart until investigation done.

• No knowledge of both native and JavaScript layer.

• Logging/Tracing
• What if the information you need was not logged?
4
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Post-mortem debugging
• OS generates a “photograph” of the program when
it crashes for later inspection with debugger.
• Application can restart right away: minimal
downtime.
• Does not require developers to know when a bug or
crash will happen.
• Investigation can happen at anytime, any number of
times, by anyone.
• Great for debugging rare bugs and production
issues!
5
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Node.js internals
6
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
mdb on SmartOS
• Understands native and JavaScript layers.
• Useful JavaScript specific commands
like ::findjsobjects and ::jsprint.
• ::findjsobjects -r to find which objects reference
which, useful for investigating memory leaks.
• Commands can be piped to other mdb commands
or to other UNIX programs.
7
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Other use cases
• Finding memory leaks.
• Investigating 100% CPU utilization issues.
• DTrace with mdb.
8
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Other platforms
• Work on support for platforms with lldb support:
https://github.com/tjfontaine/lldb-v8.
• Using mdb to load Linux core files: http://
www.joyent.com/blog/mdb-and-linux.
9
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
The workshop
10
© 2015 Joyent, Inc.	 	 	 	 	 	 Proprietary & Confidential Information of Joyent, Inc.	 	 	 	 	 		
	 	 .
Learn more
• Join us for the workshop tonight :)
• npm install -g node-debug-school or git clone
https://github.com/joyent/node-debug-school.
• https://www.joyent.com/developers/node/debug/
mdb.
• @misterdjules.
11

Node.js post-mortem debugging with mdb and SmartOS

  • 1.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. Node.js post-mortem debugging with mdb and SmartOS 1
  • 2.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Node.js var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(4242, '127.0.0.1'); Platform built on top of Chrome's JavaScript runtime for easily building fast, scalable network applications. 2
  • 3.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Debugging challenge 3 “My application crashes randomly every few days, what’s going on?”
  • 4.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Common debugging tools • Live debuggers • How to reproduce the bug in a timely manner? • Application cannot restart until investigation done. • No knowledge of both native and JavaScript layer. • Logging/Tracing • What if the information you need was not logged? 4
  • 5.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Post-mortem debugging • OS generates a “photograph” of the program when it crashes for later inspection with debugger. • Application can restart right away: minimal downtime. • Does not require developers to know when a bug or crash will happen. • Investigation can happen at anytime, any number of times, by anyone. • Great for debugging rare bugs and production issues! 5
  • 6.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Node.js internals 6
  • 7.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . mdb on SmartOS • Understands native and JavaScript layers. • Useful JavaScript specific commands like ::findjsobjects and ::jsprint. • ::findjsobjects -r to find which objects reference which, useful for investigating memory leaks. • Commands can be piped to other mdb commands or to other UNIX programs. 7
  • 8.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Other use cases • Finding memory leaks. • Investigating 100% CPU utilization issues. • DTrace with mdb. 8
  • 9.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Other platforms • Work on support for platforms with lldb support: https://github.com/tjfontaine/lldb-v8. • Using mdb to load Linux core files: http:// www.joyent.com/blog/mdb-and-linux. 9
  • 10.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . The workshop 10
  • 11.
    © 2015 Joyent,Inc. Proprietary & Confidential Information of Joyent, Inc. . Learn more • Join us for the workshop tonight :) • npm install -g node-debug-school or git clone https://github.com/joyent/node-debug-school. • https://www.joyent.com/developers/node/debug/ mdb. • @misterdjules. 11