Bug 483262

Summary: Valgrind doesn't work with GDB properly
Product: Red Hat Enterprise Linux 4 Reporter: Jan Kratochvil <jan.kratochvil>
Component: gdbAssignee: Jan Kratochvil <jan.kratochvil>
Status: CLOSED WONTFIX QA Contact: BaseOS QE <qe-baseos-auto>
Severity: medium Docs Contact:
Priority: high    
Version: 4.6CC: ebachalo, pmuller
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 453688 Environment:
Last Closed: 2010-09-14 03:36:08 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 233746, 453688    
Bug Blocks:    

Description Jan Kratochvil 2009-01-30 16:13:06 UTC
+++ This bug was initially created as a clone of Bug #453688 +++

Description of problem:
Attempting to use valgrind with --db-attach=yes on a program that triggers an
error, and then attaching gdb causes gdb to error, and is unusable. Once gdb
exits, valgrind resumes control, and the program (seems to) continue normally.

Version-Release number of selected component (if applicable):
broken: RHEL-4.6 gdb-6.3.0.0-1.153.el4.x86_64 (by valgrind-3.1.1-1.EL4.x86_64)
OK:     RHEL-4.5 gdb-6.3.0.0-1.143.el4.x86_64 (by valgrind-3.1.1-1.EL4.x86_64)

How reproducible:
Every time

Steps to Reproduce:
1. Create a program that causes valgrind to detect an error, such as an invalid
read or write. The following example is sufficient
#include <stdlib.h>

int
main() {
  int* arr = (int*)malloc(8);
  int j = arr[30];
  return 0;
}

2. Compile the example program (gcc -g3 -Wall val-db.c -o val-db)
3. Run valgrind with the following options "valgrind --db-attach=yes ./val-db"
  
Actual results:
GDB freaks out, and cannot debug. The following occurs on-screen:
[bash]root.bos.redhat.com:/root/jkratoch/redhat# valgrind --db-attach=yes ./val-db
==25917== Memcheck, a memory error detector.
==25917== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==25917== Using LibVEX rev 1575, a library for dynamic binary translation.
==25917== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==25917== Using valgrind-3.1.1, a dynamic binary instrumentation framework.
==25917== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==25917== For more details, rerun with: -v
==25917== 
==25917== Invalid read of size 4
==25917==    at 0x4004C6: main (val-db.c:6)
==25917==  Address 0x4A3C0A8 is not stack'd, malloc'd or (recently) free'd
==25917== 
==25917== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- y
==25917== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- starting debugger
==25917== starting debugger with cmd: /usr/bin/gdb -nw /proc/25918/fd/1014 25918
GNU gdb Red Hat Linux (6.3.0.0-1.153.el4rh)
Copyright 2004 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 "x86_64-redhat-linux-gnu"...Using host libthread_db library "/lib64/tls/libthread_db.so.1".

Attaching to program: /proc/25918/fd/1014, process 25918
Redelivering pending Segmentation fault.

valgrind: m_signals.c:1001 (default_action): Assertion 'VG_(is_running_thread)(tid)' failed.
==25918==    at 0x70010E08: report_and_quit (m_libcassert.c:122)

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable
==25918==    at 0x4004C6: main (val-db.c:6)


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: www.valgrind.org

In the bug report, send all the above text, the valgrind
version, and what Linux distro you are using.  Thanks.

Program process 0 exited: 1 (exited)

/root/jkratoch/redhat/25918: No such file or directory.


Expected results:
GDB attaches properly, and developer is able to debug the process.

Additional info:

Comment 1 Jan Kratochvil 2009-01-30 16:18:51 UTC
Regression by the Bug 233746:
* Mon Jul 30 2007 Jan Kratochvil <jan.kratochvil> - 6.3.0.0-1.151
- Never lose any pending signal while attaching - resubmit them (BZ 233746).

Comment 2 RHEL Program Management 2009-01-30 17:17:05 UTC
This bugzilla has Keywords: Regression.  

Since no regressions are allowed between releases, 
it is also being proposed as a blocker for this release.  

Please resolve ASAP.