Bug 228744 - gdb unexplained memory access at 0x0
Summary: gdb unexplained memory access at 0x0
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 9
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Alexandre Oliva
QA Contact:
Whiteboard: bzcl34nup
: 250414 (view as bug list)
Depends On:
Blocks: 173278
TreeView+ depends on / blocked
Reported: 2007-02-14 19:18 UTC by Tom Stevelt
Modified: 2008-10-13 15:02 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2008-10-13 15:02:51 UTC
Type: ---

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 29628 0 None None None Never

Description Tom Stevelt 2007-02-14 19:18:41 UTC
GDB throws an unexplained "cannot access memory at 0x0"
after accessing argc or argv[] in a subsidary function.


How reproducible: always

Steps to Reproduce:

1. run attached program using gdb.
2. set a breakpoint on line 6  ( getargs: printf ... argc )
3. run, giving the name of any existing file
4. at breakpoint, execute bt (backtrace) and examine the
   output, which looks normal.
5. execute n (next) 
6. execute another bt and see the messed up output which 
   includes "cannot access memeory at 0x0".  

Actual results:

(gdb) bt
#0  getargs (argc=2, argv=0xbfe1a7b4) at foo6.c:7
#1  0x080483e5 in main (argc=Cannot access memory at address 0x0
) at foo6.c:17

Expected results:

(gdb) bt
#0  getargs (argc=2, argv=0xbfe1a7b4) at foo6.c:6
#1  0x080483e5 in main (argc=2, argv=0xbfe1a7b4) at foo6.c:17

Additional info:

Problem occures wiht either argc or argv.

If you uncomment either of the printf statements in
main(), then the problem in getargs goes away.

Here is the source code.

#include	<stdio.h>

void getargs ( int argc, char *argv[] )
  printf ( "argc %d\n", argc );        /* set breakpoint here */
  printf ( "filename %s\n", argv[1] );
  printf ( "hello world\n" );

int main ( int argc, char *argv[] )
  // printf ( "argc %d\n", argc );
  // printf ( "filename %s\n", argv[1] );
  getargs ( argc, argv );
  return ( 0 );

Comment 1 Jan Kratochvil 2007-02-17 01:32:27 UTC
Yes, you are right.
It is a GCC Bug, though, regarding its DWARF generation.
ECX is a volatile (callee unsaved) register which currently gets referenced:
 <2><162>: Abbrev Number: 6 (DW_TAG_formal_parameter)
     DW_AT_name        : argc
     DW_AT_location    : 2 byte block: 71 0     (DW_OP_breg1: 0)
 <2><171>: Abbrev Number: 6 (DW_TAG_formal_parameter)
     DW_AT_name        : argv
     DW_AT_location    : 2 byte block: 71 4     (DW_OP_breg1: 4)


Fortunately if you use argc/argv more in main() it gets saved more persistently
and the bug gets no longer exposed.

Related Bug / Jakub's comment upstream:

Comment 3 Jan Kratochvil 2007-08-01 14:01:37 UTC
*** Bug 250414 has been marked as a duplicate of this bug. ***

Comment 4 Bug Zapper 2008-04-03 19:09:07 UTC
Based on the date this bug was created, it appears to have been reported
against rawhide during the development of a Fedora release that is no
longer maintained. In order to refocus our efforts as a project we are
flagging all of the open bugs for releases which are no longer
maintained. If this bug remains in NEEDINFO thirty (30) days from now,
we will automatically close it.

If you can reproduce this bug in a maintained Fedora version (7, 8, or
rawhide), please change this bug to the respective version and change
the status to ASSIGNED. (If you're unable to change the bug's version
or status, add a comment to the bug and someone will change it for you.)

Thanks for your help, and we apologize again that we haven't handled
these issues to this point.

The process we're following is outlined here:

We will be following the process here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping to ensure this
doesn't happen again.

Comment 5 Luciano Rocha 2008-04-07 16:11:01 UTC
I still have the same problem, that I reported in #250414.

Fedora 8:

Comment 6 Luciano Rocha 2008-04-07 16:18:26 UTC
Note that the bug I reported, closed as duplicate of this one, was reported for
Fedora 7, not yet EOL.

Comment 7 Luciano Rocha 2008-05-07 10:40:05 UTC
Same problem with fedora 9 preview:

Comment 8 Bug Zapper 2008-05-14 02:37:10 UTC
Changing version to '9' as part of upcoming Fedora 9 GA.
More information and reason for this action is here:

Comment 9 Jan Kratochvil 2008-10-13 15:02:51 UTC
It is fixed in the current upstream snapshot:
GNU C (GCC) version 4.4.0 20081007 (experimental) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.4.0 20081007 (experimental), GMP version 4.2.2, MPFR version 2.3.1.

Breakpoint 1, getargs (argc=1, argv=0xffffc514) at rh228744.c:5
5	  printf ( "argc %d\n", argc );        /* set breakpoint here */
Missing separate debuginfos, use: debuginfo-install glibc.i686
(gdb) bt
#0  getargs (argc=1, argv=0xffffc514) at rh228744.c:5
#1  0x0804844e in main (argc=1, argv=0xffffc514) at rh228744.c:14
(gdb) n
argc 1
6	  printf ( "filename %s\n", argv[1] );
(gdb) bt
#0  getargs (argc=1, argv=0xffffc514) at rh228744.c:6
#1  0x0804844e in main (argc=1, argv=0xffffc514) at rh228744.c:14

Closing this Bug as not so serious while it should be present in Fedora gcc-4.4.

Note You need to log in before you can comment on or make changes to this bug.