Hi,
When i debug the program using gdb , the gdb is entering the definations of std lib functions (ex: printf, strcpy ect) and other internal functions.
Initially the debuger was working fine, i dont have clue when it got changed.I guess some of the flags of gdb might have changed.

Please let me know how to bring it back to normal state.
Please find the attachment for reference.
below is the code i am using for gdb test.

int main( void )
{
    int i;
    for (i =0;i<5;i++)
        printf("Helloo\n);

    return 0;
}
Attachments
skl@skl:~/Player$ gcc ex.c -g

ex.c: In function main:
ex.c:5:2: warning: incompatible implicit declaration of built-in function printf 

[enabled by default] 
skl@skl:~/Player$ gdb a.out

GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/skl/Player/a.out...done.


(gdb) b main

Breakpoint 1 at 0x80483dd: file ex.c, line 4.

(gdb) r

Starting program: /home/skl/Player/a.out 

Breakpoint 1, main () at ex.c:4
4	
for(i =0;i<5;i++)
(gdb) s
5
		printf(" Heello\n");

(gdb) s
_IO_puts (str=0x80484e0 " Heello") at ioputs.c:35
35	ioputs.c: No such file or directory.
	in ioputs.c
(gdb) s
37	in ioputs.c
(gdb) s
35	in ioputs.c
(gdb) s
37	in ioputs.c
(gdb) s
35	in ioputs.c
(gdb) s
37	in ioputs.c
(gdb) s
__strlen_ia32 () at ../sysdeps/i386/i686/multiarch/../../i586/strlen.S:47
47	../sysdeps/i386/i686/multiarch/../../i586/strlen.S: No such file or directory.
	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
49	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
51	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
53	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
99	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
100	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
102	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
103	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
105	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
106	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
108	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
110	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
112	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
115	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
116	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
118	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
119	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
121	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
122	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
163	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
164	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
166	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
167	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
169	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
170	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
172	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
174	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
175	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
177	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
178	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
180	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
183	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
__strlen_ia32 () at ../sysdeps/i386/i686/multiarch/../../i586/strlen.S:187
187	in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) s
_IO_puts (str=0x80484e0 " Heello") at ioputs.c:38
38	ioputs.c: No such file or directory.
	in ioputs.c
(gdb) s
37	in ioputs.c
(gdb) s
38	in ioputs.c
(gdb) s
40	in ioputs.c
(gdb) s
41	in ioputs.c
(gdb) s
42	in ioputs.c
(gdb) s
_IO_new_file_xsputn (f=0xb7fc5500, data=0x80484e0, n=7) at fileops.c:1296
1296	fileops.c: No such file or directory.
	in fileops.c
(gdb) s
1303	in fileops.c
(gdb) s
1296	in fileops.c
(gdb) s
1302	in fileops.c
(gdb) s
1296	in fileops.c
(gdb) s
1302	in fileops.c
(gdb) s
1292	in fileops.c
(gdb) s
_IO_new_file_xsputn (n=7, data=0x80484e0, f=0xb7fc5500) at fileops.c:1309
1309	in fileops.c
(gdb) s
1326	in fileops.c
(gdb) s
1358	in fileops.c
(gdb) s
_IO_new_file_overflow (f=0xb7fc5500, ch=-1) at fileops.c:837
837	in fileops.c
(gdb) s
838	in fileops.c
(gdb) s
837	in fileops.c
(gdb) s
838	in fileops.c
(gdb) s
845	in fileops.c
(gdb) s
848	in fileops.c
(gdb) s
850	in fileops.c
(gdb) s
_IO_doallocbuf (fp=0xb7fc5500) at genops.c:419
419	genops.c: No such file or directory.
	in genops.c
(gdb) s
420	in genops.c
(gdb) s
422	in genops.c
(gdb) s
423	in genops.c
(gdb) s
_IO_file_doallocate (fp=0xb7fc5500) at filedoalloc.c:88
88	filedoalloc.c: No such file or directory.
	in filedoalloc.c
(gdb) s
103	in filedoalloc.c
(gdb) s
88	in filedoalloc.c
(gdb) s
102	in filedoalloc.c
(gdb) s
103	in filedoalloc.c
(gdb) s
_IO_file_stat (fp=0xb7fc5500, st=0xbffff1c4) at fileops.c:1233
1233	fileops.c: No such file or directory.
	in fileops.c
(gdb) s
1235	in fileops.c
(gdb) s
___fxstat64 (vers=3, fd=1, buf=0xbffff1c4) at ../sysdeps/unix/sysv/linux/fxstat64.c:46
46	../sysdeps/unix/sysv/linux/fxstat64.c: No such file or directory.
	in ../sysdeps/unix/sysv/linux/fxstat64.c
(gdb) s
49	in ../sysdeps/unix/sysv/linux/fxstat64.c
(gdb) s
46	in ../sysdeps/unix/sysv/linux/fxstat64.c
(gdb) s
49	in ../sysdeps/unix/sysv/linux/fxstat64.c
(gdb) s
82	in ../sysdeps/unix/sysv/linux/fxstat64.c

It's supposed to do that. It's how the debugger works. You step through functions like that.

Edited 3 Years Ago by Moschops

But iam not able to debug my original program, because the program goes very deep into std definations.
The orinigal behaviour of Debugger is to skip the std function( i mean dont go to definations , but yeild the result) and continue with user code.

This is really irritating, and i am not able to debug .

(gdb) help s
Step program until it reaches a different source line.
Argument N means do this N times (or till program stops for another reason).
(gdb) help n
Step program, proceeding through subroutine calls.
Like the "step" command as long as subroutine calls do not happen;
when they do, the call is treated as one instruction.
Argument N means do this N times (or till program stops for another reason).

Also, up will take you upwards through the call stack, function by function. Stop typing up when you are at the function you're interested in.

This is basically a case of RTFM.

I guess the shared library symbol table is getting loaded.
Try the below command in gdb, before running the program.

show auto-solib-add -- this will indicate the current status. Incase if this mode is ON, turn it OFF using the command set auto-solib-add mode off

Hope it helps :)

I guess the shared library symbol table is getting loaded.
Try the below command in gdb, before running the program.

show auto-solib-add -- this will indicate the current status. Incase if this mode is ON, turn it OFF using the command set auto-solib-add mode off

Hope it helps :)

That did the trick but i am getting all the std functions out put at the same time no matter how many.
Well that is not what is expected, normal behaviour is , it should process line by line and give out put if any printf or any likes and wait for the next action.

(gdb) set auto-solib-add off
(gdb) b main
Breakpoint 1 at 0x804843e: file f1.c, line 5.
(gdb) r
Starting program: /home/slb/a.out 

Breakpoint 1, main () at f1.c:5
5   {
(gdb) s
6       char str[] = "Hello";
(gdb) s
8       printf("len = %d\n",strlen("Hello"));
(gdb) list
3   
4   int main( void)
5   {
6       char str[] = "Hello";
7       int len,size;
8       printf("len = %d\n",strlen("Hello"));
9       len = strlen(str);
10      printf("len = %d\n",len);
11      size = sizeof("Hello");
12      printf("size = %d\n", size);
(gdb) s
len = 5
len = 5
size = 6
0xb7e60113 in ?? () from /lib/i386-linux-gnu/libc.so.6
(gdb) set auto-solib-add off
(gdb) b main
Breakpoint 1 at 0x804843e: file f1.c, line 5.
(gdb) r
Starting program: /home/slb/a.out 

Breakpoint 1, main () at f1.c:5
5   {
(gdb) s
6       char str[] = "Hello";
(gdb) s
8       printf("len = %d\n",strlen("Hello"));
(gdb) list
3   
4   int main( void)
5   {
6       char str[] = "Hello";
7       int len,size;
8       printf("len = %d\n",strlen("Hello"));
9       len = strlen(str);
10      printf("len = %d\n",len);
11      size = sizeof("Hello");
12      printf("size = %d\n", size);
(gdb) s
len = 5
len = 5
size = 6
0xb7e60113 in ?? () from /lib/i386-linux-gnu/libc.so.6
(gdb) s
Cannot find bounds of current function

Also, up will take you upwards through the call stack, function by function. Stop typing up when you are at the function you're interested in.

This is basically a case of RTFM.

I guess this takes a long time until we get out of the unwanted code.

(gdb) help s
Step program until it reaches a different source line.
Argument N means do this N times (or till program stops for another reason).
(gdb) help n
Step program, proceeding through subroutine calls.
Like the "step" command as long as subroutine calls do not happen;
when they do, the call is treated as one instruction.
Argument N means do this N times (or till program stops for another reason).

Sorry , I dont understand what you are trying to say here , if i knew how many lines i have to skip in advance, its easy, but i cannot always.

L7Sqr , your suggesin seeenm to work, i post the response later, schduled power cuts , need run..

Gaiety: That is expected when auto-solib-add mode is off. The step command in gdb will stop at the next function where the symbols are found.

Warning: If you use the step command while control is within a function that was compiled without debugging information, execution proceeds until control reaches a function that does have debugging information. Likewise, it will not step into a function which is compiled without debugging information.

Can you try with next command and let us know, what is that you are getting.

I guess the problem is that, the standard library is compiled with debug flags. Otherwise, this problem wouldn't have come in the first place. :)

please show the next command

Just press the 'n' in gdb session.

rustysynate
with next command its not entering any inetrnal code of lib functions, it works fine.

Thanks All.

This article has been dead for over six months. Start a new discussion instead.