]> git.proxmox.com Git - mirror_qemu.git/blame - include/sysemu/replay.h
gdbstub: add reverse step support in replay mode
[mirror_qemu.git] / include / sysemu / replay.h
CommitLineData
d73abd6d
PD
1#ifndef REPLAY_H
2#define REPLAY_H
3
4/*
5 * replay.h
6 *
7 * Copyright (c) 2010-2015 Institute for System Programming
8 * of the Russian Academy of Sciences.
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
12 *
13 */
14
112ed241 15#include "qapi/qapi-types-misc.h"
d5938f29 16#include "qapi/qapi-types-run-state.h"
43d7e1d7 17#include "qapi/qapi-types-replay.h"
112ed241 18#include "qapi/qapi-types-ui.h"
e4ec5ad4 19#include "block/aio.h"
d73abd6d 20
8eda206e
PD
21/* replay clock kinds */
22enum ReplayClockKind {
23 /* host_clock */
24 REPLAY_CLOCK_HOST,
25 /* virtual_rt_clock */
26 REPLAY_CLOCK_VIRTUAL_RT,
27 REPLAY_CLOCK_COUNT
28};
29typedef enum ReplayClockKind ReplayClockKind;
30
8bd7f71d
PD
31/* IDs of the checkpoints */
32enum ReplayCheckpoint {
e76d1798
PD
33 CHECKPOINT_CLOCK_WARP_START,
34 CHECKPOINT_CLOCK_WARP_ACCOUNT,
8bd7f71d
PD
35 CHECKPOINT_RESET_REQUESTED,
36 CHECKPOINT_SUSPEND_REQUESTED,
37 CHECKPOINT_CLOCK_VIRTUAL,
38 CHECKPOINT_CLOCK_HOST,
39 CHECKPOINT_CLOCK_VIRTUAL_RT,
40 CHECKPOINT_INIT,
41 CHECKPOINT_RESET,
42 CHECKPOINT_COUNT
43};
44typedef enum ReplayCheckpoint ReplayCheckpoint;
45
646c5478
PD
46typedef struct ReplayNetState ReplayNetState;
47
d73abd6d
PD
48extern ReplayMode replay_mode;
49
9c2037d0
PD
50/* Name of the initial VM snapshot */
51extern char *replay_snapshot;
52
a36544d3
AB
53/* Replay locking
54 *
55 * The locks are needed to protect the shared structures and log file
56 * when doing record/replay. They also are the main sync-point between
57 * the main-loop thread and the vCPU thread. This was a role
58 * previously filled by the BQL which has been busy trying to reduce
59 * its impact across the code. This ensures blocks of events stay
60 * sequential and reproducible.
61 */
62
63void replay_mutex_lock(void);
64void replay_mutex_unlock(void);
65
7615936e
PD
66/* Replay process control functions */
67
68/*! Enables recording or saving event log with specified parameters */
69void replay_configure(struct QemuOpts *opts);
70/*! Initializes timers used for snapshotting and enables events recording */
71void replay_start(void);
72/*! Closes replay log file and frees other resources. */
73void replay_finish(void);
0194749a
PD
74/*! Adds replay blocker with the specified error description */
75void replay_add_blocker(Error *reason);
56db1198
PD
76/* Returns name of the replay log file */
77const char *replay_get_filename(void);
fda8458b
PD
78/*
79 * Start making one step in backward direction.
80 * Used by gdbstub for backwards debugging.
81 * Returns true on success.
82 */
83bool replay_reverse_step(void);
84/*
85 * Returns true if replay module is processing
86 * reverse_continue or reverse_step request
87 */
88bool replay_running_debug(void);
7615936e 89
26bc60ac
PD
90/* Processing the instructions */
91
92/*! Returns number of executed instructions. */
13f26713 93uint64_t replay_get_current_icount(void);
8b427044
PD
94/*! Returns number of instructions to execute in replay mode. */
95int replay_get_instructions(void);
96/*! Updates instructions counter in replay mode. */
97void replay_account_executed_instructions(void);
26bc60ac 98
6f060969
PD
99/* Interrupts and exceptions */
100
101/*! Called by exception handler to write or read
102 exception processing events. */
103bool replay_exception(void);
104/*! Used to determine that exception is pending.
105 Does not proceed to the next event in the log. */
106bool replay_has_exception(void);
107/*! Called by interrupt handlers to write or read
108 interrupt processing events.
109 \return true if interrupt should be processed */
110bool replay_interrupt(void);
111/*! Tries to read interrupt event from the file.
112 Returns true, when interrupt request is pending */
113bool replay_has_interrupt(void);
114
8eda206e
PD
115/* Processing clocks and other time sources */
116
117/*! Save the specified clock */
74c0b816
PB
118int64_t replay_save_clock(ReplayClockKind kind, int64_t clock,
119 int64_t raw_icount);
8eda206e
PD
120/*! Read the specified clock from the log or return cached data */
121int64_t replay_read_clock(ReplayClockKind kind);
122/*! Saves or reads the clock depending on the current replay mode. */
123#define REPLAY_CLOCK(clock, value) \
124 (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \
125 : replay_mode == REPLAY_MODE_RECORD \
8191d368 126 ? replay_save_clock((clock), (value), icount_get_raw()) \
74c0b816
PB
127 : (value))
128#define REPLAY_CLOCK_LOCKED(clock, value) \
129 (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \
130 : replay_mode == REPLAY_MODE_RECORD \
8191d368 131 ? replay_save_clock((clock), (value), icount_get_raw_locked()) \
8eda206e
PD
132 : (value))
133
878ec29b
PD
134/* Processing data from random generators */
135
136/* Saves the values from the random number generator */
137void replay_save_random(int ret, void *buf, size_t len);
138/* Loads the saved values for the random number generator */
139int replay_read_random(void *buf, size_t len);
140
b60c48a7
PD
141/* Events */
142
143/*! Called when qemu shutdown is requested. */
802f045a 144void replay_shutdown_request(ShutdownCause cause);
8bd7f71d
PD
145/*! Should be called at check points in the execution.
146 These check points are skipped, if they were not met.
147 Saves checkpoint in the SAVE mode and validates in the PLAY mode.
148 Returns 0 in PLAY mode if checkpoint was not found.
149 Returns 1 in all other cases. */
150bool replay_checkpoint(ReplayCheckpoint checkpoint);
0c08185f
PD
151/*! Used to determine that checkpoint is pending.
152 Does not proceed to the next event in the log. */
153bool replay_has_checkpoint(void);
b60c48a7 154
c0c071d0
PD
155/* Asynchronous events queue */
156
157/*! Disables storing events in the queue */
158void replay_disable_events(void);
6d0ceb80
PD
159/*! Enables storing events in the queue */
160void replay_enable_events(void);
c0c071d0
PD
161/*! Returns true when saving events is enabled */
162bool replay_events_enabled(void);
f9a9fb65
PD
163/* Flushes events queue */
164void replay_flush_events(void);
8a354bd9
PD
165/*! Adds bottom half event to the queue */
166void replay_bh_schedule_event(QEMUBH *bh);
e4ec5ad4
PD
167/* Adds oneshot bottom half event to the queue */
168void replay_bh_schedule_oneshot_event(AioContext *ctx,
169 QEMUBHFunc *cb, void *opaque);
ee312992
PD
170/*! Adds input event to the queue */
171void replay_input_event(QemuConsole *src, InputEvent *evt);
172/*! Adds input sync event to the queue */
173void replay_input_sync_event(void);
63785678
PD
174/*! Adds block layer event to the queue */
175void replay_block_event(QEMUBH *bh, uint64_t id);
6d0ceb80
PD
176/*! Returns ID for the next block event */
177uint64_t blkreplay_next_id(void);
6f060969 178
33577b47
PD
179/* Character device */
180
181/*! Registers char driver to save it's events */
0ec7b3e7 182void replay_register_char_driver(struct Chardev *chr);
33577b47 183/*! Saves write to char device event to the log */
0ec7b3e7 184void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len);
33577b47
PD
185/*! Writes char write return value to the replay log. */
186void replay_char_write_event_save(int res, int offset);
187/*! Reads char write return value from the replay log. */
188void replay_char_write_event_load(int *res, int *offset);
189/*! Reads information about read_all character event. */
190int replay_char_read_all_load(uint8_t *buf);
191/*! Writes character read_all error code into the replay log. */
192void replay_char_read_all_save_error(int res);
193/*! Writes character read_all execution result into the replay log. */
194void replay_char_read_all_save_buf(uint8_t *buf, int offset);
195
646c5478
PD
196/* Network */
197
198/*! Registers replay network filter attached to some backend. */
199ReplayNetState *replay_register_net(NetFilterState *nfs);
200/*! Unregisters replay network filter. */
201void replay_unregister_net(ReplayNetState *rns);
202/*! Called to write network packet to the replay log. */
203void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
204 const struct iovec *iov, int iovcnt);
205
3d4d16f4
PD
206/* Audio */
207
208/*! Saves/restores number of played samples of audio out operation. */
7520462b 209void replay_audio_out(size_t *played);
3d4d16f4 210/*! Saves/restores recorded samples of audio in operation. */
7520462b 211void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);
3d4d16f4 212
9c2037d0
PD
213/* VM state operations */
214
215/*! Called at the start of execution.
216 Loads or saves initial vmstate depending on execution mode. */
217void replay_vmstate_init(void);
377b21cc
PD
218/*! Called to ensure that replay state is consistent and VM snapshot
219 can be created */
220bool replay_can_snapshot(void);
9c2037d0 221
d73abd6d 222#endif