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
.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 print_tabs(fd
, depth
);
196 fprintf(fd
, "<id \"");
197 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
198 fprintf(fd
, "\" />\n");
201 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
202 print_tabs(fd
, depth
);
203 fprintf(fd
, "<type_declarator>\n");
204 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
205 node
->u
.type_declarator
.u
.nested
.type_declarator
);
208 print_tabs(fd
, depth
);
209 fprintf(fd
, "</type_declarator>\n");
211 if (node
->u
.type_declarator
.u
.nested
.length
) {
212 print_tabs(fd
, depth
);
213 fprintf(fd
, "<length>\n");
214 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
215 node
->u
.type_declarator
.u
.nested
.length
);
218 print_tabs(fd
, depth
);
219 fprintf(fd
, "</length>\n");
221 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
222 print_tabs(fd
, depth
);
223 fprintf(fd
, "<length>\n");
224 print_tabs(fd
, depth
);
225 fprintf(fd
, "</length>\n");
227 if (node
->u
.type_declarator
.bitfield_len
) {
228 print_tabs(fd
, depth
);
229 fprintf(fd
, "<bitfield_len>\n");
230 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
231 node
->u
.type_declarator
.bitfield_len
);
234 print_tabs(fd
, depth
);
235 fprintf(fd
, "</bitfield_len>\n");
238 case TYPEDEC_UNKNOWN
:
240 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
241 (int) node
->u
.type_declarator
.type
);
246 print_tabs(fd
, depth
);
247 fprintf(fd
, "</type_declarator>\n");
251 int ctf_visitor_print_xml(FILE *fd
, int depth
, struct ctf_node
*node
)
254 struct ctf_node
*iter
;
256 switch (node
->type
) {
258 print_tabs(fd
, depth
);
259 fprintf(fd
, "<root>\n");
260 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
262 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
266 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
268 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
272 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
273 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
277 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
278 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
282 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
283 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
287 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
288 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
292 print_tabs(fd
, depth
);
293 fprintf(fd
, "</root>\n");
297 print_tabs(fd
, depth
);
298 fprintf(fd
, "<event>\n");
299 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
300 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
304 print_tabs(fd
, depth
);
305 fprintf(fd
, "</event>\n");
308 print_tabs(fd
, depth
);
309 fprintf(fd
, "<stream>\n");
310 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
311 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
315 print_tabs(fd
, depth
);
316 fprintf(fd
, "</stream>\n");
319 print_tabs(fd
, depth
);
320 fprintf(fd
, "<trace>\n");
321 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
322 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
326 print_tabs(fd
, depth
);
327 fprintf(fd
, "</trace>\n");
330 case NODE_CTF_EXPRESSION
:
331 print_tabs(fd
, depth
);
332 fprintf(fd
, "<ctf_expression>\n");
334 print_tabs(fd
, depth
);
335 fprintf(fd
, "<left>\n");
336 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
337 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
342 print_tabs(fd
, depth
);
343 fprintf(fd
, "</left>\n");
345 print_tabs(fd
, depth
);
346 fprintf(fd
, "<right>\n");
347 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
348 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
352 print_tabs(fd
, depth
);
353 fprintf(fd
, "</right>\n");
355 print_tabs(fd
, depth
);
356 fprintf(fd
, "</ctf_expression>\n");
358 case NODE_UNARY_EXPRESSION
:
359 return ctf_visitor_print_unary_expression(fd
, depth
, node
);
362 print_tabs(fd
, depth
);
363 fprintf(fd
, "<typedef>\n");
365 print_tabs(fd
, depth
);
366 fprintf(fd
, "<declaration_specifier>\n");
367 cds_list_for_each_entry(iter
, &node
->u
._typedef
.declaration_specifier
, siblings
) {
368 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
372 print_tabs(fd
, depth
);
373 fprintf(fd
, "</declaration_specifier>\n");
375 print_tabs(fd
, depth
);
376 fprintf(fd
, "<type_declarators>\n");
377 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
378 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
382 print_tabs(fd
, depth
);
383 fprintf(fd
, "</type_declarators>\n");
385 print_tabs(fd
, depth
);
386 fprintf(fd
, "</typedef>\n");
388 case NODE_TYPEALIAS_TARGET
:
389 print_tabs(fd
, depth
);
390 fprintf(fd
, "<target>\n");
393 print_tabs(fd
, depth
);
394 fprintf(fd
, "<declaration_specifier>\n");
395 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
396 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
400 print_tabs(fd
, depth
);
401 fprintf(fd
, "</declaration_specifier>\n");
403 print_tabs(fd
, depth
);
404 fprintf(fd
, "<type_declarators>\n");
405 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
406 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
410 print_tabs(fd
, depth
);
411 fprintf(fd
, "</type_declarators>\n");
414 print_tabs(fd
, depth
);
415 fprintf(fd
, "</target>\n");
417 case NODE_TYPEALIAS_ALIAS
:
418 print_tabs(fd
, depth
);
419 fprintf(fd
, "<alias>\n");
422 print_tabs(fd
, depth
);
423 fprintf(fd
, "<declaration_specifier>\n");
424 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
425 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
429 print_tabs(fd
, depth
);
430 fprintf(fd
, "</declaration_specifier>\n");
432 print_tabs(fd
, depth
);
433 fprintf(fd
, "<type_declarators>\n");
434 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
435 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
439 print_tabs(fd
, depth
);
440 fprintf(fd
, "</type_declarators>\n");
443 print_tabs(fd
, depth
);
444 fprintf(fd
, "</alias>\n");
447 print_tabs(fd
, depth
);
448 fprintf(fd
, "<typealias>\n");
449 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
452 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
455 print_tabs(fd
, depth
);
456 fprintf(fd
, "</typealias>\n");
459 case NODE_TYPE_SPECIFIER
:
460 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
465 print_tabs(fd
, depth
);
466 if (node
->u
.pointer
.const_qualifier
)
467 fprintf(fd
, "<const_pointer />\n");
469 fprintf(fd
, "<pointer />\n");
471 case NODE_TYPE_DECLARATOR
:
472 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
477 case NODE_FLOATING_POINT
:
478 print_tabs(fd
, depth
);
479 fprintf(fd
, "<floating_point>\n");
480 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
481 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
485 print_tabs(fd
, depth
);
486 fprintf(fd
, "</floating_point>\n");
489 print_tabs(fd
, depth
);
490 fprintf(fd
, "<integer>\n");
491 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
492 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
496 print_tabs(fd
, depth
);
497 fprintf(fd
, "</integer>\n");
500 print_tabs(fd
, depth
);
501 fprintf(fd
, "<string>\n");
502 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
503 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
507 print_tabs(fd
, depth
);
508 fprintf(fd
, "</string>\n");
510 case NODE_ENUMERATOR
:
511 print_tabs(fd
, depth
);
512 fprintf(fd
, "<enumerator");
513 if (node
->u
.enumerator
.id
)
514 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
516 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
517 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
521 print_tabs(fd
, depth
);
522 fprintf(fd
, "</enumerator>\n");
525 print_tabs(fd
, depth
);
526 if (node
->u
._struct
.name
)
527 fprintf(fd
, "<enum name=\"%s\">\n",
528 node
->u
._enum
.enum_id
);
530 fprintf(fd
, "<enum >\n");
533 if (node
->u
._enum
.container_type
) {
534 print_tabs(fd
, depth
);
535 fprintf(fd
, "<container_type>\n");
536 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
539 print_tabs(fd
, depth
);
540 fprintf(fd
, "</container_type>\n");
543 print_tabs(fd
, depth
);
544 fprintf(fd
, "<enumerator_list>\n");
545 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
546 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
550 print_tabs(fd
, depth
);
551 fprintf(fd
, "</enumerator_list>\n");
554 print_tabs(fd
, depth
);
555 fprintf(fd
, "</enum>\n");
557 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
558 print_tabs(fd
, depth
);
559 fprintf(fd
, "<declaration_specifier>\n");
560 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
561 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
565 print_tabs(fd
, depth
);
566 fprintf(fd
, "</declaration_specifier>\n");
568 print_tabs(fd
, depth
);
569 fprintf(fd
, "<type_declarators>\n");
570 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
571 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
575 print_tabs(fd
, depth
);
576 fprintf(fd
, "</type_declarators>\n");
579 print_tabs(fd
, depth
);
580 fprintf(fd
, "<variant");
581 if (node
->u
.variant
.name
)
582 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
583 if (node
->u
.variant
.choice
)
584 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
586 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
587 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
591 print_tabs(fd
, depth
);
592 fprintf(fd
, "</variant>\n");
595 print_tabs(fd
, depth
);
596 if (node
->u
._struct
.name
)
597 fprintf(fd
, "<struct name=\"%s\">\n",
598 node
->u
._struct
.name
);
600 fprintf(fd
, "<struct>\n");
601 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
602 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
606 print_tabs(fd
, depth
);
607 fprintf(fd
, "</struct>\n");
612 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,