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
);
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
);
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
)
140 print_tabs(fd
, depth
);
142 switch (node
->u
.type_specifier
.type
) {
149 case TYPESPEC_DOUBLE
:
150 case TYPESPEC_SIGNED
:
151 case TYPESPEC_UNSIGNED
:
153 case TYPESPEC_COMPLEX
:
154 case TYPESPEC_IMAGINARY
:
156 case TYPESPEC_ID_TYPE
:
157 fprintf(fd
, "<type_specifier \"");
159 case TYPESPEC_FLOATING_POINT
:
160 case TYPESPEC_INTEGER
:
161 case TYPESPEC_STRING
:
162 case TYPESPEC_STRUCT
:
163 case TYPESPEC_VARIANT
:
165 fprintf(fd
, "<type_specifier>\n");
168 case TYPESPEC_UNKNOWN
:
170 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
171 (int) node
->u
.type_specifier
.type
);
175 switch (node
->u
.type_specifier
.type
) {
183 fprintf(fd
, "short");
192 fprintf(fd
, "float");
194 case TYPESPEC_DOUBLE
:
195 fprintf(fd
, "double");
197 case TYPESPEC_SIGNED
:
198 fprintf(fd
, "signed");
200 case TYPESPEC_UNSIGNED
:
201 fprintf(fd
, "unsigned");
206 case TYPESPEC_COMPLEX
:
207 fprintf(fd
, "_Complex");
209 case TYPESPEC_IMAGINARY
:
210 fprintf(fd
, "_Imaginary");
213 fprintf(fd
, "const");
215 case TYPESPEC_ID_TYPE
:
216 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
218 case TYPESPEC_FLOATING_POINT
:
219 case TYPESPEC_INTEGER
:
220 case TYPESPEC_STRING
:
221 case TYPESPEC_STRUCT
:
222 case TYPESPEC_VARIANT
:
224 return ctf_visitor_print_xml(fd
, depth
, node
->u
.type_specifier
.node
);
225 case TYPESPEC_UNKNOWN
:
227 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
228 (int) node
->u
.type_specifier
.type
);
232 switch (node
->u
.type_specifier
.type
) {
239 case TYPESPEC_DOUBLE
:
240 case TYPESPEC_SIGNED
:
241 case TYPESPEC_UNSIGNED
:
243 case TYPESPEC_COMPLEX
:
244 case TYPESPEC_IMAGINARY
:
246 case TYPESPEC_ID_TYPE
:
247 fprintf(fd
, "\"/>\n");
249 case TYPESPEC_FLOATING_POINT
:
250 case TYPESPEC_INTEGER
:
251 case TYPESPEC_STRING
:
252 case TYPESPEC_STRUCT
:
253 case TYPESPEC_VARIANT
:
255 print_tabs(fd
, depth
);
256 fprintf(fd
, "</type_specifier>\n");
259 case TYPESPEC_UNKNOWN
:
261 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
262 (int) node
->u
.type_specifier
.type
);
270 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
273 struct ctf_node
*iter
;
275 print_tabs(fd
, depth
);
276 fprintf(fd
, "<type_declarator>\n");
279 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
280 print_tabs(fd
, depth
);
281 fprintf(fd
, "<pointers>\n");
282 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
284 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
288 print_tabs(fd
, depth
);
289 fprintf(fd
, "</pointers>\n");
292 switch (node
->u
.type_declarator
.type
) {
294 if (node
->u
.type_declarator
.u
.id
) {
295 print_tabs(fd
, depth
);
296 fprintf(fd
, "<id \"");
297 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
298 fprintf(fd
, "\" />\n");
302 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
303 print_tabs(fd
, depth
);
304 fprintf(fd
, "<type_declarator>\n");
305 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
306 node
->u
.type_declarator
.u
.nested
.type_declarator
);
309 print_tabs(fd
, depth
);
310 fprintf(fd
, "</type_declarator>\n");
312 if (node
->u
.type_declarator
.u
.nested
.length
) {
313 print_tabs(fd
, depth
);
314 fprintf(fd
, "<length>\n");
315 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.type_declarator
.u
.nested
.length
);
318 print_tabs(fd
, depth
);
319 fprintf(fd
, "</length>\n");
321 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
322 print_tabs(fd
, depth
);
323 fprintf(fd
, "<length>\n");
324 print_tabs(fd
, depth
);
325 fprintf(fd
, "</length>\n");
327 if (node
->u
.type_declarator
.bitfield_len
) {
328 print_tabs(fd
, depth
);
329 fprintf(fd
, "<bitfield_len>\n");
330 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
331 node
->u
.type_declarator
.bitfield_len
);
334 print_tabs(fd
, depth
);
335 fprintf(fd
, "</bitfield_len>\n");
338 case TYPEDEC_UNKNOWN
:
340 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
341 (int) node
->u
.type_declarator
.type
);
346 print_tabs(fd
, depth
);
347 fprintf(fd
, "</type_declarator>\n");
351 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
354 struct ctf_node
*iter
;
356 switch (node
->type
) {
358 print_tabs(fd
, depth
);
359 fprintf(fd
, "<root>\n");
360 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
362 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
366 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
367 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
371 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
372 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
376 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
377 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
381 print_tabs(fd
, depth
);
382 fprintf(fd
, "</root>\n");
386 print_tabs(fd
, depth
);
387 fprintf(fd
, "<event>\n");
388 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
389 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
393 print_tabs(fd
, depth
);
394 fprintf(fd
, "</event>\n");
397 print_tabs(fd
, depth
);
398 fprintf(fd
, "<stream>\n");
399 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
400 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
404 print_tabs(fd
, depth
);
405 fprintf(fd
, "</stream>\n");
408 print_tabs(fd
, depth
);
409 fprintf(fd
, "<trace>\n");
410 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
411 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
415 print_tabs(fd
, depth
);
416 fprintf(fd
, "</trace>\n");
419 case NODE_CTF_EXPRESSION
:
420 print_tabs(fd
, depth
);
421 fprintf(fd
, "<ctf_expression>\n");
423 print_tabs(fd
, depth
);
424 fprintf(fd
, "<left>\n");
425 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
426 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
431 print_tabs(fd
, depth
);
432 fprintf(fd
, "</left>\n");
434 print_tabs(fd
, depth
);
435 fprintf(fd
, "<right>\n");
436 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
437 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
441 print_tabs(fd
, depth
);
442 fprintf(fd
, "</right>\n");
444 print_tabs(fd
, depth
);
445 fprintf(fd
, "</ctf_expression>\n");
447 case NODE_UNARY_EXPRESSION
:
448 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
451 print_tabs(fd
, depth
);
452 fprintf(fd
, "<typedef>\n");
454 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
458 print_tabs(fd
, depth
);
459 fprintf(fd
, "<type_declarator_list>\n");
460 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
461 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
465 print_tabs(fd
, depth
);
466 fprintf(fd
, "</type_declarator_list>\n");
468 print_tabs(fd
, depth
);
469 fprintf(fd
, "</typedef>\n");
471 case NODE_TYPEALIAS_TARGET
:
472 print_tabs(fd
, depth
);
473 fprintf(fd
, "<target>\n");
476 ret
= ctf_visitor_print_xml(fd
, depth
, node
->u
.typealias_target
.type_specifier_list
);
480 print_tabs(fd
, depth
);
481 fprintf(fd
, "<type_declarator_list>\n");
482 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
483 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
487 print_tabs(fd
, depth
);
488 fprintf(fd
, "</type_declarator_list>\n");
491 print_tabs(fd
, depth
);
492 fprintf(fd
, "</target>\n");
494 case NODE_TYPEALIAS_ALIAS
:
495 print_tabs(fd
, depth
);
496 fprintf(fd
, "<alias>\n");
499 ret
= ctf_visitor_print_xml(fd
, depth
, node
->u
.typealias_alias
.type_specifier_list
);
503 print_tabs(fd
, depth
);
504 fprintf(fd
, "<type_declarator_list>\n");
505 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
506 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
510 print_tabs(fd
, depth
);
511 fprintf(fd
, "</type_declarator_list>\n");
514 print_tabs(fd
, depth
);
515 fprintf(fd
, "</alias>\n");
518 print_tabs(fd
, depth
);
519 fprintf(fd
, "<typealias>\n");
520 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
523 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
526 print_tabs(fd
, depth
);
527 fprintf(fd
, "</typealias>\n");
530 case NODE_TYPE_SPECIFIER_LIST
:
531 ret
= ctf_visitor_print_type_specifier_list(fd
, depth
, node
);
536 case NODE_TYPE_SPECIFIER
:
537 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
542 print_tabs(fd
, depth
);
543 if (node
->u
.pointer
.const_qualifier
)
544 fprintf(fd
, "<const_pointer />\n");
546 fprintf(fd
, "<pointer />\n");
548 case NODE_TYPE_DECLARATOR
:
549 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
554 case NODE_FLOATING_POINT
:
555 print_tabs(fd
, depth
);
556 fprintf(fd
, "<floating_point>\n");
557 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
558 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
562 print_tabs(fd
, depth
);
563 fprintf(fd
, "</floating_point>\n");
566 print_tabs(fd
, depth
);
567 fprintf(fd
, "<integer>\n");
568 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
569 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
573 print_tabs(fd
, depth
);
574 fprintf(fd
, "</integer>\n");
577 print_tabs(fd
, depth
);
578 fprintf(fd
, "<string>\n");
579 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
580 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
584 print_tabs(fd
, depth
);
585 fprintf(fd
, "</string>\n");
587 case NODE_ENUMERATOR
:
588 print_tabs(fd
, depth
);
589 fprintf(fd
, "<enumerator");
590 if (node
->u
.enumerator
.id
)
591 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
593 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
594 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
598 print_tabs(fd
, depth
);
599 fprintf(fd
, "</enumerator>\n");
602 print_tabs(fd
, depth
);
603 if (node
->u
._struct
.name
)
604 fprintf(fd
, "<enum name=\"%s\">\n",
605 node
->u
._enum
.enum_id
);
607 fprintf(fd
, "<enum >\n");
610 if (node
->u
._enum
.container_type
) {
611 print_tabs(fd
, depth
);
612 fprintf(fd
, "<container_type>\n");
613 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
616 print_tabs(fd
, depth
);
617 fprintf(fd
, "</container_type>\n");
620 print_tabs(fd
, depth
);
621 fprintf(fd
, "<enumerator_list>\n");
622 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
623 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
627 print_tabs(fd
, depth
);
628 fprintf(fd
, "</enumerator_list>\n");
631 print_tabs(fd
, depth
);
632 fprintf(fd
, "</enum>\n");
634 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
635 ret
= ctf_visitor_print_xml(fd
, depth
,
636 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
640 print_tabs(fd
, depth
);
641 fprintf(fd
, "<type_declarator_list>\n");
642 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
643 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
647 print_tabs(fd
, depth
);
648 fprintf(fd
, "</type_declarator_list>\n");
651 print_tabs(fd
, depth
);
652 fprintf(fd
, "<variant");
653 if (node
->u
.variant
.name
)
654 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
655 if (node
->u
.variant
.choice
)
656 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
658 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
659 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
663 print_tabs(fd
, depth
);
664 fprintf(fd
, "</variant>\n");
667 print_tabs(fd
, depth
);
668 if (node
->u
._struct
.name
)
669 fprintf(fd
, "<struct name=\"%s\">\n",
670 node
->u
._struct
.name
);
672 fprintf(fd
, "<struct>\n");
673 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
674 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
678 print_tabs(fd
, depth
);
679 fprintf(fd
, "</struct>\n");
684 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,