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.
26 #include <babeltrace/list.h>
27 #include "ctf-scanner.h"
28 #include "ctf-parser.h"
31 #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args)
33 static void print_tabs(FILE *fd
, int depth
)
37 for (i
= 0; i
< depth
; i
++)
41 int ctf_visitor_print_unary_expression(FILE *fd
, int depth
, struct ctf_node
*node
)
45 switch (node
->u
.unary_expression
.link
) {
46 case UNARY_LINK_UNKNOWN
:
49 print_tabs(fd
, depth
);
50 fprintf(fd
, "<dotlink/>\n");
53 print_tabs(fd
, depth
);
54 fprintf(fd
, "<arrowlink/>\n");
57 print_tabs(fd
, depth
);
58 fprintf(fd
, "<dotdotdot/>\n");
61 fprintf(stderr
, "[error] %s: unknown expression link type %d\n", __func__
,
62 (int) node
->u
.unary_expression
.link
);
66 switch (node
->u
.unary_expression
.type
) {
68 print_tabs(fd
, depth
);
69 fprintf(fd
, "<unary_expression value=");
70 fprintf(fd
, "\"%s\"", node
->u
.unary_expression
.u
.string
);
73 case UNARY_SIGNED_CONSTANT
:
74 print_tabs(fd
, depth
);
75 fprintf(fd
, "<unary_expression value=");
76 fprintf(fd
, "%lld", node
->u
.unary_expression
.u
.signed_constant
);
79 case UNARY_UNSIGNED_CONSTANT
:
80 print_tabs(fd
, depth
);
81 fprintf(fd
, "<unary_expression value=");
82 fprintf(fd
, "%llu", node
->u
.unary_expression
.u
.signed_constant
);
86 print_tabs(fd
, depth
);
87 fprintf(fd
, "<unary_expression_sbrac>");
88 ret
= ctf_visitor_print_unary_expression(fd
, depth
+ 1,
89 node
->u
.unary_expression
.u
.sbrac_exp
);
92 print_tabs(fd
, depth
);
93 fprintf(fd
, "</unary_expression_sbrac>");
96 print_tabs(fd
, depth
);
97 fprintf(fd
, "<unary_expression_nested>");
98 ret
= ctf_visitor_print_unary_expression(fd
, depth
+ 1,
99 node
->u
.unary_expression
.u
.nested_exp
);
102 print_tabs(fd
, depth
);
103 fprintf(fd
, "</unary_expression_nested>");
108 fprintf(stderr
, "[error] %s: unknown expression type %d\n", __func__
,
109 (int) node
->u
.unary_expression
.type
);
115 int ctf_visitor_print_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
117 print_tabs(fd
, depth
);
118 fprintf(fd
, "<type_specifier \"");
120 switch (node
->u
.type_specifier
.type
) {
128 fprintf(fd
, "short");
137 fprintf(fd
, "float");
139 case TYPESPEC_DOUBLE
:
140 fprintf(fd
, "double");
142 case TYPESPEC_SIGNED
:
143 fprintf(fd
, "signed");
145 case TYPESPEC_UNSIGNED
:
146 fprintf(fd
, "unsigned");
151 case TYPESPEC_COMPLEX
:
152 fprintf(fd
, "complex");
155 fprintf(fd
, "const");
157 case TYPESPEC_ID_TYPE
:
158 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
161 case TYPESPEC_UNKNOWN
:
163 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
164 (int) node
->u
.type_specifier
.type
);
167 fprintf(fd
, "\"/>\n");
171 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
174 struct ctf_node
*iter
;
176 print_tabs(fd
, depth
);
177 fprintf(fd
, "<type_declarator>\n");
180 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
181 print_tabs(fd
, depth
);
182 fprintf(fd
, "<pointers>\n");
183 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
185 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
189 print_tabs(fd
, depth
);
190 fprintf(fd
, "</pointers>\n");
193 switch (node
->u
.type_declarator
.type
) {
195 if (node
->u
.type_declarator
.u
.id
) {
196 print_tabs(fd
, depth
);
197 fprintf(fd
, "<id \"");
198 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
199 fprintf(fd
, "\" />\n");
203 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
204 print_tabs(fd
, depth
);
205 fprintf(fd
, "<type_declarator>\n");
206 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
207 node
->u
.type_declarator
.u
.nested
.type_declarator
);
210 print_tabs(fd
, depth
);
211 fprintf(fd
, "</type_declarator>\n");
213 if (node
->u
.type_declarator
.u
.nested
.length
) {
214 print_tabs(fd
, depth
);
215 fprintf(fd
, "<length>\n");
216 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
217 node
->u
.type_declarator
.u
.nested
.length
);
220 print_tabs(fd
, depth
);
221 fprintf(fd
, "</length>\n");
223 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
224 print_tabs(fd
, depth
);
225 fprintf(fd
, "<length>\n");
226 print_tabs(fd
, depth
);
227 fprintf(fd
, "</length>\n");
229 if (node
->u
.type_declarator
.bitfield_len
) {
230 print_tabs(fd
, depth
);
231 fprintf(fd
, "<bitfield_len>\n");
232 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
233 node
->u
.type_declarator
.bitfield_len
);
236 print_tabs(fd
, depth
);
237 fprintf(fd
, "</bitfield_len>\n");
240 case TYPEDEC_UNKNOWN
:
242 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
243 (int) node
->u
.type_declarator
.type
);
248 print_tabs(fd
, depth
);
249 fprintf(fd
, "</type_declarator>\n");
253 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
256 struct ctf_node
*iter
;
258 switch (node
->type
) {
260 print_tabs(fd
, depth
);
261 fprintf(fd
, "<root>\n");
262 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
264 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
268 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
270 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
274 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
275 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
279 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
280 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
284 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
285 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
289 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
290 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
294 print_tabs(fd
, depth
);
295 fprintf(fd
, "</root>\n");
299 print_tabs(fd
, depth
);
300 fprintf(fd
, "<event>\n");
301 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
302 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
306 print_tabs(fd
, depth
);
307 fprintf(fd
, "</event>\n");
310 print_tabs(fd
, depth
);
311 fprintf(fd
, "<stream>\n");
312 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
313 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
317 print_tabs(fd
, depth
);
318 fprintf(fd
, "</stream>\n");
321 print_tabs(fd
, depth
);
322 fprintf(fd
, "<trace>\n");
323 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
324 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
328 print_tabs(fd
, depth
);
329 fprintf(fd
, "</trace>\n");
332 case NODE_CTF_EXPRESSION
:
333 print_tabs(fd
, depth
);
334 fprintf(fd
, "<ctf_expression>\n");
336 print_tabs(fd
, depth
);
337 fprintf(fd
, "<left>\n");
338 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
339 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
344 print_tabs(fd
, depth
);
345 fprintf(fd
, "</left>\n");
347 print_tabs(fd
, depth
);
348 fprintf(fd
, "<right>\n");
349 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
350 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
354 print_tabs(fd
, depth
);
355 fprintf(fd
, "</right>\n");
357 print_tabs(fd
, depth
);
358 fprintf(fd
, "</ctf_expression>\n");
360 case NODE_UNARY_EXPRESSION
:
361 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
364 print_tabs(fd
, depth
);
365 fprintf(fd
, "<typedef>\n");
367 print_tabs(fd
, depth
);
368 fprintf(fd
, "<declaration_specifier>\n");
369 cds_list_for_each_entry(iter
, &node
->u
._typedef
.declaration_specifier
, siblings
) {
370 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
374 print_tabs(fd
, depth
);
375 fprintf(fd
, "</declaration_specifier>\n");
377 print_tabs(fd
, depth
);
378 fprintf(fd
, "<type_declarators>\n");
379 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
380 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
384 print_tabs(fd
, depth
);
385 fprintf(fd
, "</type_declarators>\n");
387 print_tabs(fd
, depth
);
388 fprintf(fd
, "</typedef>\n");
390 case NODE_TYPEALIAS_TARGET
:
391 print_tabs(fd
, depth
);
392 fprintf(fd
, "<target>\n");
395 print_tabs(fd
, depth
);
396 fprintf(fd
, "<declaration_specifier>\n");
397 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
398 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
402 print_tabs(fd
, depth
);
403 fprintf(fd
, "</declaration_specifier>\n");
405 print_tabs(fd
, depth
);
406 fprintf(fd
, "<type_declarators>\n");
407 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
408 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
412 print_tabs(fd
, depth
);
413 fprintf(fd
, "</type_declarators>\n");
416 print_tabs(fd
, depth
);
417 fprintf(fd
, "</target>\n");
419 case NODE_TYPEALIAS_ALIAS
:
420 print_tabs(fd
, depth
);
421 fprintf(fd
, "<alias>\n");
424 print_tabs(fd
, depth
);
425 fprintf(fd
, "<declaration_specifier>\n");
426 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
427 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
431 print_tabs(fd
, depth
);
432 fprintf(fd
, "</declaration_specifier>\n");
434 print_tabs(fd
, depth
);
435 fprintf(fd
, "<type_declarators>\n");
436 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
437 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
441 print_tabs(fd
, depth
);
442 fprintf(fd
, "</type_declarators>\n");
445 print_tabs(fd
, depth
);
446 fprintf(fd
, "</alias>\n");
449 print_tabs(fd
, depth
);
450 fprintf(fd
, "<typealias>\n");
451 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
454 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
457 print_tabs(fd
, depth
);
458 fprintf(fd
, "</typealias>\n");
461 case NODE_TYPE_SPECIFIER
:
462 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
467 print_tabs(fd
, depth
);
468 if (node
->u
.pointer
.const_qualifier
)
469 fprintf(fd
, "<const_pointer />\n");
471 fprintf(fd
, "<pointer />\n");
473 case NODE_TYPE_DECLARATOR
:
474 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
479 case NODE_FLOATING_POINT
:
480 print_tabs(fd
, depth
);
481 fprintf(fd
, "<floating_point>\n");
482 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
483 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
487 print_tabs(fd
, depth
);
488 fprintf(fd
, "</floating_point>\n");
491 print_tabs(fd
, depth
);
492 fprintf(fd
, "<integer>\n");
493 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
494 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
498 print_tabs(fd
, depth
);
499 fprintf(fd
, "</integer>\n");
502 print_tabs(fd
, depth
);
503 fprintf(fd
, "<string>\n");
504 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
505 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
509 print_tabs(fd
, depth
);
510 fprintf(fd
, "</string>\n");
512 case NODE_ENUMERATOR
:
513 print_tabs(fd
, depth
);
514 fprintf(fd
, "<enumerator");
515 if (node
->u
.enumerator
.id
)
516 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
518 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
519 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
523 print_tabs(fd
, depth
);
524 fprintf(fd
, "</enumerator>\n");
527 print_tabs(fd
, depth
);
528 if (node
->u
._struct
.name
)
529 fprintf(fd
, "<enum name=\"%s\">\n",
530 node
->u
._enum
.enum_id
);
532 fprintf(fd
, "<enum >\n");
535 if (node
->u
._enum
.container_type
) {
536 print_tabs(fd
, depth
);
537 fprintf(fd
, "<container_type>\n");
538 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
541 print_tabs(fd
, depth
);
542 fprintf(fd
, "</container_type>\n");
545 print_tabs(fd
, depth
);
546 fprintf(fd
, "<enumerator_list>\n");
547 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
548 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
552 print_tabs(fd
, depth
);
553 fprintf(fd
, "</enumerator_list>\n");
556 print_tabs(fd
, depth
);
557 fprintf(fd
, "</enum>\n");
559 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
560 print_tabs(fd
, depth
);
561 fprintf(fd
, "<declaration_specifier>\n");
562 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
563 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
567 print_tabs(fd
, depth
);
568 fprintf(fd
, "</declaration_specifier>\n");
570 print_tabs(fd
, depth
);
571 fprintf(fd
, "<type_declarators>\n");
572 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
573 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
577 print_tabs(fd
, depth
);
578 fprintf(fd
, "</type_declarators>\n");
581 print_tabs(fd
, depth
);
582 fprintf(fd
, "<variant");
583 if (node
->u
.variant
.name
)
584 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
585 if (node
->u
.variant
.choice
)
586 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
588 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
589 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
593 print_tabs(fd
, depth
);
594 fprintf(fd
, "</variant>\n");
597 print_tabs(fd
, depth
);
598 if (node
->u
._struct
.name
)
599 fprintf(fd
, "<struct name=\"%s\">\n",
600 node
->u
._struct
.name
);
602 fprintf(fd
, "<struct>\n");
603 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
604 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
608 print_tabs(fd
, depth
);
609 fprintf(fd
, "</struct>\n");
614 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,