1 1.7 christos /* Tracefile declarations 2 1.7 christos Copyright (C) 2014-2024 Free Software Foundation, Inc. 3 1.7 christos 4 1.7 christos This file is part of GDB. 5 1.7 christos 6 1.7 christos This program is free software; you can redistribute it and/or modify 7 1.7 christos it under the terms of the GNU General Public License as published by 8 1.7 christos the Free Software Foundation; either version 3 of the License, or 9 1.7 christos (at your option) any later version. 10 1.7 christos 11 1.7 christos This program is distributed in the hope that it will be useful, 12 1.7 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.7 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.7 christos GNU General Public License for more details. 15 1.7 christos 16 1.7 christos You should have received a copy of the GNU General Public License 17 1.7 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 1.7 christos 19 1.7 christos #ifndef GDB_TRACEFILE_H 20 1.7 christos #define GDB_TRACEFILE_H 21 1.1 christos 22 1.1 christos #include "tracepoint.h" 23 1.5 christos #include "target.h" 24 1.5 christos #include "process-stratum-target.h" 25 1.1 christos 26 1.1 christos struct trace_file_writer; 27 1.1 christos 28 1.1 christos /* Operations to write trace frames to a specific trace format. */ 29 1.1 christos 30 1.1 christos struct trace_frame_write_ops 31 1.1 christos { 32 1.1 christos /* Write a new trace frame. The tracepoint number of this trace 33 1.1 christos frame is TPNUM. */ 34 1.1 christos void (*start) (struct trace_file_writer *self, uint16_t tpnum); 35 1.1 christos 36 1.1 christos /* Write an 'R' block. Buffer BUF contains its contents and SIZE is 37 1.1 christos its size. */ 38 1.1 christos void (*write_r_block) (struct trace_file_writer *self, 39 1.1 christos gdb_byte *buf, int32_t size); 40 1.1 christos 41 1.1 christos /* Write an 'M' block, the header and memory contents respectively. 42 1.1 christos The header of 'M' block is composed of the start address and the 43 1.1 christos length of memory collection, and the memory contents contain 44 1.1 christos the collected memory contents in tracing. 45 1.1 christos For extremely large M block, GDB is unable to get its contents 46 1.1 christos and write them into trace file in one go, due to the limitation 47 1.1 christos of the remote target or the size of internal buffer, we split 48 1.1 christos the operation to 'M' block to two operations. */ 49 1.1 christos /* Write the head of 'M' block. ADDR is the start address of 50 1.1 christos collected memory and LENGTH is the length of memory contents. */ 51 1.1 christos void (*write_m_block_header) (struct trace_file_writer *self, 52 1.1 christos uint64_t addr, uint16_t length); 53 1.1 christos /* Write the memory contents of 'M' block. Buffer BUF contains 54 1.1 christos its contents and LENGTH is its length. This method can be called 55 1.1 christos multiple times to write large memory contents of a single 'M' 56 1.1 christos block. */ 57 1.1 christos void (*write_m_block_memory) (struct trace_file_writer *self, 58 1.1 christos gdb_byte *buf, uint16_t length); 59 1.1 christos 60 1.1 christos /* Write a 'V' block. NUM is the trace variable number and VAL is 61 1.1 christos the value of the trace variable. */ 62 1.1 christos void (*write_v_block) (struct trace_file_writer *self, int32_t num, 63 1.1 christos uint64_t val); 64 1.1 christos 65 1.1 christos /* The end of the trace frame. */ 66 1.1 christos void (*end) (struct trace_file_writer *self); 67 1.1 christos }; 68 1.1 christos 69 1.1 christos /* Operations to write trace buffers to a specific trace format. */ 70 1.1 christos 71 1.1 christos struct trace_file_write_ops 72 1.1 christos { 73 1.1 christos /* Destructor. Releases everything from SELF (but not SELF 74 1.1 christos itself). */ 75 1.1 christos void (*dtor) (struct trace_file_writer *self); 76 1.1 christos 77 1.1 christos /* Save the data to file or directory NAME of desired format in 78 1.1 christos target side. Return true for success, otherwise return 79 1.1 christos false. */ 80 1.1 christos int (*target_save) (struct trace_file_writer *self, 81 1.1 christos const char *name); 82 1.1 christos 83 1.1 christos /* Write the trace buffers to file or directory NAME. */ 84 1.1 christos void (*start) (struct trace_file_writer *self, 85 1.1 christos const char *name); 86 1.1 christos 87 1.1 christos /* Write the trace header. */ 88 1.1 christos void (*write_header) (struct trace_file_writer *self); 89 1.1 christos 90 1.1 christos /* Write the type of block about registers. SIZE is the size of 91 1.1 christos all registers on the target. */ 92 1.1 christos void (*write_regblock_type) (struct trace_file_writer *self, 93 1.1 christos int size); 94 1.1 christos 95 1.1 christos /* Write trace status TS. */ 96 1.1 christos void (*write_status) (struct trace_file_writer *self, 97 1.1 christos struct trace_status *ts); 98 1.1 christos 99 1.1 christos /* Write the uploaded TSV. */ 100 1.1 christos void (*write_uploaded_tsv) (struct trace_file_writer *self, 101 1.1 christos struct uploaded_tsv *tsv); 102 1.1 christos 103 1.1 christos /* Write the uploaded tracepoint TP. */ 104 1.1 christos void (*write_uploaded_tp) (struct trace_file_writer *self, 105 1.1 christos struct uploaded_tp *tp); 106 1.1 christos 107 1.4 christos /* Write target description. */ 108 1.4 christos void (*write_tdesc) (struct trace_file_writer *self); 109 1.4 christos 110 1.1 christos /* Write to mark the end of the definition part. */ 111 1.1 christos void (*write_definition_end) (struct trace_file_writer *self); 112 1.1 christos 113 1.1 christos /* Write the data of trace buffer without parsing. The content is 114 1.1 christos in BUF and length is LEN. */ 115 1.1 christos void (*write_trace_buffer) (struct trace_file_writer *self, 116 1.1 christos gdb_byte *buf, LONGEST len); 117 1.1 christos 118 1.1 christos /* Operations to write trace frames. The user of this field is 119 1.1 christos responsible to parse the data of trace buffer. Either field 120 1.1 christos 'write_trace_buffer' or field ' frame_ops' is NULL. */ 121 1.1 christos const struct trace_frame_write_ops *frame_ops; 122 1.1 christos 123 1.1 christos /* The end of writing trace buffers. */ 124 1.1 christos void (*end) (struct trace_file_writer *self); 125 1.1 christos }; 126 1.1 christos 127 1.1 christos /* Trace file writer for a given format. */ 128 1.1 christos 129 1.1 christos struct trace_file_writer 130 1.1 christos { 131 1.1 christos const struct trace_file_write_ops *ops; 132 1.1 christos }; 133 1.1 christos 134 1.1 christos extern struct trace_file_writer *tfile_trace_file_writer_new (void); 135 1.1 christos 136 1.5 christos /* Base class for tracefile related targets. */ 137 1.5 christos 138 1.5 christos class tracefile_target : public process_stratum_target 139 1.5 christos { 140 1.5 christos public: 141 1.5 christos tracefile_target () = default; 142 1.5 christos 143 1.5 christos int get_trace_status (trace_status *ts) override; 144 1.5 christos bool has_all_memory () override; 145 1.5 christos bool has_memory () override; 146 1.5 christos bool has_stack () override; 147 1.5 christos bool has_registers () override; 148 1.6 christos bool has_execution (inferior *inf) override { return false; } 149 1.5 christos bool thread_alive (ptid_t ptid) override; 150 1.5 christos }; 151 1.1 christos 152 1.1 christos extern void tracefile_fetch_registers (struct regcache *regcache, int regno); 153 1.1 christos 154 1.7 christos #endif /* GDB_TRACEFILE_H */ 155