3 Copyright (C) 2012-2019 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"
34 #include "common/filestuff.h"
38 static const target_info ctf_target_info = {
41 N_("(Use a CTF directory as a target.\n\
42 Specify the filename of the CTF directory.")
45 class ctf_target final : public tracefile_target
48 const target_info &info () const override
49 { return ctf_target_info; }
51 void close () override;
52 void fetch_registers (struct regcache *, int) override;
53 enum target_xfer_status xfer_partial (enum target_object object,
56 const gdb_byte *writebuf,
57 ULONGEST offset, ULONGEST len,
58 ULONGEST *xfered_len) override;
59 void files_info () override;
60 int trace_find (enum trace_find_type type, int num,
61 CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override;
62 bool get_trace_state_variable_value (int tsv, LONGEST *val) override;
63 traceframe_info_up traceframe_info () override;
66 /* GDB saves trace buffers and other information (such as trace
67 status) got from the remote target into Common Trace Format (CTF).
68 The following types of information are expected to save in CTF:
70 1. The length (in bytes) of register cache. Event "register" will
71 be defined in metadata, which includes the length.
73 2. Trace status. Event "status" is defined in metadata, which
74 includes all aspects of trace status.
76 3. Uploaded trace variables. Event "tsv_def" is defined in
77 metadata, which is about all aspects of a uploaded trace variable.
78 Uploaded tracepoints. Event "tp_def" is defined in meta, which
79 is about all aspects of an uploaded tracepoint. Note that the
80 "sequence" (a CTF type, which is a dynamically-sized array.) is
81 used for "actions" "step_actions" and "cmd_strings".
83 4. Trace frames. Each trace frame is composed by several blocks
84 of different types ('R', 'M', 'V'). One trace frame is saved in
85 one CTF packet and the blocks of this frame are saved as events.
86 4.1: The trace frame related information (such as the number of
87 tracepoint associated with this frame) is saved in the packet
89 4.2: The block 'M', 'R' and 'V' are saved in event "memory",
90 "register" and "tsv" respectively.
91 4.3: When iterating over events, babeltrace can't tell iterator
92 goes to a new packet, so we need a marker or anchor to tell GDB
93 that iterator goes into a new packet or frame. We define event
96 #define CTF_MAGIC 0xC1FC1FC1
97 #define CTF_SAVE_MAJOR 1
98 #define CTF_SAVE_MINOR 8
100 #define CTF_METADATA_NAME "metadata"
101 #define CTF_DATASTREAM_NAME "datastream"
103 /* Reserved event id. */
105 #define CTF_EVENT_ID_REGISTER 0
106 #define CTF_EVENT_ID_TSV 1
107 #define CTF_EVENT_ID_MEMORY 2
108 #define CTF_EVENT_ID_FRAME 3
109 #define CTF_EVENT_ID_STATUS 4
110 #define CTF_EVENT_ID_TSV_DEF 5
111 #define CTF_EVENT_ID_TP_DEF 6
115 /* The state kept while writing the CTF datastream file. */
117 struct trace_write_handler
119 /* File descriptor of metadata. */
121 /* File descriptor of traceframes. */
124 /* This is the content size of the current packet. */
127 /* This is the start offset of current packet. */
131 /* Write metadata in FORMAT. */
134 ctf_save_write_metadata (struct trace_write_handler *handler,
135 const char *format, ...)
136 ATTRIBUTE_PRINTF (2, 3);
139 ctf_save_write_metadata (struct trace_write_handler *handler,
140 const char *format, ...)
144 va_start (args, format);
145 if (vfprintf (handler->metadata_fd, format, args) < 0)
146 error (_("Unable to write metadata file (%s)"),
147 safe_strerror (errno));
151 /* Write BUF of length SIZE to datastream file represented by
155 ctf_save_write (struct trace_write_handler *handler,
156 const gdb_byte *buf, size_t size)
158 if (fwrite (buf, size, 1, handler->datastream_fd) != 1)
159 error (_("Unable to write file for saving trace data (%s)"),
160 safe_strerror (errno));
162 handler->content_size += size;
167 /* Write a unsigned 32-bit integer to datastream file represented by
170 #define ctf_save_write_uint32(HANDLER, U32) \
171 ctf_save_write (HANDLER, (gdb_byte *) &U32, 4)
173 /* Write a signed 32-bit integer to datastream file represented by
176 #define ctf_save_write_int32(HANDLER, INT32) \
177 ctf_save_write ((HANDLER), (gdb_byte *) &(INT32), 4)
179 /* Set datastream file position. Update HANDLER->content_size
180 if WHENCE is SEEK_CUR. */
183 ctf_save_fseek (struct trace_write_handler *handler, long offset,
186 gdb_assert (whence != SEEK_END);
187 gdb_assert (whence != SEEK_SET
188 || offset <= handler->content_size + handler->packet_start);
190 if (fseek (handler->datastream_fd, offset, whence))
191 error (_("Unable to seek file for saving trace data (%s)"),
192 safe_strerror (errno));
194 if (whence == SEEK_CUR)
195 handler->content_size += offset;
200 /* Change the datastream file position to align on ALIGN_SIZE,
201 and write BUF to datastream file. The size of BUF is SIZE. */
204 ctf_save_align_write (struct trace_write_handler *handler,
206 size_t size, size_t align_size)
209 = (align_up (handler->content_size, align_size)
210 - handler->content_size);
212 if (ctf_save_fseek (handler, offset, SEEK_CUR))
215 if (ctf_save_write (handler, buf, size))
221 /* Write events to next new packet. */
224 ctf_save_next_packet (struct trace_write_handler *handler)
226 handler->packet_start += (handler->content_size + 4);
227 ctf_save_fseek (handler, handler->packet_start, SEEK_SET);
228 handler->content_size = 0;
231 /* Write the CTF metadata header. */
234 ctf_save_metadata_header (struct trace_write_handler *handler)
236 ctf_save_write_metadata (handler, "/* CTF %d.%d */\n",
237 CTF_SAVE_MAJOR, CTF_SAVE_MINOR);
238 ctf_save_write_metadata (handler,
239 "typealias integer { size = 8; align = 8; "
240 "signed = false; encoding = ascii;}"
242 ctf_save_write_metadata (handler,
243 "typealias integer { size = 8; align = 8; "
246 ctf_save_write_metadata (handler,
247 "typealias integer { size = 16; align = 16;"
248 "signed = false; } := uint16_t;\n");
249 ctf_save_write_metadata (handler,
250 "typealias integer { size = 32; align = 32;"
251 "signed = false; } := uint32_t;\n");
252 ctf_save_write_metadata (handler,
253 "typealias integer { size = 64; align = 64;"
254 "signed = false; base = hex;}"
256 ctf_save_write_metadata (handler,
257 "typealias integer { size = 32; align = 32;"
258 "signed = true; } := int32_t;\n");
259 ctf_save_write_metadata (handler,
260 "typealias integer { size = 64; align = 64;"
261 "signed = true; } := int64_t;\n");
262 ctf_save_write_metadata (handler,
263 "typealias string { encoding = ascii;"
265 ctf_save_write_metadata (handler, "\n");
267 /* Get the byte order of the host and write CTF data in this byte
270 #define HOST_ENDIANNESS "be"
272 #define HOST_ENDIANNESS "le"
275 ctf_save_write_metadata (handler,
279 " byte_order = %s;\n"
280 " packet.header := struct {\n"
286 " packet.context := struct {\n"
287 " uint32_t content_size;\n"
288 " uint32_t packet_size;\n"
291 " event.header := struct {\n"
295 CTF_SAVE_MAJOR, CTF_SAVE_MINOR,
297 ctf_save_write_metadata (handler, "\n");
300 /* CTF trace writer. */
302 struct ctf_trace_file_writer
304 struct trace_file_writer base;
306 /* States related to writing CTF trace file. */
307 struct trace_write_handler tcs;
310 /* This is the implementation of trace_file_write_ops method
314 ctf_dtor (struct trace_file_writer *self)
316 struct ctf_trace_file_writer *writer
317 = (struct ctf_trace_file_writer *) self;
319 if (writer->tcs.metadata_fd != NULL)
320 fclose (writer->tcs.metadata_fd);
322 if (writer->tcs.datastream_fd != NULL)
323 fclose (writer->tcs.datastream_fd);
327 /* This is the implementation of trace_file_write_ops method
331 ctf_target_save (struct trace_file_writer *self,
334 /* Don't support save trace file to CTF format in the target. */
338 /* This is the implementation of trace_file_write_ops method
339 start. It creates the directory DIRNAME, metadata and datastream
343 ctf_start (struct trace_file_writer *self, const char *dirname)
345 struct ctf_trace_file_writer *writer
346 = (struct ctf_trace_file_writer *) self;
347 mode_t hmode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH;
349 /* Create DIRNAME. */
350 if (mkdir (dirname, hmode) && errno != EEXIST)
351 error (_("Unable to open directory '%s' for saving trace data (%s)"),
352 dirname, safe_strerror (errno));
354 memset (&writer->tcs, '\0', sizeof (writer->tcs));
356 std::string file_name = string_printf ("%s/%s", dirname, CTF_METADATA_NAME);
358 writer->tcs.metadata_fd
359 = gdb_fopen_cloexec (file_name.c_str (), "w").release ();
360 if (writer->tcs.metadata_fd == NULL)
361 error (_("Unable to open file '%s' for saving trace data (%s)"),
362 file_name.c_str (), safe_strerror (errno));
364 ctf_save_metadata_header (&writer->tcs);
366 file_name = string_printf ("%s/%s", dirname, CTF_DATASTREAM_NAME);
367 writer->tcs.datastream_fd
368 = gdb_fopen_cloexec (file_name.c_str (), "w").release ();
369 if (writer->tcs.datastream_fd == NULL)
370 error (_("Unable to open file '%s' for saving trace data (%s)"),
371 file_name.c_str (), safe_strerror (errno));
374 /* This is the implementation of trace_file_write_ops method
375 write_header. Write the types of events on trace variable and
379 ctf_write_header (struct trace_file_writer *self)
381 struct ctf_trace_file_writer *writer
382 = (struct ctf_trace_file_writer *) self;
385 ctf_save_write_metadata (&writer->tcs, "\n");
386 ctf_save_write_metadata (&writer->tcs,
387 "event {\n\tname = \"memory\";\n\tid = %u;\n"
388 "\tfields := struct { \n"
389 "\t\tuint64_t address;\n"
390 "\t\tuint16_t length;\n"
391 "\t\tuint8_t contents[length];\n"
393 "};\n", CTF_EVENT_ID_MEMORY);
395 ctf_save_write_metadata (&writer->tcs, "\n");
396 ctf_save_write_metadata (&writer->tcs,
397 "event {\n\tname = \"tsv\";\n\tid = %u;\n"
398 "\tfields := struct { \n"
399 "\t\tuint64_t val;\n"
400 "\t\tuint32_t num;\n"
402 "};\n", CTF_EVENT_ID_TSV);
404 ctf_save_write_metadata (&writer->tcs, "\n");
405 ctf_save_write_metadata (&writer->tcs,
406 "event {\n\tname = \"frame\";\n\tid = %u;\n"
407 "\tfields := struct { \n"
409 "};\n", CTF_EVENT_ID_FRAME);
411 ctf_save_write_metadata (&writer->tcs, "\n");
412 ctf_save_write_metadata (&writer->tcs,
413 "event {\n\tname = \"tsv_def\";\n"
414 "\tid = %u;\n\tfields := struct { \n"
415 "\t\tint64_t initial_value;\n"
416 "\t\tint32_t number;\n"
417 "\t\tint32_t builtin;\n"
420 "};\n", CTF_EVENT_ID_TSV_DEF);
422 ctf_save_write_metadata (&writer->tcs, "\n");
423 ctf_save_write_metadata (&writer->tcs,
424 "event {\n\tname = \"tp_def\";\n"
425 "\tid = %u;\n\tfields := struct { \n"
426 "\t\tuint64_t addr;\n"
427 "\t\tuint64_t traceframe_usage;\n"
428 "\t\tint32_t number;\n"
429 "\t\tint32_t enabled;\n"
430 "\t\tint32_t step;\n"
431 "\t\tint32_t pass;\n"
432 "\t\tint32_t hit_count;\n"
433 "\t\tint32_t type;\n"
436 "\t\tuint32_t action_num;\n"
437 "\t\tchars actions[action_num];\n"
439 "\t\tuint32_t step_action_num;\n"
440 "\t\tchars step_actions[step_action_num];\n"
442 "\t\tchars at_string;\n"
443 "\t\tchars cond_string;\n"
445 "\t\tuint32_t cmd_num;\n"
446 "\t\tchars cmd_strings[cmd_num];\n"
448 "};\n", CTF_EVENT_ID_TP_DEF);
450 gdb_assert (writer->tcs.content_size == 0);
451 gdb_assert (writer->tcs.packet_start == 0);
453 /* Create a new packet to contain this event. */
454 self->ops->frame_ops->start (self, 0);
457 /* This is the implementation of trace_file_write_ops method
458 write_regblock_type. Write the type of register event in
462 ctf_write_regblock_type (struct trace_file_writer *self, int size)
464 struct ctf_trace_file_writer *writer
465 = (struct ctf_trace_file_writer *) self;
467 ctf_save_write_metadata (&writer->tcs, "\n");
469 ctf_save_write_metadata (&writer->tcs,
470 "event {\n\tname = \"register\";\n\tid = %u;\n"
471 "\tfields := struct { \n"
472 "\t\tascii contents[%d];\n"
475 CTF_EVENT_ID_REGISTER, size);
478 /* This is the implementation of trace_file_write_ops method
482 ctf_write_status (struct trace_file_writer *self,
483 struct trace_status *ts)
485 struct ctf_trace_file_writer *writer
486 = (struct ctf_trace_file_writer *) self;
489 ctf_save_write_metadata (&writer->tcs, "\n");
490 ctf_save_write_metadata (&writer->tcs,
491 "event {\n\tname = \"status\";\n\tid = %u;\n"
492 "\tfields := struct { \n"
493 "\t\tint32_t stop_reason;\n"
494 "\t\tint32_t stopping_tracepoint;\n"
495 "\t\tint32_t traceframe_count;\n"
496 "\t\tint32_t traceframes_created;\n"
497 "\t\tint32_t buffer_free;\n"
498 "\t\tint32_t buffer_size;\n"
499 "\t\tint32_t disconnected_tracing;\n"
500 "\t\tint32_t circular_buffer;\n"
503 CTF_EVENT_ID_STATUS);
505 id = CTF_EVENT_ID_STATUS;
507 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
509 ctf_save_write_int32 (&writer->tcs, ts->stop_reason);
510 ctf_save_write_int32 (&writer->tcs, ts->stopping_tracepoint);
511 ctf_save_write_int32 (&writer->tcs, ts->traceframe_count);
512 ctf_save_write_int32 (&writer->tcs, ts->traceframes_created);
513 ctf_save_write_int32 (&writer->tcs, ts->buffer_free);
514 ctf_save_write_int32 (&writer->tcs, ts->buffer_size);
515 ctf_save_write_int32 (&writer->tcs, ts->disconnected_tracing);
516 ctf_save_write_int32 (&writer->tcs, ts->circular_buffer);
519 /* This is the implementation of trace_file_write_ops method
520 write_uploaded_tsv. */
523 ctf_write_uploaded_tsv (struct trace_file_writer *self,
524 struct uploaded_tsv *tsv)
526 struct ctf_trace_file_writer *writer
527 = (struct ctf_trace_file_writer *) self;
530 const gdb_byte zero = 0;
533 int32 = CTF_EVENT_ID_TSV_DEF;
534 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int32, 4, 4);
537 int64 = tsv->initial_value;
538 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int64, 8, 8);
541 ctf_save_write_int32 (&writer->tcs, tsv->number);
544 ctf_save_write_int32 (&writer->tcs, tsv->builtin);
547 if (tsv->name != NULL)
548 ctf_save_write (&writer->tcs, (gdb_byte *) tsv->name,
550 ctf_save_write (&writer->tcs, &zero, 1);
553 /* This is the implementation of trace_file_write_ops method
554 write_uploaded_tp. */
557 ctf_write_uploaded_tp (struct trace_file_writer *self,
558 struct uploaded_tp *tp)
560 struct ctf_trace_file_writer *writer
561 = (struct ctf_trace_file_writer *) self;
565 const gdb_byte zero = 0;
568 int32 = CTF_EVENT_ID_TP_DEF;
569 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int32, 4, 4);
573 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int64, 8, 8);
575 /* traceframe_usage */
576 int64 = tp->traceframe_usage;
577 ctf_save_align_write (&writer->tcs, (gdb_byte *) &int64, 8, 8);
580 ctf_save_write_int32 (&writer->tcs, tp->number);
583 ctf_save_write_int32 (&writer->tcs, tp->enabled);
586 ctf_save_write_int32 (&writer->tcs, tp->step);
589 ctf_save_write_int32 (&writer->tcs, tp->pass);
592 ctf_save_write_int32 (&writer->tcs, tp->hit_count);
595 ctf_save_write_int32 (&writer->tcs, tp->type);
598 if (tp->cond != NULL)
599 ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond.get (),
600 strlen (tp->cond.get ()));
601 ctf_save_write (&writer->tcs, &zero, 1);
604 u32 = tp->actions.size ();
605 ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
606 for (const auto &act : tp->actions)
607 ctf_save_write (&writer->tcs, (gdb_byte *) act.get (),
608 strlen (act.get ()) + 1);
611 u32 = tp->step_actions.size ();
612 ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
613 for (const auto &act : tp->step_actions)
614 ctf_save_write (&writer->tcs, (gdb_byte *) act.get (),
615 strlen (act.get ()) + 1);
618 if (tp->at_string != NULL)
619 ctf_save_write (&writer->tcs, (gdb_byte *) tp->at_string.get (),
620 strlen (tp->at_string.get ()));
621 ctf_save_write (&writer->tcs, &zero, 1);
624 if (tp->cond_string != NULL)
625 ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond_string.get (),
626 strlen (tp->cond_string.get ()));
627 ctf_save_write (&writer->tcs, &zero, 1);
630 u32 = tp->cmd_strings.size ();
631 ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
632 for (const auto &act : tp->cmd_strings)
633 ctf_save_write (&writer->tcs, (gdb_byte *) act.get (),
634 strlen (act.get ()) + 1);
638 /* This is the implementation of trace_file_write_ops method
642 ctf_write_tdesc (struct trace_file_writer *self)
644 /* Nothing so far. */
647 /* This is the implementation of trace_file_write_ops method
648 write_definition_end. */
651 ctf_write_definition_end (struct trace_file_writer *self)
653 self->ops->frame_ops->end (self);
656 /* This is the implementation of trace_file_write_ops method
660 ctf_end (struct trace_file_writer *self)
662 struct ctf_trace_file_writer *writer = (struct ctf_trace_file_writer *) self;
664 gdb_assert (writer->tcs.content_size == 0);
667 /* This is the implementation of trace_frame_write_ops method
671 ctf_write_frame_start (struct trace_file_writer *self, uint16_t tpnum)
673 struct ctf_trace_file_writer *writer
674 = (struct ctf_trace_file_writer *) self;
675 uint32_t id = CTF_EVENT_ID_FRAME;
678 /* Step 1: Write packet context. */
681 ctf_save_write_uint32 (&writer->tcs, u32);
682 /* content_size and packet_size.. We still don't know the value,
684 ctf_save_fseek (&writer->tcs, 4, SEEK_CUR);
685 ctf_save_fseek (&writer->tcs, 4, SEEK_CUR);
686 /* Tracepoint number. */
687 ctf_save_write (&writer->tcs, (gdb_byte *) &tpnum, 2);
689 /* Step 2: Write event "frame". */
691 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
694 /* This is the implementation of trace_frame_write_ops method
698 ctf_write_frame_r_block (struct trace_file_writer *self,
699 gdb_byte *buf, int32_t size)
701 struct ctf_trace_file_writer *writer
702 = (struct ctf_trace_file_writer *) self;
703 uint32_t id = CTF_EVENT_ID_REGISTER;
706 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
708 /* array contents. */
709 ctf_save_align_write (&writer->tcs, buf, size, 1);
712 /* This is the implementation of trace_frame_write_ops method
713 write_m_block_header. */
716 ctf_write_frame_m_block_header (struct trace_file_writer *self,
717 uint64_t addr, uint16_t length)
719 struct ctf_trace_file_writer *writer
720 = (struct ctf_trace_file_writer *) self;
721 uint32_t event_id = CTF_EVENT_ID_MEMORY;
724 ctf_save_align_write (&writer->tcs, (gdb_byte *) &event_id, 4, 4);
727 ctf_save_align_write (&writer->tcs, (gdb_byte *) &addr, 8, 8);
730 ctf_save_align_write (&writer->tcs, (gdb_byte *) &length, 2, 2);
733 /* This is the implementation of trace_frame_write_ops method
734 write_m_block_memory. */
737 ctf_write_frame_m_block_memory (struct trace_file_writer *self,
738 gdb_byte *buf, uint16_t length)
740 struct ctf_trace_file_writer *writer
741 = (struct ctf_trace_file_writer *) self;
744 ctf_save_align_write (&writer->tcs, (gdb_byte *) buf, length, 1);
747 /* This is the implementation of trace_frame_write_ops method
751 ctf_write_frame_v_block (struct trace_file_writer *self,
752 int32_t num, uint64_t val)
754 struct ctf_trace_file_writer *writer
755 = (struct ctf_trace_file_writer *) self;
756 uint32_t id = CTF_EVENT_ID_TSV;
759 ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
762 ctf_save_align_write (&writer->tcs, (gdb_byte *) &val, 8, 8);
764 ctf_save_align_write (&writer->tcs, (gdb_byte *) &num, 4, 4);
767 /* This is the implementation of trace_frame_write_ops method
771 ctf_write_frame_end (struct trace_file_writer *self)
773 struct ctf_trace_file_writer *writer
774 = (struct ctf_trace_file_writer *) self;
778 /* Write the content size to packet header. */
779 ctf_save_fseek (&writer->tcs, writer->tcs.packet_start + 4,
781 u32 = writer->tcs.content_size * TARGET_CHAR_BIT;
783 t = writer->tcs.content_size;
784 ctf_save_write_uint32 (&writer->tcs, u32);
786 /* Write the packet size. */
787 u32 += 4 * TARGET_CHAR_BIT;
788 ctf_save_write_uint32 (&writer->tcs, u32);
790 writer->tcs.content_size = t;
792 /* Write zero at the end of the packet. */
793 ctf_save_fseek (&writer->tcs, writer->tcs.packet_start + t,
796 ctf_save_write_uint32 (&writer->tcs, u32);
797 writer->tcs.content_size = t;
799 ctf_save_next_packet (&writer->tcs);
802 /* Operations to write various types of trace frames into CTF
805 static const struct trace_frame_write_ops ctf_write_frame_ops =
807 ctf_write_frame_start,
808 ctf_write_frame_r_block,
809 ctf_write_frame_m_block_header,
810 ctf_write_frame_m_block_memory,
811 ctf_write_frame_v_block,
815 /* Operations to write trace buffers into CTF format. */
817 static const struct trace_file_write_ops ctf_write_ops =
823 ctf_write_regblock_type,
825 ctf_write_uploaded_tsv,
826 ctf_write_uploaded_tp,
828 ctf_write_definition_end,
830 &ctf_write_frame_ops,
834 /* Return a trace writer for CTF format. */
836 struct trace_file_writer *
837 ctf_trace_file_writer_new (void)
839 struct ctf_trace_file_writer *writer = XNEW (struct ctf_trace_file_writer);
841 writer->base.ops = &ctf_write_ops;
843 return (struct trace_file_writer *) writer;
846 #if HAVE_LIBBABELTRACE
847 /* Use libbabeltrace to read CTF data. The libbabeltrace provides
848 iterator to iterate over each event in CTF data and APIs to get
849 details of event and packet, so it is very convenient to use
850 libbabeltrace to access events in CTF. */
852 #include <babeltrace/babeltrace.h>
853 #include <babeltrace/ctf/events.h>
854 #include <babeltrace/ctf/iterator.h>
856 /* The struct pointer for current CTF directory. */
857 static int handle_id = -1;
858 static struct bt_context *ctx = NULL;
859 static struct bt_ctf_iter *ctf_iter = NULL;
860 /* The position of the first packet containing trace frame. */
861 static struct bt_iter_pos *start_pos;
863 /* The name of CTF directory. */
864 static char *trace_dirname;
866 static ctf_target ctf_ops;
868 /* Destroy ctf iterator and context. */
873 if (ctf_iter != NULL)
875 bt_ctf_iter_destroy (ctf_iter);
880 bt_context_put (ctx);
885 /* Open CTF trace data in DIRNAME. */
888 ctf_open_dir (const char *dirname)
890 struct bt_iter_pos begin_pos;
891 unsigned int count, i;
892 struct bt_ctf_event_decl * const *list;
894 ctx = bt_context_create ();
896 error (_("Unable to create bt_context"));
897 handle_id = bt_context_add_trace (ctx, dirname, "ctf", NULL, NULL, NULL);
901 error (_("Unable to use libbabeltrace on directory \"%s\""),
905 begin_pos.type = BT_SEEK_BEGIN;
906 ctf_iter = bt_ctf_iter_create (ctx, &begin_pos, NULL);
907 if (ctf_iter == NULL)
910 error (_("Unable to create bt_iterator"));
913 /* Look for the declaration of register block. Get the length of
914 array "contents" to set trace_regblock_size. */
916 bt_ctf_get_event_decl_list (handle_id, ctx, &list, &count);
917 for (i = 0; i < count; i++)
918 if (strcmp ("register", bt_ctf_get_decl_event_name (list[i])) == 0)
920 const struct bt_ctf_field_decl * const *field_list;
921 const struct bt_declaration *decl;
923 bt_ctf_get_decl_fields (list[i], BT_EVENT_FIELDS, &field_list,
926 gdb_assert (count == 1);
927 gdb_assert (0 == strcmp ("contents",
928 bt_ctf_get_decl_field_name (field_list[0])));
929 decl = bt_ctf_get_decl_from_field_decl (field_list[0]);
930 trace_regblock_size = bt_ctf_get_array_len (decl);
936 #define SET_INT32_FIELD(EVENT, SCOPE, VAR, FIELD) \
937 (VAR)->FIELD = (int) bt_ctf_get_int64 (bt_ctf_get_field ((EVENT), \
941 #define SET_ENUM_FIELD(EVENT, SCOPE, VAR, TYPE, FIELD) \
942 (VAR)->FIELD = (TYPE) bt_ctf_get_int64 (bt_ctf_get_field ((EVENT), \
947 /* EVENT is the "status" event and TS is filled in. */
950 ctf_read_status (struct bt_ctf_event *event, struct trace_status *ts)
952 const struct bt_definition *scope
953 = bt_ctf_get_top_level_scope (event, BT_EVENT_FIELDS);
955 SET_ENUM_FIELD (event, scope, ts, enum trace_stop_reason, stop_reason);
956 SET_INT32_FIELD (event, scope, ts, stopping_tracepoint);
957 SET_INT32_FIELD (event, scope, ts, traceframe_count);
958 SET_INT32_FIELD (event, scope, ts, traceframes_created);
959 SET_INT32_FIELD (event, scope, ts, buffer_free);
960 SET_INT32_FIELD (event, scope, ts, buffer_size);
961 SET_INT32_FIELD (event, scope, ts, disconnected_tracing);
962 SET_INT32_FIELD (event, scope, ts, circular_buffer);
964 bt_iter_next (bt_ctf_get_iter (ctf_iter));
967 /* Read the events "tsv_def" one by one, extract its contents and fill
968 in the list UPLOADED_TSVS. */
971 ctf_read_tsv (struct uploaded_tsv **uploaded_tsvs)
973 gdb_assert (ctf_iter != NULL);
977 struct bt_ctf_event *event;
978 const struct bt_definition *scope;
979 const struct bt_definition *def;
981 struct uploaded_tsv *utsv = NULL;
983 event = bt_ctf_iter_read_event (ctf_iter);
984 scope = bt_ctf_get_top_level_scope (event,
985 BT_STREAM_EVENT_HEADER);
986 event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
988 if (event_id != CTF_EVENT_ID_TSV_DEF)
991 scope = bt_ctf_get_top_level_scope (event,
994 def = bt_ctf_get_field (event, scope, "number");
995 utsv = get_uploaded_tsv ((int32_t) bt_ctf_get_int64 (def),
998 def = bt_ctf_get_field (event, scope, "builtin");
999 utsv->builtin = (int32_t) bt_ctf_get_int64 (def);
1000 def = bt_ctf_get_field (event, scope, "initial_value");
1001 utsv->initial_value = bt_ctf_get_int64 (def);
1003 def = bt_ctf_get_field (event, scope, "name");
1004 utsv->name = xstrdup (bt_ctf_get_string (def));
1006 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1012 /* Read the value of element whose index is NUM from CTF and write it
1013 to the corresponding VAR->ARRAY. */
1015 #define SET_ARRAY_FIELD(EVENT, SCOPE, VAR, NUM, ARRAY) \
1019 const struct bt_definition *def; \
1021 lu32 = (uint32_t) bt_ctf_get_uint64 (bt_ctf_get_field ((EVENT), \
1024 def = bt_ctf_get_field ((EVENT), (SCOPE), #ARRAY); \
1025 for (i = 0; i < lu32; i++) \
1027 const struct bt_definition *element \
1028 = bt_ctf_get_index ((EVENT), def, i); \
1030 (VAR)->ARRAY.emplace_back \
1031 (xstrdup (bt_ctf_get_string (element))); \
1036 /* Read a string from CTF and set VAR->FIELD. If the length of string
1037 is zero, set VAR->FIELD to NULL. */
1039 #define SET_STRING_FIELD(EVENT, SCOPE, VAR, FIELD) \
1042 const char *p = bt_ctf_get_string (bt_ctf_get_field ((EVENT), \
1046 if (strlen (p) > 0) \
1047 (VAR)->FIELD.reset (xstrdup (p)); \
1049 (VAR)->FIELD = NULL; \
1053 /* Read the events "tp_def" one by one, extract its contents and fill
1054 in the list UPLOADED_TPS. */
1057 ctf_read_tp (struct uploaded_tp **uploaded_tps)
1059 gdb_assert (ctf_iter != NULL);
1063 struct bt_ctf_event *event;
1064 const struct bt_definition *scope;
1068 struct uploaded_tp *utp = NULL;
1070 event = bt_ctf_iter_read_event (ctf_iter);
1071 scope = bt_ctf_get_top_level_scope (event,
1072 BT_STREAM_EVENT_HEADER);
1073 u32 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
1075 if (u32 != CTF_EVENT_ID_TP_DEF)
1078 scope = bt_ctf_get_top_level_scope (event,
1080 int32 = (int32_t) bt_ctf_get_int64 (bt_ctf_get_field (event,
1083 u64 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
1085 utp = get_uploaded_tp (int32, u64, uploaded_tps);
1087 SET_INT32_FIELD (event, scope, utp, enabled);
1088 SET_INT32_FIELD (event, scope, utp, step);
1089 SET_INT32_FIELD (event, scope, utp, pass);
1090 SET_INT32_FIELD (event, scope, utp, hit_count);
1091 SET_ENUM_FIELD (event, scope, utp, enum bptype, type);
1093 /* Read 'cmd_strings'. */
1094 SET_ARRAY_FIELD (event, scope, utp, cmd_num, cmd_strings);
1095 /* Read 'actions'. */
1096 SET_ARRAY_FIELD (event, scope, utp, action_num, actions);
1097 /* Read 'step_actions'. */
1098 SET_ARRAY_FIELD (event, scope, utp, step_action_num,
1101 SET_STRING_FIELD(event, scope, utp, at_string);
1102 SET_STRING_FIELD(event, scope, utp, cond_string);
1104 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1109 /* This is the implementation of target_ops method to_open. Open CTF
1110 trace data, read trace status, trace state variables and tracepoint
1111 definitions from the first packet. Set the start position at the
1112 second packet which contains events on trace blocks. */
1115 ctf_target_open (const char *dirname, int from_tty)
1117 struct bt_ctf_event *event;
1119 const struct bt_definition *scope;
1120 struct uploaded_tsv *uploaded_tsvs = NULL;
1121 struct uploaded_tp *uploaded_tps = NULL;
1124 error (_("No CTF directory specified."));
1126 ctf_open_dir (dirname);
1128 target_preopen (from_tty);
1130 /* Skip the first packet which about the trace status. The first
1131 event is "frame". */
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_FRAME)
1136 error (_("Wrong event id of the first event"));
1137 /* The second event is "status". */
1138 bt_iter_next (bt_ctf_get_iter (ctf_iter));
1139 event = bt_ctf_iter_read_event (ctf_iter);
1140 scope = bt_ctf_get_top_level_scope (event, BT_STREAM_EVENT_HEADER);
1141 event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
1142 if (event_id != CTF_EVENT_ID_STATUS)
1143 error (_("Wrong event id of the second event"));
1144 ctf_read_status (event, current_trace_status ());
1146 ctf_read_tsv (&uploaded_tsvs);
1148 ctf_read_tp (&uploaded_tps);
1150 event = bt_ctf_iter_read_event (ctf_iter);
1151 /* EVENT can be NULL if we've already gone to the end of stream of
1155 scope = bt_ctf_get_top_level_scope (event,
1156 BT_STREAM_EVENT_HEADER);
1157 event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event,
1159 if (event_id != CTF_EVENT_ID_FRAME)
1160 error (_("Wrong event id of the first event of the second packet"));
1163 start_pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1164 gdb_assert (start_pos->type == BT_SEEK_RESTORE);
1166 trace_dirname = xstrdup (dirname);
1167 push_target (&ctf_ops);
1169 inferior_appeared (current_inferior (), CTF_PID);
1170 inferior_ptid = ptid_t (CTF_PID);
1171 add_thread_silent (inferior_ptid);
1173 merge_uploaded_trace_state_variables (&uploaded_tsvs);
1174 merge_uploaded_tracepoints (&uploaded_tps);
1176 post_create_inferior (&ctf_ops, from_tty);
1179 /* This is the implementation of target_ops method to_close. Destroy
1180 CTF iterator and context. */
1183 ctf_target::close ()
1186 xfree (trace_dirname);
1187 trace_dirname = NULL;
1189 inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
1190 exit_inferior_silent (current_inferior ());
1192 trace_reset_local_state ();
1195 /* This is the implementation of target_ops method to_files_info.
1196 Print the directory name of CTF trace data. */
1199 ctf_target::files_info ()
1201 printf_filtered ("\t`%s'\n", trace_dirname);
1204 /* This is the implementation of target_ops method to_fetch_registers.
1205 Iterate over events whose name is "register" in current frame,
1206 extract contents from events, and set REGCACHE with the contents.
1207 If no matched events are found, mark registers unavailable. */
1210 ctf_target::fetch_registers (struct regcache *regcache, int regno)
1212 struct gdbarch *gdbarch = regcache->arch ();
1213 struct bt_ctf_event *event = NULL;
1214 struct bt_iter_pos *pos;
1216 /* An uninitialized reg size says we're not going to be
1217 successful at getting register blocks. */
1218 if (trace_regblock_size == 0)
1221 gdb_assert (ctf_iter != NULL);
1222 /* Save the current position. */
1223 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1224 gdb_assert (pos->type == BT_SEEK_RESTORE);
1229 struct bt_ctf_event *event1;
1231 event1 = bt_ctf_iter_read_event (ctf_iter);
1233 name = bt_ctf_event_name (event1);
1235 if (name == NULL || strcmp (name, "frame") == 0)
1237 else if (strcmp (name, "register") == 0)
1243 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1247 /* Restore the position. */
1248 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1252 int offset, regsize, regn;
1253 const struct bt_definition *scope
1254 = bt_ctf_get_top_level_scope (event,
1256 const struct bt_definition *array
1257 = bt_ctf_get_field (event, scope, "contents");
1258 gdb_byte *regs = (gdb_byte *) bt_ctf_get_char_array (array);
1260 /* Assume the block is laid out in GDB register number order,
1261 each register with the size that it has in GDB. */
1263 for (regn = 0; regn < gdbarch_num_regs (gdbarch); regn++)
1265 regsize = register_size (gdbarch, regn);
1266 /* Make sure we stay within block bounds. */
1267 if (offset + regsize >= trace_regblock_size)
1269 if (regcache->get_register_status (regn) == REG_UNKNOWN)
1273 regcache->raw_supply (regno, regs + offset);
1276 else if (regno == -1)
1278 regcache->raw_supply (regn, regs + offset);
1285 tracefile_fetch_registers (regcache, regno);
1288 /* This is the implementation of target_ops method to_xfer_partial.
1289 Iterate over events whose name is "memory" in
1290 current frame, extract the address and length from events. If
1291 OFFSET is within the range, read the contents from events to
1294 enum target_xfer_status
1295 ctf_target::xfer_partial (enum target_object object,
1296 const char *annex, gdb_byte *readbuf,
1297 const gdb_byte *writebuf, ULONGEST offset,
1298 ULONGEST len, ULONGEST *xfered_len)
1300 /* We're only doing regular memory for now. */
1301 if (object != TARGET_OBJECT_MEMORY)
1302 return TARGET_XFER_E_IO;
1304 if (readbuf == NULL)
1305 error (_("ctf_xfer_partial: trace file is read-only"));
1307 if (get_traceframe_number () != -1)
1309 struct bt_iter_pos *pos;
1310 enum target_xfer_status res;
1311 /* Records the lowest available address of all blocks that
1312 intersects the requested range. */
1313 ULONGEST low_addr_available = 0;
1315 gdb_assert (ctf_iter != NULL);
1316 /* Save the current position. */
1317 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1318 gdb_assert (pos->type == BT_SEEK_RESTORE);
1320 /* Iterate through the traceframe's blocks, looking for
1327 const struct bt_definition *scope;
1328 const struct bt_definition *def;
1329 struct bt_ctf_event *event
1330 = bt_ctf_iter_read_event (ctf_iter);
1331 const char *name = bt_ctf_event_name (event);
1333 if (name == NULL || strcmp (name, "frame") == 0)
1335 else if (strcmp (name, "memory") != 0)
1337 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1343 scope = bt_ctf_get_top_level_scope (event,
1346 def = bt_ctf_get_field (event, scope, "address");
1347 maddr = bt_ctf_get_uint64 (def);
1348 def = bt_ctf_get_field (event, scope, "length");
1349 mlen = (uint16_t) bt_ctf_get_uint64 (def);
1351 /* If the block includes the first part of the desired
1352 range, return as much it has; GDB will re-request the
1353 remainder, which might be in a different block of this
1355 if (maddr <= offset && offset < (maddr + mlen))
1357 const struct bt_definition *array
1358 = bt_ctf_get_field (event, scope, "contents");
1362 contents = (gdb_byte *) xmalloc (mlen);
1364 for (k = 0; k < mlen; k++)
1366 const struct bt_definition *element
1367 = bt_ctf_get_index (event, array, k);
1369 contents[k] = (gdb_byte) bt_ctf_get_uint64 (element);
1372 amt = (maddr + mlen) - offset;
1376 memcpy (readbuf, &contents[offset - maddr], amt);
1380 /* Restore the position. */
1381 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1384 return TARGET_XFER_EOF;
1388 return TARGET_XFER_OK;
1392 if (offset < maddr && maddr < (offset + len))
1393 if (low_addr_available == 0 || low_addr_available > maddr)
1394 low_addr_available = maddr;
1396 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1400 /* Restore the position. */
1401 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1403 /* Requested memory is unavailable in the context of traceframes,
1404 and this address falls within a read-only section, fallback
1405 to reading from executable, up to LOW_ADDR_AVAILABLE */
1406 if (offset < low_addr_available)
1407 len = std::min (len, low_addr_available - offset);
1408 res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);
1410 if (res == TARGET_XFER_OK)
1411 return TARGET_XFER_OK;
1414 /* No use trying further, we know some memory starting
1415 at MEMADDR isn't available. */
1417 return TARGET_XFER_UNAVAILABLE;
1422 /* Fallback to reading from read-only sections. */
1423 return section_table_read_available_memory (readbuf, offset, len, xfered_len);
1427 /* This is the implementation of target_ops method
1428 to_get_trace_state_variable_value.
1429 Iterate over events whose name is "tsv" in current frame. When the
1430 trace variable is found, set the value of it to *VAL and return
1431 true, otherwise return false. */
1434 ctf_target::get_trace_state_variable_value (int tsvnum, LONGEST *val)
1436 struct bt_iter_pos *pos;
1439 gdb_assert (ctf_iter != NULL);
1440 /* Save the current position. */
1441 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1442 gdb_assert (pos->type == BT_SEEK_RESTORE);
1444 /* Iterate through the traceframe's blocks, looking for 'V'
1448 struct bt_ctf_event *event
1449 = bt_ctf_iter_read_event (ctf_iter);
1450 const char *name = bt_ctf_event_name (event);
1452 if (name == NULL || strcmp (name, "frame") == 0)
1454 else if (strcmp (name, "tsv") == 0)
1456 const struct bt_definition *scope;
1457 const struct bt_definition *def;
1459 scope = bt_ctf_get_top_level_scope (event,
1462 def = bt_ctf_get_field (event, scope, "num");
1463 if (tsvnum == (int32_t) bt_ctf_get_uint64 (def))
1465 def = bt_ctf_get_field (event, scope, "val");
1466 *val = bt_ctf_get_uint64 (def);
1472 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1476 /* Restore the position. */
1477 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1482 /* Return the tracepoint number in "frame" event. */
1485 ctf_get_tpnum_from_frame_event (struct bt_ctf_event *event)
1487 /* The packet context of events has a field "tpnum". */
1488 const struct bt_definition *scope
1489 = bt_ctf_get_top_level_scope (event, BT_STREAM_PACKET_CONTEXT);
1491 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "tpnum"));
1496 /* Return the address at which the current frame was collected. */
1499 ctf_get_traceframe_address (void)
1501 struct bt_ctf_event *event = NULL;
1502 struct bt_iter_pos *pos;
1505 gdb_assert (ctf_iter != NULL);
1506 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1507 gdb_assert (pos->type == BT_SEEK_RESTORE);
1512 struct bt_ctf_event *event1;
1514 event1 = bt_ctf_iter_read_event (ctf_iter);
1516 name = bt_ctf_event_name (event1);
1520 else if (strcmp (name, "frame") == 0)
1526 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1532 int tpnum = ctf_get_tpnum_from_frame_event (event);
1533 struct tracepoint *tp
1534 = get_tracepoint_by_number_on_target (tpnum);
1537 addr = tp->loc->address;
1540 /* Restore the position. */
1541 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1546 /* This is the implementation of target_ops method to_trace_find.
1547 Iterate the events whose name is "frame", extract the tracepoint
1548 number in it. Return traceframe number when matched. */
1551 ctf_target::trace_find (enum trace_find_type type, int num,
1552 CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
1564 gdb_assert (ctf_iter != NULL);
1565 /* Set iterator back to the start. */
1566 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), start_pos);
1570 struct bt_ctf_event *event;
1573 event = bt_ctf_iter_read_event (ctf_iter);
1575 name = bt_ctf_event_name (event);
1577 if (event == NULL || name == NULL)
1580 if (strcmp (name, "frame") == 0)
1584 if (type == tfind_number)
1586 /* Looking for a specific trace frame. */
1592 /* Start from the _next_ trace frame. */
1593 if (tfnum > get_traceframe_number ())
1599 struct tracepoint *tp = get_tracepoint (num);
1602 && (tp->number_on_target
1603 == ctf_get_tpnum_from_frame_event (event)))
1608 tfaddr = ctf_get_traceframe_address ();
1609 if (tfaddr == addr1)
1613 tfaddr = ctf_get_traceframe_address ();
1614 if (addr1 <= tfaddr && tfaddr <= addr2)
1618 tfaddr = ctf_get_traceframe_address ();
1619 if (!(addr1 <= tfaddr && tfaddr <= addr2))
1623 internal_error (__FILE__, __LINE__, _("unknown tfind type"));
1630 *tpp = ctf_get_tpnum_from_frame_event (event);
1632 /* Skip the event "frame". */
1633 bt_iter_next (bt_ctf_get_iter (ctf_iter));
1640 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1647 /* This is the implementation of target_ops method to_traceframe_info.
1648 Iterate the events whose name is "memory", in current
1649 frame, extract memory range information, and return them in
1653 ctf_target::traceframe_info ()
1655 traceframe_info_up info (new struct traceframe_info);
1657 struct bt_iter_pos *pos;
1659 gdb_assert (ctf_iter != NULL);
1660 /* Save the current position. */
1661 pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
1662 gdb_assert (pos->type == BT_SEEK_RESTORE);
1666 struct bt_ctf_event *event
1667 = bt_ctf_iter_read_event (ctf_iter);
1669 name = bt_ctf_event_name (event);
1671 if (name == NULL || strcmp (name, "register") == 0
1672 || strcmp (name, "frame") == 0)
1674 else if (strcmp (name, "memory") == 0)
1676 const struct bt_definition *scope
1677 = bt_ctf_get_top_level_scope (event,
1679 const struct bt_definition *def;
1681 def = bt_ctf_get_field (event, scope, "address");
1682 CORE_ADDR start = bt_ctf_get_uint64 (def);
1684 def = bt_ctf_get_field (event, scope, "length");
1685 int length = (uint16_t) bt_ctf_get_uint64 (def);
1687 info->memory.emplace_back (start, length);
1689 else if (strcmp (name, "tsv") == 0)
1692 const struct bt_definition *scope
1693 = bt_ctf_get_top_level_scope (event,
1695 const struct bt_definition *def;
1697 def = bt_ctf_get_field (event, scope, "num");
1698 vnum = (int) bt_ctf_get_uint64 (def);
1699 info->tvars.push_back (vnum);
1703 warning (_("Unhandled trace block type (%s) "
1704 "while building trace frame info."),
1708 if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
1711 while (name != NULL && strcmp (name, "frame") != 0);
1713 /* Restore the position. */
1714 bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
1721 /* module initialization */
1724 _initialize_ctf (void)
1726 #if HAVE_LIBBABELTRACE
1727 add_target (ctf_target_info, ctf_target_open, filename_completer);