4 * Common Trace Format Metadata Visitor (XML dump).
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
27 #include <babeltrace/list.h>
28 #include "ctf-scanner.h"
29 #include "ctf-parser.h"
32 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
35 void print_tabs(FILE *fd
, int depth
)
39 for (i
= 0; i
< depth
; i
++)
44 int ctf_visitor_print_unary_expression(FILE *fd
, int depth
, struct ctf_node
*node
)
48 switch (node
->u
.unary_expression
.link
) {
49 case UNARY_LINK_UNKNOWN
:
52 print_tabs(fd
, depth
);
53 fprintf(fd
, "<dotlink/>\n");
56 print_tabs(fd
, depth
);
57 fprintf(fd
, "<arrowlink/>\n");
60 print_tabs(fd
, depth
);
61 fprintf(fd
, "<dotdotdot/>\n");
64 fprintf(stderr
, "[error] %s: unknown expression link type %d\n", __func__
,
65 (int) node
->u
.unary_expression
.link
);
69 switch (node
->u
.unary_expression
.type
) {
71 print_tabs(fd
, depth
);
72 fprintf(fd
, "<unary_expression value=");
73 fprintf(fd
, "\"%s\"", node
->u
.unary_expression
.u
.string
);
76 case UNARY_SIGNED_CONSTANT
:
77 print_tabs(fd
, depth
);
78 fprintf(fd
, "<unary_expression value=");
79 fprintf(fd
, "%" PRId64
, node
->u
.unary_expression
.u
.signed_constant
);
82 case UNARY_UNSIGNED_CONSTANT
:
83 print_tabs(fd
, depth
);
84 fprintf(fd
, "<unary_expression value=");
85 fprintf(fd
, "%" PRIu64
, node
->u
.unary_expression
.u
.signed_constant
);
89 print_tabs(fd
, depth
);
90 fprintf(fd
, "<unary_expression_sbrac>\n");
91 ret
= ctf_visitor_print_unary_expression(fd
, depth
+ 1,
92 node
->u
.unary_expression
.u
.sbrac_exp
);
95 print_tabs(fd
, depth
);
96 fprintf(fd
, "</unary_expression_sbrac>\n");
99 print_tabs(fd
, depth
);
100 fprintf(fd
, "<unary_expression_nested>\n");
101 ret
= ctf_visitor_print_unary_expression(fd
, depth
+ 1,
102 node
->u
.unary_expression
.u
.nested_exp
);
105 print_tabs(fd
, depth
);
106 fprintf(fd
, "</unary_expression_nested>\n");
111 fprintf(stderr
, "[error] %s: unknown expression type %d\n", __func__
,
112 (int) node
->u
.unary_expression
.type
);
119 int ctf_visitor_print_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
121 print_tabs(fd
, depth
);
122 fprintf(fd
, "<type_specifier \"");
124 switch (node
->u
.type_specifier
.type
) {
132 fprintf(fd
, "short");
141 fprintf(fd
, "float");
143 case TYPESPEC_DOUBLE
:
144 fprintf(fd
, "double");
146 case TYPESPEC_SIGNED
:
147 fprintf(fd
, "signed");
149 case TYPESPEC_UNSIGNED
:
150 fprintf(fd
, "unsigned");
155 case TYPESPEC_COMPLEX
:
156 fprintf(fd
, "_Complex");
158 case TYPESPEC_IMAGINARY
:
159 fprintf(fd
, "_Imaginary");
162 fprintf(fd
, "const");
164 case TYPESPEC_ID_TYPE
:
165 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
168 case TYPESPEC_UNKNOWN
:
170 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
171 (int) node
->u
.type_specifier
.type
);
174 fprintf(fd
, "\"/>\n");
179 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
182 struct ctf_node
*iter
;
184 print_tabs(fd
, depth
);
185 fprintf(fd
, "<type_declarator>\n");
188 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
189 print_tabs(fd
, depth
);
190 fprintf(fd
, "<pointers>\n");
191 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
193 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
197 print_tabs(fd
, depth
);
198 fprintf(fd
, "</pointers>\n");
201 switch (node
->u
.type_declarator
.type
) {
203 if (node
->u
.type_declarator
.u
.id
) {
204 print_tabs(fd
, depth
);
205 fprintf(fd
, "<id \"");
206 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
207 fprintf(fd
, "\" />\n");
211 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
212 print_tabs(fd
, depth
);
213 fprintf(fd
, "<type_declarator>\n");
214 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
215 node
->u
.type_declarator
.u
.nested
.type_declarator
);
218 print_tabs(fd
, depth
);
219 fprintf(fd
, "</type_declarator>\n");
221 if (!cds_list_empty(&node
->u
.type_declarator
.u
.nested
.length
)) {
222 print_tabs(fd
, depth
);
223 fprintf(fd
, "<length>\n");
225 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
227 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
231 if (!cds_list_empty(&node
->u
.type_declarator
.u
.nested
.length
)) {
232 print_tabs(fd
, depth
);
233 fprintf(fd
, "</length>\n");
235 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
236 print_tabs(fd
, depth
);
237 fprintf(fd
, "<length>\n");
238 print_tabs(fd
, depth
);
239 fprintf(fd
, "</length>\n");
241 if (node
->u
.type_declarator
.bitfield_len
) {
242 print_tabs(fd
, depth
);
243 fprintf(fd
, "<bitfield_len>\n");
244 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
245 node
->u
.type_declarator
.bitfield_len
);
248 print_tabs(fd
, depth
);
249 fprintf(fd
, "</bitfield_len>\n");
252 case TYPEDEC_UNKNOWN
:
254 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
255 (int) node
->u
.type_declarator
.type
);
260 print_tabs(fd
, depth
);
261 fprintf(fd
, "</type_declarator>\n");
265 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
268 struct ctf_node
*iter
;
270 switch (node
->type
) {
272 print_tabs(fd
, depth
);
273 fprintf(fd
, "<root>\n");
274 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
276 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
280 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
282 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
286 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
287 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
291 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
292 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
296 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
297 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
301 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
302 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
306 print_tabs(fd
, depth
);
307 fprintf(fd
, "</root>\n");
311 print_tabs(fd
, depth
);
312 fprintf(fd
, "<event>\n");
313 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
314 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
318 print_tabs(fd
, depth
);
319 fprintf(fd
, "</event>\n");
322 print_tabs(fd
, depth
);
323 fprintf(fd
, "<stream>\n");
324 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
325 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
329 print_tabs(fd
, depth
);
330 fprintf(fd
, "</stream>\n");
333 print_tabs(fd
, depth
);
334 fprintf(fd
, "<trace>\n");
335 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
336 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
340 print_tabs(fd
, depth
);
341 fprintf(fd
, "</trace>\n");
344 case NODE_CTF_EXPRESSION
:
345 print_tabs(fd
, depth
);
346 fprintf(fd
, "<ctf_expression>\n");
348 print_tabs(fd
, depth
);
349 fprintf(fd
, "<left>\n");
350 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
351 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
356 print_tabs(fd
, depth
);
357 fprintf(fd
, "</left>\n");
359 print_tabs(fd
, depth
);
360 fprintf(fd
, "<right>\n");
361 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
362 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
366 print_tabs(fd
, depth
);
367 fprintf(fd
, "</right>\n");
369 print_tabs(fd
, depth
);
370 fprintf(fd
, "</ctf_expression>\n");
372 case NODE_UNARY_EXPRESSION
:
373 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
376 print_tabs(fd
, depth
);
377 fprintf(fd
, "<typedef>\n");
379 print_tabs(fd
, depth
);
380 fprintf(fd
, "<declaration_specifier>\n");
381 cds_list_for_each_entry(iter
, &node
->u
._typedef
.declaration_specifier
, siblings
) {
382 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
386 print_tabs(fd
, depth
);
387 fprintf(fd
, "</declaration_specifier>\n");
389 print_tabs(fd
, depth
);
390 fprintf(fd
, "<type_declarators>\n");
391 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
392 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
396 print_tabs(fd
, depth
);
397 fprintf(fd
, "</type_declarators>\n");
399 print_tabs(fd
, depth
);
400 fprintf(fd
, "</typedef>\n");
402 case NODE_TYPEALIAS_TARGET
:
403 print_tabs(fd
, depth
);
404 fprintf(fd
, "<target>\n");
407 print_tabs(fd
, depth
);
408 fprintf(fd
, "<declaration_specifier>\n");
409 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
410 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
414 print_tabs(fd
, depth
);
415 fprintf(fd
, "</declaration_specifier>\n");
417 print_tabs(fd
, depth
);
418 fprintf(fd
, "<type_declarators>\n");
419 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
420 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
424 print_tabs(fd
, depth
);
425 fprintf(fd
, "</type_declarators>\n");
428 print_tabs(fd
, depth
);
429 fprintf(fd
, "</target>\n");
431 case NODE_TYPEALIAS_ALIAS
:
432 print_tabs(fd
, depth
);
433 fprintf(fd
, "<alias>\n");
436 print_tabs(fd
, depth
);
437 fprintf(fd
, "<declaration_specifier>\n");
438 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
439 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
443 print_tabs(fd
, depth
);
444 fprintf(fd
, "</declaration_specifier>\n");
446 print_tabs(fd
, depth
);
447 fprintf(fd
, "<type_declarators>\n");
448 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
449 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
453 print_tabs(fd
, depth
);
454 fprintf(fd
, "</type_declarators>\n");
457 print_tabs(fd
, depth
);
458 fprintf(fd
, "</alias>\n");
461 print_tabs(fd
, depth
);
462 fprintf(fd
, "<typealias>\n");
463 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
466 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
469 print_tabs(fd
, depth
);
470 fprintf(fd
, "</typealias>\n");
473 case NODE_TYPE_SPECIFIER
:
474 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
479 print_tabs(fd
, depth
);
480 if (node
->u
.pointer
.const_qualifier
)
481 fprintf(fd
, "<const_pointer />\n");
483 fprintf(fd
, "<pointer />\n");
485 case NODE_TYPE_DECLARATOR
:
486 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
491 case NODE_FLOATING_POINT
:
492 print_tabs(fd
, depth
);
493 fprintf(fd
, "<floating_point>\n");
494 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
495 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
499 print_tabs(fd
, depth
);
500 fprintf(fd
, "</floating_point>\n");
503 print_tabs(fd
, depth
);
504 fprintf(fd
, "<integer>\n");
505 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
506 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
510 print_tabs(fd
, depth
);
511 fprintf(fd
, "</integer>\n");
514 print_tabs(fd
, depth
);
515 fprintf(fd
, "<string>\n");
516 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
517 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
521 print_tabs(fd
, depth
);
522 fprintf(fd
, "</string>\n");
524 case NODE_ENUMERATOR
:
525 print_tabs(fd
, depth
);
526 fprintf(fd
, "<enumerator");
527 if (node
->u
.enumerator
.id
)
528 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
530 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
531 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
535 print_tabs(fd
, depth
);
536 fprintf(fd
, "</enumerator>\n");
539 print_tabs(fd
, depth
);
540 if (node
->u
._struct
.name
)
541 fprintf(fd
, "<enum name=\"%s\">\n",
542 node
->u
._enum
.enum_id
);
544 fprintf(fd
, "<enum >\n");
547 if (!cds_list_empty(&node
->u
._enum
.container_type
)) {
548 print_tabs(fd
, depth
);
549 fprintf(fd
, "<container_type>\n");
552 cds_list_for_each_entry(iter
, &node
->u
._enum
.container_type
,
554 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
558 if (!cds_list_empty(&node
->u
._enum
.container_type
)) {
559 print_tabs(fd
, depth
);
560 fprintf(fd
, "</container_type>\n");
563 print_tabs(fd
, depth
);
564 fprintf(fd
, "<enumerator_list>\n");
565 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
566 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
570 print_tabs(fd
, depth
);
571 fprintf(fd
, "</enumerator_list>\n");
574 print_tabs(fd
, depth
);
575 fprintf(fd
, "</enum>\n");
577 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
578 print_tabs(fd
, depth
);
579 fprintf(fd
, "<declaration_specifier>\n");
580 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
581 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
585 print_tabs(fd
, depth
);
586 fprintf(fd
, "</declaration_specifier>\n");
588 print_tabs(fd
, depth
);
589 fprintf(fd
, "<type_declarators>\n");
590 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
591 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
595 print_tabs(fd
, depth
);
596 fprintf(fd
, "</type_declarators>\n");
599 print_tabs(fd
, depth
);
600 fprintf(fd
, "<variant");
601 if (node
->u
.variant
.name
)
602 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
603 if (node
->u
.variant
.choice
)
604 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
606 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
607 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
611 print_tabs(fd
, depth
);
612 fprintf(fd
, "</variant>\n");
615 print_tabs(fd
, depth
);
616 if (node
->u
._struct
.name
)
617 fprintf(fd
, "<struct name=\"%s\">\n",
618 node
->u
._struct
.name
);
620 fprintf(fd
, "<struct>\n");
621 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
622 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
626 print_tabs(fd
, depth
);
627 fprintf(fd
, "</struct>\n");
632 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,