* -fdump-translation-unit-xml @ 2002-09-28 9:40 Lorenzo Delana 2002-09-30 11:14 ` -fdump-translation-unit-xml Matt Austern 0 siblings, 1 reply; 13+ messages in thread From: Lorenzo Delana @ 2002-09-28 9:40 UTC (permalink / raw) To: gcc If you try to parse the result to `-fdump-translation-unit' you meet some problems specially for the question about where a string end, etc.. This problem was addressed in the past by someone in this list... Someone of you know http://www.gccxml.org, that creates a patch to GCC totally apart ( not intrusive ), but this patch is actually uncompleted ( eg.templates, etc.. ) and need you to understand a new semantic of nodes... well, can be simplified and collected respect to the raw translation unit dump of gcc... In any case I made a patch to tree.h and tree-dump.c, to let -fdump-translation-unit-xml to dump the .tu file in XML mode, so you get something like: <?xml version='1.0'?> <!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd"> <GXXTranslationUnit> <Node index="1" codename="namespace_decl"> <ChildField name="name" value="2"/> <StringField name="srcp" value="<internal>:0"/> <ChildField name="dcls" value="3"/> </Node> <Node index="2" codename="identifier_node"> <String name="strg" value="::"/> <Integer name="lngt" value="2"/> </Node> <Node index="3" codename="function_decl"> <ChildField name="name" value="4"/> <ChildField name="type" value="5"/> <StringField name="srcp" value="t.cxx:27"/> <ChildField name="chan" value="6"/> <String value="C"/> <String value="extern"/> <ChildField name="body" value="7"/> </Node> <Node index="4" codename="identifier_node"> <String name="strg" value="main"/> <Integer name="lngt" value="4"/> </Node> <Node index="5" codename="function_type"> <ChildField name="size" value="8"/> <Integer name="algn" value="64"/> <ChildField name="retn" value="9"/> <ChildField name="prms" value="10"/> </Node> <Node index="6" codename="namespace_decl"> <ChildField name="name" value="11"/> <ChildField name="type" value="12"/> <StringField name="srcp" value="t.cxx:3"/> <ChildField name="chan" value="13"/> <ChildField name="dcls" value="14"/> </Node> <Node index="7" codename="compound_stmt"> <Integer name="line" value="32"/> <ChildField name="body" value="15"/> <ChildField name="next" value="16"/> </Node> <Node index="8" codename="integer_cst"> <ChildField name="type" value="17"/> <Integer name="low" value="64"/> </Node> <Node index="9" codename="integer_type"> <ChildField name="name" value="18"/> <ChildField name="size" value="19"/> <Integer name="algn" value="32"/> <Integer name="prec" value="32"/> <ChildField name="min" value="20"/> <ChildField name="max" value="21"/> </Node> <Node index="10" codename="tree_list"> <ChildField name="valu" value="12"/> </Node> ... <Node index="889" codename="type_decl"> <ChildField name="name" value="890"/> <ChildField name="type" value="9"/> <StringField name="srcp" value="<internal>:0"/> <ChildField name="chan" value="491"/> </Node> <Node index="890" codename="identifier_node"> <String name="strg" value="__builtin_ptrdiff_t"/> <Integer name="lngt" value="19"/> </Node> </GXXTranslationUnit> Instead of: @1 namespace_decl name: @2 srcp: <internal>:0 dcls: @3 @2 identifier_node strg: :: lngt: 2 @3 function_decl name: @4 type: @5 srcp: t.cxx:27 chan: @6 C extern body: @7 @4 identifier_node strg: main lngt: 4 @5 function_type size: @8 algn: 64 retn: @9 prms: @10 @6 namespace_decl name: @11 type: @12 srcp: t.cxx:3 chan: @13 dcls: @14 @7 compound_stmt line: 32 body: @15 next: @16 @8 integer_cst type: @17 low : 64 @9 integer_type name: @18 size: @19 algn: 32 prec: 32 min : @20 max : @21 @10 tree_list valu: @12 ... @889 type_decl name: @890 type: @9 srcp: <internal>:0 chan: @491 @890 identifier_node strg: __builtin_ptrdiff_t lngt: 19 --------------------------------- The XML version are longer by simpler to parse...:) The simple DTD applied is this: <!ELEMENT GXXTranslationUnit (TUNode)> <!ELEMENT Node (ChildField|PointerField|IntegerField|StringField|QualifierField|SourceposField)> <!ATTLIST Node index CDATA #REQUIRED codename CDATA #REQUIRED> <!ELEMENT Field EMPTY> <!ATTLIST Field name CDATA #IMPLIED value CDATA #REQUIRED> <!ELEMENT ChildField (Field)> <!ELEMENT PointerField (Field)> <!ELEMENT IntegerField (Field)> <!ELEMENT StringField (Field)> --------------------- The DTD struct: GXXTranslationUnit --> Node ( index, codename ) --> Field ( name, value ) Where "Field" can be one of: "ChildField": states a field where the value means a Node `index' "PointerField": states a field where the value means a pointer in HEX "IntegerField": states a field where the value means a signed integer value "StringField": states a field, when exists name attribute (eg.dump_string_field), or a simple string keyword (eg.dump_string), like "C" or "C++" or "operator", etc.. where value represents the string itself Some final words: - with this xml output you don't have nothing that the .tu file in XML mode, without modifications - the { Child, Pointer, Integer, String }Field, specification let you to know exactly when a field is an integer or a child, or some other type... For example may be that in certain case a field "low" is dumped as an integer, other times are dumped as a child! with this specification no ambiguities are allowed. Follow, the patches relative to the GCC-3.2 release version: ==> 1) tree.h: add this line: #define TDF_XML (1 << 2 ) /* dump as XML too */ after #define TDF_SLIM ... ==> 2) and tree-dump.c === START OF: tree-dump.c-diff === --- /usr/src/gcc-3.2/gcc/tree-dump.c 2002-03-16 01:07:54.000000000 +0000 +++ tree-dump.c 2002-09-28 17:58:04.000000000 +0000 @@ -116,11 +116,15 @@ /* If we haven't, add it to the queue. */ index = queue (di, t, flags); - /* Print the index of the node. */ - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: ", field); - di->column += 6; - dump_index (di, index); + if (di->flags == TDF_XML) + fprintf (di->stream, " <ChildField name=\"%s\" value=\"%u\"/>\n", field, index); + else { + /* Print the index of the node. */ + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: ", field); + di->column += 6; + dump_index (di, index); + } } /* Dump the type of T. */ @@ -145,6 +149,7 @@ dump_new_line (di) dump_info_p di; { + if (di->flags == TDF_XML) return; fprintf (di->stream, "\n%*s", SOL_COLUMN, ""); di->column = SOL_COLUMN; } @@ -157,6 +162,8 @@ { int extra; + if (di->flags == TDF_XML) return; + /* See if we need a new line. */ if (di->column > EOL_COLUMN) dump_new_line (di); @@ -176,9 +183,14 @@ const char *field; void *ptr; { - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: %-8lx ", field, (long) ptr); - di->column += 15; + if (di->flags == TDF_XML) + fprintf (di->stream, " <Pointer name=\"%s\" value=\"%lx\"/>\n", field, (long) ptr ); + else + { + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: %-8lx ", field, (long) ptr); + di->column += 15; + } } /* Dump integer I using FIELD to identify it. */ @@ -189,9 +201,14 @@ const char *field; int i; { - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: %-7d ", field, i); - di->column += 14; + if (di->flags == TDF_XML) + fprintf (di->stream, " <Integer name=\"%s\" value=\"%d\"/>\n", field, i ); + else + { + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: %-7d ", field, i); + di->column += 14; + } } /* Dump the string S. */ @@ -201,12 +218,17 @@ dump_info_p di; const char *string; { - dump_maybe_newline (di); - fprintf (di->stream, "%-13s ", string); - if (strlen (string) > 13) - di->column += strlen (string) + 1; + if (di->flags == TDF_XML) + fprintf (di->stream, " <String value=\"%s\"/>\n", string ); else - di->column += 14; + { + dump_maybe_newline (di); + fprintf (di->stream, "%-13s ", string); + if (strlen (string) > 13) + di->column += strlen (string) + 1; + else + di->column += 14; + } } /* Dump the string field S. */ @@ -217,12 +239,17 @@ const char *field; const char *string; { - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: %-7s ", field, string); - if (strlen (string) > 7) - di->column += 6 + strlen (string) + 1; + if (di->flags == TDF_XML) + fprintf (di->stream, " <String name=\"%s\" value=\"%s\"/>\n", field, string ); else - di->column += 14; + { + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: %-7s ", field, string); + if (strlen (string) > 7) + di->column += 6 + strlen (string) + 1; + else + di->column += 14; + } } /* Dump information common to statements from STMT. */ @@ -232,7 +259,10 @@ dump_info_p di; tree t; { - dump_int (di, "line", STMT_LINENO (t)); + if (di->flags == TDF_XML) + fprintf (di->stream, " <Integer name=\"line\" value=\"%d\"/>\n", STMT_LINENO (t)); + else + dump_int (di, "line", STMT_LINENO (t)); } /* Dump the next statement after STMT. */ @@ -272,17 +302,25 @@ if (!di->queue) di->queue_end = 0; dq->next = di->free_list; - di->free_list = dq; + di->free_list = dq; - /* Print the node index. */ - dump_index (di, index); + if (di->flags != TDF_XML) + { + /* Print the node index. */ + dump_index (di, index); + } /* And the type of node this is. */ if (dni->binfo_p) code_name = "binfo"; else code_name = tree_code_name[(int) TREE_CODE (t)]; - fprintf (di->stream, "%-16s ", code_name); - di->column = 25; + if (di->flags != TDF_XML) + { + fprintf (di->stream, "%-16s ", code_name); + di->column = 25; + } + else + fprintf (di->stream, " <Node index=\"%u\" codename=\"%s\">\n", index, code_name ); /* Figure out what kind of node this is. */ code = TREE_CODE (t); @@ -355,10 +393,16 @@ /* Skip the slash. */ ++filename; - dump_maybe_newline (di); - fprintf (di->stream, "srcp: %s:%-6d ", filename, - DECL_SOURCE_LINE (t)); - di->column += 6 + strlen (filename) + 8; + if (di->flags == TDF_XML) + fprintf (di->stream, " <StringField name=\"srcp\" value=\"%s:%d\"/>\n", + filename, DECL_SOURCE_LINE(t)); + else + { + dump_maybe_newline (di); + fprintf (di->stream, "srcp: %s:%-6d ", filename, + DECL_SOURCE_LINE (t)); + di->column += 6 + strlen (filename) + 8; + } } /* And any declaration can be compiler-generated. */ if (DECL_ARTIFICIAL (t)) @@ -373,12 +417,20 @@ if (quals != TYPE_UNQUALIFIED) { - fprintf (di->stream, "qual: %c%c%c ", - (quals & TYPE_QUAL_CONST) ? 'c' : ' ', - (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ', - (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' '); - di->column += 14; - } + if (di->flags == TDF_XML) + fprintf (di->stream, " <StringField name=\"qual\" value=\"%c%c%c\"/>\n", + (quals & TYPE_QUAL_CONST) ? 'c' : ' ', + (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ', + (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' '); + else + { + fprintf (di->stream, "qual: %c%c%c ", + (quals & TYPE_QUAL_CONST) ? 'c' : ' ', + (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ', + (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' '); + di->column += 14; + } + } /* All types have associated declarations. */ dump_child ("name", TYPE_NAME (t)); @@ -649,8 +701,14 @@ break; case STRING_CST: - fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t)); - dump_int (di, "lngt", TREE_STRING_LENGTH (t)); + if (di->flags == TDF_XML) + fprintf (di->stream, " <StringField name=\"strg\" value=\"%s\"/>\n", + TREE_STRING_POINTER (t)); + else + { + fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t)); + dump_int (di, "lngt", TREE_STRING_LENGTH (t)); + } break; case TRUTH_NOT_EXPR: @@ -734,8 +792,13 @@ if (dump_flag (di, TDF_ADDRESS, NULL)) dump_pointer (di, "addr", (void *)t); - /* Terminate the line. */ - fprintf (di->stream, "\n"); + if (di->flags == TDF_XML) + fprintf (di->stream, " </Node>\n"); + else + { + /* Terminate the line. */ + fprintf (di->stream, "\n"); + } } /* Return non-zero if FLAG has been specified for the dump, and NODE @@ -773,6 +836,12 @@ di.nodes = splay_tree_new (splay_tree_compare_pointers, 0, (splay_tree_delete_value_fn) &free); + if ( di.flags == TDF_XML ) { + fprintf( stream, "<?xml version='1.0'?>\n" ); + fprintf( stream, "<!DOCTYPE GXXTranslationUnit SYSTEM \"GXXTranslationUnit.dtd\">\n" ); + fprintf( stream, "<GXXTranslationUnit>\n" ); + } + /* Queue up the first node. */ queue (&di, t, DUMP_NONE); @@ -780,6 +849,11 @@ while (di.queue) dequeue_and_dump (&di); + if ( di.flags == TDF_XML ) { + fprintf( stream, "</GXXTranslationUnit>\n" ); + } + + /* Now, clean up. */ for (dq = di.free_list; dq; dq = next_dq) { @@ -822,6 +896,7 @@ { {"address", TDF_ADDRESS}, {"slim", TDF_SLIM}, + {"xml", TDF_XML}, {"all", ~0}, {NULL, 0} }; @@ -838,10 +913,11 @@ { FILE *stream; char *name; - + + printf( "Opening %s for phase %d suffix = %s\n", dump_base_name, phase, dump_files[phase].suffix ); if (!dump_files[phase].state) return NULL; - + printf( "Opened %s for phase %d\n", dump_base_name, phase ); name = concat (dump_base_name, dump_files[phase].suffix, NULL); stream = fopen (name, dump_files[phase].state < 0 ? "w" : "a"); if (!stream) === END OF: tree-dump.c-diff === ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-28 9:40 -fdump-translation-unit-xml Lorenzo Delana @ 2002-09-30 11:14 ` Matt Austern 2002-09-30 11:18 ` -fdump-translation-unit-xml Zack Weinberg ` (3 more replies) 0 siblings, 4 replies; 13+ messages in thread From: Matt Austern @ 2002-09-30 11:14 UTC (permalink / raw) To: gcc On Saturday, September 28, 2002, at 11:01 AM, Lorenzo Delana wrote: > > If you try to parse the result to `-fdump-translation-unit' you meet > some > problems specially for the question about where a string end, etc.. > This problem was addressed in the past by someone in this list... Not a direct response, but this reminded me of something I'd been meaning to bring up before... -fdump-translation-unit is very useful, but I'd describe it more as human-parsable than as human-readable. You can step through it by hand, but it's essentially impossible to use it to understand anything about tree structure at a glance. At Apple, we've developed an alternative tree dumper that's less useful for reading by machine, but much more human readable. We've found our alternative tree dumper to be very useful for debugging. Is there any interest in an alternative tree dumper? If so, we'd be very happy to talk some more about it, to show some examples of the tree dumps it produces, and to clean up the code for a patch. And just to state the obvious: we don't think of this as a replacement for -fdump-translation-unit. We think of the two tree dumpers as complementary. --Matt ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 11:14 ` -fdump-translation-unit-xml Matt Austern @ 2002-09-30 11:18 ` Zack Weinberg 2002-09-30 11:25 ` -fdump-translation-unit-xml Gabriel Dos Reis ` (2 subsequent siblings) 3 siblings, 0 replies; 13+ messages in thread From: Zack Weinberg @ 2002-09-30 11:18 UTC (permalink / raw) To: Matt Austern; +Cc: gcc On Mon, Sep 30, 2002 at 11:09:18AM -0700, Matt Austern wrote: > At Apple, we've developed an alternative tree dumper that's > less useful for reading by machine, but much more human > readable. We've found our alternative tree dumper to be very > useful for debugging. > > Is there any interest in an alternative tree dumper? If so, we'd > be very happy to talk some more about it, to show some > examples of the tree dumps it produces, and to clean up the > code for a patch. I for one would be very interested in a tree dumper better suited to debugging. zw ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 11:14 ` -fdump-translation-unit-xml Matt Austern 2002-09-30 11:18 ` -fdump-translation-unit-xml Zack Weinberg @ 2002-09-30 11:25 ` Gabriel Dos Reis 2002-09-30 12:23 ` -fdump-translation-unit-xml Pop Sébastian 2002-09-30 23:57 ` -fdump-translation-unit-xml ( patch ) Lorenzo Delana 3 siblings, 0 replies; 13+ messages in thread From: Gabriel Dos Reis @ 2002-09-30 11:25 UTC (permalink / raw) To: Matt Austern; +Cc: gcc Matt Austern <austern@apple.com> writes: [...] | Is there any interest in an alternative tree dumper? I'm supportive of such a tool -- I bet other GCC developers out there would be interested as well. [...] | And just to state the obvious: we don't think of this as a | replacement for -fdump-translation-unit. We think of the two | tree dumpers as complementary. Indeed. -- Gaby ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 11:14 ` -fdump-translation-unit-xml Matt Austern 2002-09-30 11:18 ` -fdump-translation-unit-xml Zack Weinberg 2002-09-30 11:25 ` -fdump-translation-unit-xml Gabriel Dos Reis @ 2002-09-30 12:23 ` Pop Sébastian 2002-09-30 12:26 ` -fdump-translation-unit-xml Mike Stump 2002-09-30 23:57 ` -fdump-translation-unit-xml ( patch ) Lorenzo Delana 3 siblings, 1 reply; 13+ messages in thread From: Pop Sébastian @ 2002-09-30 12:23 UTC (permalink / raw) To: Matt Austern; +Cc: gcc On Mon, Sep 30, 2002 at 11:09:18AM -0700, Matt Austern wrote: > Is there any interest in an alternative tree dumper? If so, we'd > be very happy to talk some more about it, to show some > examples of the tree dumps it produces, and to clean up the > code for a patch. > I look forward to see this new tree dumper. Sebastian. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 12:23 ` -fdump-translation-unit-xml Pop Sébastian @ 2002-09-30 12:26 ` Mike Stump 2002-09-30 12:27 ` -fdump-translation-unit-xml Pop Sébastian 0 siblings, 1 reply; 13+ messages in thread From: Mike Stump @ 2002-09-30 12:26 UTC (permalink / raw) To: Pop Sébastian; +Cc: Matt Austern, gcc On Monday, September 30, 2002, at 11:28 AM, Pop Sébastian wrote: > On Mon, Sep 30, 2002 at 11:09:18AM -0700, Matt Austern wrote: > >> Is there any interest in an alternative tree dumper? If so, we'd >> be very happy to talk some more about it, to show some >> examples of the tree dumps it produces, and to clean up the >> code for a patch. >> > > I look forward to see this new tree dumper. I do as well. I've been looking at the current format for a long while, and for simple little questions, it is ok, however, for things that take 2 or 3 levels, it seriously breaks down. The output is time comsuming to wade through. I've not seen the new format, so I don't know just how god or bad it is, but, I think it would be good to have alternate format available for debugging. Once size probably won't fit all, and if some group finds a better way to look at these things, I think we should tend to be supportive. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 12:26 ` -fdump-translation-unit-xml Mike Stump @ 2002-09-30 12:27 ` Pop Sébastian 2002-09-30 12:41 ` -fdump-translation-unit-xml Phil Edwards 2002-09-30 13:59 ` -fdump-translation-unit-xml Matt Austern 0 siblings, 2 replies; 13+ messages in thread From: Pop Sébastian @ 2002-09-30 12:27 UTC (permalink / raw) To: Mike Stump; +Cc: Matt Austern, gcc On Mon, Sep 30, 2002 at 12:06:13PM -0700, Mike Stump wrote: > I do as well. I've been looking at the current format for a long > while, and for simple little questions, it is ok, however, for things > that take 2 or 3 levels, it seriously breaks down. The output is time > comsuming to wade through. Yep, I'd like to have something more flexible to browse the tree... Why not having a TreeBrowser on the same model as Open64 WHIRL Browser? WB> h The following commands are available: R: Go to the root of the program unit E: Go to the parent of the current node N: Go to the next node in the subtree chain P: Go to the previous node in the subtree chain =: Set the current node to the following address @: Set the current node to this numbered node >: Increase the fanciness level for printing <: Decrease the fanciness level for printing W: Print tree in whirl2[fc] format at current node K: Print the kids of this node S: Print the list of statements under this node T: Print the tree at the current node %: Print the addresses of nodes in this subtree U: Print the uses at the current node D: Print the definitions at the current node A: Print the access info at the current node G: Print the node dep graph info at current node g: Print the stmt dep graph info at current node V: Print the vertices of the dep graph r: Print the reduction manager a: Print the alias info for this node e: Print the ancestors of this node s: Print the symbol table entry for this node t: Print the type table entry for this node #: Print node of this type at this address L: Sketch the loop nests in the program unit l: Sketch the loop nests in Suresh Tool format y: Perform a transformation C: Check the program unit for consistency F: Find nodes with this symbol in the subtree $: Find symbols with this name o: Find nodes with this operator type f: Change WHIRL-TO-SOURCE language to FORTRAN c: Change WHIRL-TO-SOURCE language to C B: Print the scratch register with this number .: Execute the previous command Y: Print the reshaped-ref map for array nodes i: Print the PROMPF ids for tree at this node I: Print the PROMPF_INFO M: Set the current node to node with this map id m: Print the map-id at this node p: Print the privatization info at this node v: Go to the node with this vertex number d: Toggle Da Vinci mode H: Print this information h: Print this information Q: Exit the debugger q: Exit the debugger WB> I think this would be of a great help for debugging as well as for developing tree optimizations. Sebastian ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 12:27 ` -fdump-translation-unit-xml Pop Sébastian @ 2002-09-30 12:41 ` Phil Edwards 2002-09-30 13:06 ` -fdump-translation-unit-xml Pop Sébastian 2002-09-30 13:20 ` -fdump-translation-unit-xml Daniel Berlin 2002-09-30 13:59 ` -fdump-translation-unit-xml Matt Austern 1 sibling, 2 replies; 13+ messages in thread From: Phil Edwards @ 2002-09-30 12:41 UTC (permalink / raw) To: Pop Sébastian; +Cc: Mike Stump, Matt Austern, gcc On Mon, Sep 30, 2002 at 09:22:54PM +0200, Pop Sébastian wrote: > On Mon, Sep 30, 2002 at 12:06:13PM -0700, Mike Stump wrote: > > I do as well. I've been looking at the current format for a long > > while, and for simple little questions, it is ok, however, for things > > that take 2 or 3 levels, it seriously breaks down. The output is time > > comsuming to wade through. Absolutely. As nice as the current dumper is, I still rarely use it. > Yep, I'd like to have something more flexible to browse the tree... > Why not having a TreeBrowser on the same model as Open64 WHIRL Browser? > > WB> h > The following commands are available: > R: Go to the root of the program unit > E: Go to the parent of the current node > N: Go to the next node in the subtree chain [...] I want a browser that uses the same interface as nethack. :-) Phil -- I would therefore like to posit that computing's central challenge, viz. "How not to make a mess of it," has /not/ been met. - Edsger Dijkstra, 1930-2002 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 12:41 ` -fdump-translation-unit-xml Phil Edwards @ 2002-09-30 13:06 ` Pop Sébastian 2002-09-30 13:20 ` -fdump-translation-unit-xml Daniel Berlin 1 sibling, 0 replies; 13+ messages in thread From: Pop Sébastian @ 2002-09-30 13:06 UTC (permalink / raw) To: Phil Edwards; +Cc: Mike Stump, Matt Austern, gcc On Mon, Sep 30, 2002 at 03:27:01PM -0400, Phil Edwards wrote: > I want a browser that uses the same interface as nethack. :-) > And I want to see it in emacs games menu :-) ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 12:41 ` -fdump-translation-unit-xml Phil Edwards 2002-09-30 13:06 ` -fdump-translation-unit-xml Pop Sébastian @ 2002-09-30 13:20 ` Daniel Berlin 2002-09-30 13:26 ` -fdump-translation-unit-xml David Carlton 1 sibling, 1 reply; 13+ messages in thread From: Daniel Berlin @ 2002-09-30 13:20 UTC (permalink / raw) To: Phil Edwards; +Cc: Pop Sébastian, Mike Stump, Matt Austern, gcc > [..] > > I want a browser that uses the same interface as nethack. :-) > I wouldn't. You'd continually get lost. "No, no, go *right* at the ARRAY_EXPR". ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 13:20 ` -fdump-translation-unit-xml Daniel Berlin @ 2002-09-30 13:26 ` David Carlton 0 siblings, 0 replies; 13+ messages in thread From: David Carlton @ 2002-09-30 13:26 UTC (permalink / raw) To: Daniel Berlin Cc: Phil Edwards, Pop Sébastian, Mike Stump, Matt Austern, gcc On Mon, 30 Sep 2002 16:00:44 -0400, Daniel Berlin <dberlin@dberlin.org> said: >> [..] >> >> I want a browser that uses the same interface as nethack. :-) >> > I wouldn't. > You'd continually get lost. > "No, no, go *right* at the ARRAY_EXPR". And just think of the confusion if you ate the wrong thing and started randomly teleporting all over the place. (Hmm: maybe that would be a natural way to provide support for using probabilistic methods for profiling?) David Carlton carlton@math.stanford.edu ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml 2002-09-30 12:27 ` -fdump-translation-unit-xml Pop Sébastian 2002-09-30 12:41 ` -fdump-translation-unit-xml Phil Edwards @ 2002-09-30 13:59 ` Matt Austern 1 sibling, 0 replies; 13+ messages in thread From: Matt Austern @ 2002-09-30 13:59 UTC (permalink / raw) To: gcc On Monday, September 30, 2002, at 12:22 PM, Pop Sébastian wrote: > On Mon, Sep 30, 2002 at 12:06:13PM -0700, Mike Stump wrote: >> I do as well. I've been looking at the current format for a long >> while, and for simple little questions, it is ok, however, for things >> that take 2 or 3 levels, it seriously breaks down. The output is time >> comsuming to wade through. > > Yep, I'd like to have something more flexible to browse the tree... > Why not having a TreeBrowser on the same model as Open64 WHIRL Browser? That would be nice! Unfortunately, we don't have it. What we do have is a tree dumper that we use from within gdb. In fact, at present that's the only way to use it: there's no command-line interface. (Yes, that ought to change.) Here's an example, where I'm dumping out the tree for a simple C++ class: (gdb) run Starting program: /Volumes/Data/work/root/lib/gcc-lib/powerpc-apple-darwin6.0/3.1/cc1plus -fpreprocessed foo.ii -fPIC -quiet -dumpbase foo.cc -version -D__private_extern__=extern -o foo.s [Switching to process 16445 thread 0xf07] GNU CPP version 3.1 20020420 (prerelease) (cpplib) (Darwin/PowerPC) GNU C++ version 3.1 20020420 (prerelease) (powerpc-apple-darwin6.0) compiled by GNU C version 3.1 20020420 (prerelease). Breakpoint 1, finish_struct (t=0x0, attributes=0x0) at ../../fearless-kitty/gcc/cp/class.c:5494 5494 const char *saved_filename = input_filename; (gdb) n 5495 int saved_lineno = lineno; (gdb) n 5493 { (gdb) n 5494 const char *saved_filename = input_filename; (gdb) n 5495 int saved_lineno = lineno; (gdb) n 5494 const char *saved_filename = input_filename; (gdb) n 5495 int saved_lineno = lineno; (gdb) n 5499 unreverse_member_declarations (t); (gdb) n 5501 cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE); (gdb) print t $1 = 0xfb9850 (gdb) call dmp_tree(t) record_type:0xfb9850 fields=0xfba4d0 mbrs=0xfb79c0 #parents=0 type-flags=#125 align=8 *this=0xfb98c0 next-variant=0xfba070 ~X() X() my_class field_decl:0xfba4d0 t=0xf8b3f0 {int} line=8(foo.cc) off-align=1 lang-flags=#3 cntxt=0xfb9850 val_ type_decl:0xfb99a0 (self-reference) t=0xfb9850 {my_class} line=1 nonlcl cntxt=0xfb9850 my_class tree_vec:0xfb79c0 (mbrs) len=8 function_decl:0xfb9af0 (mbrs:0) t=0xfb9a80 {method_type} line=3 ext pub lang-flags=#3 cntxt=0xfb9850 ctor my_class parm_decl:0xfb9bd0 t=0xfb9b60 {pointer_type} line=3 arg-type=0xfb9b60 sz=32(4) this function_decl:0xfb9d20 (mbrs:1) t=0xfb9e70 {method_type} line=4 ext pub virt lang-flags=#3 cntxt=0xfb9850 dtor my_class parm_decl:0xfb9d90 t=0xfb9b60 {pointer_type} line=4 arg-type=0xfb9b60 sz=32(4) this parm_decl:0xfb9e00 t=0xf8b3f0 {int} line=4 arg-type=0xf8b3f0 sz=32(4) __in_chrg overload:0xfa9a80 (mbrs:2) t=0xfaf1c0 {unknown type} ovld=0xfba3f0 next-ovld=0xfa9a70 val function_decl:0xfba3f0 (ovld) t=0xfba380 {method_type} line=6 ext pub lang-flags=#3 cntxt=0xfb9850 val parm_decl:0xfba460 t=0xfb9b60 {pointer_type} line=6 arg-type=0xfb9b60 sz=32(4) this parm_decl:0xfba2a0 t=0xf8b3f0 {int} line=6 arg-type=0xf8b3f0 sz=32(4) x overload:0xfa9a70 t=0xfaf1c0 {unknown type} ovld=0xfba000 val function_decl:0xfba000 (ovld) t=0xfba0e0 {method_type} line=5 ext pub lang-flags=#3 cntxt=0xfb9850 const val parm_decl:0xfba230 t=0xfba1c0 {pointer_type} line=5 arg-type=0xfba1c0 sz=32(4) this (gdb) ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: -fdump-translation-unit-xml ( patch ) 2002-09-30 11:14 ` -fdump-translation-unit-xml Matt Austern ` (2 preceding siblings ...) 2002-09-30 12:23 ` -fdump-translation-unit-xml Pop Sébastian @ 2002-09-30 23:57 ` Lorenzo Delana 3 siblings, 0 replies; 13+ messages in thread From: Lorenzo Delana @ 2002-09-30 23:57 UTC (permalink / raw) To: gcc; +Cc: Matt Austern [-- Attachment #1: Type: text/plain, Size: 12250 bytes --] Here is the patch to let a gcc switch `-fdump-translation-unit-xml' to dump the .tu file containing an xml like this produced: ~ $ ~/cc1plus -fdump-translation-unit-xml simple.cxx X::A<T>::A() virtual X::A<T>::~A() int X::A<T>::fn(int) int X::A<T>::fn(int, int)Opening simple.cxx for phase 1 suffix = .class Opening simple.cxx for phase 0 suffix = .tu Opened simple.cxx for phase 0 Execution times (seconds) varconst : 0.02 (67%) usr 0.00 ( 0%) sys 0.02 (67%) wall TOTAL : 0.03 0.00 0.03 ~ $ head -n 20 simple.cxx.tu <?xml version='1.0'?> <!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd"> <GXXTranslationUnit> <node index="1" codename="namespace_decl"> <field type="_c_" name="name" value="2"/> <field type="_s_" name="srcp" value="<internal>:0"/> <field type="_c_" name="dcls" value="3"/> </node> <node index="2" codename="identifier_node"> <field type="_s_" name="strg" value="::"/> <field type="_i_" name="lngt" value="2"/> </node> <node index="3" codename="namespace_decl"> <field type="_c_" name="name" value="4"/> <field type="_c_" name="type" value="5"/> <field type="_s_" name="srcp" value="simple.cxx:2"/> <field type="_c_" name="chan" value="6"/> ~ $ tail simple.cxx.tu <field type="_s_" name="srcp" value="<internal>:0"/> <field type="_c_" name="chan" value="423"/> </node> <node index="846" codename="identifier_node"> <field type="_s_" name="strg" value="__builtin_ptrdiff_t"/> <field type="_i_" name="lngt" value="19"/> </node> </GXXTranslationUnit> Notes: a - admin questions: a1 - the patch sync'ed with CVS files: gcc/tree.h, gcc/tree-dump.c sync at the time Tue Oct 1 03:19 UTC 2002 ( so i recently ) a2 - I build and tested this patch with my gcc-3.2 and works as demonstrated in the upper region of the email a3 - someone would apply this patch to gcc from CVS ( I cannot download entire cvs version, because my 5kmodem ), simply by copying files tree.h-diff and tree-dump.c-diff in the gcc/gcc dir and then patch < (diff-file) for each one. To test use `-fdump-translation-unit' and produce the TU that gcc produces before the patch, then `-fdump-translation-unit-xml' produces the TU with XML formatting. a4 - if <<... approved ...>>, someone could commit this thing? g - general questions: g1 - the DTD: choosing a DTD is an hard thing, or choosing the right DTD is an hard thing... in any case I propose this, the resulting DTD from modification may be correct any if different, but consider that this DTD is very simple and inobtrusive respect the original TU format: ****************************************** *** FIRST ( implemented in patch ) DTD *** <!ELEMENT GXXTranslationUnit (node*)> <!ELEMENT node (field*)> <!ATTLIST node index CDATA #REQUIRED codename CDATA #REQUIRED> <!ELEMENT field EMPTY> <!ATTLIST field type (_c_,_p_,_i_,_s_) #REQUIRED name CDATA #IMPLIED value CDATA #REQUIRED> Example: <?xml version='1.0'?> <!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd"> <GXXTranslationUnit> <node index="1" codename="namespace_decl"> <field type="_s_" name="name" value="2"/> <field type="_s_" name="srcp" value="<internal>:0"/> <field type="_s_" name="dcls" value="3"/> </node> </GXXTranslationUnit> g1-2 - The `type' field of the `node' element is the only thing added to the TU informations that you can retrieve from the actual tu format... and this type serve to eliminate the ambiguities about the the type to convert the `value' field of the node ( that's a string ) to a correct type. Note: the "srcp" TU field ( source pos ) doesn't need a particular type, like as for "qual" TU field ( qualifier ) because they are strings... NOTE: maybe possible reduce the DTD to this: ****************** *** SECOND DTD *** <!ELEMENT GXXTranslationUnit (node*)> <!ELEMENT node (child*,leaf*)> <!ATTLIST node index CDATA #REQUIRED codename CDATA #REQUIRED> <!ELEMENT child EMPTY> <!ATTLIST child name CDATA #REQUIRED value CDATA #REQUIRED> <!ELEMENT leaf EMPTY> <!ATTLIST leaf name CDATA #IMPLIED value CDATA #REQUIRED> Prev. example: <?xml version='1.0'?> <!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd"> <GXXTranslationUnit> <node index="1" codename="namespace_decl"> <child name="name" value="2"/> <leaf name="srcp" value="<internal>:0"/> <child name="dcls" value="3"/> </node> </GXXTranslationUnit> This XML sample states only `child' and 'leaf' node fields... ( only two types ) NOTE: at most ( of reduction ) the DTD may be: ***************** *** THIRD DTD *** <!ELEMENT GXXTranslationUnit (node*)> <!ELEMENT node (child*,leaf*)> <!ATTLIST node index CDATA #REQUIRED codename CDATA #REQUIRED> <!ELEMENT field EMPTY> <!ATTLIST field name CDATA #REQUIRED value CDATA #REQUIRED> Prev. example: <?xml version='1.0'?> <!DOCTYPE GXXTranslationUnit SYSTEM "GXXTranslationUnit.dtd"> <GXXTranslationUnit> <node index="1" codename="namespace_decl"> <field name="name" value="@2"/> <field name="srcp" value="<internal>:0"/> <field name="dcls" value="@3"/> </node> </GXXTranslationUnit> Note that in this last case, I must encode the type "child" with @ start symbol... but what happens if I would, for example, to encode a node, with a field that's supposed to be a string where the value starts with '@' ? AMBIGUITIES... as demonstrated by this actual TU dump sample ( where a simple .cxx file with a const string "@ciao" is preprocessed ): @52 string_cst type: @78 strg: @ciao lngt: 6 So I suppose that the second DTD may be correct, but I implemented for the first DTD that reflect in some aspect the follow tree-dump.c routines: - dump_index : CHILD - dump_pointer : POINTER - dump_int : INT - dump_string : STRING [----- hear this, please: Finally: I ask someone that know ( I don't, exactly ) the AST of the GCC and future direction to get a feedback where is opinable to change this patch from first DTD to the second, or another one... YEap, the question maybe if from a field name I can get the exact type of the value it states. -----] d - devel questions: d1 - the code is organized by static functions: * static void dump_xml_field PARAMS ((dump_info_p, xml_field_type, const char*, const char*, ...)); * static void dump_xml_string PARAMS ((dump_info_p, const char*)); d2 - and this ( c-source ) typedef * typedef enum { xml_field_child_type, xml_field_pointer_type, xml_field_integer_type, xml_field_string_type } xml_field_type; - with a macro: #define XML_FIELD_TYPE_GET_NAME(_t_) \ (((_t_) == xml_field_child_type) ? "_c_" : \ (((_t_) == xml_field_pointer_type) ? "_p_" : \ (((_t_) == xml_field_integer_type) ? "_i_" : \ (((_t_) == xml_field_string_type) ? "_s_" : NULL)))) used in the dump rules... also this macro defines the root node name: #define XML_GXX_TU_DOCTYPE "GXXTranslationUnit" d3 - for each part where a dump on the stream is made there is a choose on the dump info flag and if XML mode ( TDF_XML ) is enabled nothing but xml is dumped out; for example follow code: /* Print the node index. */ dump_index (di, index); /* And the type of node this is. */ if (dni->binfo_p) code_name = "binfo"; else code_name = tree_code_name[(int) TREE_CODE (t)]; fprintf (di->stream, "%-16s ", code_name); di->column = 25; == changed to ==> /* Determine the type of node this is */ if (dni->binfo_p) code_name = "binfo"; else code_name = tree_code_name[(int) TREE_CODE (t)]; if (di->flags != TDF_XML) { /* Print the node index. */ dump_index (di, index); /* And the type of node this is. */ fprintf (di->stream, "%-16s ", code_name); di->column = 25; } else fprintf (di->stream, "\n <node index=\"%u\" codename=\"%s\">\n", index, code_name ); d4 - the two functions dump_xml_{field,string} serves as dumper for an XML field, where the <node index="xxx" codename="yyy"> is opened and for dumping a string as xml string ( with & < > ' " changes to & < > ... ); for example: /* Print the index of the node. */ if (di->flags == TDF_XML) dump_xml_field (di, xml_field_child_type, field, "%u", index); // <== else { dump_maybe_newline (di); fprintf (di->stream, "%-4s: ", field); di->column += 6; dump_index (di, index); } * di - dump info ( to get the stream output with out purpose ) * xml_field_child_type - I say to `dump_xml_field' that the type is, in the enumerative typedef of the type `xml_field_type', a "child" type; This is used to print out the "type" attribute of the "field" xml element. * "%u", index - a printf like format to print what you want ( var arg ) Note on `dump_xml_field' memory allocation: the "value" attribute of the field may contains some xml unescaped characters like for the string "<internal:0>" that must came "<internal:0>"; I don't use at this time the `dump_xml_string' because, I cannot use formatting needed for example when dump an `srcp' field ( "%s:%d", filename, lineno )... so xml_dump_field, supply the generation of the string to pass to `dump_xml_string' by using vsnprintf and to have a temp string buffer length enough an automatic memory reallocation mechanism is used, conform to glibc 2.0.6 and glibc>=2.1 ( eg.vsnprintf can return -1 or ( >0 = nr.char needed )... this tmpbuf string is a static char* and never freed but consuming only the max string lenght printed out +/- a chunk of bytes equal to a parameter static in the function itself called `tmpbuf_size_chunk' actually 25... To debug this tremendous behavior :)... simply add a printf here: if ((vsnprintf_ret == -1) || (vsnprintf_ret > tmpbuf_size-1)) { tmpbuf_size += tmpbuf_size_chunk; printf( "EXPANDING tmpbuf to %d\n", tmpbuf_size ); tmpbuf = (char*)xrealloc (tmpbuf, tmpbuf_size); } and sets tmpbuf_size_chunk to 8, for example... d5 - the flag -fdump-translation-unit-xml are enabled by adding in gcc/tree-dump.c: `dump_options' array, an entry referring the TDF_XML constant added in the gcc/tree.h after TDF_SLIM to the next bit free ( 1L<<2) d6 - TODO: evenutally, but I don't see the need... let a phase with an .xml extension output instead to use .tu extension... Actually a .tu file is generated containing XML if -f..-xml is given. On Monday 30 September 2002 18:09, Matt Austern wrote: > On Saturday, September 28, 2002, at 11:01 AM, Lorenzo Delana wrote: > > If you try to parse the result to `-fdump-translation-unit' you meet > > some > > problems specially for the question about where a string end, etc.. > > This problem was addressed in the past by someone in this list... > > Not a direct response, but this reminded me of something > I'd been meaning to bring up before... > > -fdump-translation-unit is very useful, but I'd describe it more > as human-parsable than as human-readable. You can step > through it by hand, but it's essentially impossible to use it to > understand anything about tree structure at a glance. > > At Apple, we've developed an alternative tree dumper that's > less useful for reading by machine, but much more human > readable. We've found our alternative tree dumper to be very > useful for debugging. > > Is there any interest in an alternative tree dumper? If so, we'd > be very happy to talk some more about it, to show some > examples of the tree dumps it produces, and to clean up the > code for a patch. > > And just to state the obvious: we don't think of this as a > replacement for -fdump-translation-unit. We think of the two > tree dumpers as complementary. > > --Matt [-- Attachment #2: tree.h-diff --] [-- Type: text/x-diff, Size: 426 bytes --] --- /home/delana/gcc-20021001_0319/gcc/tree.h 2002-10-01 03:19:37.000000000 +0000 +++ tree.h 2002-10-01 05:40:16.000000000 +0000 @@ -3097,6 +3097,7 @@ values, extend the DUMP_OPTIONS array in tree-dump.c */ #define TDF_ADDRESS (1 << 0) /* dump node addresses */ #define TDF_SLIM (1 << 1) /* don't go wild following links */ +#define TDF_XML (1 << 2) /* dump in XML format */ typedef struct dump_info *dump_info_p; [-- Attachment #3: tree-dump.c-diff --] [-- Type: text/x-diff, Size: 10875 bytes --] --- /home/delana/gcc-20021001_0319/gcc/tree-dump.c 2002-10-01 03:19:37.000000000 +0000 +++ tree-dump.c 2002-10-01 06:29:44.000000000 +0000 @@ -35,6 +35,25 @@ static void dump_maybe_newline PARAMS ((dump_info_p)); static void dump_string_field PARAMS ((dump_info_p, const char *, const char *)); +#define XML_GXX_TU_DOCTYPE "GXXTranslationUnit" + +typedef enum { + xml_field_child_type, + xml_field_pointer_type, + xml_field_integer_type, + xml_field_string_type +} xml_field_type; + +#define XML_FIELD_TYPE_GET_NAME(_t_) \ +(((_t_) == xml_field_child_type) ? "_c_" : \ + (((_t_) == xml_field_pointer_type) ? "_p_" : \ + (((_t_) == xml_field_integer_type) ? "_i_" : \ + (((_t_) == xml_field_string_type) ? "_s_" : NULL)))) + +static void dump_xml_field PARAMS ((dump_info_p, xml_field_type, const char*, + const char*, ...)); +static void dump_xml_string PARAMS ((dump_info_p, const char*)); + /* Add T to the end of the queue of nodes to dump. Returns the index assigned to T. */ @@ -116,10 +135,15 @@ index = queue (di, t, flags); /* Print the index of the node. */ - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: ", field); - di->column += 6; - dump_index (di, index); + if (di->flags == TDF_XML) + dump_xml_field (di, xml_field_child_type, field, "%u", index); + else + { + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: ", field); + di->column += 6; + dump_index (di, index); + } } /* Dump the type of T. */ @@ -144,6 +168,7 @@ dump_new_line (di) dump_info_p di; { + if (di->flags == TDF_XML) return; fprintf (di->stream, "\n%*s", SOL_COLUMN, ""); di->column = SOL_COLUMN; } @@ -156,6 +181,8 @@ { int extra; + if (di->flags == TDF_XML) return; + /* See if we need a new line. */ if (di->column > EOL_COLUMN) dump_new_line (di); @@ -175,9 +202,14 @@ const char *field; void *ptr; { - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: %-8lx ", field, (long) ptr); - di->column += 15; + if (di->flags == TDF_XML) + dump_xml_field (di, xml_field_pointer_type, field, "%lx", (long)ptr); + else + { + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: %-8lx ", field, (long) ptr); + di->column += 15; + } } /* Dump integer I using FIELD to identify it. */ @@ -188,9 +220,14 @@ const char *field; int i; { - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: %-7d ", field, i); - di->column += 14; + if (di->flags == TDF_XML) + dump_xml_field (di, xml_field_integer_type, field, "%d", i); + else + { + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: %-7d ", field, i); + di->column += 14; + } } /* Dump the string S. */ @@ -200,12 +237,17 @@ dump_info_p di; const char *string; { - dump_maybe_newline (di); - fprintf (di->stream, "%-13s ", string); - if (strlen (string) > 13) - di->column += strlen (string) + 1; + if (di->flags == TDF_XML) + dump_xml_field (di, xml_field_string_type, NULL, "%s", string); else - di->column += 14; + { + dump_maybe_newline (di); + fprintf (di->stream, "%-13s ", string); + if (strlen (string) > 13) + di->column += strlen (string) + 1; + else + di->column += 14; + } } /* Dump the string field S. */ @@ -216,12 +258,110 @@ const char *field; const char *string; { - dump_maybe_newline (di); - fprintf (di->stream, "%-4s: %-7s ", field, string); - if (strlen (string) > 7) - di->column += 6 + strlen (string) + 1; + if (di->flags == TDF_XML) + dump_xml_field (di, xml_field_string_type, field, "%s", string); else - di->column += 14; + { + dump_maybe_newline (di); + fprintf (di->stream, "%-4s: %-7s ", field, string); + if (strlen (string) > 7) + di->column += 6 + strlen (string) + 1; + else + di->column += 14; + } +} + +/* Dump the given string in xml-escaped mode */ + +static void +dump_xml_string (di, str) + dump_info_p di; + const char* str; +{ + if (str == NULL) return; + while (*str) + { + switch (*str) + { + case '&': + fprintf (di->stream, "&"); + break; + case '\'': + fprintf (di->stream, "'"); + break; + case '>': + fprintf (di->stream, ">"); + break; + case '<': + fprintf (di->stream, "<"); + break; + case '"': + fprintf (di->stream, """); + break; + default: + fprintf (di->stream, "%c", *str); + } + str++; + } +} + +/* Dump the given xml field and its attributes */ + +static void +dump_xml_field (di, type, name, value) + dump_info_p di; + xml_field_type type; + const char* name; + const char* value; +{ + static char* tmpbuf = NULL; + static int tmpbuf_size_chunk = 25; + static int tmpbuf_size = 0; + int vsnprintf_ret; + + // dump the xml `field' element ( open mark ) + fprintf (di->stream, " <field "); + + // dump the `type' attribute of the xml `field' element ( xml-unescaped ) + fprintf (di->stream, "type=\"%s\" ", XML_FIELD_TYPE_GET_NAME (type)); + + // dump the `name' attribute of the xml `field' element ( xml-unescaped ) + if (name) fprintf (di->stream, "name=\"%s\" ", name); + + // allocate a minimal string buffer, if needed + if (tmpbuf==NULL) + { + tmpbuf_size += tmpbuf_size_chunk; + tmpbuf = (char*)xmalloc(tmpbuf_size); + } + + // print in the string buffer, extending it if necessary, the + // `value' attribute of the xml `field' element ( xml-unescaped ) + VA_OPEN (ap, value); + VA_FIXEDARG (ap, dump_info_p, di); + VA_FIXEDARG (ap, xml_field_type, type); + VA_FIXEDARG (ap, const char*, name); + + while (1) + { + vsnprintf_ret = vsnprintf (tmpbuf, tmpbuf_size-1, value, ap); + if ((vsnprintf_ret == -1) || (vsnprintf_ret > tmpbuf_size-1)) + { + tmpbuf_size += tmpbuf_size_chunk; + tmpbuf = (char*)xrealloc (tmpbuf, tmpbuf_size); + } + else break; + } + + VA_CLOSE (ap); + + // then dump the `value' field attribute as xml-escaped string + fprintf (di->stream, "value=\""); + dump_xml_string (di, tmpbuf); + fprintf (di->stream, "\""); + + // dump the xml `field' element ( close mark ) + fprintf (di->stream, "/>\n"); } /* Dump the next node in the queue. */ @@ -253,15 +393,22 @@ dq->next = di->free_list; di->free_list = dq; - /* Print the node index. */ - dump_index (di, index); - /* And the type of node this is. */ + /* Determine the type of node this is */ if (dni->binfo_p) code_name = "binfo"; else code_name = tree_code_name[(int) TREE_CODE (t)]; - fprintf (di->stream, "%-16s ", code_name); - di->column = 25; + + if (di->flags != TDF_XML) + { + /* Print the node index. */ + dump_index (di, index); + /* And the type of node this is. */ + fprintf (di->stream, "%-16s ", code_name); + di->column = 25; + } + else + fprintf (di->stream, "\n <node index=\"%u\" codename=\"%s\">\n", index, code_name ); /* Figure out what kind of node this is. */ code = TREE_CODE (t); @@ -334,10 +481,15 @@ /* Skip the slash. */ ++filename; - dump_maybe_newline (di); - fprintf (di->stream, "srcp: %s:%-6d ", filename, - DECL_SOURCE_LINE (t)); - di->column += 6 + strlen (filename) + 8; + if (di->flags != TDF_XML) + { + dump_maybe_newline (di); + fprintf (di->stream, "srcp: %s:%-6d ", filename, + DECL_SOURCE_LINE (t)); + di->column += 6 + strlen (filename) + 8; + } + else + dump_xml_field (di, xml_field_string_type, "srcp", "%s:%d", filename, DECL_SOURCE_LINE (t)); } /* And any declaration can be compiler-generated. */ if (DECL_ARTIFICIAL (t)) @@ -351,13 +503,21 @@ int quals = (*lang_hooks.tree_dump.type_quals) (t); if (quals != TYPE_UNQUALIFIED) - { - fprintf (di->stream, "qual: %c%c%c ", - (quals & TYPE_QUAL_CONST) ? 'c' : ' ', - (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ', - (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' '); - di->column += 14; - } + { + if (di->flags != TDF_XML) + { + fprintf (di->stream, "qual: %c%c%c ", + (quals & TYPE_QUAL_CONST) ? 'c' : ' ', + (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ', + (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' '); + di->column += 14; + } + else + dump_xml_field (di, xml_field_string_type, "qual", "%c%c%c", + (quals & TYPE_QUAL_CONST) ? 'c' : ' ', + (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ', + (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' '); + } /* All types have associated declarations. */ dump_child ("name", TYPE_NAME (t)); @@ -507,7 +667,10 @@ break; case STRING_CST: - fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t)); + if (di->flags != TDF_XML) + fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t)); + else + dump_xml_field (di, xml_field_string_type, "strg", "%s", TREE_STRING_POINTER (t)); dump_int (di, "lngt", TREE_STRING_LENGTH (t)); break; @@ -588,8 +751,11 @@ if (dump_flag (di, TDF_ADDRESS, NULL)) dump_pointer (di, "addr", (void *)t); - /* Terminate the line. */ - fprintf (di->stream, "\n"); + /* Terminate the xml node / line. */ + if (di->flags == TDF_XML) + fprintf (di->stream, " </node>\n"); + else + fprintf (di->stream, "\n"); } /* Return nonzero if FLAG has been specified for the dump, and NODE @@ -627,6 +793,14 @@ di.nodes = splay_tree_new (splay_tree_compare_pointers, 0, (splay_tree_delete_value_fn) &free); + if ( di.flags == TDF_XML ) { + /* Dump XML header and root node ( open mark ) */ + fprintf( stream, "<?xml version='1.0'?>\n" ); + fprintf( stream, "<!DOCTYPE %s SYSTEM \"%s.dtd\">\n", + XML_GXX_TU_DOCTYPE, XML_GXX_TU_DOCTYPE ); + fprintf( stream, "<%s>\n", XML_GXX_TU_DOCTYPE ); + } + /* Queue up the first node. */ queue (&di, t, DUMP_NONE); @@ -634,6 +808,10 @@ while (di.queue) dequeue_and_dump (&di); + if ( di.flags == TDF_XML ) + /* Dump the xml root node ( close mark ) */ + fprintf( stream, "\n</%s>\n", XML_GXX_TU_DOCTYPE ); + /* Now, clean up. */ for (dq = di.free_list; dq; dq = next_dq) { @@ -676,6 +854,7 @@ { {"address", TDF_ADDRESS}, {"slim", TDF_SLIM}, + {"xml", TDF_XML}, {"all", ~0}, {NULL, 0} }; ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2002-10-01 5:19 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-09-28 9:40 -fdump-translation-unit-xml Lorenzo Delana 2002-09-30 11:14 ` -fdump-translation-unit-xml Matt Austern 2002-09-30 11:18 ` -fdump-translation-unit-xml Zack Weinberg 2002-09-30 11:25 ` -fdump-translation-unit-xml Gabriel Dos Reis 2002-09-30 12:23 ` -fdump-translation-unit-xml Pop Sébastian 2002-09-30 12:26 ` -fdump-translation-unit-xml Mike Stump 2002-09-30 12:27 ` -fdump-translation-unit-xml Pop Sébastian 2002-09-30 12:41 ` -fdump-translation-unit-xml Phil Edwards 2002-09-30 13:06 ` -fdump-translation-unit-xml Pop Sébastian 2002-09-30 13:20 ` -fdump-translation-unit-xml Daniel Berlin 2002-09-30 13:26 ` -fdump-translation-unit-xml David Carlton 2002-09-30 13:59 ` -fdump-translation-unit-xml Matt Austern 2002-09-30 23:57 ` -fdump-translation-unit-xml ( patch ) Lorenzo Delana
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).