This is the mail archive of the gdb@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

breakpoints on weak functions


Hi!


I think that gdb does not show the right function when seting a
breakpoint in a function that is defined as a weak function. 

Here is an example, it consists of 2 files t.c and main.c
Compile and link them. 

--t.c--
int test_weak (void) __attribute__ ((weak));
     
int
test_weak (void)
{
  return 1;
}

int
test (void)
{
  return test_weak ();
}
--end t.c--

--main.c--
int test (void);

int
test_weak (void)
{
  return 2;
}

int
main (void)
{
  int val;
  val =  test ();
  printf ("val = %d\n", val);
  return val;
}
--end main.c--

I used the latest egcs snapshot to compile it on a
sparc-sun-solaris2.5.1

The program executes correctly, ie it will print 
val = 2

but when trying to set a breakpoint in test_weak here is what happens:


godzilla:/tmp> gdb a.out
GNU gdb 4.17
Copyright 1998 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.5"...
(gdb) b test_weak
Breakpoint 1 at 0x108fc: file t.c, line 6.
(gdb) break main.c:14
Breakpoint 2 at 0x10920: file main.c, line 14.
(gdb) r
Starting program: /tmp/a.out 

Breakpoint 1, test_weak () at t.c:6
6         return 1;
(gdb) l
1       int test_weak (void) __attribute__ ((weak));
2            
3       int
4       test_weak (void)
5       {
6         return 1;
7       }
8
9       int
10      test (void)
(gdb) c
Continuing.

Breakpoint 2, main () at main.c:14
14        printf ("val = %d\n", val);
(gdb) p val
$1 = 2
(gdb) c
Continuing.
val = 2

Program exited with code 02.
(gdb) 



Is this a problem with weak functions in general or is a gdb problem? 

Sun's dbx says that it cannot set a breakpoint in that function:

(dbx) stop in test_weak
dbx: warning: 'test_weak' has no debugger info -- will trigger on first instruction
(2) stop in test_weak

Thanks.
	Dan

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]