LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2011, 09:21 AM   #1
vijayabcdef
LQ Newbie
 
Registered: Jul 2010
Posts: 8

Rep: Reputation: 0
how to get list of variables of particular type


Hi,
I have a C header file which have arrays of predefined(known) structure type. But i dont have names of arrays and their size. when i include that file and compile my application, i want to know the names and sizesof those arrays.
purpose of application is to get the content of those arrays and to explain it in descriptive words instead of hex numbers.ofcourse this can be done by file pointers and reading also with out header file inclusion, but as i am working in C, once compiled, those variables are in my address space in i include header file.

any suggestion to get variable names is welcome.

yours vijay
 
Old 06-15-2011, 04:25 PM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
That can't really be done in C without e.g. parsing the header file.
 
Old 06-16-2011, 04:04 AM   #3
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Are you speaking of the content of the file, or the memory content at runtime?

For the former I remember General Edit for Mac, and there might be something similar for Linux.
 
Old 06-20-2011, 09:39 AM   #4
vijayabcdef
LQ Newbie
 
Registered: Jul 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Question how to get list of variables of particular type

Thanks Mr Graham and Mr Reuti,

I want to get whats there in those array elements in run time Just like GDB and Valgrind pointing to particular variable or function in case of any fault. That indicates me we may be able to read what variables are there in process address space when it is running. similarly can we know address of arrays and number of elements in it.


Hope that this will clarify my requirement.

yours vijay
 
Old 06-20-2011, 01:34 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Do you know python? If so, gdb has an API for python. I don't know python, but this looks like a good start:
http://sourceware.org/gdb/wiki/PythonGdbTutorial

Kevin Barry
 
Old 06-21-2011, 01:41 AM   #6
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by vijayabcdef View Post
Thanks Mr Graham and Mr Reuti,

I want to get whats there in those array elements in run time Just like GDB and Valgrind pointing to particular variable or function in case of any fault. That indicates me we may be able to read what variables are there in process address space when it is running. similarly can we know address of arrays and number of elements in it.


Hope that this will clarify my requirement.

yours vijay
Your requirement was quite clear from the beginning. valgrind doesn't (to my knowledge...?) tell you the types of variables etc. and gdb does exactly what I said before - it uses debugging information to find the source files the program uses and (I believe) a program called addr2line (see `man 1 addr2line') to tell what line of the program it is.

At run-time, variables in C don't have "types" - they are simply memory addresses you use as if they were certain types. These addresses are known as "symbols" in the ELF file you run. You can take the address of variables you're interested in or even parse the ELF file to find the symbols, but finding the type of them at run-time will require you to find the source/header file and parse it.

Go with another method, like ta0kira suggests.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
E:Type 'Reading' is not known on line 53 in source list /etc/apt/sources.list, E:The hunterclan0405 Linux - Newbie 2 01-15-2011 11:08 PM
How to list the variables that are used in a script? alexandrum77 Linux - Newbie 2 05-10-2010 03:23 AM
apt-get; E: Type 'GPG' is not known on line 20 in source list /etc/apt/sources.list tomorrow Linux - Newbie 9 05-21-2009 08:42 AM
Get strings from list using variables mwade Programming 5 10-28-2006 08:01 PM
list<type> how can I make type be a pointer? exodist Programming 2 06-06-2005 08:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration