Variable showing "unable to create variable object"
I am experimenting with CLion for embedded development. I hope I can stop having to use Eclipse for this purpose. I am using CLion plus the plugin "OpenOCD + STM32CubeMX support for ARM embedded development" which I like very well. I am finding one problem though that I hope someone can help me with.
Here is a simple program that I have created that illustrates my problem. (In order to make this problem easier to understand, I have eliminated a bunch of code that initializes various embedded peripherals to create the simplified program below.)
char const mydata[]="this is some data";
//char mydata[]="this is some data";
int main(void)
{
char data;
data = mydata[0];
while (1)
{
}
}
I am experimenting with various optimization levels and also with declaring the mydata[] array to be CONST or not. If it is not set as CONST, mydata is put in SRAM. If it is const, mydata is put in flash which is, of course, in a different memory location.
Using the default CMakeLists.txt file, if I create the mydata variable without CONST, the variable display properly shows the variable and when I enter 'x mydata' into the GDB window, I see the variable is in the proper memory space.
However, when I add the CONST qualifier, the variable windows says "-var-create: unable to create variable object" and the GDB window says "No symbol "mydata" in current context."
Changing the optimization level by adding
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
to CMakeLists.txt does not help.
When I perform the same test with Eclipse I see the intended behavior: I can see the proper memory contents in the proper memory space whether I set CONST or not.
Can I make any setup changes that will allow me to see the actual memory address of my variables?
Clark
请先登录再写评论。
Elijah, the awesome developer who created the plugin for ARM and STM32, contacted me. He explained how my program allows the compiler to optimize out the mydata character array. Changing
char data;
data = mydata[0];
to
char *data;
data = &mydata[0];
prevents the compiler from doing the optimization.
After making this change, CLion reports the correct memory address if the mydata variable is declared with or without the CONST modifier.
So everything is working just like it should.