4 * Copyright (c) 2010-2016 Institute for System Programming
5 * of the Russian Academy of Sciences.
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu-common.h"
15 #include "sysemu/replay.h"
16 #include "replay-internal.h"
17 #include "sysemu/sysemu.h"
18 #include "monitor/monitor.h"
19 #include "qapi/qmp/qstring.h"
20 #include "qemu/error-report.h"
21 #include "migration/vmstate.h"
22 #include "migration/snapshot.h"
24 static void replay_pre_save(void *opaque
)
26 ReplayState
*state
= opaque
;
27 state
->file_offset
= ftell(replay_file
);
30 static int replay_post_load(void *opaque
, int version_id
)
32 ReplayState
*state
= opaque
;
33 fseek(replay_file
, state
->file_offset
, SEEK_SET
);
34 /* If this was a vmstate, saved in recording mode,
35 we need to initialize replay data fields. */
36 replay_fetch_data_kind();
41 static const VMStateDescription vmstate_replay
= {
44 .minimum_version_id
= 1,
45 .pre_save
= replay_pre_save
,
46 .post_load
= replay_post_load
,
47 .fields
= (VMStateField
[]) {
48 VMSTATE_INT64_ARRAY(cached_clock
, ReplayState
, REPLAY_CLOCK_COUNT
),
49 VMSTATE_UINT64(current_step
, ReplayState
),
50 VMSTATE_INT32(instructions_count
, ReplayState
),
51 VMSTATE_UINT32(data_kind
, ReplayState
),
52 VMSTATE_UINT32(has_unread_data
, ReplayState
),
53 VMSTATE_UINT64(file_offset
, ReplayState
),
54 VMSTATE_UINT64(block_request_id
, ReplayState
),
59 void replay_vmstate_register(void)
61 vmstate_register(NULL
, 0, &vmstate_replay
, &replay_state
);
64 void replay_vmstate_init(void)
68 if (replay_snapshot
) {
69 if (replay_mode
== REPLAY_MODE_RECORD
) {
70 if (save_snapshot(replay_snapshot
, &err
) != 0) {
71 error_report_err(err
);
72 error_report("Could not create snapshot for icount record");
75 } else if (replay_mode
== REPLAY_MODE_PLAY
) {
76 if (load_snapshot(replay_snapshot
, &err
) != 0) {
77 error_report_err(err
);
78 error_report("Could not load snapshot for icount replay");