Adding reflection to a C project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding reflection to a C project

864 Views
michelkuenemann
Contributor III

Hi all,

I have coded a small and handy monitor which I link to all my projects. Now I would like to add to this monitor the ability to print out the value of any variable during run time, without having to add manually a symbol table to the project, as far as possible.

This feature is called "reflection".

See how this topic is treated in Stack Overflow here: linux - Can a running C program access its own symbol table? - Stack Overflow 

My questions:

1 - is there a way to add reflection to an LPCxpresso project ?

2 - where can I find examples of LPCxpresso projects implementing reflection ?

Thanks a lot,

Regards,

Michel Kuenemann

0 Kudos
4 Replies

548 Views
lpcxpresso_supp
NXP Employee
NXP Employee

The GNU tools for ARM embedded used by LPCXpresso IDE are called "arm-none-eabi-nm" etc.

Regards,

LPCXpresso Support

548 Views
michelkuenemann
Contributor III

Thanks a lot, I will try this soon.

BTW - is there a tuto somewhere made by someone who has already made this ?  Or am I really the first one to do this ?

Regards,

Michel

0 Kudos

548 Views
thefallguy
Contributor IV

At runtime you do not have access to the symbol table of the axf file. In an Embedded system there is not the space. Symbol tables are huge compared with the flash space available. Megabytes vs kilobytes.

on Linux you have the executable file on disk so the symbol table can be found and searched.

so, unless you executable file is very very small this is not possible on any embedded system.

0 Kudos

548 Views
michelkuenemann
Contributor III

OK - I completely agree that it has no sense to try to access all the symbols, but if you read the bottom of the topic, you will see a "semi-automatic" solution to create a symbol table from the project source files thanks to a script executed at compile time. This script seems to create a new C file containing a structure with all the interesting symbols.

Based on this, I have tried to add a Pre-Build step in my project with commands lines like these ones:

nm $@ | awk 'BEGIN{ print "#include <stdio.h>"; print "#include \"reflect.h\""; print "struct sym_table_t gbl_sym_table[]={" } 
{ if(NF==3){print "{\"" $$3 "\", (void*)0x" $$1 "},"}} END{print "{NULL,NULL} };"}' > .reflect.real.c         gcc -c .reflect.real.c -o .reflect.real.o         gcc -o $@ $^ .reflect.real.o

I get errors, because LPCxpresso is not able to find the "nm" utility...

Do you know how it would be possible to create this "reflect.c" file in an LPCxpresso Pre-Build step ?

Thank you,

Michel

0 Kudos