[GCC-XML]Adding function body information

Brad King brad.king at kitware.com
Fri Oct 5 16:44:26 EDT 2001


> an extension that allows me to dump also parts of function bodies to xml. 
If you succeed in this implementation, we would love to have it
contributed.  Thanks for your efforts.

> Unfortuneally this is only working for inline functions. When I use 
> DECL_SAVED_TREE on a non inline function it returns always 0, regardless if 
> the funtion is defined or not in the translation unit.
> Are the function bodies pherhaps already removed from the trees when the xml 
> extension is invoked (translated into something else) ?
GCC saves memory by throwing away function bodies once it has finished
with their implementation code.  Only inline functions need to be kept
around so that their code can be re-used.  Since the extension is invoked
after the whole translation unit has been processed (to allow for template
instantiation), the bodies are already gone.

Look at the function "expand_body" in gcc/cp/semantics.c
At the bottom, it throws away the function body in the following segment
of code:

  /* If possible, obliterate the body of the function so that it can
     be garbage collected.  */
  if (dump_enabled_p (TDI_all))
    /* Keep the body; we're going to dump it.  */
  else if (DECL_INLINE (fn) && flag_inline_trees)
    /* We might need the body of this function so that we can expand
       it inline somewhere else.  */
    /* We don't need the body; blow it away.  */

You can prevent this behavior by adding these lines before the last

  else if (flag_xml)
    /* Keep the body; it will be dumped in the XML output.  */

I haven't actually tried this, so let me know if it works.  If so, I'll
add the change to the GCC-XML patch of sematics.c.  Thanks.

> Can I get the collumn in the source file - not only the line - for a node ? 
The DECL_SOURCE_FILE and DECL_SOURCE_LINE macros access a node as a
"tree_decl", which looks like this:
struct tree_decl
  struct tree_common common;
  const char *filename;
  int linenum;
  unsigned int uid;
  union tree_node *size;
  ENUM_BITFIELD(machine_mode) mode : 8;
I'm afraid that the column number is not stored here, unless some other
macro uses a leftover field for it.  You'll have to trace the parser in
parse.y and lex.c to see when the values are stored, and add one yourself.

Good luck,

More information about the gccxml mailing list