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 (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
317 print_tabs(fd
, depth
);
318 fprintf(fd
, "<length>\n");
319 print_tabs(fd
, depth
);
320 fprintf(fd
, "</length>\n");
321 } else if (!cds_list_empty(&node
->u
.type_declarator
.u
.nested
.length
)) {
322 print_tabs(fd
, depth
);
323 fprintf(fd
, "<length>\n");
324 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
326 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
330 print_tabs(fd
, depth
);
331 fprintf(fd
, "</length>\n");
333 if (node
->u
.type_declarator
.bitfield_len
) {
334 print_tabs(fd
, depth
);
335 fprintf(fd
, "<bitfield_len>\n");
336 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
337 node
->u
.type_declarator
.bitfield_len
);
340 print_tabs(fd
, depth
);
341 fprintf(fd
, "</bitfield_len>\n");
344 case TYPEDEC_UNKNOWN
:
346 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
347 (int) node
->u
.type_declarator
.type
);
352 print_tabs(fd
, depth
);
353 fprintf(fd
, "</type_declarator>\n");
357 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
360 struct ctf_node
*iter
;
362 switch (node
->type
) {
364 print_tabs(fd
, depth
);
365 fprintf(fd
, "<root>\n");
366 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
368 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
372 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
373 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
377 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
378 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
382 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
383 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
387 print_tabs(fd
, depth
);
388 fprintf(fd
, "</root>\n");
392 print_tabs(fd
, depth
);
393 fprintf(fd
, "<event>\n");
394 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
395 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
399 print_tabs(fd
, depth
);
400 fprintf(fd
, "</event>\n");
403 print_tabs(fd
, depth
);
404 fprintf(fd
, "<stream>\n");
405 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
406 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
410 print_tabs(fd
, depth
);
411 fprintf(fd
, "</stream>\n");
414 print_tabs(fd
, depth
);
415 fprintf(fd
, "<trace>\n");
416 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
417 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
421 print_tabs(fd
, depth
);
422 fprintf(fd
, "</trace>\n");
425 case NODE_CTF_EXPRESSION
:
426 print_tabs(fd
, depth
);
427 fprintf(fd
, "<ctf_expression>\n");
429 print_tabs(fd
, depth
);
430 fprintf(fd
, "<left>\n");
431 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
432 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
437 print_tabs(fd
, depth
);
438 fprintf(fd
, "</left>\n");
440 print_tabs(fd
, depth
);
441 fprintf(fd
, "<right>\n");
442 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
443 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
447 print_tabs(fd
, depth
);
448 fprintf(fd
, "</right>\n");
450 print_tabs(fd
, depth
);
451 fprintf(fd
, "</ctf_expression>\n");
453 case NODE_UNARY_EXPRESSION
:
454 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
457 print_tabs(fd
, depth
);
458 fprintf(fd
, "<typedef>\n");
460 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
464 print_tabs(fd
, depth
);
465 fprintf(fd
, "<type_declarator_list>\n");
466 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
467 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
471 print_tabs(fd
, depth
);
472 fprintf(fd
, "</type_declarator_list>\n");
474 print_tabs(fd
, depth
);
475 fprintf(fd
, "</typedef>\n");
477 case NODE_TYPEALIAS_TARGET
:
478 print_tabs(fd
, depth
);
479 fprintf(fd
, "<target>\n");
482 ret
= ctf_visitor_print_xml(fd
, depth
, node
->u
.typealias_target
.type_specifier_list
);
486 print_tabs(fd
, depth
);
487 fprintf(fd
, "<type_declarator_list>\n");
488 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
489 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
493 print_tabs(fd
, depth
);
494 fprintf(fd
, "</type_declarator_list>\n");
497 print_tabs(fd
, depth
);
498 fprintf(fd
, "</target>\n");
500 case NODE_TYPEALIAS_ALIAS
:
501 print_tabs(fd
, depth
);
502 fprintf(fd
, "<alias>\n");
505 ret
= ctf_visitor_print_xml(fd
, depth
, node
->u
.typealias_alias
.type_specifier_list
);
509 print_tabs(fd
, depth
);
510 fprintf(fd
, "<type_declarator_list>\n");
511 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
512 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
516 print_tabs(fd
, depth
);
517 fprintf(fd
, "</type_declarator_list>\n");
520 print_tabs(fd
, depth
);
521 fprintf(fd
, "</alias>\n");
524 print_tabs(fd
, depth
);
525 fprintf(fd
, "<typealias>\n");
526 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
529 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
532 print_tabs(fd
, depth
);
533 fprintf(fd
, "</typealias>\n");
536 case NODE_TYPE_SPECIFIER_LIST
:
537 ret
= ctf_visitor_print_type_specifier_list(fd
, depth
, node
);
542 case NODE_TYPE_SPECIFIER
:
543 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
548 print_tabs(fd
, depth
);
549 if (node
->u
.pointer
.const_qualifier
)
550 fprintf(fd
, "<const_pointer />\n");
552 fprintf(fd
, "<pointer />\n");
554 case NODE_TYPE_DECLARATOR
:
555 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
560 case NODE_FLOATING_POINT
:
561 print_tabs(fd
, depth
);
562 fprintf(fd
, "<floating_point>\n");
563 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
564 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
568 print_tabs(fd
, depth
);
569 fprintf(fd
, "</floating_point>\n");
572 print_tabs(fd
, depth
);
573 fprintf(fd
, "<integer>\n");
574 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
575 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
579 print_tabs(fd
, depth
);
580 fprintf(fd
, "</integer>\n");
583 print_tabs(fd
, depth
);
584 fprintf(fd
, "<string>\n");
585 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
586 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
590 print_tabs(fd
, depth
);
591 fprintf(fd
, "</string>\n");
593 case NODE_ENUMERATOR
:
594 print_tabs(fd
, depth
);
595 fprintf(fd
, "<enumerator");
596 if (node
->u
.enumerator
.id
)
597 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
599 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
600 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
604 print_tabs(fd
, depth
);
605 fprintf(fd
, "</enumerator>\n");
608 print_tabs(fd
, depth
);
609 if (node
->u
._struct
.name
)
610 fprintf(fd
, "<enum name=\"%s\">\n",
611 node
->u
._enum
.enum_id
);
613 fprintf(fd
, "<enum >\n");
616 if (node
->u
._enum
.container_type
) {
617 print_tabs(fd
, depth
);
618 fprintf(fd
, "<container_type>\n");
619 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
622 print_tabs(fd
, depth
);
623 fprintf(fd
, "</container_type>\n");
626 print_tabs(fd
, depth
);
627 fprintf(fd
, "<enumerator_list>\n");
628 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
629 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
633 print_tabs(fd
, depth
);
634 fprintf(fd
, "</enumerator_list>\n");
637 print_tabs(fd
, depth
);
638 fprintf(fd
, "</enum>\n");
640 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
641 ret
= ctf_visitor_print_xml(fd
, depth
,
642 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
646 print_tabs(fd
, depth
);
647 fprintf(fd
, "<type_declarator_list>\n");
648 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
649 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
653 print_tabs(fd
, depth
);
654 fprintf(fd
, "</type_declarator_list>\n");
657 print_tabs(fd
, depth
);
658 fprintf(fd
, "<variant");
659 if (node
->u
.variant
.name
)
660 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
661 if (node
->u
.variant
.choice
)
662 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
664 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
665 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
669 print_tabs(fd
, depth
);
670 fprintf(fd
, "</variant>\n");
673 print_tabs(fd
, depth
);
674 if (node
->u
._struct
.name
)
675 fprintf(fd
, "<struct name=\"%s\">\n",
676 node
->u
._struct
.name
);
678 fprintf(fd
, "<struct>\n");
679 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
680 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
684 print_tabs(fd
, depth
);
685 fprintf(fd
, "</struct>\n");
686 if (!cds_list_empty(&node
->u
._struct
.min_align
)) {
687 print_tabs(fd
, depth
);
688 fprintf(fd
, "<align>\n");
689 cds_list_for_each_entry(iter
, &node
->u
._struct
.min_align
, siblings
) {
690 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
694 print_tabs(fd
, depth
);
695 fprintf(fd
, "</align>\n");
701 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,