GDB를 이용한 디버깅
Debugging Under Unix: gdb Tutorial
실행 중인 process에 attach
$ gdb - `pidof PROCESS이름`
gdb 를 통한 디버깅 따라하기
GDB 사용법
var http = require("http"); function start() { function onRequest(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); } http.createServer(onRequest).listen(8888); console.log("Server has started."); } exports.start = start;http server를 사용해서 hello world를 만들 것이므로
var server = require("./server"); server.start();다른 js파일을 내장 모듈 불러오듯 require를 사용해서 불러오고 export된 함수를 사용.
url.parse(string).query | url.parse(string).pathname | | | | | ------ ------------------- http://localhost:8888/start?foo=bar&hello=world --- ----- | | | | querystring(string)["foo"] | | querystring(string)["hello"]
var http = require("http"); var url = require("url"); function start(route, handle) { function onRequest(request, response) { var pathname = url.parse(request.url).pathname; console.log("Request for " + pathname + " received."); route(handle, pathname); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); } http.createServer(onRequest).listen(8888); console.log("Server has started."); } exports.start = start;기본 hello world server에서 변경된 점은
function route(handle, pathname) { console.log("About to route a request for " + pathname); if (typeof handle[pathname] === 'function') { handle[pathname](); } else { console.log("No request handler found for " + pathname); } } exports.route = route;hanlder들 중에서 pathname의 key를 가진 function object를 찾아서 실행함.
var server = require("./server"); var router = require("./router"); var requestHandlers = require("./requestHandlers"); var handle = {} handle["/"] = requestHandlers.start; handle["/start"] = requestHandlers.start; handle["/upload"] = requestHandlers.upload; server.start(router.route, handle);url path에 따른 handler들을 매핑한 뒤