Re: How to debug wget ?

2008-09-02 Thread Micah Cowan
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jinhui Li wrote:
 I am browsing the source code. And want to debug it to figure out how it
 works.
 
 So, somebody please tell me how to debug ( with GDB ) or where can I
 find information that I need.

IMO, GDB is a great tool for diagnosing a particular problem one
encounters with a program; it's not all that terribly useful for
actually understanding the code itself, though. I find it much quicker
to read through the code using a powerful viewer or editor, and making
use of tools such as cscope and ctags. The best editors, such as Vim and
Emacs, are integrated these tools, and so a simple control-click or key
combination can bring up the definition of the function being called or
the variable being referenced, or (in the case of cscope) the list of
places where a particular function is being called, etc.

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
http://micah.cowan.name/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIvcPD7M8hyUobTrERAsCEAJ9oQDJWzD/OPAvzvgJorlByd4YqyACfdLM1
GmQUVu/xnQ7HOr493hiWG28=
=0XwB
-END PGP SIGNATURE-


Re: How to debug wget ?

2008-09-01 Thread Saint Xavier
Hi
* Jinhui Li ([EMAIL PROTECTED]) wrote:
 I am browsing the source code. And want to debug it to figure out how it
 works.

 So, somebody please tell me how to debug ( with GDB ) or where can I find
 information that I need.

Compile Wget with debug informations (-g flag for GCC) and then run wget into
GDB. You can now use and see variables name, structs, function name instead
of unfriendly adresses and raw bytes, ...

I can't show every aspect of GDB. Use your favorite search engine for
more usage info.

Hints:
http://www.gnu.org/software/gdb/documentation/
http://www.google.com/search?hl=enq=gdb+howtobtnG=Search

Quick example:
$ CFLAGS=-g ./configure
$ make
$ cd src/
$ gdb ./wget
(gdb) set args -P tmpdir/ -p www.google.com
(gdb) break retrieve_url
Breakpoint 1 at 0x420260: file retr.c, line 601.
(gdb) break url_parse
Breakpoint 2 at 0x4231a0: file url.c, line 644.
(gdb) run
Starting program: /home/xav/xav/sxav/src/wget -P tmpdir/ -p www.google.com
[Thread debugging using libthread_db enabled]
[New Thread 0x7f1ad48566e0 (LWP 6580)]
[Switching to Thread 0x7f1ad48566e0 (LWP 6580)]

Breakpoint 2, url_parse (url=0x665810 http://www.google.com;, 
error=0x7fffdc866aa0, iri=0x665830) at url.c:644
644 {
(gdb) continue
Continuing.

Breakpoint 1, retrieve_url (origurl=0x665ae0 http://www.google.com/;, 
file=0x7fffdc866a70, newloc=0x7fffdc866a78, refurl=0x0, dt=0x7fffdc866a98, 
recursive=false, iri=0x665830) at retr.c:601
601 {
(gdb) bt
#0  retrieve_url (origurl=0x665ae0 http://www.google.com/;, 
file=0x7fffdc866a70, newloc=0x7fffdc866a78, refurl=0x0, dt=0x7fffdc866a98, 
recursive=false, iri=0x665830) at retr.c:601
#1  0x0041ed48 in retrieve_tree (start_url=0x665810 
http://www.google.com;, pi=0x0) at recur.c:292
#2  0x0041bc31 in main (argc=5, argv=0x7fffdc866d28) at main.c:1201
(gdb) p iri
$1 = (struct iri *) 0x665830
(gdb) p *iri
$2 = {uri_encoding = 0x665850 UTF-8, content_encoding = 0x0, utf8_encode = 
false}
(gdb) p iri-uri_encoding
$3 = 0x665850 UTF-8
(gdb) continue
Continuing.

Breakpoint 2, url_parse (url=0x665b20 http://www.google.com/;, 
error=0x7fffdc8669e0, iri=0x665830) at url.c:644
644 {
(gdb) continue
Continuing.
--2008-09-01 14:57:15--  http://www.google.com/
Resolving www.google.com (www.google.com)... 66.249.93.99
Connecting to www.google.com (www.google.com)|66.249.93.99|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.be/ [following]

Breakpoint 2, url_parse (url=0x669660 http://www.google.be/;, 
error=0x7fffdc8669e0, iri=0x665830) at url.c:644
644 {
(gdb) continue
Continuing.
--2008-09-01 14:57:18--  http://www.google.be/
Resolving www.google.be (www.google.be)... 66.249.93.104
Connecting to www.google.be (www.google.be)|66.249.93.104|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `tmpdir/www.google.be/index.html'

[ =  ] 6,146   --.-K/s   in 0.07s   

2008-09-01 14:57:18 (82.1 KB/s) - `tmpdir/www.google.be/index.html'
saved [6146]


Breakpoint 2, url_parse (url=0x665ae0 http://www.google.com/;, error=0x0, 
iri=0x0) at url.c:644
644 {
(gdb) q
The program is running.  Exit anyway? (y or n) y

Regards,
Saint Xavier.