Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

IDE Debugger

Altera_Forum
Honored Contributor II
1,430 Views

I started to use the IDE debug environment on Tuesday. So far it looks cool, however I had some problems last night. When I did multiple single steps, the PC was executing lines of C code at random (so it seemed). It was not sequential. I even pulled out of the IDE and ran the nios2-debug (GNU) and it did the same thing. Looks like the assembly is not in sync with the C code. Breakpoints worked, but when I modified variables the program did not behave as I expected. Is there some option that I accidentaly enabled? I had it working before without this issue.... 

 

Rick
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
344 Views

Classic debug problem: compiler optimization... makes things act very strange when debugging and appear to "jump around". I suggest you go into your source & syslib project's "properties" in the IDE and locate C/C++ build options, turn optimization off (-O0). 

 

You should also be able to just selet "Debug" (vs. "Release") in the same part of the GUI to do this, then re-compile. 

 

Note: you should do this for BOTH your application and the syslib project.
0 Kudos
Altera_Forum
Honored Contributor II
344 Views

Hi guys, 

 

What if there is a need to debug with optimized code? How can things be kept in sync? 

 

Rob http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/huh.gif
0 Kudos
Altera_Forum
Honored Contributor II
344 Views

Keeping it in sync. as in debugging it in the linear fashion instead of jumping around? I think that would be even more confusing since that is not what the compiled optimized code is doing. 

 

It is good practice to debug everything with no optimization first (if possible) and work out the bugs functionally then you optimize it to get some extra speed/smaller memory footprint. If there is problems there then you take a look at the debugger with the optimized code to see what the compiler did to break your previously working functionality.
0 Kudos
Altera_Forum
Honored Contributor II
344 Views

Perhaps this is the wrong place to post this, but as a software engineer, I do not trust all compiler&#39;s optimization without running in the debug environment first. They can sometimes do wierd stuff to your code. If the optimization doen&#39;t work, but the non-optimized does, how are you supposed to debug it? The Nios2 debugger is the first debugger that I have ever used that does not debug optimized code.

0 Kudos
Altera_Forum
Honored Contributor II
344 Views

As a hard- and software engineer, I do not trust compilers at all ;-) I have seen strange behavior with optimized code with different debuggers, I suppose that is in the nature of the optimization (how can you step e.g. through a for-loop that was simply optimized away?). And I have spent hours of searching errors that turned out to be compiler-bugs... 

 

Thomas
0 Kudos
Altera_Forum
Honored Contributor II
344 Views

 

--- Quote Start ---  

originally posted by rppolicy@Jan 3 2005, 12:07 PM 

perhaps this is the wrong place to post this, but as a software engineer, i do not trust all compiler&#39;s optimization without running in the debug environment first.  they can sometimes do wierd stuff to your code.  if the optimization doen&#39;t work, but the non-optimized does, how are you supposed to debug it?  the nios2 debugger is the first debugger that i have ever used that does not debug optimized code. 

--- Quote End ---  

 

rpppolicy, 

 

The Nios2 debugger does debug optimised code. Your original complaint was that the debugger jumps around the C code. This is simply because the compiler has re-orderred the code for optimal efficiency, so the debugger follows the code sequence which is executed. This is in common with many debuggers
0 Kudos
Reply