home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / object / 5036 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  2.5 KB

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