@@ -11,7 +11,8 @@ static void log_insn_mem_access(unsigned int vcpu_index,
11
11
qemu_plugin_meminfo_t info , uint64_t vaddr ,
12
12
void * userdata ) {}
13
13
14
- static void add_post_state_regs (VCPU * vcpu , unsigned int vcpu_index , GArray * current_regs ) {
14
+ static void add_post_reg_state (VCPU * vcpu , unsigned int vcpu_index ,
15
+ GArray * current_regs , FrameBuffer * fbuf ) {
15
16
GByteArray * rtmp = g_byte_array_new ();
16
17
for (size_t i = 0 ; i < current_regs -> len ; ++ i ) {
17
18
Register * prev_reg = vcpu -> registers -> pdata [i ];
@@ -26,36 +27,75 @@ static void add_post_state_regs(VCPU *vcpu, unsigned int vcpu_index, GArray *cur
26
27
}
27
28
28
29
OperandInfo * rinfo = init_reg_operand_info (prev_reg -> name , rtmp -> data ,
29
- rtmp -> len , OperandRead );
30
+ rtmp -> len , OperandWritten );
30
31
g_assert (rinfo );
32
+ frame_buffer_append_op_info (fbuf , rinfo );
33
+ }
34
+ }
31
35
32
- g_rw_lock_writer_lock (& state .frame_buffer_lock );
33
- FrameBuffer * fb = g_ptr_array_index (state .frame_buffer , vcpu_index );
34
- frame_buffer_append_op_info (fb , rinfo );
35
- g_rw_lock_writer_unlock (& state .frame_buffer_lock );
36
+ static void add_pre_reg_state (VCPU * vcpu , unsigned int vcpu_index ,
37
+ GArray * current_regs , FrameBuffer * fbuf ) {
38
+ GByteArray * rtmp = g_byte_array_new ();
39
+ for (size_t i = 0 ; i < current_regs -> len ; ++ i ) {
40
+ qemu_plugin_reg_descriptor * reg =
41
+ & g_array_index (current_regs , qemu_plugin_reg_descriptor , i );
42
+ qemu_plugin_read_register (reg -> handle , rtmp );
43
+ OperandInfo * rinfo = init_reg_operand_info (reg -> name , rtmp -> data ,
44
+ rtmp -> len , OperandRead );
45
+ g_assert (rinfo );
46
+ frame_buffer_append_op_info (fbuf , rinfo );
36
47
}
37
48
}
38
49
50
+ static void add_new_insn_frame (VCPU * vcpu , unsigned int vcpu_index ,
51
+ FrameBuffer * fbuf , Instruction * insn ) {
52
+ Frame * frame = frame_buffer_new_frame (fbuf );
53
+ frame__init (frame );
54
+
55
+ StdFrame * sframe = g_new (StdFrame , 1 );
56
+ std_frame__init (sframe );
57
+ frame -> std_frame = sframe ;
58
+
59
+ sframe -> thread_id = vcpu_index ;
60
+ sframe -> address = insn -> vaddr ;
61
+ sframe -> rawbytes .len = insn -> size ;
62
+ sframe -> rawbytes .data = g_malloc (insn -> size );
63
+ memcpy (sframe -> rawbytes .data , insn -> bytes , insn -> size );
64
+
65
+ OperandValueList * ol_in = g_new (OperandValueList , 1 );
66
+ operand_value_list__init (ol_in );
67
+ ol_in -> n_elem = 0 ;
68
+ sframe -> operand_pre_list = ol_in ;
69
+
70
+ OperandValueList * ol_out = g_new (OperandValueList , 1 );
71
+ operand_value_list__init (ol_out );
72
+ ol_out -> n_elem = 0 ;
73
+ sframe -> operand_post_list = ol_out ;
74
+ }
75
+
39
76
static void log_insn_reg_access (unsigned int vcpu_index , void * udata ) {
40
77
g_rw_lock_reader_lock (& state .vcpus_array_lock );
78
+ g_rw_lock_writer_lock (& state .frame_buffer_lock );
79
+ g_rw_lock_writer_lock (& state .file_lock );
41
80
81
+ FrameBuffer * fbuf = g_ptr_array_index (state .frame_buffer , vcpu_index );
42
82
VCPU * vcpu = & g_array_index (state .vcpus , VCPU , vcpu_index );
43
83
GArray * current_regs = qemu_plugin_get_registers ();
44
84
g_assert (current_regs -> len == vcpu -> registers -> len );
45
85
46
- add_post_state_regs (vcpu , vcpu_index , current_regs );
86
+ add_post_reg_state (vcpu , vcpu_index , current_regs , fbuf );
47
87
48
- g_rw_lock_writer_lock (& state .frame_buffer_lock );
49
- g_rw_lock_writer_lock (& state .file_lock );
50
- FrameBuffer * vcpu_buf = g_ptr_array_index (state .frame_buffer , vcpu_index );
51
- if (frame_buffer_is_full (vcpu_buf )) {
52
- frame_buffer_flush_to_file (vcpu_buf , state .file );
88
+ if (frame_buffer_is_full (fbuf )) {
89
+ frame_buffer_flush_to_file (fbuf , state .file );
53
90
}
54
- g_rw_lock_writer_unlock (& state .file_lock );
55
- g_rw_lock_writer_unlock (& state .frame_buffer_lock );
56
91
57
92
// Open new one.
58
93
Instruction * insn = udata ;
94
+ add_new_insn_frame (vcpu , vcpu_index , fbuf , insn );
95
+ add_pre_reg_state (vcpu , vcpu_index , current_regs , fbuf );
96
+
97
+ g_rw_lock_writer_unlock (& state .file_lock );
98
+ g_rw_lock_writer_unlock (& state .frame_buffer_lock );
59
99
g_rw_lock_reader_unlock (& state .vcpus_array_lock );
60
100
61
101
return ;
0 commit comments