Some examples

Jacek Wojdel wojdel at kbs.twi.tudelft.nl
Fri Sep 3 08:54:18 BST 1999


On Thu, 02 Sep 1999, you wrote:
> >
> >         Hi,
> > Did you remember to compile the code without optimisations ? Even on quite
> > standard level (-O2) there are some things that go skipped/unrolled/misaligned
> > in the code, so gdb (backend used by kdbg) can't synchronize well with the
> > sourcecode.
>
> Isn't that only a problem with gcc? I heard g++ was okay. I've had no
> trouble using using kdbg with g++ compiled programs with -O3.
>
> JFunk
	Hi,
I'm using GNU g++ version 2.95.1 and GNU gdb version 4.18 on Solaris machine. I
decided just to test if you're right, so I wrote the following program:
 1- #include <stdio.h>
 2-
 3- void main()
 4- {
 5-   int d = 0;
 6-   for (int i = 0; i < 100; i++ )
 7-     {
 8-       printf("%d\n", d);
 9-       d++;
10-     }
11- }

I compiled it with options -g3 -O3 and started debugger (at work I use XEmacs
as a front-end, but this shoudn't matter to the way the gdb works). When doing
step-by-step execution the line number 9 is never visited. Even if you set the
breakpoint on that line, the execution will stop at line 10. When compiling
with -O0, the line #9 is normally visited. Of course for some more complicated
programs the results of optimizations can be more "twisted" which results in
seemingly random jumping over some statements. If you really don't experience
such behavior, I'd like to know which versions of gcc/g++/gdb you use... and
upgrade, upgrade, UPGRADE !!! :)
Regards,
	Jacek
--
+-------------------------------------+
|from: J.C.Wojdel                     |
|      J.C.Wojdel at cs.tudelft.nl       |
+-------------------------------------+



More information about the KDevelop mailing list