Bug 10466 - Can't debug the first function in a C file that is included in another C file
Summary: Can't debug the first function in a C file that is included in another C file
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 3.2.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-23 16:46 UTC by stevee
Modified: 2024-01-23 15:21 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-07-10 00:11:43


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description stevee 2003-04-23 16:46:00 UTC
If a C file #includes another C file that contains function definitions 
it is not possible to break on the first function in the included C file.
The debugger behaves as though there is no debug information for
the function.
All other functions within the included C file can have break points added and they work fine.
This is using gdb 5.3

Release:
3.2.2

Environment:
Solaris 2.6
Comment 1 Daniel Jacobowitz 2003-04-25 02:18:24 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: Please see the bug reporting instructions on gcc.gnu.org.
    Could you supply a small testcase?
Comment 2 stevee 2003-04-25 09:53:43 UTC
From: Steve Evans <stevee@zuken.co.uk>
To: drow@sources.redhat.com, chrisha@zuken.co.uk, gcc-bugs@gcc.gnu.org,
        gcc-prs@gcc.gnu.org, marcusb@zuken.co.uk, nobody@gcc.gnu.org,
        stevee@zuken.co.uk, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: debug/10466: Can't debug the first function in a C file that is included in another C file
Date: 25 Apr 2003 09:53:43 +0100

 --=-=-=
 
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 On 25 Apr 2003, drow@sources.redhat.com wrote:
 
 >Synopsis: Can't debug the first function in a C file that is included
 >in another C file
 >
 >State-Changed-From-To: open->feedback
 >State-Changed-By: drow
 >State-Changed-When: Fri Apr 25 02:18:24 2003
 >State-Changed-Why:
 >Please see the bug reporting instructions on gcc.gnu.org.
 >Could you supply a small testcase?
 >
 >http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10466
 
 Ok. Enclosed are two files, foo.c and bar.c. Compile foo.c, which
 #includes "bar.c"  as:
 
   gcc -f -fPIC foo.c
 
 Note that since reporting the bug I have discovered that it only
 occurs when compiled with -fPIC. I attempted  to add this information
 to the bug report, but can't edit a report when logged on as guest and
 there doesn't seem to be any way of creating a new login ID.
 
 The run the debugger on it and attempt to break in the function bar,
 which is the first function in bar.c:
 
 ,----
 | stevee@gorbag:MY CLONE> gdb ./a.out
 | GNU gdb 5.3
 | Copyright 2002 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 "sparc-sun-solaris2.6"...
 | (gdb) b bar
 | Breakpoint 1 at 0x10aa8
 | (gdb) b bar2
 | Breakpoint 2 at 0x10aec: file bar.c, line 13.
 | (gdb) r
 | Starting program: /tmp/a.out 
 | foo
 | 
 | Breakpoint 1, 0x00010aa8 in bar ()
 | (gdb) l
 | 1       #include <stdio.h>
 | 2
 | 3       extern void foo(void);
 | 4       extern int bar(void);
 | 5       extern int bar2(void);
 | 6
 | 7       int main()
 | 8       {
 | 9           foo();
 | 10          bar();
 | (gdb) 
 `----
 
 Note that the function bar2 which exists in the same source file can
 have a break point added successfully.
 
 Thanks for any help with this problem.
 
 
 --=-=-=
 Content-Type: application/octet-stream
 Content-Disposition: attachment; filename=foo.c
 
 #include <stdio.h>
 
 extern void foo(void);
 extern int bar(void);
 extern int bar2(void);
 
 int main()
 {
     foo();
     bar();
     bar2();
 
     return 0;
 }
 
 void foo()
 {
     printf( "foo\n" );
 }
 
 #include "bar.c"
 
 --=-=-=
 Content-Type: application/octet-stream
 Content-Disposition: attachment; filename=bar.c
 
 
 int
 bar()
 {
     printf( "bar\n" );
 
     return 0;
 }
 
 int
 bar2()
 {
     printf( "bar2\n" );
 
     return 2;
 }
 
 --=-=-=
 
 
 Steve
 - -- 
 ____________________________________________________________________________
 Steve Evans,
 Zuken Limited,                     TEL:   +44 (0)1454 207800 ext 8607
 1500 Aztec West,                   Fax:   +44 (0)1454 207803
 Almondsbury,                       mailto:stevee@zuken.co.uk
 Bristol, BS32 4RF, UK              Web:   http://www.zuken.com
 Registered Linux user #217906:     http://counter.li.org
 Public Encryption Key:             http://www.gorbag.com/public-key-work.html
 _____________________________________________________________________________
 
 "We are all slaves to our histories. If there is to be a ..
  bright future, we must learn to break those chains."
 	-- Delenn to Garibaldi in Babylon 5:"GROPOS"
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.1 (SunOS)
 Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
 
 iD8DBQE+qPeT1a67iNP86GcRAqTuAJ44uyoY1zJr/2/cRSCjZYfjOHi1QQCfWltl
 Woad71WrkYk2iHuacIa4Twg=
 =NYKO
 -----END PGP SIGNATURE-----
 
 --=-=-=--
Comment 3 Daniel Jacobowitz 2003-04-25 13:10:32 UTC
State-Changed-From-To: feedback->open
State-Changed-Why: Thanks, feedback received.
Comment 4 Andrew Pinski 2003-11-18 10:02:47 UTC
Is a GCC bug or a GDB bug?
Comment 5 stevee 2003-11-18 10:14:47 UTC
Subject: Re:  Can't debug the first function in a C file
 that is included in another C file

On 18 Nov 2003, gcc-bugzilla@gcc.gnu.org wrote:

>
> ------- Additional Comments From pinskia at gcc dot gnu dot org
>         2003-11-18 10:02 -------
> Is a GCC bug or a GDB bug?

I suspect it is a GCC bug, but I can't be certain.
Comment 6 Richard Biener 2024-01-23 15:21:27 UTC
Reading symbols from ./a.out...
(gdb) b bar
Breakpoint 1 at 0x400545: file b.c, line 4.
(gdb) b bar2
Breakpoint 2 at 0x40055a: file b.c, line 12.
(gdb) r
Starting program: /tmp/a.out 
Missing separate debuginfos, use: zypper install glibc-debuginfo-2.31-150300.63.1.x86_64
foo

Breakpoint 1, bar () at b.c:4
4         printf( "bar\n" );
(gdb) l
1       int
2       bar()
3       {
4         printf( "bar\n" );
5
6         return 0;
7       }
8
9       int
10      bar2()

Works for me (named the file b.c), with both gcc 7.5 and gcc 13.2.  I'm
using quite recent gdb though, gdb 12.1

Either fixed or a gdb bug (which was also fixed meanwhile).