Abrupt GDB Behaviour

Gdb on my system is behaving abruptly.
Say if your program has some 10 lines of code in a function in your program.
Code are simple statements with no looping or jumps.
Example:

fn()
 {
   printf("0");
   printf("1");
   printf("2");
   printf("3");
   printf("4");
   printf("5");
   printf("6");
   printf("7");
   printf("8");
   printf("9");
  }
  
 main()
 {
    fn();
   
    return(0);
 }

Say you put breakpoint at fn() start.
Your breakpoint hits and then say after debugging(using next/n gdb command) till 3 lines in the function the gdb shows directly the line say 7th line which it must not. Note that gdb does not execute the statement at that line.
Press again next and it will show properly 4th line now.

Why gdb is behaving so and how to make it normal?

GDB is GNU gdb (GDB) SUSE (7.3-0.6.1)
OS is SLES 64 bit.

Just compiled the code like this:

$ gcc -g3 -Wall -Werror main.c -o M2
$ ll
total 20
-rwxr-xr-x  1 praveen_218  grp  14144 Apr 10 19:45 M2
-rw-r--r--  1 praveen_218  grp    270 Apr 10 19:34 main.c

The output should be like the below:


$ gdb ./M2
GNU gdb 6.1.1 [FreeBSD]
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 "i386-marcel-freebsd"...
(gdb) r
Starting program: /.amd/bng-enghomes001-cf1-6/vol/home6/homes6/pkumarpr/tr/gdbTrials/M2
0123456789

Program exited normally.
(gdb) b fn
Breakpoint 1 at 0x8048406: file main.c, line 10.
(gdb) r
Starting program: /.amd/bng-enghomes001-cf1-6/vol/home6/homes6/pkumarpr/tr/gdbTrials/M2

Breakpoint 1, fn () at main.c:10
10         printf("0");
(gdb) n
11         printf("1");
(gdb) n
12         printf("2");
(gdb) n
13         printf("3");
(gdb) n 2
15         printf("5");
(gdb) n 4
19         printf("9");
(gdb) n 3
0123456789
28          return(0);
(gdb)

This is the behavior expected, however it is on FreeBSD7.1 and the gdb on Linux behaves exactly the same unless on the latest version of GDB linux port introducing any kind of gdb-local environmental variable masking the next default. This might be the latest feature. Without this I don't find any reason (no doubt on the GDB code unless you compiled a tweaked source of it to install the same).

Look the release note of the GDB version you are using and try to grep for next to get better insight on the environmental variable, if any.

I am using just n and not "n N" and still its showing me further lines though not executing them.

Did you compile it with the debugging "-g" switch on...

obviously shamrock.
without it how can I debug it with gdb?

This is what I want to convey. Simply using 'n' and it behaves like 'n 1' as default. In your case it's 'n 7' as default. So just try explicitly as 'n 1' and see what happens. You may also try 'n -6' , 'n -2', 'n -1' to observe what happens.

My suggestion:
Just look at the release note of the GDB version your using or the latest manual for 'stepping' and/or 'next' behavior of the latest release.

I will try that.
But that jump by 1 is not consistent.
sometimes it is n 1 and some time n N.