Graphics Programs Reference
In-Depth Information
(gdb) bt
#0 0xb7fe77f2 in ?? ()
#1 0xb7f691e1 in ?? ()
#2 0x08048ccf in main () at tinyweb.c:44
(gdb) list 44
39 if (listen(sockfd, 20) == -1)
40 fatal("listening on socket");
41
42 while(1) { // Accept loop
43 sin_size = sizeof(struct sockaddr_in);
44 new_sockfd = accept(sockfd, (struct sockaddr *)&client_addr, &sin_size);
45 if(new_sockfd == -1)
46 fatal("accepting connection");
47
48 handle_connection(new_sockfd, &client_addr);
(gdb) list handle_connection
53 /* This function handles the connection on the passed socket from the
54 * passed client address. The connection is processed as a web request
55 * and this function replies over the connected socket. Finally, the
56 * passed socket is closed at the end of the function.
57 */
58 void handle_connection(int sockfd, struct sockaddr_in *client_addr_ptr) {
59 unsigned char *ptr, request[500], resource[500];
60 int fd, length;
61
62 length = recv_line(sockfd, request);
(gdb) break 62
Breakpoint 1 at 0x8048d02: file tinyweb.c, line 62.
(gdb) cont
Continuing.
After attaching to the running process, a stack backtrace shows the pro-
gram is currenty in main() , waiting for a connection. After setting a breakpoint
at the first recv_line() call on line 62 (
), the program is allowed to continue.
At this point, the program's execution must be advanced by making a web
request using wget in another terminal or a browser. Then the breakpoint in
handle_connection() will be hit.
Breakpoint 2, handle_connection (sockfd=4, client_addr_ptr=0xbffff810) at tinyweb.c:62
62 length = recv_line(sockfd, request);
(gdb) x/x request
0xbffff5c0: 0x00000000
(gdb) bt
#0 handle_connection (sockfd=4, client_addr_ptr=0xbffff810) at tinyweb.c:62
#1 0x08048cf6 in main () at tinyweb.c:48
(gdb) x/16xw request+500
0xbffff7b4: 0xb7fd5ff4 0xb8000ce0 0x00000000 0xbffff848
0xbffff7c4: 0xb7ff9300 0xb7fd5ff4 0xbffff7e0 0xb7f691c0
0xbffff7d4: 0xb7fd5ff4 0xbffff848 0x08048cf6 0x00000004
0xbffff7e4: 0xbffff810 0xbffff80c 0xbffff834 0x00000004
(gdb) x/x 0xbffff7d4+8
0xbffff7dc: 0x08048cf6
(gdb) p 0xbffff7dc - 0xbffff5c0
Search WWH ::




Custom Search