Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I am debugging a program with gdb and something that I don't understand is happening. After serveral hours working ok, the program gets stuck and the gdb shows the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2010
    Location
    Madrid
    Posts
    32

    Strange thing debugging with GDB


    Hi,
    I am debugging a program with gdb and something that I don't understand is happening.

    After serveral hours working ok, the program gets stuck and the gdb shows the folowing info.

    Code:
    (gdb) bt
    #0  0xb7da8021 in write () from /lib/libc.so.6
    #1  0xb7d5256f in _IO_file_write () from /lib/libc.so.6
    #2  0xb7d52213 in ?? () from /lib/libc.so.6
    #3  0xb7d524a6 in _IO_file_xsputn () from /lib/libc.so.6
    #4  0xb7d2e31d in ?? () from /lib/libc.so.6
    #5  0xb7d29b0e in vfprintf () from /lib/libc.so.6
    #6  0xb7d3316f in fprintf () from /lib/libc.so.6
    #7  0x080771b6 in print_screen (ws_row=63, ws_col=237, if_num=1) at server.c:8279
    #8  0x0807196a in thread_one (arg=0x0) at server.c:5389
    #9  0xb7e61f3b in start_thread () from /lib/libpthread.so.0
    #10 0xb7db6d0e in clone () from /lib/libc.so.6
    (gdb) frame  7
    #7  0x080771b6 in print_screen (ws_row=63, ws_col=237, if_num=1) at server.c:8279
    8279                    fprintf(stderr, " %s", strbuf);
    (gdb) p strbuf
    $14 = " AKD3384HH", ' ' <repeats 139 times>, "\000", ' ' <repeats 106 times>, '\0' <repeats 255 times>
    (gdb)
    (gdb) p &strbuf
    $15 = (char (*)[512]) 0xb54cee1c
    (gdb) info registers
    eax            0x6      6
    ecx            0xb54cc280       -1253260672
    edx            0x96     150
    ebx            0x20     32
    esp            0xb54ce980       0xb54ce980
    ebp            0xb54cf058       0xb54cf058
    esi            0x5a     90
    edi            0x65     101
    eip            0x80771b6        0x80771b6 <print_screen+5914>
    eflags         0x200246 [ PF ZF IF ID ]
    cs             0x73     115
    ss             0x7b     123
    ds             0x7b     123
    es             0x7b     123
    fs             0x0      0
    gs             0x33     51
    In function print_screen I call to fprintf with (apparently) valid arguments and, somehow, the libc gets stuck in write syscall.
    I don't know where the problem can be, I am just writing the stderr with a valid string buffer..

    I am getting mad with this problem. Any help or clue will be appreciated!!

    (Notice that this function print_screen and the fprintf call has been working right during 5hours)

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,748
    I'd suggest enabling memory corruption detection in the debugger. Your problem may be something as simple (but hard to find) as an occasional buffer overrun.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    May 2010
    Location
    Madrid
    Posts
    32
    Quote Originally Posted by Rubberman View Post
    I'd suggest enabling memory corruption detection in the debugger. Your problem may be something as simple (but hard to find) as an occasional buffer overrun.
    Thanks for your answer Rubberman, can I do that with gdb or do you mean to use other tools like valgrind?
    Like:
    valgrind --leak-check=yes ./program

    The only problem is that, since the error occurs after many hours, I suppose that the logs will be huge and the error will be difficult to find. Hopefully it will be the last record

    Thanks again, I'll try it

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,748
    You probably want some other options as well such --vgdb so you can use it with GDB. The valgrind man page is pretty complete - you probably want to study it a bit before you start, if you haven't already.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •