7
7
8
8
static TraceState state ;
9
9
10
- static void log_insn_exec (unsigned int vcpu_index , void * udata ) {
10
+ static void log_insn_reg_access (unsigned int vcpu_index , void * udata ) {
11
11
g_rw_lock_reader_lock (& state .vcpus_array_lock );
12
12
// VCPU *c = &g_array_index(state.vcpus, VCPU, vcpu_index);
13
13
@@ -22,9 +22,43 @@ static void log_insn_exec(unsigned int vcpu_index, void *udata) {
22
22
return ;
23
23
}
24
24
25
+ static Register * init_vcpu_register (qemu_plugin_reg_descriptor * desc )
26
+ {
27
+ Register * reg = g_new0 (Register , 1 );
28
+ g_autofree gchar * lower = g_utf8_strdown (desc -> name , -1 );
29
+ int r ;
30
+
31
+ reg -> handle = desc -> handle ;
32
+ reg -> name = g_intern_string (lower );
33
+ reg -> content = g_byte_array_new ();
34
+
35
+ /* read the initial value */
36
+ r = qemu_plugin_read_register (reg -> handle , reg -> content );
37
+ g_assert (r > 0 );
38
+ return reg ;
39
+ }
40
+
41
+ static GPtrArray * registers_init (int vcpu_index ) {
42
+ g_autoptr (GPtrArray ) registers = g_ptr_array_new ();
43
+ g_autoptr (GArray ) reg_list = qemu_plugin_get_registers ();
44
+
45
+ if (!reg_list -> len ) {
46
+ return NULL ;
47
+ }
48
+ for (int r = 0 ; r < reg_list -> len ; r ++ ) {
49
+ qemu_plugin_reg_descriptor * rd =
50
+ & g_array_index (reg_list , qemu_plugin_reg_descriptor , r );
51
+ Register * reg = init_vcpu_register (rd );
52
+ g_ptr_array_add (registers , reg );
53
+ }
54
+
55
+ return registers -> len ? g_steal_pointer (& registers ) : NULL ;
56
+ }
57
+
25
58
static void vcpu_init (qemu_plugin_id_t id , unsigned int vcpu_index ) {
26
59
g_rw_lock_writer_lock (& state .vcpus_array_lock );
27
60
VCPU * vcpu = calloc (sizeof (VCPU ), 1 );
61
+ vcpu -> registers = registers_init (vcpu_index );
28
62
g_array_insert_vals (state .vcpus , vcpu_index , & vcpu , 1 );
29
63
g_rw_lock_writer_unlock (& state .vcpus_array_lock );
30
64
}
@@ -39,7 +73,7 @@ static void cb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) {
39
73
size_t n_insns = qemu_plugin_tb_n_insns (tb );
40
74
for (size_t i = 0 ; i < n_insns ; i ++ ) {
41
75
insn = qemu_plugin_tb_get_insn (tb , i );
42
- qemu_plugin_register_vcpu_insn_exec_cb (insn , log_insn_exec ,
76
+ qemu_plugin_register_vcpu_insn_exec_cb (insn , log_insn_reg_access ,
43
77
QEMU_PLUGIN_CB_R_REGS , NULL );
44
78
}
45
79
}
0 commit comments