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/babeltrace.h>
28 #include <babeltrace/list.h>
29 #include "ctf-scanner.h"
30 #include "ctf-parser.h"
33 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
36 void print_tabs(FILE *fd
, int depth
)
40 for (i
= 0; i
< depth
; i
++)
45 int ctf_visitor_print_unary_expression(FILE *fd
, int depth
, struct ctf_node
*node
)
49 switch (node
->u
.unary_expression
.link
) {
50 case UNARY_LINK_UNKNOWN
:
53 print_tabs(fd
, depth
);
54 fprintf(fd
, "<dotlink/>\n");
57 print_tabs(fd
, depth
);
58 fprintf(fd
, "<arrowlink/>\n");
61 print_tabs(fd
, depth
);
62 fprintf(fd
, "<dotdotdot/>\n");
65 fprintf(stderr
, "[error] %s: unknown expression link type %d\n", __func__
,
66 (int) node
->u
.unary_expression
.link
);
70 switch (node
->u
.unary_expression
.type
) {
72 print_tabs(fd
, depth
);
73 fprintf(fd
, "<unary_expression value=");
74 fprintf(fd
, "\"%s\"", node
->u
.unary_expression
.u
.string
);
77 case UNARY_SIGNED_CONSTANT
:
78 print_tabs(fd
, depth
);
79 fprintf(fd
, "<unary_expression value=\"");
80 fprintf(fd
, "%" PRId64
, node
->u
.unary_expression
.u
.signed_constant
);
81 fprintf(fd
, "\" />\n");
83 case UNARY_UNSIGNED_CONSTANT
:
84 print_tabs(fd
, depth
);
85 fprintf(fd
, "<unary_expression value=\"");
86 fprintf(fd
, "%" PRIu64
, node
->u
.unary_expression
.u
.signed_constant
);
87 fprintf(fd
, "\" />\n");
90 print_tabs(fd
, depth
);
91 fprintf(fd
, "<unary_expression_sbrac>\n");
92 ret
= ctf_visitor_print_unary_expression(fd
, depth
+ 1,
93 node
->u
.unary_expression
.u
.sbrac_exp
);
96 print_tabs(fd
, depth
);
97 fprintf(fd
, "</unary_expression_sbrac>\n");
100 print_tabs(fd
, depth
);
101 fprintf(fd
, "<unary_expression_nested>\n");
102 ret
= ctf_visitor_print_unary_expression(fd
, depth
+ 1,
103 node
->u
.unary_expression
.u
.nested_exp
);
106 print_tabs(fd
, depth
);
107 fprintf(fd
, "</unary_expression_nested>\n");
112 fprintf(stderr
, "[error] %s: unknown expression type %d\n", __func__
,
113 (int) node
->u
.unary_expression
.type
);
120 int ctf_visitor_print_type_specifier_list(FILE *fd
, int depth
, struct ctf_node
*node
)
122 struct ctf_node
*iter
;
125 print_tabs(fd
, depth
);
126 fprintf(fd
, "<type_specifier_list>\n");
127 cds_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
128 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
132 print_tabs(fd
, depth
);
133 fprintf(fd
, "</type_specifier_list>\n");
138 int ctf_visitor_print_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
141 print_tabs(fd
, depth
);
143 switch (node
->u
.type_specifier
.type
) {
150 case TYPESPEC_DOUBLE
:
151 case TYPESPEC_SIGNED
:
152 case TYPESPEC_UNSIGNED
:
154 case TYPESPEC_COMPLEX
:
155 case TYPESPEC_IMAGINARY
:
157 case TYPESPEC_ID_TYPE
:
158 fprintf(fd
, "<type_specifier type=\"");
160 case TYPESPEC_FLOATING_POINT
:
161 case TYPESPEC_INTEGER
:
162 case TYPESPEC_STRING
:
163 case TYPESPEC_STRUCT
:
164 case TYPESPEC_VARIANT
:
166 fprintf(fd
, "<type_specifier>\n");
169 case TYPESPEC_UNKNOWN
:
171 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
172 (int) node
->u
.type_specifier
.type
);
176 switch (node
->u
.type_specifier
.type
) {
184 fprintf(fd
, "short");
193 fprintf(fd
, "float");
195 case TYPESPEC_DOUBLE
:
196 fprintf(fd
, "double");
198 case TYPESPEC_SIGNED
:
199 fprintf(fd
, "signed");
201 case TYPESPEC_UNSIGNED
:
202 fprintf(fd
, "unsigned");
207 case TYPESPEC_COMPLEX
:
208 fprintf(fd
, "_Complex");
210 case TYPESPEC_IMAGINARY
:
211 fprintf(fd
, "_Imaginary");
214 fprintf(fd
, "const");
216 case TYPESPEC_ID_TYPE
:
217 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
219 case TYPESPEC_FLOATING_POINT
:
220 case TYPESPEC_INTEGER
:
221 case TYPESPEC_STRING
:
222 case TYPESPEC_STRUCT
:
223 case TYPESPEC_VARIANT
:
225 ret
= ctf_visitor_print_xml(fd
, depth
, node
->u
.type_specifier
.node
);
229 case TYPESPEC_UNKNOWN
:
231 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
232 (int) node
->u
.type_specifier
.type
);
236 switch (node
->u
.type_specifier
.type
) {
243 case TYPESPEC_DOUBLE
:
244 case TYPESPEC_SIGNED
:
245 case TYPESPEC_UNSIGNED
:
247 case TYPESPEC_COMPLEX
:
248 case TYPESPEC_IMAGINARY
:
250 case TYPESPEC_ID_TYPE
:
251 fprintf(fd
, "\"/>\n");
253 case TYPESPEC_FLOATING_POINT
:
254 case TYPESPEC_INTEGER
:
255 case TYPESPEC_STRING
:
256 case TYPESPEC_STRUCT
:
257 case TYPESPEC_VARIANT
:
260 print_tabs(fd
, depth
);
261 fprintf(fd
, "</type_specifier>\n");
263 case TYPESPEC_UNKNOWN
:
265 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
266 (int) node
->u
.type_specifier
.type
);
274 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
277 struct ctf_node
*iter
;
279 print_tabs(fd
, depth
);
280 fprintf(fd
, "<type_declarator>\n");
283 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
284 print_tabs(fd
, depth
);
285 fprintf(fd
, "<pointers>\n");
286 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
288 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
292 print_tabs(fd
, depth
);
293 fprintf(fd
, "</pointers>\n");
296 switch (node
->u
.type_declarator
.type
) {
298 if (node
->u
.type_declarator
.u
.id
) {
299 print_tabs(fd
, depth
);
300 fprintf(fd
, "<id name=\"");
301 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
302 fprintf(fd
, "\" />\n");
306 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
307 print_tabs(fd
, depth
);
308 fprintf(fd
, "<type_declarator>\n");
309 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
310 node
->u
.type_declarator
.u
.nested
.type_declarator
);
313 print_tabs(fd
, depth
);
314 fprintf(fd
, "</type_declarator>\n");
316 if (!cds_list_empty(&node
->u
.type_declarator
.u
.nested
.length
)) {
317 print_tabs(fd
, depth
);
318 fprintf(fd
, "<length>\n");
319 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
321 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
325 print_tabs(fd
, depth
);
326 fprintf(fd
, "</length>\n");
328 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
329 print_tabs(fd
, depth
);
330 fprintf(fd
, "<length>\n");
331 print_tabs(fd
, depth
);
332 fprintf(fd
, "</length>\n");
334 if (node
->u
.type_declarator
.bitfield_len
) {
335 print_tabs(fd
, depth
);
336 fprintf(fd
, "<bitfield_len>\n");
337 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
338 node
->u
.type_declarator
.bitfield_len
);
341 print_tabs(fd
, depth
);
342 fprintf(fd
, "</bitfield_len>\n");
345 case TYPEDEC_UNKNOWN
:
347 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
348 (int) node
->u
.type_declarator
.type
);
353 print_tabs(fd
, depth
);
354 fprintf(fd
, "</type_declarator>\n");
358 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
361 struct ctf_node
*iter
;
363 switch (node
->type
) {
365 print_tabs(fd
, depth
);
366 fprintf(fd
, "<root>\n");
367 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
369 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
373 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
374 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
378 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
379 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
383 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
384 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
388 print_tabs(fd
, depth
);
389 fprintf(fd
, "</root>\n");
393 print_tabs(fd
, depth
);
394 fprintf(fd
, "<event>\n");
395 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
396 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
400 print_tabs(fd
, depth
);
401 fprintf(fd
, "</event>\n");
404 print_tabs(fd
, depth
);
405 fprintf(fd
, "<stream>\n");
406 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
407 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
411 print_tabs(fd
, depth
);
412 fprintf(fd
, "</stream>\n");
415 print_tabs(fd
, depth
);
416 fprintf(fd
, "<trace>\n");
417 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
418 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
422 print_tabs(fd
, depth
);
423 fprintf(fd
, "</trace>\n");
426 case NODE_CTF_EXPRESSION
:
427 print_tabs(fd
, depth
);
428 fprintf(fd
, "<ctf_expression>\n");
430 print_tabs(fd
, depth
);
431 fprintf(fd
, "<left>\n");
432 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
433 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
438 print_tabs(fd
, depth
);
439 fprintf(fd
, "</left>\n");
441 print_tabs(fd
, depth
);
442 fprintf(fd
, "<right>\n");
443 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
444 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
448 print_tabs(fd
, depth
);
449 fprintf(fd
, "</right>\n");
451 print_tabs(fd
, depth
);
452 fprintf(fd
, "</ctf_expression>\n");
454 case NODE_UNARY_EXPRESSION
:
455 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
458 print_tabs(fd
, depth
);
459 fprintf(fd
, "<typedef>\n");
461 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
465 print_tabs(fd
, depth
);
466 fprintf(fd
, "<type_declarator_list>\n");
467 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
468 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
472 print_tabs(fd
, depth
);
473 fprintf(fd
, "</type_declarator_list>\n");
475 print_tabs(fd
, depth
);
476 fprintf(fd
, "</typedef>\n");
478 case NODE_TYPEALIAS_TARGET
:
479 print_tabs(fd
, depth
);
480 fprintf(fd
, "<target>\n");
483 ret
= ctf_visitor_print_xml(fd
, depth
, node
->u
.typealias_target
.type_specifier_list
);
487 print_tabs(fd
, depth
);
488 fprintf(fd
, "<type_declarator_list>\n");
489 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
490 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
494 print_tabs(fd
, depth
);
495 fprintf(fd
, "</type_declarator_list>\n");
498 print_tabs(fd
, depth
);
499 fprintf(fd
, "</target>\n");
501 case NODE_TYPEALIAS_ALIAS
:
502 print_tabs(fd
, depth
);
503 fprintf(fd
, "<alias>\n");
506 ret
= ctf_visitor_print_xml(fd
, depth
, node
->u
.typealias_alias
.type_specifier_list
);
510 print_tabs(fd
, depth
);
511 fprintf(fd
, "<type_declarator_list>\n");
512 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
513 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
517 print_tabs(fd
, depth
);
518 fprintf(fd
, "</type_declarator_list>\n");
521 print_tabs(fd
, depth
);
522 fprintf(fd
, "</alias>\n");
525 print_tabs(fd
, depth
);
526 fprintf(fd
, "<typealias>\n");
527 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
530 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
533 print_tabs(fd
, depth
);
534 fprintf(fd
, "</typealias>\n");
537 case NODE_TYPE_SPECIFIER_LIST
:
538 ret
= ctf_visitor_print_type_specifier_list(fd
, depth
, node
);
543 case NODE_TYPE_SPECIFIER
:
544 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
549 print_tabs(fd
, depth
);
550 if (node
->u
.pointer
.const_qualifier
)
551 fprintf(fd
, "<const_pointer />\n");
553 fprintf(fd
, "<pointer />\n");
555 case NODE_TYPE_DECLARATOR
:
556 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
561 case NODE_FLOATING_POINT
:
562 print_tabs(fd
, depth
);
563 fprintf(fd
, "<floating_point>\n");
564 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
565 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
569 print_tabs(fd
, depth
);
570 fprintf(fd
, "</floating_point>\n");
573 print_tabs(fd
, depth
);
574 fprintf(fd
, "<integer>\n");
575 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
576 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
580 print_tabs(fd
, depth
);
581 fprintf(fd
, "</integer>\n");
584 print_tabs(fd
, depth
);
585 fprintf(fd
, "<string>\n");
586 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
587 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
591 print_tabs(fd
, depth
);
592 fprintf(fd
, "</string>\n");
594 case NODE_ENUMERATOR
:
595 print_tabs(fd
, depth
);
596 fprintf(fd
, "<enumerator");
597 if (node
->u
.enumerator
.id
)
598 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
600 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
601 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
605 print_tabs(fd
, depth
);
606 fprintf(fd
, "</enumerator>\n");
609 print_tabs(fd
, depth
);
610 if (node
->u
._struct
.name
)
611 fprintf(fd
, "<enum name=\"%s\">\n",
612 node
->u
._enum
.enum_id
);
614 fprintf(fd
, "<enum >\n");
617 if (node
->u
._enum
.container_type
) {
618 print_tabs(fd
, depth
);
619 fprintf(fd
, "<container_type>\n");
620 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
623 print_tabs(fd
, depth
);
624 fprintf(fd
, "</container_type>\n");
627 print_tabs(fd
, depth
);
628 fprintf(fd
, "<enumerator_list>\n");
629 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
630 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
634 print_tabs(fd
, depth
);
635 fprintf(fd
, "</enumerator_list>\n");
638 print_tabs(fd
, depth
);
639 fprintf(fd
, "</enum>\n");
641 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
642 ret
= ctf_visitor_print_xml(fd
, depth
,
643 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
647 print_tabs(fd
, depth
);
648 fprintf(fd
, "<type_declarator_list>\n");
649 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
650 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
654 print_tabs(fd
, depth
);
655 fprintf(fd
, "</type_declarator_list>\n");
658 print_tabs(fd
, depth
);
659 fprintf(fd
, "<variant");
660 if (node
->u
.variant
.name
)
661 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
662 if (node
->u
.variant
.choice
)
663 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
665 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
666 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
670 print_tabs(fd
, depth
);
671 fprintf(fd
, "</variant>\n");
674 print_tabs(fd
, depth
);
675 if (node
->u
._struct
.name
)
676 fprintf(fd
, "<struct name=\"%s\">\n",
677 node
->u
._struct
.name
);
679 fprintf(fd
, "<struct>\n");
680 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
681 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
685 print_tabs(fd
, depth
);
686 fprintf(fd
, "</struct>\n");
687 if (!cds_list_empty(&node
->u
._struct
.min_align
)) {
688 print_tabs(fd
, depth
);
689 fprintf(fd
, "<align>\n");
690 cds_list_for_each_entry(iter
, &node
->u
._struct
.min_align
, siblings
) {
691 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
695 print_tabs(fd
, depth
);
696 fprintf(fd
, "</align>\n");
702 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,