I am trying to play with __attribute__so that the function is essentially compiled with different flags from the rest of the code. For instance:
#include <iostream>
#include <vector>
void MyNormalFunction();
void MyDebugabbleFunction() __attribute__((optimize(0)));
void MyNormalFunction()
{
std::cout << "Test" << std::endl;
std::vector<int> a;
for(unsigned int i = 0; i < 10; ++i)
{
a.push_back(i);
}
}
void MyDebugabbleFunction()
{
std::cout << "Test" << std::endl;
std::vector<int> a;
for(unsigned int i = 0; i < 10; ++i)
{
a.push_back(i);
}
}
int main()
{
MyNormalFunction();
MyDebugabbleFunction();
return 0;
}
I am creating with -g -O2, but I want to be able to debug MyDebugabbleFunction(), so I used __attribute__((optimize(0)))in his declaration. However, I cannot say any difference when going through these two functions using the debugger. I would expect the "seemingly unstable" behavior that I usually see when I try to execute optimized code in MyNormalFunction, but the standard behavior of "-g" is only a debugger in MyDebuggableFunction.
- __attribute__? - (.. , " " ) ? , ?
gcc 4.6.
EDIT GManNickG
-O2 -g:
#include <iostream>
#include <vector>
int MyNormalFunction();
int MyDebugabbleFunction() __attribute__((optimize(0)));
int MyNormalFunction()
{
int val = 0;
val = 1;
val = 2;
return val;
}
int MyDebugabbleFunction()
{
int val = 0;
val = 1;
val = 2;
return val;
}
int main()
{
int a = MyNormalFunction();
std::cout << a << std::endl;
int b = MyDebugabbleFunction();
std::cout << b << std::endl;
return 0;
}