3 Copyright (C) 2012-2018 Free Software Foundation, Inc.
4 Contributed by Hui Zhu <hui_zhu@mentor.com>
5 Contributed by Yao Qi <yao@codesourcery.com>
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "tracepoint.h"
28 #include "completer.h"
30 #include "gdbthread.h"
31 #include "tracefile.h"
37 static const target_info ctf_target_info = {
40 N_("(Use a CTF directory as a target.\n\
41 Specify the filename of the CTF directory.")
44 class ctf_target final : public tracefile_target
47 const target_info &info () const override
48 { return ctf_target_info; }
50 void close () override;
51 void fetch_registers (struct regcache *, int) override;
52 enum target_xfer_status xfer_partial (enum target_object object,
55 const gdb_byte *writebuf,
56 ULONGEST offset, ULONGEST len,
57 ULONGEST *xfered_len) override;
58 void files_info () override;
59 int trace_find (enum trace_find_type type, int num,
60 CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override;
61 bool get_trace_state_variable_value (int tsv, LONGEST *val) override;
62 traceframe_info_up traceframe_info () override;
65 /* GDB saves trace buffers and other information (such as trace
66 status) got from the remote target into Common Trace Format (CTF).
67 The following types of information are expected to save in CTF:
69 1. The length (in bytes) of register cache. Event "register" will
70 be defined in metadata, which includes the length.
72 2. Trace status. Event "status" is defined in metadata, which
73 includes all aspects of trace status.
75 3. Uploaded trace variables. Event "tsv_def" is defined in
76 metadata, which is about all aspects of a uploaded trace variable.
77 Uploaded tracepoints. Event "tp_def" is defined in meta, which
78 is about all aspects of an uploaded tracepoint. Note that the
79 "sequence" (a CTF type, which is a dynamically-sized array.) is
80 used for "actions" "step_actions" and "cmd_strings".
82 4. Trace frames. Each trace frame is composed by several blocks
83 of different types ('R', 'M', 'V'). One trace frame is saved in
84 one CTF packet and the blocks of this frame are saved as events.
85 4.1: The trace frame related information (such as the number of
86 tracepoint associated with this frame) is saved in the packet
88 4.2: The block 'M', 'R' and 'V' are saved in event "memory",
89 "register" and "tsv" respectively.
90 4.3: When iterating over events, babeltrace can't tell iterator
91 goes to a new packet, so we need a marker or anchor to tell GDB
92 that iterator goes into a new packet or frame. We define event
95 #define CTF_MAGIC 0xC1FC1FC1
96 #define CTF_SAVE_MAJOR 1
97 #define CTF_SAVE_MINOR 8
99 #define CTF_METADATA_NAME "metadata"
100 #define CTF_DATASTREAM_NAME "datastream"
102 /* Reserved event id. */
104 #define CTF_EVENT_ID_REGISTER 0
105 #define CTF_EVENT_ID_TSV 1
106 #define CTF_EVENT_ID_MEMORY 2
107 #define CTF_EVENT_ID_FRAME 3
108 #define CTF_EVENT_ID_STATUS 4
109 #define CTF_EVENT_ID_TSV_DEF 5
110 #define CTF_EVENT_ID_TP_DEF 6
114 /* The state kept while writing the CTF datastream file. */
116 struct trace_write_handler
118 /* File descriptor of metadata. */
120 /* File descriptor of traceframes. */
123 /* This is the content size of the current packet. */
126 /* This is the start offset of current packet. */
130 /* Write metadata in FORMAT. */
133 ctf_save_write_metadata (struct trace_write_handler *handler,
134 const char *format, ...)
135 ATTRIBUTE_PRINTF (2, 3);
138 ctf_save_write_metadata (struct trace_write_handler *handler,
139 const char *format, ...)
143 va_start (args, format);
144 if (vfprintf (handler->metadata_fd, format, args) < 0)
145 error (_("Unable to write metadata file (%s)"),
146 safe_strerror (errno));
150 /* Write BUF of length SIZE to datastream file represented by
154 ctf_save_write (struct trace_write_handler *handler,
155 const gdb_byte *buf, size_t size)
157 if (fwrite (buf, size, 1, handler->datastream_fd) != 1)
158 error (_("Unable to write file for saving trace data (%s)"),
159 safe_strerror (errno));
161 handler->content_size += size;
166 /* Write a unsigned 32-bit integer to datastream file represented by
169 #define ctf_save_write_uint32(HANDLER, U32) \
170 ctf_save_write (HANDLER, (gdb_byte *) &U32, 4)
172 /* Write a signed 32-bit integer to datastream file represented by
175 #define ctf_save_write_int32(HANDLER, INT32) \
176 ctf_save_write ((HANDLER), (gdb_byte *) &(INT32), 4)
178 /* Set datastream file position. Update HANDLER->content_size
179 if WHENCE is SEEK_CUR. */
182 ctf_save_fseek (struct trace_write_handler *handler, long offset,
185 gdb_assert (whence != SEEK_END);
186 gdb_assert (whence != SEEK_SET
187 || offset <= handler->content_size + handler->packet_start);
189 if (fseek (handler->datastream_fd, offset, whence))
190 error (_("Unable to seek file for saving trace data (%s)"),
191 safe_strerror (errno));
193 if (whence == SEEK_CUR)
194 handler->content_size += offset;
199 /* Change the datastream file position to align on ALIGN_SIZE,
200 and write BUF to datastream file. The size of BUF is SIZE. */
203 ctf_save_align_write (struct trace_write_handler *handler,
205 size_t size, size_t align_size)
208 = (align_up (handler->content_size, align_size)
209 - handler->content_size);
211 if (ctf_save_fseek (handler, offset, SEEK_CUR))
214 if (ctf_save_write (handler, buf, size))
220 /* Write events to next new packet. */
223 ctf_save_next_packet (struct trace_write_handler *handler)
225 handler->packet_start += (handler->content_size + 4);
226 ctf_save_fseek (handler, handler->packet_start, SEEK_SET);
227 handler->content_size = 0;
230 /* Write the CTF metadata header. */
233 ctf_save_metadata_header (struct trace_write_handler *handler)
235 ctf_save_write_metadata (handler, "/* CTF %d.%d */\n",
236 CTF_SAVE_MAJOR, CTF_SAVE_MINOR);
237 ctf_save_write_metadata (handler,
238 "typealias integer { size = 8; align = 8; "
239 "signed = false; encoding = ascii;}"
241 ctf_save_write_metadata (handler,
242 "typealias integer { size = 8; align = 8; "
245 ctf_save_write_metadata (handler,
246 "typealias integer { size = 16; align = 16;"
247 "signed = false; } := uint16_t;\n");
248 ctf_save_write_metadata (handler,
249 "typealias integer { size = 32; align = 32;"
250 "signed = false; } := uint32_t;\n");
251 ctf_save_write_metadata (handler,
252 "typealias integer { size = 64; align = 64;"
253 "signed = false; base = hex;}"
255 ctf_save_write_metadata (handler,
256 "typealias integer { size = 32; align = 32;"
257 "signed = true; } := int32_t;\n");
258 ctf_save_write_metadata (handler,
259 "typealias integer { size = 64; align = 64;"
260 "signed = true; } := int64_t;\n");
261 ctf_save_write_metadata (handler,
262 "typealias string { encoding = ascii;"
264 ctf_save_write_metadata (handler, "\n");
266 /* Get the byte order of the host and write CTF data in this byte
269 #define HOST_ENDIANNESS "be"
271 #define HOST_ENDIANNESS "le"
274 ctf_save_write_metadata (handler,
278 " byte_order = %s;\n"
279 " packet.header := struct {\n"
285 " packet.context := struct {\n"
286 " uint32_t content_size;\n"
287 " uint32_t packet_size;\n"
290 " event.header := struct {\n"
294 CTF_SAVE_MAJOR, CTF_SAVE_MINOR,
296 ctf_save_write_metadata (handler, "\n");
299 /* CTF trace writer. */
301 struct ctf_trace_file_writer
303 struct trace_file_writer base;
305 /* States related to writing CTF trace file. */
306 struct trace_write_handler tcs;
309 /* This is the implementation of trace_file_write_ops method
313 ctf_dtor (struct trace_file_writer *self)
315 struct ctf_trace_file_writer *writer
316 = (struct ctf_trace_file_writer *) self;
318 if (writer->tcs.metadata_fd != NULL)
319 fclose (writer->tcs.metadata_fd);
321 if (writer->tcs.datastream_fd != NULL)
322 fclose (writer->tcs.datastream_fd);
326 /* This is the implementation of trace_file_write_ops method
330 ctf_target_save (struct trace_file_writer *self,
333 /* Don't support save trace file to CTF format in the target. */
337 /* This is the implementation of trace_file_write_ops method
338 start. It creates the directory DIRNAME, metadata and datastream
342 ctf_start (struct trace_file_writer *self, const char *dirname)
344 struct ctf_trace_file_writer *writer
345 = (struct ctf_trace_file_writer *) self;
346 mode_t hmode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH;
348 /* Create DIRNAME. */
349 if (mkdir (dirname, hmode) && errno != EEXIST)
350 error (_("Unable to open directory '%s' for saving trace data (%s)"),
351 dirname, safe_strerror (errno));
353 memset (&writer->tcs, '\0', sizeof (writer->tcs));
355 std::string file_name = string_printf ("%s/%s", dirname, CTF_METADATA_NAME);
357 writer->tcs.metadata_fd = fopen (file_name.c_str (), "w");
358 if (writer->tcs.metadata_fd == NULL)
359 error (_("Unable to open file '%s' for saving trace data (%s)"),
360 file_name.c_str (), safe_strerror (errno));
362 ctf_save_metadata_header (&writer->tcs);
364 file_name = string_printf ("%s/%s", dirname, CTF_DATASTREAM_NAME);
365 writer->tcs.datastream_fd = fopen (file_name.c_str (), "w");
366 if (writer->tcs.datastream_fd == NULL)
367 error (_("Unable to open file '%s' for saving trace data (%s)"),
368 file_name.c_str (), safe_strerror (errno));
371 /* This is the implementation of trace_file_write_ops method
372 write_header. Write the types of events on trace variable and
376 ctf_write_header (struct trace_file_writer *self)
378 struct ctf_trace_file_writer *writer
379 = (struct ctf_trace_file_writer *) self;
382 ctf_save_write_metadata (&writer->tcs, "\n");
383 ctf_save_write_metadata (&writer->tcs,
384 "event {\n\tname = \"memory\";\n\tid = %u;\n"
385 "\tfields := struct { \n"
386 "\t\tuint64_t address;\n"
387 "\t\tuint16_t length;\n"
388 "\t\tuint8_t contents[length];\n"
390 "};\n", CTF_EVENT_ID_MEMORY);
392 ctf_save_write_metadata (&writer->tcs, "\n");
393 ctf_save_write_metadata (&writer->tcs,
394 "event {\n\tname = \"tsv\";\n\tid = %u;\n"
395 "\tfields := struct { \n"
396 "\t\tuint64_t val;\n"
397 "\t\tuint32_t num;\n"
399 "};\n", CTF_EVENT_ID_TSV);
401 ctf_save_write_metadata (&writer->tcs, "\n");
402 ctf_save_write_metadata (&writer->tcs,
403 "event {\n\tname = \"frame\";\n\tid = %u;\n"
404 "\tfields := struct { \n"
406 "};\n", CTF_EVENT_ID_FRAME);
408 ctf_save_write_metadata (&writer->tcs, "\n");
409 ctf_save_write_metadata (&writer->tcs,
410 "event {\n\tname = \"tsv_def\";\n"
411 "\tid = %u;\n\tfields := struct { \n"
412 "\t\tint64_t initial_value;\n"
413 "\t\tint32_t number;\n"
414 "\t\tint32_t builtin;\n"
417 "};\n", CTF_EVENT_ID_TSV_DEF);
419 ctf_save_write_metadata (&writer->tcs, "\n");
420 ctf_save_write_metadata (&writer->tcs,
421 "event {\n\tname = \"tp_def\";\n"
422 "\tid = %u;\n\tfields := struct { \n"
423 "\t\tuint64_t addr;\n"
424 "\t\tuint64_t traceframe_usage;\n"
425 "\t\tint32_t number;\n"
426 "\t\tint32_t enabled;\n"
427 "\t\tint32_t step;\n"
428 "\t\tint32_t pass;\n"
429 "\t\tint32_t hit_count;\n"
430 "\t\tint32_t type;\n"
433 "\t\tuint32_t action_num;\n"
434 "\t\tchars actions[action_num];\n"
436 "\t\tuint32_t step_action_num;\n"
437 "\t\tchars step_actions[step_action_num];\n"
439 "\t\tchars at_string;\n"
440 "\t\tchars cond_string;\n"
442 "\t\tuint32_t cmd_num;\n"
443 "\t\tchars cmd_strings[cmd_num];\n"
445 "};\n", CTF_EVENT_ID_TP_DEF);
447 gdb_assert (writer->tcs.content_size == 0);
448 gdb_assert (writer->tcs.packet_start == 0);
450 /* Create a new packet to contain this event. */
451 self->ops->frame_ops->start (self, 0);
454 /* This is the implementation of trace_file_write_ops method
455 write_regblock_type. Write the type of register event in
459 ctf_write_regblock_type (struct trace_file_writer *self, int size)
461 struct ctf_trace_file_writer *writer
462 = (struct ctf_trace_file_writer *) self;
464 ctf_save_write_metadata (&writer->tcs, "\n");
466 ctf_save_write_metadata (&writer->tcs,
467 "event {\n\tname = \"register\";\n\tid = %u;\n"
468 "\tfields := struct { \n"
469 "\t\tascii contents[%d];\n"
472 CTF_EVENT_ID_REGISTER, size);
475 /* This is the implementation of trace_file_write_ops method
479 ctf_write_status (struct trace_file_writer *self,
480 struct trace_status *ts)
482 struct ctf_trace_file_writer *writer
483 = (struct ctf_trace_file_writer *) self;
486 ctf_save_write_metadata (&writer->tcs, "\n");
487 ctf_save_write_metadata (&writer->tcs,
488 "event {\n\tname = \"status\";\n\tid = %u;\n"
489 "\tfields := struct { \n"
490 "\t\tint32_t stop_reason;\n"
491 "\t\tint32_t stopping_tracepoint;\n"
492 "\t\tint32_t traceframe_count;\n"
493 "\t\tint32_t traceframes_created;\n"
494 "\t\tint32_t buffer_free;\n"
495 "\t\tint32_t buffer_size;\n"
496 "\t\tint32_t disconnected_tracing;\n"
497 "\t\tint32_t circular_buffer;\n"
500 CTF_EVENT_ID_STATUS);
502 id = CTF_EVENT_ID_STATUS;
504 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
506 ctf_save_write_int32 (&writer->tcs, ts->stop_reason);
507 ctf_save_write_int32 (&writer->tcs, ts->stopping_tracepoint);
508 ctf_save_write_int32 (&writer->tcs, ts->traceframe_count);
509 ctf_save_write_int32 (&writer->tcs, ts->traceframes_created);
510 ctf_save_write_int32 (&writer->tcs, ts->buffer_free);
511 ctf_save_write_int32 (&writer->tcs, ts->buffer_size);
512 ctf_save_write_int32 (&writer->tcs, ts->disconnected_tracing);
513 ctf_save_write_int32 (&writer->tcs, ts->circular_buffer);
516 /* This is the implementation of trace_file_write_ops method
517 write_uploaded_tsv. */
520 ctf_write_uploaded_tsv (struct trace_file_writer *self,
521 struct uploaded_tsv *tsv)
523 struct ctf_trace_file_writer *writer
524 = (struct ctf_trace_file_writer *) self;
527 const gdb_byte zero = 0;
530 int32 = CTF_EVENT_ID_TSV_DEF;
531 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int32, 4, 4);
534 int64 = tsv->initial_value;
535 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int64, 8, 8);
538 ctf_save_write_int32 (&writer->tcs, tsv->number);
541 ctf_save_write_int32 (&writer->tcs, tsv->builtin);
544 if (tsv->name != NULL)
545 ctf_save_write (&writer->tcs, (gdb_byte *) tsv->name,
547 ctf_save_write (&writer->tcs, &zero, 1);
550 /* This is the implementation of trace_file_write_ops method
551 write_uploaded_tp. */
554 ctf_write_uploaded_tp (struct trace_file_writer *self,
555 struct uploaded_tp *tp)
557 struct ctf_trace_file_writer *writer
558 = (struct ctf_trace_file_writer *) self;
562 const gdb_byte zero = 0;
565 int32 = CTF_EVENT_ID_TP_DEF;
566 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int32, 4, 4);
570 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int64, 8, 8);
572 /* traceframe_usage */
573 int64 = tp->traceframe_usage;
574 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int64, 8, 8);
577 ctf_save_write_int32 (&writer->tcs, tp->number);
580 ctf_save_write_int32 (&writer->tcs, tp->enabled);
583 ctf_save_write_int32 (&writer->tcs, tp->step);
586 ctf_save_write_int32 (&writer->tcs, tp->pass);
589 ctf_save_write_int32 (&writer->tcs, tp->hit_count);
592 ctf_save_write_int32 (&writer->tcs, tp->type);
595 if (tp->cond != NULL)
596 ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond, strlen (tp->cond));
597 ctf_save_write (&writer->tcs, &zero, 1);
600 u32 = tp->actions.size ();
601 ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
602 for (char *act : tp->actions)
603 ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
606 u32 = tp->step_actions.size ();
607 ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
608 for (char *act : tp->step_actions)
609 ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
612 if (tp->at_string != NULL)
613 ctf_save_write (&writer->tcs, (gdb_byte *) tp->at_string,
614 strlen (tp->at_string));
615 ctf_save_write (&writer->tcs, &zero, 1);
618 if (tp->cond_string != NULL)
619 ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond_string,
620 strlen (tp->cond_string));
621 ctf_save_write (&writer->tcs, &zero, 1);
624 u32 = tp->cmd_strings.size ();
625 ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
626 for (char *act : tp->cmd_strings)
627 ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
631 /* This is the implementation of trace_file_write_ops method
635 ctf_write_tdesc (struct trace_file_writer *self)
637 /* Nothing so far. */
640 /* This is the implementation of trace_file_write_ops method
641 write_definition_end. */
644 ctf_write_definition_end (struct trace_file_writer *self)
646 self->ops->frame_ops->end (self);
649 /* This is the implementation of trace_file_write_ops method
653 ctf_end (struct trace_file_writer *self)
655 struct ctf_trace_file_writer *writer = (struct ctf_trace_file_writer *) self;
657 gdb_assert (writer->tcs.content_size == 0);
660 /* This is the implementation of trace_frame_write_ops method
664 ctf_write_frame_start (struct trace_file_writer *self, uint16_t tpnum)
666 struct ctf_trace_file_writer *writer
667 = (struct ctf_trace_file_writer *) self;
668 uint32_t id = CTF_EVENT_ID_FRAME;
671 /* Step 1: Write packet context. */
674 ctf_save_write_uint32 (&writer->tcs, u32);
675 /* content_size and packet_size.. We still don't know the value,
677 ctf_save_fseek (&writer->tcs, 4, SEEK_CUR);
678 ctf_save_fseek (&writer->tcs, 4, SEEK_CUR);
679 /* Tracepoint number. */
680 ctf_save_write (&writer->tcs, (gdb_byte *) &tpnum, 2);
682 /* Step 2: Write event "frame". */
684 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
687 /* This is the implementation of trace_frame_write_ops method
691 ctf_write_frame_r_block (struct trace_file_writer *self,
692 gdb_byte *buf, int32_t size)
694 struct ctf_trace_file_writer *writer
695 = (struct ctf_trace_file_writer *) self;
696 uint32_t id = CTF_EVENT_ID_REGISTER;
699 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
701 /* array contents. */
702 ctf_save_align_write (&writer->tcs, buf, size, 1);
705 /* This is the implementation of trace_frame_write_ops method
706 write_m_block_header. */
709 ctf_write_frame_m_block_header (struct trace_file_writer *self,
710 uint64_t addr, uint16_t length)
712 struct ctf_trace_file_writer *writer
713 = (struct ctf_trace_file_writer *) self;
714 uint32_t event_id = CTF_EVENT_ID_MEMORY;
717 ctf_save_align_write (&writer->tcs, (gdb_byte *) &event_id, 4, 4);
720 ctf_save_align_write (&writer->tcs, (gdb_byte *) &addr, 8, 8);
723 ctf_save_align_write (&writer->tcs, (gdb_byte *) &length, 2, 2);
726 /* This is the implementation of trace_frame_write_ops method
727 write_m_block_memory. */
730 ctf_write_frame_m_block_memory (struct trace_file_writer *self,
731 gdb_byte *buf, uint16_t length)
733 struct ctf_trace_file_writer *writer
734 = (struct ctf_trace_file_writer *) self;
737 ctf_save_align_write (&writer->tcs, (gdb_byte *) buf, length, 1);
740 /* This is the implementation of trace_frame_write_ops method
744 ctf_write_frame_v_block (struct trace_file_writer *self,
745 int32_t num, uint64_t val)
747 struct ctf_trace_file_writer *writer
748 = (struct ctf_trace_file_writer *) self;
749 uint32_t id = CTF_EVENT_ID_TSV;
752 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
755 ctf_save_align_write (&writer->tcs, (gdb_byte *) &val, 8, 8);
757 ctf_save_align_write (&writer->tcs, (gdb_byte *) &num, 4, 4);
760 /* This is the implementation of trace_frame_write_ops method
764 ctf_write_frame_end (struct trace_file_writer *self)
766 struct ctf_trace_file_writer *writer
767 = (struct ctf_trace_file_writer *) self;
771 /* Write the content size to packet header. */
772 ctf_save_fseek (&writer->tcs, writer->tcs.packet_start + 4,
774 u32 = writer->tcs.content_size * TARGET_CHAR_BIT;
776 t = writer->tcs.content_size;
777 ctf_save_write_uint32 (&writer->tcs, u32);
779 /* Write the packet size. */
780 u32 += 4 * TARGET_CHAR_BIT;
781 ctf_save_write_uint32 (&writer->tcs, u32);
783 writer->tcs.content_size = t;
785 /* Write zero at the end of the packet. */
786 ctf_save_fseek (&writer->tcs, writer->tcs.packet_start + t,
789 ctf_save_write_uint32 (&writer->tcs, u32);
790 writer->tcs.content_size = t;
792 ctf_save_next_packet (&writer->tcs);
795 /* Operations to write various types of trace frames into CTF
798 static const struct trace_frame_write_ops ctf_write_frame_ops =
800 ctf_write_frame_start,
801 ctf_write_frame_r_block,
802 ctf_write_frame_m_block_header,
803 ctf_write_frame_m_block_memory,
804 ctf_write_frame_v_block,
808 /* Operations to write trace buffers into CTF format. */
810 static const struct trace_file_write_ops ctf_write_ops =
816 ctf_write_regblock_type,
818 ctf_write_uploaded_tsv,
819 ctf_write_uploaded_tp,
821 ctf_write_definition_end,
823 &ctf_write_frame_ops,
827 /* Return a trace writer for CTF format. */
829 struct trace_file_writer *
830 ctf_trace_file_writer_new (void)
832 struct ctf_trace_file_writer *writer = XNEW (struct ctf_trace_file_writer);
834 writer->base.ops = &ctf_write_ops;
836 return (struct trace_file_writer *) writer;
839 #if HAVE_LIBBABELTRACE
840 /* Use libbabeltrace to read CTF data. The libbabeltrace provides
841 iterator to iterate over each event in CTF data and APIs to get
842 details of event and packet, so it is very convenient to use
843 libbabeltrace to access events in CTF. */
845 #include <babeltrace/babeltrace.h>
846 #include <babeltrace/ctf/events.h>
847 #include <babeltrace/ctf/iterator.h>
849 /* The struct pointer for current CTF directory. */
850 static int handle_id = -1;
851 static struct bt_context *ctx = NULL;
852 static struct bt_ctf_iter *ctf_iter = NULL;
853 /* The position of the first packet containing trace frame. */
854 static struct bt_iter_pos *start_pos;
856 /* The name of CTF directory. */
857 static char *trace_dirname;
859 static ctf_target ctf_ops;
861 /* Destroy ctf iterator and context. */
866 if (ctf_iter != NULL)
868 bt_ctf_iter_destroy (ctf_iter);
873 bt_context_put (ctx);
878 /* Open CTF trace data in DIRNAME. */
881 ctf_open_dir (const char *dirname)
883 struct bt_iter_pos begin_pos;
884 unsigned int count, i;
885 struct bt_ctf_event_decl * const *list;
887 ctx = bt_context_create ();
889 error (_("Unable to create bt_context"));
890 handle_id = bt_context_add_trace (ctx, dirname, "ctf", NULL, NULL, NULL);
894 error (_("Unable to use libbabeltrace on directory \"%s\""),
898 begin_pos.type = BT_SEEK_BEGIN;
899 ctf_iter = bt_ctf_iter_create (ctx, &begin_pos, NULL);
900 if (ctf_iter == NULL)
903 error (_("Unable to create bt_iterator"));
906 /* Look for the declaration of register block. Get the length of
907 array "contents" to set trace_regblock_size. */
909 bt_ctf_get_event_decl_list (handle_id, ctx, &list, &count);
910 for (i = 0; i < count; i++)
911 if (strcmp ("register", bt_ctf_get_decl_event_name (list[i])) == 0)
913 const struct bt_ctf_field_decl * const *field_list;
914 const struct bt_declaration *decl;
916 bt_ctf_get_decl_fields (list[i], BT_EVENT_FIELDS, &field_list,
919 gdb_assert (count == 1);
920 gdb_assert (0 == strcmp ("contents",
921 bt_ctf_get_decl_field_name (field_list[0])));
922 decl = bt_ctf_get_decl_from_field_decl (field_list[0]);
923 trace_regblock_size = bt_ctf_get_array_len (decl);
929 #define SET_INT32_FIELD(EVENT, SCOPE, VAR, FIELD) \
930 (VAR)->FIELD = (int) bt_ctf_get_int64 (bt_ctf_get_field ((EVENT), \
934 #define SET_ENUM_FIELD(EVENT, SCOPE, VAR, TYPE, FIELD) \
935 (VAR)->FIELD = (TYPE) bt_ctf_get_int64 (bt_ctf_get_field ((EVENT), \
940 /* EVENT is the "status" event and TS is filled in. */
943 ctf_read_status (struct bt_ctf_event *event, struct trace_status *ts)
945 const struct bt_definition *scope
946 = bt_ctf_get_top_level_scope (event, BT_EVENT_FIELDS);
948 SET_ENUM_FIELD (event, scope, ts, enum trace_stop_reason, stop_reason);
949 SET_INT32_FIELD (event, scope, ts, stopping_tracepoint);
950 SET_INT32_FIELD (event, scope, ts, traceframe_count);
951 SET_INT32_FIELD (event, scope, ts, traceframes_created);
952 SET_INT32_FIELD (event, scope, ts, buffer_free);
953 SET_INT32_FIELD (event, scope, ts, buffer_size);
954 SET_INT32_FIELD (event, scope, ts, disconnected_tracing);
955 SET_INT32_FIELD (event, scope, ts, circular_buffer);
957 bt_iter_next (bt_ctf_get_iter (ctf_iter));
960 /* Read the events "tsv_def" one by one, extract its contents and fill
961 in the list UPLOADED_TSVS. */
964 ctf_read_tsv (struct uploaded_tsv **uploaded_tsvs)
966 gdb_assert (ctf_iter != NULL);
970 struct bt_ctf_event *event;
971 const struct bt_definition *scope;
972 const struct bt_definition *def;
974 struct uploaded_tsv *utsv = NULL;
976 event = bt_ctf_iter_read_event (ctf_iter);
977 scope = bt_ctf_get_top_level_scope (event,
978 BT_STREAM_EVENT_HEADER);
979 event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
981 if (event_id != CTF_EVENT_ID_TSV_DEF)
984 scope = bt_ctf_get_top_level_scope (event,
987 def = bt_ctf_get_field (event, scope, "number");
988 utsv = get_uploaded_tsv ((int32_t) bt_ctf_get_int64 (def),
991 def = bt_ctf_get_field (event, scope, "builtin");
992 utsv->builtin = (int32_t) bt_ctf_get_int64 (def);
993 def = bt_ctf_get_field (event, scope, "initial_value");
994 utsv->initial_value = bt_ctf_get_int64 (def);
996 def = bt_ctf_get_field (event, scope, "name");
997 utsv->name = xstrdup (bt_ctf_get_string (def));
999 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1005 /* Read the value of element whose index is NUM from CTF and write it
1006 to the corresponding VAR->ARRAY. */
1008 #define SET_ARRAY_FIELD(EVENT, SCOPE, VAR, NUM, ARRAY) \
1012 const struct bt_definition *def; \
1014 u32 = (uint32_t) bt_ctf_get_uint64 (bt_ctf_get_field ((EVENT), \
1017 def = bt_ctf_get_field ((EVENT), (SCOPE), #ARRAY); \
1018 for (i = 0; i < u32; i++) \
1020 const struct bt_definition *element \
1021 = bt_ctf_get_index ((EVENT), def, i); \
1023 (VAR)->ARRAY.push_back \
1024 (xstrdup (bt_ctf_get_string (element))); \
1029 /* Read a string from CTF and set VAR->FIELD. If the length of string
1030 is zero, set VAR->FIELD to NULL. */
1032 #define SET_STRING_FIELD(EVENT, SCOPE, VAR, FIELD) \
1035 const char *p = bt_ctf_get_string (bt_ctf_get_field ((EVENT), \
1039 if (strlen (p) > 0) \
1040 (VAR)->FIELD = xstrdup (p); \
1042 (VAR)->FIELD = NULL; \
1046 /* Read the events "tp_def" one by one, extract its contents and fill
1047 in the list UPLOADED_TPS. */
1050 ctf_read_tp (struct uploaded_tp **uploaded_tps)
1052 gdb_assert (ctf_iter != NULL);
1056 struct bt_ctf_event *event;
1057 const struct bt_definition *scope;
1061 struct uploaded_tp *utp = NULL;
1063 event = bt_ctf_iter_read_event (ctf_iter);
1064 scope = bt_ctf_get_top_level_scope (event,
1065 BT_STREAM_EVENT_HEADER);
1066 u32 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
1068 if (u32 != CTF_EVENT_ID_TP_DEF)
1071 scope = bt_ctf_get_top_level_scope (event,
1073 int32 = (int32_t) bt_ctf_get_int64 (bt_ctf_get_field (event,
1076 u64 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
1078 utp = get_uploaded_tp (int32, u64, uploaded_tps);
1080 SET_INT32_FIELD (event, scope, utp, enabled);
1081 SET_INT32_FIELD (event, scope, utp, step);
1082 SET_INT32_FIELD (event, scope, utp, pass);
1083 SET_INT32_FIELD (event, scope, utp, hit_count);
1084 SET_ENUM_FIELD (event, scope, utp, enum bptype, type);
1086 /* Read 'cmd_strings'. */
1087 SET_ARRAY_FIELD (event, scope, utp, cmd_num, cmd_strings);
1088 /* Read 'actions'. */
1089 SET_ARRAY_FIELD (event, scope, utp, action_num, actions);
1090 /* Read 'step_actions'. */
1091 SET_ARRAY_FIELD (event, scope, utp, step_action_num,
1094 SET_STRING_FIELD(event, scope, utp, at_string);
1095 SET_STRING_FIELD(event, scope, utp, cond_string);
1097 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1102 /* This is the implementation of target_ops method to_open. Open CTF
1103 trace data, read trace status, trace state variables and tracepoint
1104 definitions from the first packet. Set the start position at the
1105 second packet which contains events on trace blocks. */
1108 ctf_target_open (const char *dirname, int from_tty)
1110 struct bt_ctf_event *event;
1112 const struct bt_definition *scope;
1113 struct uploaded_tsv *uploaded_tsvs = NULL;
1114 struct uploaded_tp *uploaded_tps = NULL;
1117 error (_("No CTF directory specified."));
1119 ctf_open_dir (dirname);
1121 target_preopen (from_tty);
1123 /* Skip the first packet which about the trace status. The first
1124 event is "frame". */
1125 event = bt_ctf_iter_read_event (ctf_iter);
1126 scope = bt_ctf_get_top_level_scope (event, BT_STREAM_EVENT_HEADER);
1127 event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
1128 if (event_id != CTF_EVENT_ID_FRAME)
1129 error (_("Wrong event id of the first event"));
1130 /* The second event is "status". */
1131 bt_iter_next (bt_ctf_get_iter (ctf_iter));
1132 event = bt_ctf_iter_read_event (ctf_iter);
1133 scope = bt_ctf_get_top_level_scope (event, BT_STREAM_EVENT_HEADER);
1134 event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
1135 if (event_id != CTF_EVENT_ID_STATUS)
1136 error (_("Wrong event id of the second event"));
1137 ctf_read_status (event, current_trace_status ());
1139 ctf_read_tsv (&uploaded_tsvs);
1141 ctf_read_tp (&uploaded_tps);
1143 event = bt_ctf_iter_read_event (ctf_iter);
1144 /* EVENT can be NULL if we've already gone to the end of stream of
1148 scope = bt_ctf_get_top_level_scope (event,
1149 BT_STREAM_EVENT_HEADER);
1150 event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event,
1152 if (event_id != CTF_EVENT_ID_FRAME)
1153 error (_("Wrong event id of the first event of the second packet"));
1156 start_pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1157 gdb_assert (start_pos->type == BT_SEEK_RESTORE);
1159 trace_dirname = xstrdup (dirname);
1160 push_target (&ctf_ops);
1162 inferior_appeared (current_inferior (), CTF_PID);
1163 inferior_ptid = pid_to_ptid (CTF_PID);
1164 add_thread_silent (inferior_ptid);
1166 merge_uploaded_trace_state_variables (&uploaded_tsvs);
1167 merge_uploaded_tracepoints (&uploaded_tps);
1169 post_create_inferior (&ctf_ops, from_tty);
1172 /* This is the implementation of target_ops method to_close. Destroy
1173 CTF iterator and context. */
1176 ctf_target::close ()
1179 xfree (trace_dirname);
1180 trace_dirname = NULL;
1182 inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
1183 exit_inferior_silent (current_inferior ());
1185 trace_reset_local_state ();
1188 /* This is the implementation of target_ops method to_files_info.
1189 Print the directory name of CTF trace data. */
1192 ctf_target::files_info ()
1194 printf_filtered ("\t`%s'\n", trace_dirname);
1197 /* This is the implementation of target_ops method to_fetch_registers.
1198 Iterate over events whose name is "register" in current frame,
1199 extract contents from events, and set REGCACHE with the contents.
1200 If no matched events are found, mark registers unavailable. */
1203 ctf_target::fetch_registers (struct regcache *regcache, int regno)
1205 struct gdbarch *gdbarch = regcache->arch ();
1206 struct bt_ctf_event *event = NULL;
1207 struct bt_iter_pos *pos;
1209 /* An uninitialized reg size says we're not going to be
1210 successful at getting register blocks. */
1211 if (trace_regblock_size == 0)
1214 gdb_assert (ctf_iter != NULL);
1215 /* Save the current position. */
1216 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1217 gdb_assert (pos->type == BT_SEEK_RESTORE);
1222 struct bt_ctf_event *event1;
1224 event1 = bt_ctf_iter_read_event (ctf_iter);
1226 name = bt_ctf_event_name (event1);
1228 if (name == NULL || strcmp (name, "frame") == 0)
1230 else if (strcmp (name, "register") == 0)
1236 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1240 /* Restore the position. */
1241 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1245 int offset, regsize, regn;
1246 const struct bt_definition *scope
1247 = bt_ctf_get_top_level_scope (event,
1249 const struct bt_definition *array
1250 = bt_ctf_get_field (event, scope, "contents");
1251 gdb_byte *regs = (gdb_byte *) bt_ctf_get_char_array (array);
1253 /* Assume the block is laid out in GDB register number order,
1254 each register with the size that it has in GDB. */
1256 for (regn = 0; regn < gdbarch_num_regs (gdbarch); regn++)
1258 regsize = register_size (gdbarch, regn);
1259 /* Make sure we stay within block bounds. */
1260 if (offset + regsize >= trace_regblock_size)
1262 if (regcache->get_register_status (regn) == REG_UNKNOWN)
1266 regcache->raw_supply (regno, regs + offset);
1269 else if (regno == -1)
1271 regcache->raw_supply (regn, regs + offset);
1278 tracefile_fetch_registers (regcache, regno);
1281 /* This is the implementation of target_ops method to_xfer_partial.
1282 Iterate over events whose name is "memory" in
1283 current frame, extract the address and length from events. If
1284 OFFSET is within the range, read the contents from events to
1287 enum target_xfer_status
1288 ctf_target::xfer_partial (enum target_object object,
1289 const char *annex, gdb_byte *readbuf,
1290 const gdb_byte *writebuf, ULONGEST offset,
1291 ULONGEST len, ULONGEST *xfered_len)
1293 /* We're only doing regular memory for now. */
1294 if (object != TARGET_OBJECT_MEMORY)
1295 return TARGET_XFER_E_IO;
1297 if (readbuf == NULL)
1298 error (_("ctf_xfer_partial: trace file is read-only"));
1300 if (get_traceframe_number () != -1)
1302 struct bt_iter_pos *pos;
1303 enum target_xfer_status res;
1304 /* Records the lowest available address of all blocks that
1305 intersects the requested range. */
1306 ULONGEST low_addr_available = 0;
1308 gdb_assert (ctf_iter != NULL);
1309 /* Save the current position. */
1310 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1311 gdb_assert (pos->type == BT_SEEK_RESTORE);
1313 /* Iterate through the traceframe's blocks, looking for
1320 const struct bt_definition *scope;
1321 const struct bt_definition *def;
1322 struct bt_ctf_event *event
1323 = bt_ctf_iter_read_event (ctf_iter);
1324 const char *name = bt_ctf_event_name (event);
1326 if (name == NULL || strcmp (name, "frame") == 0)
1328 else if (strcmp (name, "memory") != 0)
1330 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1336 scope = bt_ctf_get_top_level_scope (event,
1339 def = bt_ctf_get_field (event, scope, "address");
1340 maddr = bt_ctf_get_uint64 (def);
1341 def = bt_ctf_get_field (event, scope, "length");
1342 mlen = (uint16_t) bt_ctf_get_uint64 (def);
1344 /* If the block includes the first part of the desired
1345 range, return as much it has; GDB will re-request the
1346 remainder, which might be in a different block of this
1348 if (maddr <= offset && offset < (maddr + mlen))
1350 const struct bt_definition *array
1351 = bt_ctf_get_field (event, scope, "contents");
1355 contents = (gdb_byte *) xmalloc (mlen);
1357 for (k = 0; k < mlen; k++)
1359 const struct bt_definition *element
1360 = bt_ctf_get_index (event, array, k);
1362 contents[k] = (gdb_byte) bt_ctf_get_uint64 (element);
1365 amt = (maddr + mlen) - offset;
1369 memcpy (readbuf, &contents[offset - maddr], amt);
1373 /* Restore the position. */
1374 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1377 return TARGET_XFER_EOF;
1381 return TARGET_XFER_OK;
1385 if (offset < maddr && maddr < (offset + len))
1386 if (low_addr_available == 0 || low_addr_available > maddr)
1387 low_addr_available = maddr;
1389 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1393 /* Restore the position. */
1394 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1396 /* Requested memory is unavailable in the context of traceframes,
1397 and this address falls within a read-only section, fallback
1398 to reading from executable, up to LOW_ADDR_AVAILABLE */
1399 if (offset < low_addr_available)
1400 len = std::min (len, low_addr_available - offset);
1401 res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);
1403 if (res == TARGET_XFER_OK)
1404 return TARGET_XFER_OK;
1407 /* No use trying further, we know some memory starting
1408 at MEMADDR isn't available. */
1410 return TARGET_XFER_UNAVAILABLE;
1415 /* Fallback to reading from read-only sections. */
1416 return section_table_read_available_memory (readbuf, offset, len, xfered_len);
1420 /* This is the implementation of target_ops method
1421 to_get_trace_state_variable_value.
1422 Iterate over events whose name is "tsv" in current frame. When the
1423 trace variable is found, set the value of it to *VAL and return
1424 true, otherwise return false. */
1427 ctf_target::get_trace_state_variable_value (int tsvnum, LONGEST *val)
1429 struct bt_iter_pos *pos;
1432 gdb_assert (ctf_iter != NULL);
1433 /* Save the current position. */
1434 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1435 gdb_assert (pos->type == BT_SEEK_RESTORE);
1437 /* Iterate through the traceframe's blocks, looking for 'V'
1441 struct bt_ctf_event *event
1442 = bt_ctf_iter_read_event (ctf_iter);
1443 const char *name = bt_ctf_event_name (event);
1445 if (name == NULL || strcmp (name, "frame") == 0)
1447 else if (strcmp (name, "tsv") == 0)
1449 const struct bt_definition *scope;
1450 const struct bt_definition *def;
1452 scope = bt_ctf_get_top_level_scope (event,
1455 def = bt_ctf_get_field (event, scope, "num");
1456 if (tsvnum == (int32_t) bt_ctf_get_uint64 (def))
1458 def = bt_ctf_get_field (event, scope, "val");
1459 *val = bt_ctf_get_uint64 (def);
1465 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1469 /* Restore the position. */
1470 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1475 /* Return the tracepoint number in "frame" event. */
1478 ctf_get_tpnum_from_frame_event (struct bt_ctf_event *event)
1480 /* The packet context of events has a field "tpnum". */
1481 const struct bt_definition *scope
1482 = bt_ctf_get_top_level_scope (event, BT_STREAM_PACKET_CONTEXT);
1484 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "tpnum"));
1489 /* Return the address at which the current frame was collected. */
1492 ctf_get_traceframe_address (void)
1494 struct bt_ctf_event *event = NULL;
1495 struct bt_iter_pos *pos;
1498 gdb_assert (ctf_iter != NULL);
1499 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1500 gdb_assert (pos->type == BT_SEEK_RESTORE);
1505 struct bt_ctf_event *event1;
1507 event1 = bt_ctf_iter_read_event (ctf_iter);
1509 name = bt_ctf_event_name (event1);
1513 else if (strcmp (name, "frame") == 0)
1519 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1525 int tpnum = ctf_get_tpnum_from_frame_event (event);
1526 struct tracepoint *tp
1527 = get_tracepoint_by_number_on_target (tpnum);
1530 addr = tp->loc->address;
1533 /* Restore the position. */
1534 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1539 /* This is the implementation of target_ops method to_trace_find.
1540 Iterate the events whose name is "frame", extract the tracepoint
1541 number in it. Return traceframe number when matched. */
1544 ctf_target::trace_find (enum trace_find_type type, int num,
1545 CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
1557 gdb_assert (ctf_iter != NULL);
1558 /* Set iterator back to the start. */
1559 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), start_pos);
1563 struct bt_ctf_event *event;
1566 event = bt_ctf_iter_read_event (ctf_iter);
1568 name = bt_ctf_event_name (event);
1570 if (event == NULL || name == NULL)
1573 if (strcmp (name, "frame") == 0)
1577 if (type == tfind_number)
1579 /* Looking for a specific trace frame. */
1585 /* Start from the _next_ trace frame. */
1586 if (tfnum > get_traceframe_number ())
1592 struct tracepoint *tp = get_tracepoint (num);
1595 && (tp->number_on_target
1596 == ctf_get_tpnum_from_frame_event (event)))
1601 tfaddr = ctf_get_traceframe_address ();
1602 if (tfaddr == addr1)
1606 tfaddr = ctf_get_traceframe_address ();
1607 if (addr1 <= tfaddr && tfaddr <= addr2)
1611 tfaddr = ctf_get_traceframe_address ();
1612 if (!(addr1 <= tfaddr && tfaddr <= addr2))
1616 internal_error (__FILE__, __LINE__, _("unknown tfind type"));
1623 *tpp = ctf_get_tpnum_from_frame_event (event);
1625 /* Skip the event "frame". */
1626 bt_iter_next (bt_ctf_get_iter (ctf_iter));
1633 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1640 /* This is the implementation of target_ops method to_traceframe_info.
1641 Iterate the events whose name is "memory", in current
1642 frame, extract memory range information, and return them in
1646 ctf_target::traceframe_info ()
1648 traceframe_info_up info (new struct traceframe_info);
1650 struct bt_iter_pos *pos;
1652 gdb_assert (ctf_iter != NULL);
1653 /* Save the current position. */
1654 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1655 gdb_assert (pos->type == BT_SEEK_RESTORE);
1659 struct bt_ctf_event *event
1660 = bt_ctf_iter_read_event (ctf_iter);
1662 name = bt_ctf_event_name (event);
1664 if (name == NULL || strcmp (name, "register") == 0
1665 || strcmp (name, "frame") == 0)
1667 else if (strcmp (name, "memory") == 0)
1669 const struct bt_definition *scope
1670 = bt_ctf_get_top_level_scope (event,
1672 const struct bt_definition *def;
1674 def = bt_ctf_get_field (event, scope, "address");
1675 CORE_ADDR start = bt_ctf_get_uint64 (def);
1677 def = bt_ctf_get_field (event, scope, "length");
1678 int length = (uint16_t) bt_ctf_get_uint64 (def);
1680 info->memory.emplace_back (start, length);
1682 else if (strcmp (name, "tsv") == 0)
1685 const struct bt_definition *scope
1686 = bt_ctf_get_top_level_scope (event,
1688 const struct bt_definition *def;
1690 def = bt_ctf_get_field (event, scope, "num");
1691 vnum = (int) bt_ctf_get_uint64 (def);
1692 info->tvars.push_back (vnum);
1696 warning (_("Unhandled trace block type (%s) "
1697 "while building trace frame info."),
1701 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1704 while (name != NULL && strcmp (name, "frame") != 0);
1706 /* Restore the position. */
1707 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1714 /* module initialization */
1717 _initialize_ctf (void)
1719 #if HAVE_LIBBABELTRACE
1720 add_target (ctf_target_info, ctf_target_open, filename_completer);