7
7
8
8
static TraceState state ;
9
9
10
- #pragma GCC diagnostic push
11
- #pragma GCC diagnostic ignored "-Wunused-function"
12
- static VCPU * get_vcpu (TraceState * state , int vcpu_index ) {
13
- VCPU * c ;
14
- g_rw_lock_reader_lock (& state -> vcpus_array_lock );
15
- c = & g_array_index (state -> vcpus , VCPU , vcpu_index );
16
- g_rw_lock_reader_unlock (& state -> vcpus_array_lock );
17
-
18
- return c ;
19
- }
20
- #pragma GCC diagnostic pop
21
-
22
- static void log_insn_frame (unsigned int cpu_index , void * udata ) {
23
- // VCPU *vcpu = get_vcpu(state, cpu_index);
10
+ static void log_insn_exec (unsigned int vcpu_index , void * udata ) {
11
+ g_rw_lock_reader_lock (& state .vcpus_array_lock );
12
+ // VCPU *c = &g_array_index(state.vcpus, VCPU, vcpu_index);
24
13
14
+ g_rw_lock_writer_lock (& state .frame_buffer_lock );
25
15
// Add change to previous frame
26
16
// Finish previous frame
27
17
// Check if buffer should be dumped to file.
28
18
// Open new one.
19
+ g_rw_lock_writer_unlock (& state .frame_buffer_lock );
20
+ g_rw_lock_reader_unlock (& state .vcpus_array_lock );
21
+
29
22
return ;
30
23
}
31
24
32
25
static void vcpu_init (qemu_plugin_id_t id , unsigned int vcpu_index ) {
33
- // Add new vcpu
26
+ g_rw_lock_writer_lock (& state .vcpus_array_lock );
27
+ VCPU * vcpu = calloc (sizeof (VCPU ), 1 );
28
+ g_array_insert_vals (state .vcpus , vcpu_index , & vcpu , 1 );
29
+ g_rw_lock_writer_unlock (& state .vcpus_array_lock );
34
30
}
35
31
36
32
static void plugin_exit (qemu_plugin_id_t id , void * udata ) {
@@ -43,23 +39,25 @@ static void cb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) {
43
39
size_t n_insns = qemu_plugin_tb_n_insns (tb );
44
40
for (size_t i = 0 ; i < n_insns ; i ++ ) {
45
41
insn = qemu_plugin_tb_get_insn (tb , i );
46
- qemu_plugin_register_vcpu_insn_exec_cb (insn , log_insn_frame ,
47
- QEMU_PLUGIN_CB_R_REGS , & state );
42
+ qemu_plugin_register_vcpu_insn_exec_cb (insn , log_insn_exec ,
43
+ QEMU_PLUGIN_CB_R_REGS , NULL );
48
44
}
49
45
}
50
46
51
47
QEMU_PLUGIN_EXPORT int qemu_plugin_install (qemu_plugin_id_t id ,
52
48
const qemu_info_t * info , int argc ,
53
49
char * * argv ) {
50
+ const char * target_path = "/tmp/test.trace" ;
51
+ state .frame_buffer = frame_buffer_init (FRAME_BUFFER_SIZE );
52
+ state .vcpus = g_array_new (false, true, sizeof (VCPU ));
53
+ state .file = fopen (target_path , "r" );
54
+ if (!(state .frame_buffer || state .vcpus || state .file )) {
55
+ return 1 ;
56
+ }
57
+
54
58
qemu_plugin_register_vcpu_init_cb (id , vcpu_init );
55
59
qemu_plugin_register_vcpu_tb_trans_cb (id , cb_trans );
56
60
qemu_plugin_register_atexit_cb (id , plugin_exit , NULL );
57
61
58
- // Get reg names
59
- // qemu_plugin_get_registers
60
- //
61
- // Logging
62
- // qemu_plugin_outs
63
-
64
62
return 0 ;
65
63
}
0 commit comments