Bug 80139 - Attaching to gdb doesn't work properly
Summary: Attaching to gdb doesn't work properly
Status: RESOLVED DUPLICATE of bug 77824
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 2.1.1
Platform: Unlisted Binaries Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-22 17:14 UTC by Stephan Wefing
Modified: 2004-04-22 20:02 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Wefing 2004-04-22 17:14:32 UTC
Hi,

I encounter some problems upon attaching to gdb during a valgrind session. I'm
using valgrind-2.1.1 with SuSE Linux 9.0 with its out of the box kernel (not
updated):

antibiotix tmp/planung> uname -a
Linux antibiotix 2.4.21-99-smp4G #1 SMP Wed Sep 24 14:13:20 UTC 2003 i686 i686 i
386 GNU/Linux

The uses the following version of glibc:

antibiotix mail/drafts> /lib/libc.so.6 
GNU C Library stable release version 2.3.2 (20030827), by Roland McGrath et al.
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Configured for i686-suse-linux.
Compiled by GNU CC version 3.3.1 (SuSE Linux).
Compiled on a Linux 2.6.0-test3 system on 2003-09-23.
Available extensions:
        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        linuxthreads-0.10 by Xavier Leroy
        NoVersion patch for broken glibc 2.0 binaries
        BIND-8.2.3-T5B
        libthread_db work sponsored by Alpha Processor Inc
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Thread-local storage support included.
Report bugs using the `glibcbug' script to <bugs@gnu.org>.

This is a small sample program used to illustrate the problem:

******************************************************************************
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   char *cp=(char *)malloc(4*sizeof(char));
   sprintf(cp,"hello world");
   return 0;
}
******************************************************************************

See the following log for an example where attaching fails:

antibiotix tmp/planung> gcc -g -o crash crash.c
antibiotix tmp/planung> valgrind crash
==7371== Memcheck, a memory error detector for x86-linux.
==7371== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward.
==7371== Using valgrind-2.1.1, a program supervision framework for x86-linux.
==7371== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward.
==7371== Valgrind library directory: /usr/local/lib/valgrind
==7371== Command line
==7371==    crash
==7371== Startup, with flags:
==7371==    --tool=memcheck
==7371==    -v
==7371==    -v
==7371==    --num-callers=20
==7371==    --db-attach=yes
==7371==    --track-fds=yes
==7371==    --memchec--leak-check=yes
==7371==    --memchec--show-reachable=yes
==7371==    --
==7371== Reading syms from /home/wefing/bin/crash (0x8048000)
==7371== Reading syms from /lib/ld-2.3.2.so (0x3C000000)
==7371==    object doesn't have any debug info
==7371== Reading syms from /lib/ld-2.3.2.so (0xB0000000)
==7371==    object doesn't have any debug info
==7371== Reading syms from /lib/libdl.so.2 (0xB0028000)
==7371==    object doesn't have any debug info
==7371== Reading syms from /lib/i686/libc.so.6 (0xB002B000)
==7371==    object doesn't have any debug info
==7371== Reading syms from /usr/local/lib/valgrind/vgskin_memcheck.so (0xB035E00
0)
==7371== Reading syms from /usr/local/lib/valgrind/stage2 (0xB8000000)
==7371== Reading suppressions file: /usr/local/lib/valgrind/default.supp
--7371-- Translation Cache: using 8 sectors of 7260151 bytes each
--7371-- Translation Table: 300007 total entries, max occupancy 240005 (80%)
==7371== REDIRECT soname:libc.so.6(__GI___errno_location) to soname:libpthread.s
o.0(__errno_location)
==7371== REDIRECT soname:libc.so.6(__errno_location) to soname:libpthread.so.0(_
_errno_location)
==7371== REDIRECT soname:libc.so.6(__GI___h_errno_location) to soname:libpthread
.so.0(__h_errno_location)
==7371== REDIRECT soname:libc.so.6(__h_errno_location) to soname:libpthread.so.0
(__h_errno_location)
==7371== REDIRECT soname:libc.so.6(__GI___res_state) to soname:libpthread.so.0(_
_res_state)
==7371== REDIRECT soname:libc.so.6(__res_state) to soname:libpthread.so.0(__res_
state)
==7371== REDIRECT soname:libc.so.6(stpcpy) to *vgpreload_memcheck.so*(stpcpy)
==7371== REDIRECT soname:libc.so.6(strnlen) to *vgpreload_memcheck.so*(strnlen)
==7371== REDIRECT soname:ld-linux.so.2(stpcpy) to *vgpreload_memcheck.so*(stpcpy
)
==7371== REDIRECT soname:ld-linux.so.2(strchr) to *vgpreload_memcheck.so*(strchr
)
==7371== 
--7371-- 0k bbs: tt 0, tc 0, after  allocation of sector 0 (size 7260151)
--7371-- 0k bbs: tt 0, tc 0, after  commission of sector 0 at time 0
==7371== Reading syms from /usr/local/lib/valgrind/vg_inject.so (0x3C01C000)
==7371== Reading syms from /usr/local/lib/valgrind/vgpreload_memcheck.so (0x3C01
F000)
--7371--   redir resolved (soname:ld-linux.so.2:strchr=0x3C0133D0 -> 
--7371--                   *vgpreload_memcheck.so*:strchr=0x3C020A30)
==7371== Discarding translation due to redirect of already called function
==7371==    strchr (0x3C0133D0 -> 0x3C020A30)
==7371== discard 1 (23 -> 320) translations in range 0x3C0133D0 .. 0x3C0133D0
--7371--   redir resolved (soname:ld-linux.so.2:stpcpy=0x3C013930 -> 
--7371--                   *vgpreload_memcheck.so*:stpcpy=0x3C0210B0)
==7371== TRANSLATE: 0x3C0133D0 redirected to 0x3C020A30
==7371== Reading syms from /lib/i686/libm.so.6 (0x3C034000)
==7371==    object doesn't have any debug info
==7371== Reading syms from /lib/i686/libc.so.6 (0x3C05A000)
==7371==    object doesn't have any debug info
--7371--   redir resolved (soname:libc.so.6:strnlen=0x3C0D32C0 -> 
--7371--                   *vgpreload_memcheck.so*:strnlen=0x3C020C30)
--7371--   redir resolved (soname:libc.so.6:stpcpy=0x3C0D4D30 -> 
--7371--                   *vgpreload_memcheck.so*:stpcpy=0x3C0210B0)
--7371--   redir resolved (soname:libc.so.6:malloc=0x3C0CDFE0 -> 
--7371--                   (null):(null)=0x3C0212C4)
--7371--   redir resolved (soname:libc.so.6:calloc=0x3C0CE870 -> 
--7371--                   (null):(null)=0x3C021A46)
--7371--   redir resolved (soname:libc.so.6:realloc=0x3C0CE280 -> 
--7371--                   (null):(null)=0x3C021AF8)
--7371--   redir resolved (soname:libc.so.6:valloc=0x3C0CE690 -> 
--7371--                   (null):(null)=0x3C021C97)
--7371--   redir resolved (soname:libc.so.6:posix_memalign=0x3C0D0690 -> 
--7371--                   (null):(null)=0x3C021CE0)
--7371--   redir resolved (soname:libc.so.6:free=0x3C0CE1B0 -> 
--7371--                   (null):(null)=0x3C021794)
--7371--   redir resolved (soname:libc.so.6:mallopt=0x3C0CEEB0 -> 
--7371--                   (null):(null)=0x3C021CD6)
--7371--   redir resolved (soname:libc.so.6:malloc_usable_size=0x3C0CEDA0 -> 
--7371--                   (null):(null)=0x3C021D2C)
--7371--   redir resolved (soname:libc.so.6:mallinfo=0x3C0CEDC0 -> 
--7371--                   (null):(null)=0x3C021EA1)
--7371--   redir resolved (soname:libc.so.6:pvalloc=0x3C0CE780 -> 
--7371--                   (null):(null)=0x3C021DFC)
--7371--   redir resolved (soname:libc.so.6:malloc_stats=0x3C0CEDB0 -> 
--7371--                   (null):(null)=0x3C021E1D)
--7371--   redir resolved (soname:libc.so.6:malloc_trim=0x3C0CED20 -> 
--7371--                   (null):(null)=0x3C021E3E)
--7371--   redir resolved (soname:libc.so.6:malloc_get_state=0x3C0CD330 -> 
--7371--                   (null):(null)=0x3C021E5F)
--7371--   redir resolved (soname:libc.so.6:malloc_set_state=0x3C0CD4D0 -> 
--7371--                   (null):(null)=0x3C021E80)
client request: code 4D430100,  addr 0x0,  len 0
--7371--   redir resolved (soname:libc.so.6:gsignal=0x3C0838C0 -> 
--7371--                   (null):(null)=0x3C01CB19)
==7371== Invalid write of size 4
==7371==    at 0x8048450: main (crash.c:4)
==7371==  Address 0x0 is not stack'd, malloc'd or free'd
==7371== 
==7371== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- y
starting debugger
==7371== starting debugger with cmd: /usr/bin/gdb -nw /proc/7374/fd/822 7374

valgrind: vg_signals.c:1587 (vg_sync_signalhandler): Assertion `info->si_code <=
 0' failed.
==7374==    at 0xB802B33E: vgPlain_skin_assert_fail (vg_mylibc.c:1211)
==7374==    by 0xB802B33D: assert_fail (vg_mylibc.c:1207)
==7374==    by 0xB802B37B: vgPlain_core_assert_fail (vg_mylibc.c:1218)
==7374==    by 0xB8030A72: vg_sync_signalhandler (vg_signals.c:1630)
==7374==    by 0xB80BBBF3: ???

sched status:

Thread 1: status = Runnable, associated_mx = 0x0, associated_cv = 0x0
==7374==    at 0x8048440: main (crash.c:2)


Note: see also the FAQ.txt in the source distribution.
It contains workarounds to several common problems.

If that doesn't help, please report this bug to: valgrind.kde.org

GNU gdb 5.3.92
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...In the bug report, send all the a
bove text, the valgrind
version, and what Linux distro you are using.  Thanks.


Attaching to program: /proc/7374/fd/822, process 7374
Reading symbols from /usr/local/lib/valgrind/vg_inject.so...done.
Loaded symbols for /usr/local/lib/valgrind/vg_inject.so
Reading symbols from /usr/local/lib/valgrind/vgpreload_memcheck.so...done.
Loaded symbols for /usr/local/lib/valgrind/vgpreload_memcheck.so
Reading symbols from /lib/i686/libm.so.6...done.
Loaded symbols for /lib/i686/libm.so.6
Reading symbols from /lib/i686/libc.so.6...done.
Loaded symbols for /lib/i686/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
0xb8042262 in ?? ()
(gdb) where
#0  0xb8042262 in ?? ()
#1  0xb80bb3c0 in ?? ()
#2  0x00000038 in ?? ()
#3  0xb80bb890 in ?? ()
#4  0xb808efc0 in ?? ()
#5  0xb802b4c6 in ?? ()
#6  0x00000004 in ?? ()
#7  0x00000337 in ?? ()
#8  0xb808efc0 in ?? ()
#9  0x00000038 in ?? ()
#10 0xb80bb3dc in ?? ()
#11 0xb8029a2e in ?? ()
#12 0x00000337 in ?? ()
#13 0xb808efc0 in ?? ()
#14 0x00000038 in ?? ()
#15 0x00000038 in ?? ()
#16 0x0000000b in ?? ()
#17 0xb80bb3f0 in ?? ()
#18 0xb802a96b in ?? ()
#19 0xb808efc0 in ?? ()
#20 0x00000038 in ?? ()
#21 0xb802b33e in ?? ()
#22 0xb80bb400 in ?? ()
#23 0xb802b2f7 in ?? ()
#24 0xb8070a00 in ?? ()
#25 0x3c189fd8 in __DTOR_END__ () from /lib/i686/libc.so.6
#26 0xb80bb424 in ?? ()
#27 0xb802b33e in ?? ()
#28 0xb806ccff in ?? ()
#29 0xb8070a40 in ?? ()
#30 0xb806ccce in ?? ()
#31 0xb807202b in ?? ()
#32 0x00000633 in ?? ()
#33 0xb8072640 in ?? ()
#34 0xb8072682 in ?? ()
#35 0xb80bb444 in ?? ()
#36 0xb802b37c in ?? ()
#37 0xb8072682 in ?? ()
#38 0xb806ccce in ?? ()
#39 0xb806ccff in ?? ()
#40 0xb807202b in ?? ()
#41 0x00000633 in ?? ()
#42 0xb8072640 in ?? ()
#43 0xb80bb87c in ?? ()
#44 0xb8030a73 in ?? ()
#45 0xb8072682 in ?? ()
#46 0xb807202b in ?? ()
#47 0x00000633 in ?? ()
#48 0xb8072640 in ?? ()
#49 0x4fffd000 in ?? ()
#50 0x4fffde9c in ?? ()
#51 0x4fffde9c in ?? ()
#52 0x00000001 in ?? ()
(gdb) q  
==7371== 
==7371== Debugger has detached.  Valgrind regains control.  We continue.
==7371== 
==7371== Process terminating with default action of signal 11 (SIGSEGV): dumping
 core
==7371==  Access not within mapped region at address 0x0
==7371==    at 0x8048450: main (crash.c:4)
==7371== 
==7371== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- c
==7371== 
==7371== FILE DESCRIPTORS: 3 open at exit.
==7371== Open file descriptor 2: /dev/pts/8
==7371==    <inherited from parent>
==7371== 
==7371== Open file descriptor 1: /dev/pts/8
==7371==    <inherited from parent>
==7371== 
==7371== Open file descriptor 0: /dev/pts/8
==7371==    <inherited from parent>
==7371== 
==7371== 
==7371== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 13 from 1)
==7371== 
==7371== 1 errors in context 1 of 1:
==7371== Invalid write of size 4
==7371==    at 0x8048450: main (crash.c:4)
==7371==  Address 0x0 is not stack'd, malloc'd or free'd
--7371-- 
--7371-- supp:   13 Ugly strchr error in /lib/ld-2.3.2.so
==7371== 
==7371== IN SUMMARY: 1 errors from 1 contexts (suppressed: 13 from 1)
==7371== 
==7371== malloc/free: in use at exit: 0 bytes in 0 blocks.
==7371== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==7371== 
==7371== No malloc'd blocks -- no leaks are possible.
--7371--     TT/TC: 0 tc sectors discarded.
--7371--            995 chainings, 2 unchainings.
--7371-- translate: new     1368 (26560 -> 340158; ratio 128:10)
--7371--            discard 1 (23 -> 320; ratio 139:10).
--7371--  dispatch: 31086 jumps (bb entries), of which 4272 (13%) were unchained
.
--7371--            33/1718 major/minor sched events.  1497 tt_fast misses.
--7371-- reg-alloc: 368 t-req-spill, 63762+3028 orig+spill uis, 7842 total-reg-r
.
--7371--    sanity: 21 cheap, 1 expensive checks.
--7371--    ccalls: 5185 C calls, 52% saves+restores avoided (15946 bytes)
--7371--            6908 args, avg 0.85 setup instrs each (1954 bytes)
--7371--            0% clear the stack (15555 bytes)
--7371--            2491 retvals, 26% of reg-reg movs avoided (1250 bytes)
Segmentation fault
Exit 139

Just before answering the first prompt "Attach to debugger ?", a "ps aux"
shows the following processes related to valgrind:

wefing    7371 13.4  1.7 1496280 8884 pts/8  S    16:45   0:00 valgrind crash
wefing    7372  0.0  1.7 1496280 8884 pts/8  S    16:45   0:00 valgrind crash

When I answered "y", a gdb session is initiated. At that time, the relevant
processes are: 

wefing    7371  2.5  1.7 1496280 8892 pts/8  S    16:45   0:00 valgrind crash
wefing    7372  0.0  1.7 1496280 8892 pts/8  S    16:45   0:00 valgrind crash
wefing    7375  4.6  1.0  7380 5208 pts/8    S    16:45   0:00 /usr/bin/gdb -nw 
/proc/7374/fd/822 7374
wefing    7374  0.3  1.7 1496280 8900 pts/8  T    16:45   0:00 valgrind crash

Kind regards

Stephan

+-------------------------------------------------------------------------+
|                                Stephan Wefing                           |
| phone : +49 (0) 228 9656 278                      Stiftung caesar       |
| fax   : +49 (0) 228 9656 118                      Ludwig-Erhard-Allee 2 |
| email : wefing@caesar.de                          D-53175 Bonn          |
| http  : www.caesar.de/searchxlinks                Germany               |
+-------------------------------------------------------------------------+
|        caesar - center of advanced european studies and research        |
+-------------------------------------------------------------------------+
Comment 1 Tom Hughes 2004-04-22 20:02:55 UTC

*** This bug has been marked as a duplicate of 77824 ***