home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.object:5036 comp.lang.c++:19838 comp.lang.c:20151
- Path: sparky!uunet!mcsun!uknet!gdt!aber!fronta.aber.ac.uk!pcg
- From: pcg@aber.ac.uk (Piercarlo Grandi)
- Newsgroups: comp.object,comp.lang.c++,comp.lang.c
- Subject: Re: Runtime access to Symbol tables
- Message-ID: <PCG.93Jan24195811@decb.aber.ac.uk>
- Date: 24 Jan 93 19:58:11 GMT
- References: <1993Jan19.214950.4762@advtech.uswest.com>
- Sender: news@aber.ac.uk (USENET news service)
- Reply-To: pcg@aber.ac.uk (Piercarlo Grandi)
- Organization: Prifysgol Cymru, Aberystwyth
- Lines: 44
- In-Reply-To: bar@advtech.uswest.com's message of 19 Jan 93 21: 49:50 GMT
- Nntp-Posting-Host: decb.aber.ac.uk
-
- >>> On 19 Jan 93 21:49:50 GMT, bar@advtech.uswest.com (Bala Ramakrishnan) said:
-
- Ramakrishnan> I would like to know if it is possible/easy to access the
- Ramakrishnan> symbol tables from the executable (a.out) for the above
- Ramakrishnan> purpose, assuming that the corresponding .o files have
- Ramakrishnan> been compiled with the '-g' option.
-
- Ah yes, of course. GDB does it fairly well. So probably your best route
- is to read the GDB code and do something similar. I would guess that on
- most machines you have to load in the *whole* of the symbol table to do
- anything useful; most symbol table formats are such that it is not easy
- to scan its sequential form to find only what you need.
-
- I think the best interface for such a function would take s tring for
- the type of the entity to print, and a pointer to the entity itself:
-
- class Square { .... }; Square a_square(....);
- cout << symbolically("Square",&a_square) << '\n';
-
- It would also be possible, if you want to print a named entity, to look
- up the type of the named entity in the symbol table, but I think that in
- practice this is extra overhead and most probably most of the time you
- would would to print symbolically the contents of an unnamed entity.
-
- But this gets into trouble, as you would seem to need a general term
- parser withing your function, as evident by your example:
-
- Ramakrishnan> LogTheObject("Bar::DoSomething()", "*f");
-
- This could become:
-
- symbolically("proc_name","a_term")
-
- where "a_term" looks quite hard to tackle (GDB more or less doe sit, and
- it's not simple). Consider the alternatives:
-
- symbolically("TreeKeyValue",root->left->right->tag.value)
- symbolically("AClass::ThisProc","root->left->right->tag.value");
-
- I think the first laternative is much easier to implement and provides
- the same value.
- --
- Piercarlo Grandi <pcg@aber.ac.uk> c/o Dept of CS
- University of Wales, Penglais, Aberystwyth SY23 3BZ, UK
-