@@ -97,9 +97,19 @@ static GPtrArray *registers_init(void) {
97
97
return registers -> len ? g_steal_pointer (& registers ) : NULL ;
98
98
}
99
99
100
+ static void write_toc_entry (FrameBuffer * fbuf ) {
101
+ g_rw_lock_writer_lock (& state .file_lock );
102
+ g_rw_lock_writer_lock (& state .toc_entries_offsets_lock );
103
+ frame_buffer_flush_to_file (fbuf , state .file );
104
+ uint64_t next_toc_entry = ftell (state .file );
105
+ g_array_append_val (state .toc_entries_offsets , next_toc_entry );
106
+ g_rw_lock_writer_unlock (& state .toc_entries_offsets_lock );
107
+ g_rw_lock_writer_unlock (& state .file_lock );
108
+ }
109
+
100
110
static void log_insn_reg_access (unsigned int vcpu_index , void * udata ) {
101
111
g_rw_lock_reader_lock (& state .vcpus_array_lock );
102
- g_rw_lock_reader_lock (& state .frame_buffer_lock );
112
+ g_rw_lock_writer_lock (& state .frame_buffer_lock );
103
113
104
114
FrameBuffer * fbuf = g_ptr_array_index (state .frame_buffer , vcpu_index );
105
115
VCPU * vcpu = g_ptr_array_index (state .vcpus , vcpu_index );
@@ -113,17 +123,15 @@ static void log_insn_reg_access(unsigned int vcpu_index, void *udata) {
113
123
}
114
124
115
125
if (frame_buffer_is_full (fbuf )) {
116
- g_rw_lock_writer_lock (& state .file_lock );
117
- frame_buffer_flush_to_file (fbuf , state .file );
118
- g_rw_lock_writer_unlock (& state .file_lock );
126
+ write_toc_entry (fbuf );
119
127
}
120
128
121
129
// Open new one.
122
130
Instruction * insn = udata ;
123
131
add_new_insn_frame (vcpu , vcpu_index , fbuf , insn );
124
132
add_pre_reg_state (vcpu , vcpu_index , current_regs , fbuf );
125
133
126
- g_rw_lock_reader_unlock (& state .frame_buffer_lock );
134
+ g_rw_lock_writer_unlock (& state .frame_buffer_lock );
127
135
g_rw_lock_reader_unlock (& state .vcpus_array_lock );
128
136
}
129
137
@@ -228,9 +236,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
228
236
229
237
const char * target_path = "/tmp/test.trace" ;
230
238
state .frame_buffer = g_ptr_array_new ();
239
+ state .toc_entries_offsets = g_array_new (false, true, sizeof (uint64_t ));
231
240
state .vcpus = g_ptr_array_new ();
232
241
state .file = fopen (target_path , "wb" );
233
- if (!(state .frame_buffer || state .vcpus || state .file )) {
242
+ if (!(state .frame_buffer || state .vcpus || state .file ||
243
+ !state .toc_entries_offsets )) {
234
244
return 1 ;
235
245
}
236
246
for (size_t i = 0 ; i < argc ; ++ i ) {
@@ -242,6 +252,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
242
252
}
243
253
// write_meta(argv, envp, target_argv, target_envp);
244
254
255
+ g_array_append_val (state .toc_entries_offsets , offset_toc_start );
256
+
245
257
qemu_plugin_register_vcpu_init_cb (id , vcpu_init );
246
258
qemu_plugin_register_vcpu_tb_trans_cb (id , cb_trans );
247
259
qemu_plugin_register_atexit_cb (id , plugin_exit , NULL );
0 commit comments