@@ -15,6 +15,7 @@ static void log_insn_mem_access(unsigned int vcpu_index,
15
15
16
16
static void add_post_reg_state (VCPU * vcpu , unsigned int vcpu_index ,
17
17
GArray * current_regs , FrameBuffer * fbuf ) {
18
+
18
19
GByteArray * rdata = g_byte_array_new ();
19
20
for (size_t i = 0 ; i < current_regs -> len ; ++ i ) {
20
21
Register * prev_reg = vcpu -> registers -> pdata [i ];
@@ -28,7 +29,8 @@ static void add_post_reg_state(VCPU *vcpu, unsigned int vcpu_index,
28
29
continue ;
29
30
}
30
31
31
- if (!frame_buffer_append_reg_info (fbuf , reg -> name , rdata , OperandWritten )) {
32
+ if (!frame_buffer_append_reg_info (fbuf , reg -> name , rdata , s ,
33
+ OperandWritten )) {
32
34
qemu_plugin_outs ("Failed to append opinfo.\n" );
33
35
g_assert (false);
34
36
}
@@ -41,15 +43,15 @@ static void add_pre_reg_state(VCPU *vcpu, unsigned int vcpu_index,
41
43
for (size_t i = 0 ; i < current_regs -> len ; ++ i ) {
42
44
qemu_plugin_reg_descriptor * reg =
43
45
& g_array_index (current_regs , qemu_plugin_reg_descriptor , i );
44
- qemu_plugin_read_register (reg -> handle , rdata );
45
- frame_buffer_append_reg_info (fbuf , reg -> name , rdata , OperandRead );
46
+ size_t s = qemu_plugin_read_register (reg -> handle , rdata );
47
+ frame_buffer_append_reg_info (fbuf , reg -> name , rdata , s , OperandRead );
46
48
}
47
49
}
48
50
49
- static void add_new_insn_frame (VCPU * vcpu , unsigned int vcpu_index ,
51
+ static bool add_new_insn_frame (VCPU * vcpu , unsigned int vcpu_index ,
50
52
FrameBuffer * fbuf , Instruction * insn ) {
51
- frame_buffer_new_frame_std (fbuf , vcpu_index , insn -> vaddr , insn -> bytes ,
52
- insn -> size );
53
+ return frame_buffer_new_frame_std (fbuf , vcpu_index , insn -> vaddr , insn -> bytes ,
54
+ insn -> size );
53
55
}
54
56
55
57
static GPtrArray * registers_init (void ) {
@@ -77,18 +79,13 @@ static void log_insn_reg_access(unsigned int vcpu_index, void *udata) {
77
79
FrameBuffer * fbuf = g_ptr_array_index (state .frame_buffer , vcpu_index );
78
80
VCPU * vcpu = g_ptr_array_index (state .vcpus , vcpu_index );
79
81
g_assert (vcpu );
80
- if (!vcpu -> registers ) {
81
- vcpu -> registers = registers_init ();
82
- if (!vcpu -> registers ) {
83
- // Registers are still not available. So return until the VCPU is
84
- // sufficiently initialized.
85
- goto unlock_return ;
86
- }
87
- }
88
82
GArray * current_regs = qemu_plugin_get_registers ();
89
83
g_assert (current_regs -> len == vcpu -> registers -> len );
90
84
91
- add_post_reg_state (vcpu , vcpu_index , current_regs , fbuf );
85
+ if (!frame_buffer_is_empty (fbuf )) {
86
+ add_post_reg_state (vcpu , vcpu_index , current_regs , fbuf );
87
+ frame_buffer_close_frame (fbuf );
88
+ }
92
89
93
90
if (frame_buffer_is_full (fbuf )) {
94
91
g_rw_lock_writer_lock (& state .file_lock );
@@ -101,7 +98,6 @@ static void log_insn_reg_access(unsigned int vcpu_index, void *udata) {
101
98
add_new_insn_frame (vcpu , vcpu_index , fbuf , insn );
102
99
add_pre_reg_state (vcpu , vcpu_index , current_regs , fbuf );
103
100
104
- unlock_return :
105
101
g_rw_lock_reader_unlock (& state .frame_buffer_lock );
106
102
g_rw_lock_reader_unlock (& state .vcpus_array_lock );
107
103
}
@@ -125,6 +121,10 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) {
125
121
g_rw_lock_writer_lock (& state .frame_buffer_lock );
126
122
127
123
VCPU * vcpu = g_malloc0 (sizeof (VCPU ));
124
+ vcpu -> registers = registers_init ();
125
+ if (!vcpu -> registers ) {
126
+ g_assert (false);
127
+ }
128
128
g_ptr_array_insert (state .vcpus , vcpu_index , vcpu );
129
129
130
130
FrameBuffer * vcpu_frame_buffer = frame_buffer_new (FRAME_BUFFER_SIZE_DEFAULT );
0 commit comments