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=en&q=gdb+howto&btnG=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  0x000000000041ed48 in retrieve_tree (start_url=0x665810 
"http://www.google.com";, pi=0x0) at recur.c:292
#2  0x000000000041bc31 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.

Reply via email to