2011-06-30 08:43:16     Variable type

Document created by Aaronwu Employee on Oct 16, 2013
Version 1Show Document
  • View in full screen mode

2011-06-30 08:43:16     Variable type

Andrea Mannuccini (SWITZERLAND)

Message: 101928   

 

Hi,

 

I am working on a bare metal application on BF534, using GNU toolchain for win 2010R1

 

I am looking for a way to automatically generate a file with some information about all the global variables used on my code: particularly I need info about the name, the size (8, 16, 32 bit) and the type signed/unsigned.

 

Now, I am not sure whether I can generate this file either through the compiler or retrieve this information from the generated executable. I found that readelf can retrieve the symbol table: here I can found all what I need but the type signed/unsigned.

 

Can you please suggest a way to generate such information?

 

Thank you in advance

 

Regards

 

Andrea

QuoteReplyEditDelete

 

 

2011-06-30 09:28:46     Re: Variable type

Peter Budny (UNITED STATES)

Message: 101930   

 

Unfortunately, once the code is compiled, there is no meaning to "signed" and "unsigned"... it's just a memory address with some bytes in it, and the code just uses some mathematical operators on it.

 

The information you want can only come from the source, but finding it will be difficult; the compiler isn't meant to output that sort of information, although there might be some backend way intended for debugging to have it dump data halfway through compilation. You might have better luck getting a list of variable names from the ELF file, then searching through the source to find their definitions (perhaps a TAGS file would help, since that's what they're for).

QuoteReplyEditDelete

 

 

2011-06-30 10:42:34     Re: Variable type

Mike Frysinger (UNITED STATES)

Message: 101932   

 

Peter is pretty much correct.  if you built all the objects with debugging (-g), you might be able to extract the type information from the DWARF tables, but that might be pretty complicated to pull off ...

 

$ cat test.c

int i;

unsigned int j;

$ bfin-elf-gcc -c test.c -g

$ bfin-elf-readelf -wi test.o

...

<1><25>: Abbrev Number: 2 (DW_TAG_variable)

    <26>   DW_AT_name        : i

...

<1><35>: Abbrev Number: 3 (DW_TAG_base_type)

    <36>   DW_AT_byte_size   : 4

    <37>   DW_AT_encoding    : 5        (signed)

    <38>   DW_AT_name        : int

...

<1><3c>: Abbrev Number: 2 (DW_TAG_variable)

    <3d>   DW_AT_name        : j

...

<1><4c>: Abbrev Number: 4 (DW_TAG_base_type)

    <4d>   DW_AT_byte_size   : 4

    <4e>   DW_AT_encoding    : 7        (unsigned)

    <4f>   DW_AT_name        : (indirect string, offset: 0x20): unsigned int

...

QuoteReplyEditDelete

 

 

2011-07-04 05:47:37     Re: Variable type

Andrea Mannuccini (SWITZERLAND)

Message: 102073   

 

Thank you guys!

 

Andrea

Attachments

    Outcomes