How to obtain address of gobal variable for MPC55xx/MPC56xx in CodeWarrior 2.x

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

How to obtain address of gobal variable for MPC55xx/MPC56xx in CodeWarrior 2.x

613 Views
plabgh
Contributor I

Hi,

I want to develop a tool which can parse the .MAP file of CodeWarrior project, and then automatically generate another file to store gobal variables name and their corresponding address.

Using CodeWarrior 5.x, there is a detailed description about  gobal variables name and their corresponding address in .map file of S12x project.

But the .MAP files vary from CodeWarrior 5.x to CodeWarrior 2.x, there is no description about variables in .MAP file of CodeWarrior 2.x.

Could you tell me how i can obtain address and name of gobal variable in .MAP/.elf/.mot file of CodeWarrior 2.x project ?

0 Kudos
2 Replies

375 Views
plabgh
Contributor I

anybody knows how to solve this problem ?

thk...

0 Kudos

375 Views
stanish
NXP Employee
NXP Employee

Hi wang heng,

It might be quite challenging to get this info from map file.

What about disassemble your .elf file using CodeWarrior linker and extract all data section names that are writable during execution (Flags have bit 0x01 set):

e.g.:

==> .sdata [13]: Section Header

    type:    00000001, flags:  00000003

    address: 00030800, offset: 00001800, size: 0000000c

    link:    00000000, info:   00000000, alignment: 8, entry size: 0

==> .sdata2 [14]: Section Header

    type:    00000001, flags:  00000002

    address: 00030810, offset: 00001810, size: 00000004

    link:    00000000, info:   00000000, alignment: 8, entry size: 0

==> .bss [15]: Section Header

    type:    00000008, flags:  00000003

    address: 400004e8, offset: 00001818, size: 0000000c

    link:    00000000, info:   00000000, alignment: 8, entry size: 0

and then filter symbol table ".symtab" bind = GLOB; type = OBJ;  for only sections (shdnx) extracted in the previous step

e.g.

==> .symtab

    entry  spndx   value     size   bind       type    other    shndx             name

    [   0]     0   00000000     0   LOC (00)   NULL(00)   00    (0000)UND        

    [   1]     1   00000000     0   LOC (00)   FILE(04)   00    (fff1)ABS         main.c

    [   2]     0   00030000     0   LOC (00)   SECT(03)   00    (0006).text_vle   .text_vle

    [   3]     0   0003041c     0   LOC (00)   SECT(03)   00    (000a)extab       extab

    [   4]     0   0003044c     0   LOC (00)   SECT(03)   00    (000b)extabindex  extabindex

    [   5]     0   400004d0     0   LOC (00)   SECT(03)   00    (000d).sdata      .sdata

    [   6]     0   400004e0     0   LOC (00)   SECT(03)   00    (000e).sdata2     .sdata2

    [   7]     8   0003041c     8   LOC (00)   OBJ (01)   00    (000a)extab       @256

    [   8]    13   0003044c    12   LOC (00)   OBJ (01)   00    (000b)extabindex  @257

    [   9]    18   00030424     8   LOC (00)   OBJ (01)   00    (000a)extab       @278

    [  10]    23   00030458    12   LOC (00)   OBJ (01)   00    (000b)extabindex  @279

    [  11]    28   0003042c     8   LOC (00)   OBJ (01)   00    (000a)extab       @296

    [  12]    33   00030464    12   LOC (00)   OBJ (01)   00    (000b)extabindex  @297

    [  13]    38   00030434     8   LOC (00)   OBJ (01)   00    (000a)extab       @306

    [  14]    43   00030470    12   LOC (00)   OBJ (01)   00    (000b)extabindex  @307

...

    [  73]   366   400004d0     4   GLOB(01)   OBJ (01)   00    (000d).sdata      myGlob

    [  74]   373   400004e0     4   GLOB(01)   OBJ (01)   00    (000e).sdata2     myConst

    [  75]   381   000300ea   102   GLOB(01)   FUNC(02)   00    (0006).text_vle   clear_CF

...

You could possibly use the command line GNU utility - readelf to get this information.

Hope it helps.

Stan

0 Kudos