parsing a c project

Discussion in 'Python' started by Aitor Garcia, Aug 4, 2010.

  1. Aitor Garcia

    Aitor Garcia Guest

    Hi,

    I need to know the memory locations of all variables in a C project including
    variables allocated inside structs.

    What I want to do in to expand the structs into its basic elements (floats,
    int16 and int8).


    In a header file (example.h) I have the following definitions.

    struct house{
    float area;

    int8 rooms;
    int16 visits;
    };


    struct car{
    float price;
    int8 color;
    };

    I have been able to extract from the project the name of every struct, the type of the struct and the beginning address of each struct.


    example_list=[]
    example_list.append(['house1','struct house','000082d0')
    example_list.append(['house2','struct house','00003000')
    example_list.append(['car1','struct car','00004000')

    I need an output like this.

    house1_struct_house_area float 000082d0
    house1_struct_house_rooms int8 000082d4
    house1_struct_house_visits int16 000082d5
    house2_struct_house_area float 00003000
    house2_struct_house_rooms int8 00003004
    house2_struct_house_visits int16 00003005
    car1_struct_car_price float 00004000
    car1_struct_car_color int8 00004004

    How can I efficiently do this in Python ?

    I do not have very clear which element of Python should I use
    to store the struct list or class

    I would be very grateful if someone could give me some pointers.

    Aitor
    Aitor Garcia, Aug 4, 2010
    #1
    1. Advertising

  2. Aitor Garcia

    Jon Clements Guest

    On 4 Aug, 12:33, Aitor Garcia <> wrote:
    > Hi,
    >
    > I need to know the memory locations of all variables in a C project including
    > variables allocated inside structs.


    Pray tell us why?

    >
    > What I want to do in to expand the structs into its basic elements (floats,
    > int16 and int8).
    >
    > In a  header file (example.h) I have the following definitions.
    >
    > struct house{
    >   float area;
    >
    >   int8 rooms;
    >   int16 visits;
    >
    > };
    >
    > struct car{
    >   float price;
    >   int8 color;
    >
    > };
    >
    > I have been able to extract from the project the name of every struct, the type of the struct and the beginning address of each struct.


    How have you done this? What compiler and debugger/profiler are you
    using? etc...
    The memory address is going to possibly change every time, unless
    you're talking static variables within an applications own address
    space (even then I'm not 100% sure -- I haven't had to touch C in 2
    years, so I'd declare myself rusty).

    >
    > example_list=[]
    > example_list.append(['house1','struct house','000082d0')
    > example_list.append(['house2','struct house','00003000')
    > example_list.append(['car1','struct car','00004000')
    >
    > I need an output like this.
    >
    > house1_struct_house_area float 000082d0
    > house1_struct_house_rooms int8 000082d4
    > house1_struct_house_visits int16 000082d5
    > house2_struct_house_area float 00003000
    > house2_struct_house_rooms int8 00003004
    > house2_struct_house_visits int16 00003005
    > car1_struct_car_price float 00004000
    > car1_struct_car_color int8 00004004
    >
    > How can I efficiently do this in Python ?


    Well using the pyparsing library, it's extremely easy to parse the C
    grammar. But that's not what you're asking.

    >
    > I do not have very clear which element of Python should I use
    > to store the struct list or class
    >
    > I would be very grateful if someone could give me some pointers.


    An un-intended C pun :) ?

    If you let the list know the use-case, then we might stand a chance of
    giving you some reference (C++ pun?)

    Jon.
    Jon Clements, Aug 4, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    873
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    578
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    608
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    431
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    727
    John Levine
    Feb 2, 2012
Loading...

Share This Page