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");
159 fprintf(fd
, "const");
161 case TYPESPEC_ID_TYPE
:
162 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
165 case TYPESPEC_UNKNOWN
:
167 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
168 (int) node
->u
.type_specifier
.type
);
171 fprintf(fd
, "\"/>\n");
176 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
179 struct ctf_node
*iter
;
181 print_tabs(fd
, depth
);
182 fprintf(fd
, "<type_declarator>\n");
185 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
186 print_tabs(fd
, depth
);
187 fprintf(fd
, "<pointers>\n");
188 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
190 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
194 print_tabs(fd
, depth
);
195 fprintf(fd
, "</pointers>\n");
198 switch (node
->u
.type_declarator
.type
) {
200 if (node
->u
.type_declarator
.u
.id
) {
201 print_tabs(fd
, depth
);
202 fprintf(fd
, "<id \"");
203 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
204 fprintf(fd
, "\" />\n");
208 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
209 print_tabs(fd
, depth
);
210 fprintf(fd
, "<type_declarator>\n");
211 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
212 node
->u
.type_declarator
.u
.nested
.type_declarator
);
215 print_tabs(fd
, depth
);
216 fprintf(fd
, "</type_declarator>\n");
218 if (node
->u
.type_declarator
.u
.nested
.length
) {
219 print_tabs(fd
, depth
);
220 fprintf(fd
, "<length>\n");
221 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
222 node
->u
.type_declarator
.u
.nested
.length
);
225 print_tabs(fd
, depth
);
226 fprintf(fd
, "</length>\n");
228 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
229 print_tabs(fd
, depth
);
230 fprintf(fd
, "<length>\n");
231 print_tabs(fd
, depth
);
232 fprintf(fd
, "</length>\n");
234 if (node
->u
.type_declarator
.bitfield_len
) {
235 print_tabs(fd
, depth
);
236 fprintf(fd
, "<bitfield_len>\n");
237 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
238 node
->u
.type_declarator
.bitfield_len
);
241 print_tabs(fd
, depth
);
242 fprintf(fd
, "</bitfield_len>\n");
245 case TYPEDEC_UNKNOWN
:
247 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
248 (int) node
->u
.type_declarator
.type
);
253 print_tabs(fd
, depth
);
254 fprintf(fd
, "</type_declarator>\n");
258 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
261 struct ctf_node
*iter
;
263 switch (node
->type
) {
265 print_tabs(fd
, depth
);
266 fprintf(fd
, "<root>\n");
267 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
269 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
273 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
275 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
279 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
280 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
284 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
285 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
289 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
290 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
294 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
295 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
299 print_tabs(fd
, depth
);
300 fprintf(fd
, "</root>\n");
304 print_tabs(fd
, depth
);
305 fprintf(fd
, "<event>\n");
306 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
307 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
311 print_tabs(fd
, depth
);
312 fprintf(fd
, "</event>\n");
315 print_tabs(fd
, depth
);
316 fprintf(fd
, "<stream>\n");
317 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
318 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
322 print_tabs(fd
, depth
);
323 fprintf(fd
, "</stream>\n");
326 print_tabs(fd
, depth
);
327 fprintf(fd
, "<trace>\n");
328 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
329 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
333 print_tabs(fd
, depth
);
334 fprintf(fd
, "</trace>\n");
337 case NODE_CTF_EXPRESSION
:
338 print_tabs(fd
, depth
);
339 fprintf(fd
, "<ctf_expression>\n");
341 print_tabs(fd
, depth
);
342 fprintf(fd
, "<left>\n");
343 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
344 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
349 print_tabs(fd
, depth
);
350 fprintf(fd
, "</left>\n");
352 print_tabs(fd
, depth
);
353 fprintf(fd
, "<right>\n");
354 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
355 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
359 print_tabs(fd
, depth
);
360 fprintf(fd
, "</right>\n");
362 print_tabs(fd
, depth
);
363 fprintf(fd
, "</ctf_expression>\n");
365 case NODE_UNARY_EXPRESSION
:
366 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
369 print_tabs(fd
, depth
);
370 fprintf(fd
, "<typedef>\n");
372 print_tabs(fd
, depth
);
373 fprintf(fd
, "<declaration_specifier>\n");
374 cds_list_for_each_entry(iter
, &node
->u
._typedef
.declaration_specifier
, siblings
) {
375 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
379 print_tabs(fd
, depth
);
380 fprintf(fd
, "</declaration_specifier>\n");
382 print_tabs(fd
, depth
);
383 fprintf(fd
, "<type_declarators>\n");
384 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
385 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
389 print_tabs(fd
, depth
);
390 fprintf(fd
, "</type_declarators>\n");
392 print_tabs(fd
, depth
);
393 fprintf(fd
, "</typedef>\n");
395 case NODE_TYPEALIAS_TARGET
:
396 print_tabs(fd
, depth
);
397 fprintf(fd
, "<target>\n");
400 print_tabs(fd
, depth
);
401 fprintf(fd
, "<declaration_specifier>\n");
402 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
403 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
407 print_tabs(fd
, depth
);
408 fprintf(fd
, "</declaration_specifier>\n");
410 print_tabs(fd
, depth
);
411 fprintf(fd
, "<type_declarators>\n");
412 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
413 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
417 print_tabs(fd
, depth
);
418 fprintf(fd
, "</type_declarators>\n");
421 print_tabs(fd
, depth
);
422 fprintf(fd
, "</target>\n");
424 case NODE_TYPEALIAS_ALIAS
:
425 print_tabs(fd
, depth
);
426 fprintf(fd
, "<alias>\n");
429 print_tabs(fd
, depth
);
430 fprintf(fd
, "<declaration_specifier>\n");
431 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
432 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
436 print_tabs(fd
, depth
);
437 fprintf(fd
, "</declaration_specifier>\n");
439 print_tabs(fd
, depth
);
440 fprintf(fd
, "<type_declarators>\n");
441 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
442 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
446 print_tabs(fd
, depth
);
447 fprintf(fd
, "</type_declarators>\n");
450 print_tabs(fd
, depth
);
451 fprintf(fd
, "</alias>\n");
454 print_tabs(fd
, depth
);
455 fprintf(fd
, "<typealias>\n");
456 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
459 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
462 print_tabs(fd
, depth
);
463 fprintf(fd
, "</typealias>\n");
466 case NODE_TYPE_SPECIFIER
:
467 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
472 print_tabs(fd
, depth
);
473 if (node
->u
.pointer
.const_qualifier
)
474 fprintf(fd
, "<const_pointer />\n");
476 fprintf(fd
, "<pointer />\n");
478 case NODE_TYPE_DECLARATOR
:
479 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
484 case NODE_FLOATING_POINT
:
485 print_tabs(fd
, depth
);
486 fprintf(fd
, "<floating_point>\n");
487 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
488 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
492 print_tabs(fd
, depth
);
493 fprintf(fd
, "</floating_point>\n");
496 print_tabs(fd
, depth
);
497 fprintf(fd
, "<integer>\n");
498 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
499 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
503 print_tabs(fd
, depth
);
504 fprintf(fd
, "</integer>\n");
507 print_tabs(fd
, depth
);
508 fprintf(fd
, "<string>\n");
509 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
510 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
514 print_tabs(fd
, depth
);
515 fprintf(fd
, "</string>\n");
517 case NODE_ENUMERATOR
:
518 print_tabs(fd
, depth
);
519 fprintf(fd
, "<enumerator");
520 if (node
->u
.enumerator
.id
)
521 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
523 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
524 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
528 print_tabs(fd
, depth
);
529 fprintf(fd
, "</enumerator>\n");
532 print_tabs(fd
, depth
);
533 if (node
->u
._struct
.name
)
534 fprintf(fd
, "<enum name=\"%s\">\n",
535 node
->u
._enum
.enum_id
);
537 fprintf(fd
, "<enum >\n");
540 if (node
->u
._enum
.container_type
) {
541 print_tabs(fd
, depth
);
542 fprintf(fd
, "<container_type>\n");
543 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
546 print_tabs(fd
, depth
);
547 fprintf(fd
, "</container_type>\n");
550 print_tabs(fd
, depth
);
551 fprintf(fd
, "<enumerator_list>\n");
552 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
553 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
557 print_tabs(fd
, depth
);
558 fprintf(fd
, "</enumerator_list>\n");
561 print_tabs(fd
, depth
);
562 fprintf(fd
, "</enum>\n");
564 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
565 print_tabs(fd
, depth
);
566 fprintf(fd
, "<declaration_specifier>\n");
567 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
568 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
572 print_tabs(fd
, depth
);
573 fprintf(fd
, "</declaration_specifier>\n");
575 print_tabs(fd
, depth
);
576 fprintf(fd
, "<type_declarators>\n");
577 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
578 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
582 print_tabs(fd
, depth
);
583 fprintf(fd
, "</type_declarators>\n");
586 print_tabs(fd
, depth
);
587 fprintf(fd
, "<variant");
588 if (node
->u
.variant
.name
)
589 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
590 if (node
->u
.variant
.choice
)
591 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
593 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
594 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
598 print_tabs(fd
, depth
);
599 fprintf(fd
, "</variant>\n");
602 print_tabs(fd
, depth
);
603 if (node
->u
._struct
.name
)
604 fprintf(fd
, "<struct name=\"%s\">\n",
605 node
->u
._struct
.name
);
607 fprintf(fd
, "<struct>\n");
608 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
609 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
613 print_tabs(fd
, depth
);
614 fprintf(fd
, "</struct>\n");
619 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,