[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to debug - apachetop



On Wed, Jan 11, 2006 at 11:10:51AM -0600, Alejandro Bonilla wrote:

> After the actual error I got with apachetop:
> debian:~# apachetop -f /var/log/apache/access.log
> *** glibc detected *** free(): invalid pointer: 0xb7da08c8 ***
> Aborted
> 
> I want to learn how to debug and see what went wrong. How can I learn to debug
> this kind of things or how can I enable some debugging for this kind of things?

  Mostly this invokes recompiling the application to make sure it
 has debugging symbols.

  As the package maintainer I took a look at this, and found a possible
 bug.  Here's how I did it.

  (I just noticed there is a bug report showing the same error reported
 a few days ago.  I posted a followup asking for more information,  as
 I hadn't seen it myself until now.)

  OK.  So we get the application and run it under gdb:

root@itchy:~# gdb apachetop
GNU gdb 6.4-debian
Copyright 2005 Free Software....
...

  Type "r" to run the application:

(gdb)  r
Starting program: /usr/sbin/apachetop 
(no debugging symbols found)
*** glibc detected *** free(): invalid pointer: 0xb7e448c0 ***

Program received signal SIGABRT, Aborted.
0xb7d397a7 in raise () from /lib/tls/libc.so.6


  Here we see two things:  There are no debugging symbols and we managed
 to see the crash.

  Rebuilding with debugging enabled we can try again:

root@itchy:~# gdb ./debian/sid/apachetop/apachetop-0.12.5/src/apachetop
GNU gdb 6.4-debian
...
(gdb) r
Starting program:
/home/skx/debian/sid/apachetop/apachetop-0.12.5/src/apachetop 
*** glibc detected *** free(): invalid pointer: 0xb7e448c0 ***

Program received signal SIGABRT, Aborted.
0xb7d397a7 in raise () from /lib/tls/libc.so.6


   Type "up" a few times to move up the call stack and see if we
  can see where it dies:

(gdb) up
#1  0xb7d3b04b in abort () from /lib/tls/libc.so.6
(gdb) up
#2  0xb7d70015 in __fsetlocking () from /lib/tls/libc.so.6
(gdb) up
#3  0xb7d76667 in malloc_usable_size () from /lib/tls/libc.so.6
(gdb) up
#4  0xb7d76b02 in free () from /lib/tls/libc.so.6
(gdb) up
#5  0x0804a15f in new_file (filename=0x804f5b9
"/var/log/apache2/access.log", 
    do_seek_to_end=true) at apachetop.cc:1029
    1029                    if (this_file->filename)
    free(this_file->filename);

  Ahah!

  We see there is an error in free, and it was caused by the line 
 "if (this_file->filename) free (this_file->filename)".

  Comment that line of the program out, and rebuild it.

  No more crash!

  That's Steve's patented introduction to solving an Apachetop crash
 with gdb ;)

  Seriously using the application under the debugger is the most obvious
 way to look for bugs for me.  Valgrind, strace, etc, are very good
 at what they do.  But if you can rebuild your application to use 
 debugging symbols then using gdb is simple enough.  There are tutorials
 on getting started which google will help you find.

  I'll try to see where the filename is getting setup and what is
 wrong with it.  Might take me a day or two, but as a quick fix you
 can safely comment out/delete the free line and just suffer a small
 memory leak for the moment.

Steve
--



Reply to: