9 years, 4 months ago.

One of my pointer values is getting optimized out. How do I prevent this?

I'm stepping through my code to see where a certain bug occurs with my display driver, and found that something strange is going on. An instance of the class gets initialized properly, but once I try to use a method of that class, the pointer value seems to have been changed somehow.

I appear to initialize correctly...

Display * volatile const sys_disp = new Display();

(gdb) p sys_disp

$1 = (Display * const volatile) 0x20002638

...but the value gets changed once I want to to use it.

sys_disp->write_all_lines();

(gdb) p sys_disp

$2 = (Display * const volatile) 0x0

Just some context about our project, we are using mbed RTOS, and this is happening only after a context switch. Could it be possible that registers are not being restored correctly kernel side (I just think of this since the 'optimized out' values are being stored in regisers)? I'll be happy to provide more debug output if necessary.

I think you'll have to provide some actual code beyond the pseudo-code.

posted by Dan East 23 Dec 2014
Be the first to answer this question.