bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gdb and assignment statements


From: Ranga Rao Ravuri
Subject: Re: Gdb and assignment statements
Date: Thu, 14 Dec 2000 11:34:31 +0530

Hi Art Berggreen 
   Please let me give the complete code it self and explain what
happened.
The following code was compiled with command
gcc -g3 -O0 x.c 
>x.c>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     1 #include <netinet/in.h>
      2 main()
      3 {
      4    int port = 5060;
      5 
      6    port=htons(port);
      7    printf("Port %d\n", port);
      8 }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Here is gdb out put after setting up the break point on line 6 

(gdb) b 6
Breakpoint 1 at 0x10a64: file x.c, line 6.
(gdb) info break
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x00010a64 in main at x.c:6
(gdb) r
Starting program: /export/home0/rangarao/examples/c/a.out 

Breakpoint 1, main () at x.c:7
7          printf("Port %d\n", port);
(gdb) info break
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x00010a64 in main at x.c:6
        breakpoint already hit 1 time
(gdb) info line 6
Line 6 of "x.c" is at address 0x10a64 <main+16> but contains no code.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Even after disabling the complete omptimization the no code generated
for line 6
If the 'port' is declared as STATIC gdb could break on that line and
showing properly
The earlier said behavior is observed even in case when 'port' is
'volatile'
Or Is this has any thing with gcc ?
Any suggestions please ..
thanks in adv
Ranga Rao R


Art Berggreen wrote:
> 
> Ranga Rao Ravuri wrote:
> 
> > I have a line in 'c' code like
> >
> >         10      int port;
> >         11      .
> >         12      .
> >         13      .
> > >>>>    14      x = htons(x);
> >         15      .
> >         16      .
> >         17
> > If I run this part of code on sun sparc with SunOs 5.7
> > the htons is defined like
> >
> > #define htons(x) (x)
> >
> > How do I break on line 14 and see what is happening ? It never breaks on
> > 14, rather it does on 15.
> > All statements (x) = (x) are ignored by gdb.For each such a case the
> > break point was set on next source statement.
> > Is that gcc which optimizes the expressions like 'x=x' by removing from
> > the code.
> >
> > Why so . In above case really I hppened to dig the header file why gdb
> > is not breaking on line: 14
> 
> Have you looked at the generated code to see if any code got produced
> for that line?  If you are compiling with any level of optimization, I
> wouldn't be surprised to find that the line got totally optimized out.
> In GDB, try "info line 14" and see what it says.  You could try making
> the variable static and volative and see what the compiler does.
> 
> Art



reply via email to

[Prev in Thread] Current Thread [Next in Thread]