Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Using -O3 optimization and trying to get a bt : (10 Items)
   
Using -O3 optimization and trying to get a bt  
is this possible if I use -fno-optimize-sibling-calls or something to that affect....

What is the maximum -O level with which I could see a bt and local variables.
I am compiling for ARM ...

Thanks 

Preeti.
Re: Using -O3 optimization and trying to get a bt  
> is this possible if I use -fno-optimize-sibling-calls or something to that 
> affect....
> 
> What is the maximum -O level with which I could see a bt and local variables.
> I am compiling for ARM ...

It should be possible to get a backtrace using -O3. Some local variables may have been removed by optimization so this 
might not always be possible.

Regards,

Ryan Mansfield 

Re: Using -O3 optimization and trying to get a bt  
-O3 does not give me a back trace ....but -O0 does ... so I needed to find the best option to get bt while I optimize...
Re: Using -O3 optimization and trying to get a bt  
> -O3 does not give me a back trace ....but -O0 does ... so I needed to find the
>  best option to get bt while I optimize...

Does not give you a backtrace as in no backtrace at all? Or is the backtrace  incorrect?

Does -O2 give you a backtrace? If it lose the ability to backtrace between -O2 and -O3, it might be that the functions 
were inlined.

For example:

int a(int x) { return x; }
int b(int x) { return a(x); }
int c(int x) { return b(x); }

int main() {
 return c(3);
}


With -O3, c is never called. No stack to backtrace
With -O2 or -O3 -fno-inline-functions, a is called but b and c calls are optimized out.

#0  0x08048333 in a ()
#1  0x0804837d in main ()
With -O2 -fno-optimize-sibling-calls, a, b and c are called and therefore we can get a backtrace.

#0  0x08048333 in a ()
#1  0x08048351 in b ()
#2  0x08048371 in c ()
#3  0x0804839d in main ()

Using -O3 does not cripple GDB's ability to do a backtrace -- better  optimizations just mean there might be less stack,
 or no stack to backtrace.

Which function calls gcc removes is very specific to the code being compiled so generalized statements about how to get 
a backtrace at O3 won't be accurate. 

Regards,

Ryan Mansfield
Re: Using -O3 optimization and trying to get a bt  
Will -fno-inline help that?

Ryan Mansfield wrote:
>
> > -O3 does not give me a back trace ....but -O0 does ... so I needed 
> to find the
> >  best option to get bt while I optimize...
>
> Does not give you a backtrace as in no backtrace at all? Or is the 
> backtrace  incorrect?
>
> Does -O2 give you a backtrace? If it lose the ability to backtrace 
> between -O2 and -O3, it might be that the functions were inlined.
>
> For example:
>
> int a(int x) { return x; }
> int b(int x) { return a(x); }
> int c(int x) { return b(x); }
>
> int main() {
>  return c(3);
> }
>
>
> With -O3, c is never called. No stack to backtrace
> With -O2 or -O3 -fno-inline-functions, a is called but b and c calls 
> are optimized out.
>
> #0  0x08048333 in a ()
> #1  0x0804837d in main ()
> With -O2 -fno-optimize-sibling-calls, a, b and c are called and 
> therefore we can get a backtrace.
>
> #0  0x08048333 in a ()
> #1  0x08048351 in b ()
> #2  0x08048371 in c ()
> #3  0x0804839d in main ()
>
> Using -O3 does not cripple GDB's ability to do a backtrace -- better  
> optimizations just mean there might be less stack, or no stack to 
> backtrace.
>
> Which function calls gcc removes is very specific to the code being 
> compiled so generalized statements about how to get a backtrace at O3 
> won't be accurate.
>
> Regards,
>
> Ryan Mansfield
>
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post3072
>

-- 
cburgess@qnx.com

Re: Using -O3 optimization and trying to get a bt  
Thanks for the detailed explanation...
I do get a bt but not complete; only one frame ; all other functions are inline ...
so that explains
Let me try -O2 -fno-optimize-sibling-calls

Will update this post with my findings ....

Thanks...

Preeti
Re: Using -O3 optimization and trying to get a bt  
Thanks for the detailed explanation...
I do get a bt but not complete; only one frame ; all other functions are inline ...
so that explains
Let me try -O2 -fno-optimize-sibling-calls

Will update this post with my findings ....

Thanks...

Preeti
Re: Using -O3 optimization and trying to get a bt  
 -fno-optimize-sibling calls gives a compile error : "Invalid option"  
I am compiling for ARM ...?

Thanks 

Preeti
Re: Using -O3 optimization and trying to get a bt  
Which version of gcc are you using? The -foptimize-sibling-calls and corresponding -fno-optimize-sibling-calls are only 
valid options in gcc 3.3.5 and newer. And depending on which version of qcc you are using, you may need to specify -Wc,-
fno-optimize-sibling-calls to have qcc pass the option down to the c/c++ frontend.

Regards,

Ryan Mansfield
Re: Using -O3 optimization and trying to get a bt  
I think we are using 2.95.3 
I am basing this on the fact that /opt/qnx630/host/linux/x86/etc/qcc/gcc/default
has DIR=2.95.3$

Also I have a -Wc option specified ahead of -fno-optimize-sibling-calls ....

Meanwhile -fno-inline worked for me...not sure what the difference is between the 2.

Thanks...

Preeti