Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > parsing a c project

Reply
Thread Tools

parsing a c project

 
 
Aitor Garcia
Guest
Posts: n/a
 
      08-04-2010
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 int.


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




 
Reply With Quote
 
 
 
 
Jon Clements
Guest
Posts: n/a
 
      08-04-2010
On 4 Aug, 12:33, Aitor Garcia <(E-Mail Removed)> 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 int.
>
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 08:58 PM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments