c - How to obtain addresses of structure members -


i'm doing testing of project based on cortex-m0. firmware developed in c using keil (v. 4.71.2) , arm linker (v. 5.03). have read/write access ram use simulate failures, , need find out addresses of variables need modify.

right i'm using linker map file handy scalar global variables:

myvar        0x00005978   data      4  file1.o(.constdata) 

here know writing 4 bytes @ address 0x00005978 alter variable myvar. however, cannot apply same approach global structures:

mystruct     0x00020000   data     400 file2.o(.data) 

i have start address of mystruct, however, have troubles access mystruct.module2.config.myvar. since code still being developed, new fields added mystruct.module1 , address of mystruct.module2 changes.

is possible force linker output addresses of individual fields in structure?

as workaround declare global variable address want:

uint32_t * const myvar_ptr = &mystruct.module2.config.myvar; 

then can find address of myvar_ptr in linker map , read obtain address of mystruct.module2.config.myvar. however, approach wastes 4 bytes of rom store each pointer, , rom size strictly limited, cannot declare 100 pointers targeting each field of mystruct. there better way?

as noted in comment, structure alignment may issue. looks keil compiler support pack() #pragma can control alignment of struct members. can use .map file starting address of struct, , use c include file defines struct calculate offsets of individual members.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -