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.
24 #include <helpers/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
.type
) {
47 print_tabs(fd
, depth
);
48 fprintf(fd
, "<unary_expression value=");
49 fprintf(fd
, "\"%s\"", node
->u
.unary_expression
.u
.string
);
52 case UNARY_SIGNED_CONSTANT
:
53 print_tabs(fd
, depth
);
54 fprintf(fd
, "<unary_expression value=");
55 fprintf(fd
, "%lld", node
->u
.unary_expression
.u
.signed_constant
);
58 case UNARY_UNSIGNED_CONSTANT
:
59 print_tabs(fd
, depth
);
60 fprintf(fd
, "<unary_expression value=");
61 fprintf(fd
, "%llu", node
->u
.unary_expression
.u
.signed_constant
);
65 print_tabs(fd
, depth
);
66 fprintf(fd
, "<unary_expression_sbrac>");
67 ret
= ctf_visitor_print_unary_expression(fd
, depth
+ 1,
68 node
->u
.unary_expression
.u
.sbrac_exp
);
71 print_tabs(fd
, depth
);
72 fprintf(fd
, "</unary_expression_sbrac>");
77 fprintf(stderr
, "[error] %s: unknown expression type %d\n", __func__
,
78 (int) node
->u
.unary_expression
.type
);
81 switch (node
->u
.unary_expression
.link
) {
82 case UNARY_LINK_UNKNOWN
:
85 print_tabs(fd
, depth
);
86 fprintf(fd
, "<dotlink/>\n");
89 print_tabs(fd
, depth
);
90 fprintf(fd
, "<arrowlink/>\n");
93 fprintf(stderr
, "[error] %s: unknown expression link type %d\n", __func__
,
94 (int) node
->u
.unary_expression
.link
);
100 int ctf_visitor_print_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
102 print_tabs(fd
, depth
);
103 fprintf(fd
, "<type_specifier =\"");
105 switch (node
->u
.type_specifier
.type
) {
113 fprintf(fd
, "short");
122 fprintf(fd
, "float");
124 case TYPESPEC_DOUBLE
:
125 fprintf(fd
, "double");
127 case TYPESPEC_SIGNED
:
128 fprintf(fd
, "signed");
130 case TYPESPEC_UNSIGNED
:
131 fprintf(fd
, "unsigned");
136 case TYPESPEC_COMPLEX
:
137 fprintf(fd
, "complex");
140 fprintf(fd
, "const");
142 case TYPESPEC_ID_TYPE
:
143 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
146 case TYPESPEC_UNKNOWN
:
148 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
149 (int) node
->u
.type_specifier
.type
);
152 fprintf(fd
, "\"/>\n");
156 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
159 struct ctf_node
*iter
;
161 print_tabs(fd
, depth
);
162 fprintf(fd
, "<type_declarator>\n");
165 print_tabs(fd
, depth
);
166 fprintf(fd
, "<pointers>\n");
167 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
169 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
173 print_tabs(fd
, depth
);
174 fprintf(fd
, "</pointers>\n");
176 switch (node
->u
.type_declarator
.type
) {
178 print_tabs(fd
, depth
);
179 fprintf(fd
, "<id \"");
180 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
181 fprintf(fd
, "<\" />\n");
184 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
185 print_tabs(fd
, depth
);
186 fprintf(fd
, "<type_declarator>\n");
187 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
188 node
->u
.type_declarator
.u
.nested
.type_declarator
);
191 print_tabs(fd
, depth
);
192 fprintf(fd
, "</type_declarator>\n");
194 if (node
->u
.type_declarator
.u
.nested
.length
) {
195 print_tabs(fd
, depth
);
196 fprintf(fd
, "<length>\n");
197 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
198 node
->u
.type_declarator
.u
.nested
.length
);
201 print_tabs(fd
, depth
);
202 fprintf(fd
, "</length>\n");
204 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
205 print_tabs(fd
, depth
);
206 fprintf(fd
, "<length>\n");
207 print_tabs(fd
, depth
);
208 fprintf(fd
, "</length>\n");
210 if (node
->u
.type_declarator
.bitfield_len
) {
211 print_tabs(fd
, depth
);
212 fprintf(fd
, "<bitfield_len>\n");
213 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
214 node
->u
.type_declarator
.bitfield_len
);
217 print_tabs(fd
, depth
);
218 fprintf(fd
, "</bitfield_len>\n");
221 case TYPEDEC_UNKNOWN
:
223 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
224 (int) node
->u
.type_declarator
.type
);
229 print_tabs(fd
, depth
);
230 fprintf(fd
, "</type_declarator>\n");
234 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
237 struct ctf_node
*iter
;
239 switch (node
->type
) {
241 print_tabs(fd
, depth
);
242 fprintf(fd
, "<root>\n");
243 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
245 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
249 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
251 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
255 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
256 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
260 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
261 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
265 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
266 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
270 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
271 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
275 print_tabs(fd
, depth
);
276 fprintf(fd
, "</root>\n");
280 print_tabs(fd
, depth
);
281 fprintf(fd
, "<event>\n");
282 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
283 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
287 print_tabs(fd
, depth
);
288 fprintf(fd
, "</event>\n");
291 print_tabs(fd
, depth
);
292 fprintf(fd
, "<stream>\n");
293 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
294 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
298 print_tabs(fd
, depth
);
299 fprintf(fd
, "</stream>\n");
302 print_tabs(fd
, depth
);
303 fprintf(fd
, "<trace>\n");
304 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
305 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
309 print_tabs(fd
, depth
);
310 fprintf(fd
, "</trace>\n");
313 case NODE_CTF_EXPRESSION
:
314 print_tabs(fd
, depth
);
315 fprintf(fd
, "<ctf_expression>\n");
317 print_tabs(fd
, depth
);
318 fprintf(fd
, "<left>\n");
319 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.ctf_expression
.left
);
322 print_tabs(fd
, depth
);
323 fprintf(fd
, "</left>\n");
325 print_tabs(fd
, depth
);
326 fprintf(fd
, "<right>\n");
327 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.ctf_expression
.right
);
330 print_tabs(fd
, depth
);
331 fprintf(fd
, "</right>\n");
333 print_tabs(fd
, depth
);
334 fprintf(fd
, "</ctf_expression>\n");
336 case NODE_UNARY_EXPRESSION
:
337 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
340 print_tabs(fd
, depth
);
341 fprintf(fd
, "<typedef>\n");
343 print_tabs(fd
, depth
);
344 fprintf(fd
, "<declaration_specifier>\n");
345 cds_list_for_each_entry(iter
, &node
->u
._typedef
.declaration_specifier
, siblings
) {
346 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
350 print_tabs(fd
, depth
);
351 fprintf(fd
, "</declaration_specifier>\n");
353 print_tabs(fd
, depth
);
354 fprintf(fd
, "<type_declarators>\n");
355 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
356 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
360 print_tabs(fd
, depth
);
361 fprintf(fd
, "</type_declarators>\n");
363 print_tabs(fd
, depth
);
364 fprintf(fd
, "</typedef>\n");
366 case NODE_TYPEALIAS_TARGET
:
367 print_tabs(fd
, depth
);
368 fprintf(fd
, "<target>\n");
371 print_tabs(fd
, depth
);
372 fprintf(fd
, "<declaration_specifier>\n");
373 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
374 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
378 print_tabs(fd
, depth
);
379 fprintf(fd
, "</declaration_specifier>\n");
381 print_tabs(fd
, depth
);
382 fprintf(fd
, "<type_declarators>\n");
383 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
384 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
388 print_tabs(fd
, depth
);
389 fprintf(fd
, "</type_declarators>\n");
392 print_tabs(fd
, depth
);
393 fprintf(fd
, "</target>\n");
395 case NODE_TYPEALIAS_ALIAS
:
396 print_tabs(fd
, depth
);
397 fprintf(fd
, "<alias>\n");
400 print_tabs(fd
, depth
);
401 fprintf(fd
, "<declaration_specifier>\n");
402 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.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_alias
.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
, "</alias>\n");
425 print_tabs(fd
, depth
);
426 fprintf(fd
, "<typealias>\n");
427 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
430 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
433 print_tabs(fd
, depth
);
434 fprintf(fd
, "</typealias>\n");
437 case NODE_TYPE_SPECIFIER
:
438 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
443 print_tabs(fd
, depth
);
444 if (node
->u
.pointer
.const_qualifier
)
445 fprintf(fd
, "<const_pointer />\n");
447 fprintf(fd
, "<pointer />\n");
449 case NODE_TYPE_DECLARATOR
:
450 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
455 case NODE_FLOATING_POINT
:
456 print_tabs(fd
, depth
);
457 fprintf(fd
, "<floating_point>\n");
458 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
459 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
463 print_tabs(fd
, depth
);
464 fprintf(fd
, "</floating_point>\n");
467 print_tabs(fd
, depth
);
468 fprintf(fd
, "<integer>\n");
469 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
470 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
474 print_tabs(fd
, depth
);
475 fprintf(fd
, "</integer>\n");
478 print_tabs(fd
, depth
);
479 fprintf(fd
, "<string>\n");
480 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
481 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
485 print_tabs(fd
, depth
);
486 fprintf(fd
, "</string>\n");
488 case NODE_ENUMERATOR
:
489 print_tabs(fd
, depth
);
490 fprintf(fd
, "<enumerator");
491 if (node
->u
.enumerator
.id
)
492 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
494 if (node
->u
.enumerator
.values
) {
495 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
496 node
->u
.enumerator
.values
);
500 print_tabs(fd
, depth
);
501 fprintf(fd
, "</enumerator>");
504 print_tabs(fd
, depth
);
505 if (node
->u
._struct
.name
)
506 fprintf(fd
, "<enum name=\"%s\">\n",
507 node
->u
._enum
.enum_id
);
509 fprintf(fd
, "<enum >\n");
512 if (node
->u
._enum
.container_type
) {
513 print_tabs(fd
, depth
);
514 fprintf(fd
, "<container_type>");
515 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
518 print_tabs(fd
, depth
);
519 fprintf(fd
, "</container_type>");
522 print_tabs(fd
, depth
);
523 fprintf(fd
, "<enumerator_list>");
524 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
525 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
529 print_tabs(fd
, depth
);
530 fprintf(fd
, "</enumerator_list>");
533 print_tabs(fd
, depth
);
534 fprintf(fd
, "</enum>\n");
536 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
537 print_tabs(fd
, depth
);
538 fprintf(fd
, "<declaration_specifier>\n");
539 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
540 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
544 print_tabs(fd
, depth
);
545 fprintf(fd
, "</declaration_specifier>\n");
547 print_tabs(fd
, depth
);
548 fprintf(fd
, "<type_declarators>\n");
549 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
550 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
554 print_tabs(fd
, depth
);
555 fprintf(fd
, "</type_declarators>\n");
558 print_tabs(fd
, depth
);
559 fprintf(fd
, "<variant");
560 if (node
->u
.variant
.name
)
561 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
562 if (node
->u
.variant
.choice
)
563 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
565 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
566 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
570 print_tabs(fd
, depth
);
571 fprintf(fd
, "</variant>\n");
574 print_tabs(fd
, depth
);
575 if (node
->u
._struct
.name
)
576 fprintf(fd
, "<struct name=\"%s\">\n",
577 node
->u
._struct
.name
);
579 fprintf(fd
, "<struct>\n");
580 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
581 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
585 print_tabs(fd
, depth
);
586 fprintf(fd
, "</struct>\n");
591 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,