Skip to content

Debug

Debug

use gdb to print local variable in other files

p 'file.c'::variable
  • value has been optimized out

It means you compiled with e.g. gcc -O3 and the gcc optimiser found that some of your variables were redundant in some way that allowed them to be optimised away. In this particular case you appear to have three variables a, b, c with the same value and presumably they can all be aliassed to a single variable. Compile with optimisation disabled, e.g. gcc -O0, if you want to see such variables (this is generally a good idea for debug builds in any case).

print structure base on structure pointer address

p *(struct mystruct*) 0x00001234

using i2c-tool to configure i2c registers, get following value

i2cconfig --port=0 --sda=18 --scl=19 --freq=100000

image-20241219210724942

image-20241220193539401

image-20241220201616624

Result

The reason of registers cannot be set is because I confuse hexadecimal with decimal, i.e. I mis-use hexadecimal as decimal to check binary bitset value.