]>
Commit | Line | Data |
---|---|---|
d02ed0bb MM |
1 | /* Process record and replay target for GDB, the GNU debugger. |
2 | ||
213516ef | 3 | Copyright (C) 2013-2023 Free Software Foundation, Inc. |
d02ed0bb MM |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "gdbcmd.h" | |
22 | #include "regcache.h" | |
23 | #include "gdbthread.h" | |
00431a78 | 24 | #include "inferior.h" |
d02ed0bb | 25 | #include "event-top.h" |
d02ed0bb MM |
26 | #include "completer.h" |
27 | #include "arch-utils.h" | |
28 | #include "gdbcore.h" | |
29 | #include "exec.h" | |
30 | #include "record.h" | |
31 | #include "record-full.h" | |
32 | #include "elf-bfd.h" | |
33 | #include "gcore.h" | |
400b5eca | 34 | #include "gdbsupport/event-loop.h" |
d02ed0bb MM |
35 | #include "inf-loop.h" |
36 | #include "gdb_bfd.h" | |
76727919 | 37 | #include "observable.h" |
45741a9c | 38 | #include "infrun.h" |
268a13a5 TT |
39 | #include "gdbsupport/gdb_unlinker.h" |
40 | #include "gdbsupport/byte-vector.h" | |
93b54c8e | 41 | #include "async-event.h" |
e24d337e | 42 | #include "valprint.h" |
d02ed0bb MM |
43 | |
44 | #include <signal.h> | |
45 | ||
46 | /* This module implements "target record-full", also known as "process | |
47 | record and replay". This target sits on top of a "normal" target | |
48 | (a target that "has execution"), and provides a record and replay | |
49 | functionality, including reverse debugging. | |
50 | ||
51 | Target record has two modes: recording, and replaying. | |
52 | ||
f6ac5f3d | 53 | In record mode, we intercept the resume and wait methods. |
d02ed0bb MM |
54 | Whenever gdb resumes the target, we run the target in single step |
55 | mode, and we build up an execution log in which, for each executed | |
56 | instruction, we record all changes in memory and register state. | |
57 | This is invisible to the user, to whom it just looks like an | |
30baf67b | 58 | ordinary debugging session (except for performance degradation). |
d02ed0bb MM |
59 | |
60 | In replay mode, instead of actually letting the inferior run as a | |
61 | process, we simulate its execution by playing back the recorded | |
62 | execution log. For each instruction in the log, we simulate the | |
63 | instruction's side effects by duplicating the changes that it would | |
64 | have made on memory and registers. */ | |
65 | ||
88d1aa9d | 66 | #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000 |
d02ed0bb | 67 | |
88d1aa9d | 68 | #define RECORD_FULL_IS_REPLAY \ |
f6ac5f3d | 69 | (record_full_list->next || ::execution_direction == EXEC_REVERSE) |
d02ed0bb | 70 | |
88d1aa9d | 71 | #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016) |
d02ed0bb MM |
72 | |
73 | /* These are the core structs of the process record functionality. | |
74 | ||
88d1aa9d MM |
75 | A record_full_entry is a record of the value change of a register |
76 | ("record_full_reg") or a part of memory ("record_full_mem"). And each | |
77 | instruction must have a struct record_full_entry ("record_full_end") | |
78 | that indicates that this is the last struct record_full_entry of this | |
d02ed0bb MM |
79 | instruction. |
80 | ||
88d1aa9d MM |
81 | Each struct record_full_entry is linked to "record_full_list" by "prev" |
82 | and "next" pointers. */ | |
d02ed0bb | 83 | |
88d1aa9d | 84 | struct record_full_mem_entry |
d02ed0bb MM |
85 | { |
86 | CORE_ADDR addr; | |
87 | int len; | |
88 | /* Set this flag if target memory for this entry | |
89 | can no longer be accessed. */ | |
90 | int mem_entry_not_accessible; | |
91 | union | |
92 | { | |
93 | gdb_byte *ptr; | |
94 | gdb_byte buf[sizeof (gdb_byte *)]; | |
95 | } u; | |
96 | }; | |
97 | ||
88d1aa9d | 98 | struct record_full_reg_entry |
d02ed0bb MM |
99 | { |
100 | unsigned short num; | |
101 | unsigned short len; | |
102 | union | |
103 | { | |
104 | gdb_byte *ptr; | |
105 | gdb_byte buf[2 * sizeof (gdb_byte *)]; | |
106 | } u; | |
107 | }; | |
108 | ||
88d1aa9d | 109 | struct record_full_end_entry |
d02ed0bb MM |
110 | { |
111 | enum gdb_signal sigval; | |
112 | ULONGEST insn_num; | |
113 | }; | |
114 | ||
88d1aa9d | 115 | enum record_full_type |
d02ed0bb | 116 | { |
88d1aa9d MM |
117 | record_full_end = 0, |
118 | record_full_reg, | |
119 | record_full_mem | |
d02ed0bb MM |
120 | }; |
121 | ||
122 | /* This is the data structure that makes up the execution log. | |
123 | ||
124 | The execution log consists of a single linked list of entries | |
88d1aa9d | 125 | of type "struct record_full_entry". It is doubly linked so that it |
d02ed0bb MM |
126 | can be traversed in either direction. |
127 | ||
128 | The start of the list is anchored by a struct called | |
88d1aa9d MM |
129 | "record_full_first". The pointer "record_full_list" either points |
130 | to the last entry that was added to the list (in record mode), or to | |
131 | the next entry in the list that will be executed (in replay mode). | |
d02ed0bb | 132 | |
88d1aa9d MM |
133 | Each list element (struct record_full_entry), in addition to next |
134 | and prev pointers, consists of a union of three entry types: mem, | |
135 | reg, and end. A field called "type" determines which entry type is | |
d02ed0bb MM |
136 | represented by a given list element. |
137 | ||
138 | Each instruction that is added to the execution log is represented | |
139 | by a variable number of list elements ('entries'). The instruction | |
140 | will have one "reg" entry for each register that is changed by | |
141 | executing the instruction (including the PC in every case). It | |
142 | will also have one "mem" entry for each memory change. Finally, | |
143 | each instruction will have an "end" entry that separates it from | |
144 | the changes associated with the next instruction. */ | |
145 | ||
88d1aa9d | 146 | struct record_full_entry |
d02ed0bb | 147 | { |
88d1aa9d MM |
148 | struct record_full_entry *prev; |
149 | struct record_full_entry *next; | |
150 | enum record_full_type type; | |
d02ed0bb MM |
151 | union |
152 | { | |
153 | /* reg */ | |
88d1aa9d | 154 | struct record_full_reg_entry reg; |
d02ed0bb | 155 | /* mem */ |
88d1aa9d | 156 | struct record_full_mem_entry mem; |
d02ed0bb | 157 | /* end */ |
88d1aa9d | 158 | struct record_full_end_entry end; |
d02ed0bb MM |
159 | } u; |
160 | }; | |
161 | ||
162 | /* If true, query if PREC cannot record memory | |
163 | change of next instruction. */ | |
491144b5 | 164 | bool record_full_memory_query = false; |
d02ed0bb | 165 | |
88d1aa9d | 166 | struct record_full_core_buf_entry |
d02ed0bb | 167 | { |
88d1aa9d | 168 | struct record_full_core_buf_entry *prev; |
d02ed0bb MM |
169 | struct target_section *p; |
170 | bfd_byte *buf; | |
171 | }; | |
172 | ||
173 | /* Record buf with core target. */ | |
c8ec2f33 | 174 | static detached_regcache *record_full_core_regbuf = NULL; |
bb2a6777 | 175 | static target_section_table record_full_core_sections; |
88d1aa9d | 176 | static struct record_full_core_buf_entry *record_full_core_buf_list = NULL; |
d02ed0bb MM |
177 | |
178 | /* The following variables are used for managing the linked list that | |
179 | represents the execution log. | |
180 | ||
88d1aa9d MM |
181 | record_full_first is the anchor that holds down the beginning of |
182 | the list. | |
d02ed0bb | 183 | |
88d1aa9d | 184 | record_full_list serves two functions: |
d02ed0bb MM |
185 | 1) In record mode, it anchors the end of the list. |
186 | 2) In replay mode, it traverses the list and points to | |
dda83cd7 | 187 | the next instruction that must be emulated. |
d02ed0bb | 188 | |
88d1aa9d MM |
189 | record_full_arch_list_head and record_full_arch_list_tail are used |
190 | to manage a separate list, which is used to build up the change | |
191 | elements of the currently executing instruction during record mode. | |
192 | When this instruction has been completely annotated in the "arch | |
193 | list", it will be appended to the main execution log. */ | |
d02ed0bb | 194 | |
88d1aa9d MM |
195 | static struct record_full_entry record_full_first; |
196 | static struct record_full_entry *record_full_list = &record_full_first; | |
197 | static struct record_full_entry *record_full_arch_list_head = NULL; | |
198 | static struct record_full_entry *record_full_arch_list_tail = NULL; | |
d02ed0bb | 199 | |
491144b5 CB |
200 | /* true ask user. false auto delete the last struct record_full_entry. */ |
201 | static bool record_full_stop_at_limit = true; | |
d02ed0bb | 202 | /* Maximum allowed number of insns in execution log. */ |
88d1aa9d MM |
203 | static unsigned int record_full_insn_max_num |
204 | = DEFAULT_RECORD_FULL_INSN_MAX_NUM; | |
d02ed0bb | 205 | /* Actual count of insns presently in execution log. */ |
7ee70bf5 | 206 | static unsigned int record_full_insn_num = 0; |
d02ed0bb MM |
207 | /* Count of insns logged so far (may be larger |
208 | than count of insns presently in execution log). */ | |
88d1aa9d | 209 | static ULONGEST record_full_insn_count; |
d02ed0bb | 210 | |
d9f719f1 PA |
211 | static const char record_longname[] |
212 | = N_("Process record and replay target"); | |
213 | static const char record_doc[] | |
214 | = N_("Log program while executing and replay execution from log."); | |
215 | ||
f6ac5f3d PA |
216 | /* Base class implementing functionality common to both the |
217 | "record-full" and "record-core" targets. */ | |
218 | ||
219 | class record_full_base_target : public target_ops | |
220 | { | |
221 | public: | |
d9f719f1 | 222 | const target_info &info () const override = 0; |
f6ac5f3d | 223 | |
66b4deae PA |
224 | strata stratum () const override { return record_stratum; } |
225 | ||
f6ac5f3d | 226 | void close () override; |
4a570176 | 227 | void async (bool) override; |
b60cea74 | 228 | ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override; |
57810aa7 PA |
229 | bool stopped_by_watchpoint () override; |
230 | bool stopped_data_address (CORE_ADDR *) override; | |
f6ac5f3d | 231 | |
57810aa7 PA |
232 | bool stopped_by_sw_breakpoint () override; |
233 | bool supports_stopped_by_sw_breakpoint () override; | |
f6ac5f3d | 234 | |
57810aa7 PA |
235 | bool stopped_by_hw_breakpoint () override; |
236 | bool supports_stopped_by_hw_breakpoint () override; | |
f6ac5f3d | 237 | |
57810aa7 | 238 | bool can_execute_reverse () override; |
f6ac5f3d PA |
239 | |
240 | /* Add bookmark target methods. */ | |
241 | gdb_byte *get_bookmark (const char *, int) override; | |
242 | void goto_bookmark (const gdb_byte *, int) override; | |
243 | enum exec_direction_kind execution_direction () override; | |
244 | enum record_method record_method (ptid_t ptid) override; | |
245 | void info_record () override; | |
246 | void save_record (const char *filename) override; | |
247 | bool supports_delete_record () override; | |
248 | void delete_record () override; | |
57810aa7 PA |
249 | bool record_is_replaying (ptid_t ptid) override; |
250 | bool record_will_replay (ptid_t ptid, int dir) override; | |
f6ac5f3d PA |
251 | void record_stop_replaying () override; |
252 | void goto_record_begin () override; | |
253 | void goto_record_end () override; | |
254 | void goto_record (ULONGEST insn) override; | |
255 | }; | |
256 | ||
257 | /* The "record-full" target. */ | |
258 | ||
d9f719f1 PA |
259 | static const target_info record_full_target_info = { |
260 | "record-full", | |
261 | record_longname, | |
262 | record_doc, | |
263 | }; | |
264 | ||
f6ac5f3d PA |
265 | class record_full_target final : public record_full_base_target |
266 | { | |
267 | public: | |
d9f719f1 PA |
268 | const target_info &info () const override |
269 | { return record_full_target_info; } | |
f6ac5f3d | 270 | |
f6ac5f3d PA |
271 | void resume (ptid_t, int, enum gdb_signal) override; |
272 | void disconnect (const char *, int) override; | |
273 | void detach (inferior *, int) override; | |
274 | void mourn_inferior () override; | |
275 | void kill () override; | |
276 | void store_registers (struct regcache *, int) override; | |
277 | enum target_xfer_status xfer_partial (enum target_object object, | |
278 | const char *annex, | |
279 | gdb_byte *readbuf, | |
280 | const gdb_byte *writebuf, | |
281 | ULONGEST offset, ULONGEST len, | |
282 | ULONGEST *xfered_len) override; | |
283 | int insert_breakpoint (struct gdbarch *, | |
284 | struct bp_target_info *) override; | |
285 | int remove_breakpoint (struct gdbarch *, | |
286 | struct bp_target_info *, | |
287 | enum remove_bp_reason) override; | |
288 | }; | |
289 | ||
290 | /* The "record-core" target. */ | |
291 | ||
d9f719f1 PA |
292 | static const target_info record_full_core_target_info = { |
293 | "record-core", | |
294 | record_longname, | |
295 | record_doc, | |
296 | }; | |
297 | ||
f6ac5f3d PA |
298 | class record_full_core_target final : public record_full_base_target |
299 | { | |
300 | public: | |
d9f719f1 PA |
301 | const target_info &info () const override |
302 | { return record_full_core_target_info; } | |
f6ac5f3d PA |
303 | |
304 | void resume (ptid_t, int, enum gdb_signal) override; | |
305 | void disconnect (const char *, int) override; | |
306 | void kill () override; | |
307 | void fetch_registers (struct regcache *regcache, int regno) override; | |
308 | void prepare_to_store (struct regcache *regcache) override; | |
309 | void store_registers (struct regcache *, int) override; | |
310 | enum target_xfer_status xfer_partial (enum target_object object, | |
311 | const char *annex, | |
312 | gdb_byte *readbuf, | |
313 | const gdb_byte *writebuf, | |
314 | ULONGEST offset, ULONGEST len, | |
315 | ULONGEST *xfered_len) override; | |
316 | int insert_breakpoint (struct gdbarch *, | |
317 | struct bp_target_info *) override; | |
318 | int remove_breakpoint (struct gdbarch *, | |
319 | struct bp_target_info *, | |
320 | enum remove_bp_reason) override; | |
321 | ||
5018ce90 | 322 | bool has_execution (inferior *inf) override; |
f6ac5f3d PA |
323 | }; |
324 | ||
325 | static record_full_target record_full_ops; | |
326 | static record_full_core_target record_full_core_ops; | |
327 | ||
328 | void | |
329 | record_full_target::detach (inferior *inf, int from_tty) | |
330 | { | |
331 | record_detach (this, inf, from_tty); | |
332 | } | |
333 | ||
334 | void | |
335 | record_full_target::disconnect (const char *args, int from_tty) | |
336 | { | |
337 | record_disconnect (this, args, from_tty); | |
338 | } | |
339 | ||
340 | void | |
341 | record_full_core_target::disconnect (const char *args, int from_tty) | |
342 | { | |
343 | record_disconnect (this, args, from_tty); | |
344 | } | |
345 | ||
346 | void | |
347 | record_full_target::mourn_inferior () | |
348 | { | |
349 | record_mourn_inferior (this); | |
350 | } | |
351 | ||
352 | void | |
353 | record_full_target::kill () | |
354 | { | |
355 | record_kill (this); | |
356 | } | |
d02ed0bb | 357 | |
8213266a PA |
358 | /* See record-full.h. */ |
359 | ||
360 | int | |
361 | record_full_is_used (void) | |
362 | { | |
363 | struct target_ops *t; | |
364 | ||
365 | t = find_record_target (); | |
366 | return (t == &record_full_ops | |
367 | || t == &record_full_core_ops); | |
368 | } | |
369 | ||
370 | ||
d02ed0bb MM |
371 | /* Command lists for "set/show record full". */ |
372 | static struct cmd_list_element *set_record_full_cmdlist; | |
373 | static struct cmd_list_element *show_record_full_cmdlist; | |
374 | ||
375 | /* Command list for "record full". */ | |
376 | static struct cmd_list_element *record_full_cmdlist; | |
377 | ||
88d1aa9d MM |
378 | static void record_full_goto_insn (struct record_full_entry *entry, |
379 | enum exec_direction_kind dir); | |
88d1aa9d MM |
380 | |
381 | /* Alloc and free functions for record_full_reg, record_full_mem, and | |
382 | record_full_end entries. */ | |
383 | ||
384 | /* Alloc a record_full_reg record entry. */ | |
385 | ||
386 | static inline struct record_full_entry * | |
387 | record_full_reg_alloc (struct regcache *regcache, int regnum) | |
388 | { | |
389 | struct record_full_entry *rec; | |
ac7936df | 390 | struct gdbarch *gdbarch = regcache->arch (); |
d02ed0bb | 391 | |
8d749320 | 392 | rec = XCNEW (struct record_full_entry); |
88d1aa9d | 393 | rec->type = record_full_reg; |
d02ed0bb MM |
394 | rec->u.reg.num = regnum; |
395 | rec->u.reg.len = register_size (gdbarch, regnum); | |
396 | if (rec->u.reg.len > sizeof (rec->u.reg.u.buf)) | |
397 | rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len); | |
398 | ||
399 | return rec; | |
400 | } | |
401 | ||
88d1aa9d | 402 | /* Free a record_full_reg record entry. */ |
d02ed0bb MM |
403 | |
404 | static inline void | |
88d1aa9d | 405 | record_full_reg_release (struct record_full_entry *rec) |
d02ed0bb | 406 | { |
88d1aa9d | 407 | gdb_assert (rec->type == record_full_reg); |
d02ed0bb MM |
408 | if (rec->u.reg.len > sizeof (rec->u.reg.u.buf)) |
409 | xfree (rec->u.reg.u.ptr); | |
410 | xfree (rec); | |
411 | } | |
412 | ||
88d1aa9d | 413 | /* Alloc a record_full_mem record entry. */ |
d02ed0bb | 414 | |
88d1aa9d MM |
415 | static inline struct record_full_entry * |
416 | record_full_mem_alloc (CORE_ADDR addr, int len) | |
d02ed0bb | 417 | { |
88d1aa9d | 418 | struct record_full_entry *rec; |
d02ed0bb | 419 | |
8d749320 | 420 | rec = XCNEW (struct record_full_entry); |
88d1aa9d | 421 | rec->type = record_full_mem; |
d02ed0bb MM |
422 | rec->u.mem.addr = addr; |
423 | rec->u.mem.len = len; | |
424 | if (rec->u.mem.len > sizeof (rec->u.mem.u.buf)) | |
425 | rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len); | |
426 | ||
427 | return rec; | |
428 | } | |
429 | ||
88d1aa9d | 430 | /* Free a record_full_mem record entry. */ |
d02ed0bb MM |
431 | |
432 | static inline void | |
88d1aa9d | 433 | record_full_mem_release (struct record_full_entry *rec) |
d02ed0bb | 434 | { |
88d1aa9d | 435 | gdb_assert (rec->type == record_full_mem); |
d02ed0bb MM |
436 | if (rec->u.mem.len > sizeof (rec->u.mem.u.buf)) |
437 | xfree (rec->u.mem.u.ptr); | |
438 | xfree (rec); | |
439 | } | |
440 | ||
88d1aa9d | 441 | /* Alloc a record_full_end record entry. */ |
d02ed0bb | 442 | |
88d1aa9d MM |
443 | static inline struct record_full_entry * |
444 | record_full_end_alloc (void) | |
d02ed0bb | 445 | { |
88d1aa9d | 446 | struct record_full_entry *rec; |
d02ed0bb | 447 | |
8d749320 | 448 | rec = XCNEW (struct record_full_entry); |
88d1aa9d | 449 | rec->type = record_full_end; |
d02ed0bb MM |
450 | |
451 | return rec; | |
452 | } | |
453 | ||
88d1aa9d | 454 | /* Free a record_full_end record entry. */ |
d02ed0bb MM |
455 | |
456 | static inline void | |
88d1aa9d | 457 | record_full_end_release (struct record_full_entry *rec) |
d02ed0bb MM |
458 | { |
459 | xfree (rec); | |
460 | } | |
461 | ||
462 | /* Free one record entry, any type. | |
463 | Return entry->type, in case caller wants to know. */ | |
464 | ||
88d1aa9d MM |
465 | static inline enum record_full_type |
466 | record_full_entry_release (struct record_full_entry *rec) | |
d02ed0bb | 467 | { |
88d1aa9d | 468 | enum record_full_type type = rec->type; |
d02ed0bb MM |
469 | |
470 | switch (type) { | |
88d1aa9d MM |
471 | case record_full_reg: |
472 | record_full_reg_release (rec); | |
d02ed0bb | 473 | break; |
88d1aa9d MM |
474 | case record_full_mem: |
475 | record_full_mem_release (rec); | |
d02ed0bb | 476 | break; |
88d1aa9d MM |
477 | case record_full_end: |
478 | record_full_end_release (rec); | |
d02ed0bb MM |
479 | break; |
480 | } | |
481 | return type; | |
482 | } | |
483 | ||
484 | /* Free all record entries in list pointed to by REC. */ | |
485 | ||
486 | static void | |
88d1aa9d | 487 | record_full_list_release (struct record_full_entry *rec) |
d02ed0bb MM |
488 | { |
489 | if (!rec) | |
490 | return; | |
491 | ||
492 | while (rec->next) | |
493 | rec = rec->next; | |
494 | ||
495 | while (rec->prev) | |
496 | { | |
497 | rec = rec->prev; | |
88d1aa9d | 498 | record_full_entry_release (rec->next); |
d02ed0bb MM |
499 | } |
500 | ||
88d1aa9d | 501 | if (rec == &record_full_first) |
d02ed0bb | 502 | { |
88d1aa9d MM |
503 | record_full_insn_num = 0; |
504 | record_full_first.next = NULL; | |
d02ed0bb MM |
505 | } |
506 | else | |
88d1aa9d | 507 | record_full_entry_release (rec); |
d02ed0bb MM |
508 | } |
509 | ||
510 | /* Free all record entries forward of the given list position. */ | |
511 | ||
512 | static void | |
88d1aa9d | 513 | record_full_list_release_following (struct record_full_entry *rec) |
d02ed0bb | 514 | { |
88d1aa9d | 515 | struct record_full_entry *tmp = rec->next; |
d02ed0bb MM |
516 | |
517 | rec->next = NULL; | |
518 | while (tmp) | |
519 | { | |
520 | rec = tmp->next; | |
88d1aa9d | 521 | if (record_full_entry_release (tmp) == record_full_end) |
d02ed0bb | 522 | { |
88d1aa9d MM |
523 | record_full_insn_num--; |
524 | record_full_insn_count--; | |
d02ed0bb MM |
525 | } |
526 | tmp = rec; | |
527 | } | |
528 | } | |
529 | ||
530 | /* Delete the first instruction from the beginning of the log, to make | |
531 | room for adding a new instruction at the end of the log. | |
532 | ||
88d1aa9d | 533 | Note -- this function does not modify record_full_insn_num. */ |
d02ed0bb MM |
534 | |
535 | static void | |
88d1aa9d | 536 | record_full_list_release_first (void) |
d02ed0bb | 537 | { |
88d1aa9d | 538 | struct record_full_entry *tmp; |
d02ed0bb | 539 | |
88d1aa9d | 540 | if (!record_full_first.next) |
d02ed0bb MM |
541 | return; |
542 | ||
88d1aa9d | 543 | /* Loop until a record_full_end. */ |
d02ed0bb MM |
544 | while (1) |
545 | { | |
88d1aa9d MM |
546 | /* Cut record_full_first.next out of the linked list. */ |
547 | tmp = record_full_first.next; | |
548 | record_full_first.next = tmp->next; | |
549 | tmp->next->prev = &record_full_first; | |
d02ed0bb MM |
550 | |
551 | /* tmp is now isolated, and can be deleted. */ | |
88d1aa9d MM |
552 | if (record_full_entry_release (tmp) == record_full_end) |
553 | break; /* End loop at first record_full_end. */ | |
d02ed0bb | 554 | |
88d1aa9d | 555 | if (!record_full_first.next) |
d02ed0bb | 556 | { |
88d1aa9d | 557 | gdb_assert (record_full_insn_num == 1); |
d02ed0bb MM |
558 | break; /* End loop when list is empty. */ |
559 | } | |
560 | } | |
561 | } | |
562 | ||
88d1aa9d | 563 | /* Add a struct record_full_entry to record_full_arch_list. */ |
d02ed0bb MM |
564 | |
565 | static void | |
88d1aa9d | 566 | record_full_arch_list_add (struct record_full_entry *rec) |
d02ed0bb MM |
567 | { |
568 | if (record_debug > 1) | |
6cb06a8c TT |
569 | gdb_printf (gdb_stdlog, |
570 | "Process record: record_full_arch_list_add %s.\n", | |
571 | host_address_to_string (rec)); | |
d02ed0bb | 572 | |
88d1aa9d | 573 | if (record_full_arch_list_tail) |
d02ed0bb | 574 | { |
88d1aa9d MM |
575 | record_full_arch_list_tail->next = rec; |
576 | rec->prev = record_full_arch_list_tail; | |
577 | record_full_arch_list_tail = rec; | |
d02ed0bb MM |
578 | } |
579 | else | |
580 | { | |
88d1aa9d MM |
581 | record_full_arch_list_head = rec; |
582 | record_full_arch_list_tail = rec; | |
d02ed0bb MM |
583 | } |
584 | } | |
585 | ||
586 | /* Return the value storage location of a record entry. */ | |
587 | static inline gdb_byte * | |
88d1aa9d | 588 | record_full_get_loc (struct record_full_entry *rec) |
d02ed0bb MM |
589 | { |
590 | switch (rec->type) { | |
88d1aa9d | 591 | case record_full_mem: |
d02ed0bb MM |
592 | if (rec->u.mem.len > sizeof (rec->u.mem.u.buf)) |
593 | return rec->u.mem.u.ptr; | |
594 | else | |
595 | return rec->u.mem.u.buf; | |
88d1aa9d | 596 | case record_full_reg: |
d02ed0bb MM |
597 | if (rec->u.reg.len > sizeof (rec->u.reg.u.buf)) |
598 | return rec->u.reg.u.ptr; | |
599 | else | |
600 | return rec->u.reg.u.buf; | |
88d1aa9d | 601 | case record_full_end: |
d02ed0bb | 602 | default: |
88d1aa9d | 603 | gdb_assert_not_reached ("unexpected record_full_entry type"); |
d02ed0bb MM |
604 | return NULL; |
605 | } | |
606 | } | |
607 | ||
88d1aa9d | 608 | /* Record the value of a register NUM to record_full_arch_list. */ |
d02ed0bb MM |
609 | |
610 | int | |
25ea693b | 611 | record_full_arch_list_add_reg (struct regcache *regcache, int regnum) |
d02ed0bb | 612 | { |
88d1aa9d | 613 | struct record_full_entry *rec; |
d02ed0bb MM |
614 | |
615 | if (record_debug > 1) | |
6cb06a8c TT |
616 | gdb_printf (gdb_stdlog, |
617 | "Process record: add register num = %d to " | |
618 | "record list.\n", | |
619 | regnum); | |
d02ed0bb | 620 | |
88d1aa9d | 621 | rec = record_full_reg_alloc (regcache, regnum); |
d02ed0bb | 622 | |
0b883586 | 623 | regcache->raw_read (regnum, record_full_get_loc (rec)); |
d02ed0bb | 624 | |
88d1aa9d | 625 | record_full_arch_list_add (rec); |
d02ed0bb MM |
626 | |
627 | return 0; | |
628 | } | |
629 | ||
630 | /* Record the value of a region of memory whose address is ADDR and | |
88d1aa9d | 631 | length is LEN to record_full_arch_list. */ |
d02ed0bb MM |
632 | |
633 | int | |
25ea693b | 634 | record_full_arch_list_add_mem (CORE_ADDR addr, int len) |
d02ed0bb | 635 | { |
88d1aa9d | 636 | struct record_full_entry *rec; |
d02ed0bb MM |
637 | |
638 | if (record_debug > 1) | |
6cb06a8c TT |
639 | gdb_printf (gdb_stdlog, |
640 | "Process record: add mem addr = %s len = %d to " | |
641 | "record list.\n", | |
642 | paddress (target_gdbarch (), addr), len); | |
d02ed0bb MM |
643 | |
644 | if (!addr) /* FIXME: Why? Some arch must permit it... */ | |
645 | return 0; | |
646 | ||
88d1aa9d | 647 | rec = record_full_mem_alloc (addr, len); |
d02ed0bb | 648 | |
88d1aa9d MM |
649 | if (record_read_memory (target_gdbarch (), addr, |
650 | record_full_get_loc (rec), len)) | |
d02ed0bb | 651 | { |
88d1aa9d | 652 | record_full_mem_release (rec); |
d02ed0bb MM |
653 | return -1; |
654 | } | |
655 | ||
88d1aa9d | 656 | record_full_arch_list_add (rec); |
d02ed0bb MM |
657 | |
658 | return 0; | |
659 | } | |
660 | ||
88d1aa9d MM |
661 | /* Add a record_full_end type struct record_full_entry to |
662 | record_full_arch_list. */ | |
d02ed0bb MM |
663 | |
664 | int | |
25ea693b | 665 | record_full_arch_list_add_end (void) |
d02ed0bb | 666 | { |
88d1aa9d | 667 | struct record_full_entry *rec; |
d02ed0bb MM |
668 | |
669 | if (record_debug > 1) | |
6cb06a8c TT |
670 | gdb_printf (gdb_stdlog, |
671 | "Process record: add end to arch list.\n"); | |
d02ed0bb | 672 | |
88d1aa9d | 673 | rec = record_full_end_alloc (); |
d02ed0bb | 674 | rec->u.end.sigval = GDB_SIGNAL_0; |
88d1aa9d | 675 | rec->u.end.insn_num = ++record_full_insn_count; |
d02ed0bb | 676 | |
88d1aa9d | 677 | record_full_arch_list_add (rec); |
d02ed0bb MM |
678 | |
679 | return 0; | |
680 | } | |
681 | ||
682 | static void | |
651ce16a | 683 | record_full_check_insn_num (void) |
d02ed0bb | 684 | { |
7ee70bf5 | 685 | if (record_full_insn_num == record_full_insn_max_num) |
d02ed0bb | 686 | { |
7ee70bf5 PA |
687 | /* Ask user what to do. */ |
688 | if (record_full_stop_at_limit) | |
d02ed0bb | 689 | { |
651ce16a | 690 | if (!yquery (_("Do you want to auto delete previous execution " |
7ee70bf5 | 691 | "log entries when record/replay buffer becomes " |
651ce16a | 692 | "full (record full stop-at-limit)?"))) |
7ee70bf5 | 693 | error (_("Process record: stopped by user.")); |
651ce16a | 694 | record_full_stop_at_limit = 0; |
d02ed0bb MM |
695 | } |
696 | } | |
697 | } | |
698 | ||
d02ed0bb MM |
699 | /* Before inferior step (when GDB record the running message, inferior |
700 | only can step), GDB will call this function to record the values to | |
88d1aa9d | 701 | record_full_list. This function will call gdbarch_process_record to |
d02ed0bb | 702 | record the running message of inferior and set them to |
88d1aa9d | 703 | record_full_arch_list, and add it to record_full_list. */ |
d02ed0bb | 704 | |
bf469271 | 705 | static void |
88d1aa9d | 706 | record_full_message (struct regcache *regcache, enum gdb_signal signal) |
d02ed0bb MM |
707 | { |
708 | int ret; | |
ac7936df | 709 | struct gdbarch *gdbarch = regcache->arch (); |
d02ed0bb | 710 | |
a70b8144 | 711 | try |
1ddbba9d TT |
712 | { |
713 | record_full_arch_list_head = NULL; | |
714 | record_full_arch_list_tail = NULL; | |
d02ed0bb | 715 | |
1ddbba9d TT |
716 | /* Check record_full_insn_num. */ |
717 | record_full_check_insn_num (); | |
718 | ||
719 | /* If gdb sends a signal value to target_resume, | |
720 | save it in the 'end' field of the previous instruction. | |
d02ed0bb | 721 | |
1ddbba9d TT |
722 | Maybe process record should record what really happened, |
723 | rather than what gdb pretends has happened. | |
d02ed0bb | 724 | |
1ddbba9d TT |
725 | So if Linux delivered the signal to the child process during |
726 | the record mode, we will record it and deliver it again in | |
727 | the replay mode. | |
d02ed0bb | 728 | |
1ddbba9d TT |
729 | If user says "ignore this signal" during the record mode, then |
730 | it will be ignored again during the replay mode (no matter if | |
731 | the user says something different, like "deliver this signal" | |
732 | during the replay mode). | |
d02ed0bb | 733 | |
1ddbba9d TT |
734 | User should understand that nothing he does during the replay |
735 | mode will change the behavior of the child. If he tries, | |
736 | then that is a user error. | |
d02ed0bb | 737 | |
1ddbba9d TT |
738 | But we should still deliver the signal to gdb during the replay, |
739 | if we delivered it during the recording. Therefore we should | |
740 | record the signal during record_full_wait, not | |
741 | record_full_resume. */ | |
742 | if (record_full_list != &record_full_first) /* FIXME better way | |
743 | to check */ | |
744 | { | |
745 | gdb_assert (record_full_list->type == record_full_end); | |
746 | record_full_list->u.end.sigval = signal; | |
747 | } | |
d02ed0bb | 748 | |
1ddbba9d TT |
749 | if (signal == GDB_SIGNAL_0 |
750 | || !gdbarch_process_record_signal_p (gdbarch)) | |
751 | ret = gdbarch_process_record (gdbarch, | |
752 | regcache, | |
753 | regcache_read_pc (regcache)); | |
754 | else | |
755 | ret = gdbarch_process_record_signal (gdbarch, | |
756 | regcache, | |
757 | signal); | |
758 | ||
759 | if (ret > 0) | |
760 | error (_("Process record: inferior program stopped.")); | |
761 | if (ret < 0) | |
762 | error (_("Process record: failed to record execution log.")); | |
763 | } | |
230d2906 | 764 | catch (const gdb_exception &ex) |
d02ed0bb | 765 | { |
1ddbba9d | 766 | record_full_list_release (record_full_arch_list_tail); |
eedc3f4f | 767 | throw; |
d02ed0bb | 768 | } |
d02ed0bb | 769 | |
88d1aa9d MM |
770 | record_full_list->next = record_full_arch_list_head; |
771 | record_full_arch_list_head->prev = record_full_list; | |
772 | record_full_list = record_full_arch_list_tail; | |
d02ed0bb | 773 | |
7ee70bf5 | 774 | if (record_full_insn_num == record_full_insn_max_num) |
88d1aa9d | 775 | record_full_list_release_first (); |
d02ed0bb | 776 | else |
88d1aa9d | 777 | record_full_insn_num++; |
d02ed0bb MM |
778 | } |
779 | ||
bf469271 | 780 | static bool |
88d1aa9d MM |
781 | record_full_message_wrapper_safe (struct regcache *regcache, |
782 | enum gdb_signal signal) | |
d02ed0bb | 783 | { |
a70b8144 | 784 | try |
bf469271 PA |
785 | { |
786 | record_full_message (regcache, signal); | |
787 | } | |
b1ffd112 | 788 | catch (const gdb_exception_error &ex) |
bf469271 PA |
789 | { |
790 | exception_print (gdb_stderr, ex); | |
791 | return false; | |
792 | } | |
d02ed0bb | 793 | |
bf469271 | 794 | return true; |
d02ed0bb MM |
795 | } |
796 | ||
88d1aa9d | 797 | /* Set to 1 if record_full_store_registers and record_full_xfer_partial |
d02ed0bb MM |
798 | doesn't need record. */ |
799 | ||
88d1aa9d | 800 | static int record_full_gdb_operation_disable = 0; |
d02ed0bb | 801 | |
07036511 | 802 | scoped_restore_tmpl<int> |
25ea693b | 803 | record_full_gdb_operation_disable_set (void) |
d02ed0bb | 804 | { |
07036511 | 805 | return make_scoped_restore (&record_full_gdb_operation_disable, 1); |
d02ed0bb MM |
806 | } |
807 | ||
808 | /* Flag set to TRUE for target_stopped_by_watchpoint. */ | |
9e8915c6 PA |
809 | static enum target_stop_reason record_full_stop_reason |
810 | = TARGET_STOPPED_BY_NO_REASON; | |
d02ed0bb MM |
811 | |
812 | /* Execute one instruction from the record log. Each instruction in | |
813 | the log will be represented by an arbitrary sequence of register | |
814 | entries and memory entries, followed by an 'end' entry. */ | |
815 | ||
816 | static inline void | |
88d1aa9d MM |
817 | record_full_exec_insn (struct regcache *regcache, |
818 | struct gdbarch *gdbarch, | |
819 | struct record_full_entry *entry) | |
d02ed0bb MM |
820 | { |
821 | switch (entry->type) | |
822 | { | |
88d1aa9d | 823 | case record_full_reg: /* reg */ |
d02ed0bb | 824 | { |
d7dcbefc | 825 | gdb::byte_vector reg (entry->u.reg.len); |
d02ed0bb | 826 | |
dda83cd7 | 827 | if (record_debug > 1) |
6cb06a8c TT |
828 | gdb_printf (gdb_stdlog, |
829 | "Process record: record_full_reg %s to " | |
830 | "inferior num = %d.\n", | |
831 | host_address_to_string (entry), | |
832 | entry->u.reg.num); | |
d02ed0bb | 833 | |
dda83cd7 SM |
834 | regcache->cooked_read (entry->u.reg.num, reg.data ()); |
835 | regcache->cooked_write (entry->u.reg.num, record_full_get_loc (entry)); | |
836 | memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len); | |
d02ed0bb MM |
837 | } |
838 | break; | |
839 | ||
88d1aa9d | 840 | case record_full_mem: /* mem */ |
d02ed0bb MM |
841 | { |
842 | /* Nothing to do if the entry is flagged not_accessible. */ | |
dda83cd7 SM |
843 | if (!entry->u.mem.mem_entry_not_accessible) |
844 | { | |
a2b2bc12 | 845 | gdb::byte_vector mem (entry->u.mem.len); |
d02ed0bb | 846 | |
dda83cd7 | 847 | if (record_debug > 1) |
6cb06a8c TT |
848 | gdb_printf (gdb_stdlog, |
849 | "Process record: record_full_mem %s to " | |
850 | "inferior addr = %s len = %d.\n", | |
851 | host_address_to_string (entry), | |
852 | paddress (gdbarch, entry->u.mem.addr), | |
853 | entry->u.mem.len); | |
d02ed0bb | 854 | |
dda83cd7 | 855 | if (record_read_memory (gdbarch, |
a2b2bc12 TT |
856 | entry->u.mem.addr, mem.data (), |
857 | entry->u.mem.len)) | |
d02ed0bb | 858 | entry->u.mem.mem_entry_not_accessible = 1; |
dda83cd7 SM |
859 | else |
860 | { | |
861 | if (target_write_memory (entry->u.mem.addr, | |
88d1aa9d | 862 | record_full_get_loc (entry), |
d02ed0bb | 863 | entry->u.mem.len)) |
dda83cd7 SM |
864 | { |
865 | entry->u.mem.mem_entry_not_accessible = 1; | |
866 | if (record_debug) | |
867 | warning (_("Process record: error writing memory at " | |
d02ed0bb | 868 | "addr = %s len = %d."), |
dda83cd7 SM |
869 | paddress (gdbarch, entry->u.mem.addr), |
870 | entry->u.mem.len); | |
871 | } | |
872 | else | |
d02ed0bb | 873 | { |
a2b2bc12 | 874 | memcpy (record_full_get_loc (entry), mem.data (), |
88d1aa9d | 875 | entry->u.mem.len); |
d02ed0bb MM |
876 | |
877 | /* We've changed memory --- check if a hardware | |
878 | watchpoint should trap. Note that this | |
879 | presently assumes the target beneath supports | |
880 | continuable watchpoints. On non-continuable | |
881 | watchpoints target, we'll want to check this | |
882 | _before_ actually doing the memory change, and | |
883 | not doing the change at all if the watchpoint | |
884 | traps. */ | |
885 | if (hardware_watchpoint_inserted_in_range | |
a01bda52 | 886 | (regcache->aspace (), |
d02ed0bb | 887 | entry->u.mem.addr, entry->u.mem.len)) |
9e8915c6 | 888 | record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT; |
d02ed0bb | 889 | } |
dda83cd7 SM |
890 | } |
891 | } | |
d02ed0bb MM |
892 | } |
893 | break; | |
894 | } | |
895 | } | |
896 | ||
88d1aa9d | 897 | static void record_full_restore (void); |
d02ed0bb MM |
898 | |
899 | /* Asynchronous signal handle registered as event loop source for when | |
900 | we have pending events ready to be passed to the core. */ | |
901 | ||
88d1aa9d | 902 | static struct async_event_handler *record_full_async_inferior_event_token; |
d02ed0bb MM |
903 | |
904 | static void | |
88d1aa9d | 905 | record_full_async_inferior_event_handler (gdb_client_data data) |
d02ed0bb | 906 | { |
b1a35af2 | 907 | inferior_event_handler (INF_REG_EVENT); |
d02ed0bb MM |
908 | } |
909 | ||
d9f719f1 | 910 | /* Open the process record target for 'core' files. */ |
d02ed0bb MM |
911 | |
912 | static void | |
014f9477 | 913 | record_full_core_open_1 (const char *name, int from_tty) |
d02ed0bb MM |
914 | { |
915 | struct regcache *regcache = get_current_regcache (); | |
ac7936df | 916 | int regnum = gdbarch_num_regs (regcache->arch ()); |
d02ed0bb MM |
917 | int i; |
918 | ||
88d1aa9d | 919 | /* Get record_full_core_regbuf. */ |
d02ed0bb | 920 | target_fetch_registers (regcache, -1); |
c8ec2f33 YQ |
921 | record_full_core_regbuf = new detached_regcache (regcache->arch (), false); |
922 | ||
d02ed0bb | 923 | for (i = 0; i < regnum; i ++) |
c8ec2f33 | 924 | record_full_core_regbuf->raw_supply (i, *regcache); |
d02ed0bb | 925 | |
2d128614 | 926 | record_full_core_sections = build_section_table (core_bfd); |
d02ed0bb | 927 | |
02980c56 | 928 | current_inferior ()->push_target (&record_full_core_ops); |
88d1aa9d | 929 | record_full_restore (); |
d02ed0bb MM |
930 | } |
931 | ||
d9f719f1 | 932 | /* Open the process record target for 'live' processes. */ |
d02ed0bb MM |
933 | |
934 | static void | |
014f9477 | 935 | record_full_open_1 (const char *name, int from_tty) |
d02ed0bb MM |
936 | { |
937 | if (record_debug) | |
6cb06a8c | 938 | gdb_printf (gdb_stdlog, "Process record: record_full_open_1\n"); |
d02ed0bb MM |
939 | |
940 | /* check exec */ | |
55f6301a | 941 | if (!target_has_execution ()) |
d02ed0bb MM |
942 | error (_("Process record: the program is not being run.")); |
943 | if (non_stop) | |
944 | error (_("Process record target can't debug inferior in non-stop mode " | |
945 | "(non-stop).")); | |
946 | ||
947 | if (!gdbarch_process_record_p (target_gdbarch ())) | |
948 | error (_("Process record: the current architecture doesn't support " | |
949 | "record function.")); | |
950 | ||
02980c56 | 951 | current_inferior ()->push_target (&record_full_ops); |
d02ed0bb MM |
952 | } |
953 | ||
88d1aa9d | 954 | static void record_full_init_record_breakpoints (void); |
d02ed0bb | 955 | |
d9f719f1 | 956 | /* Open the process record target. */ |
d02ed0bb | 957 | |
d9f719f1 PA |
958 | static void |
959 | record_full_open (const char *name, int from_tty) | |
d02ed0bb | 960 | { |
d02ed0bb | 961 | if (record_debug) |
6cb06a8c | 962 | gdb_printf (gdb_stdlog, "Process record: record_full_open\n"); |
d02ed0bb | 963 | |
8213266a | 964 | record_preopen (); |
d02ed0bb | 965 | |
d02ed0bb | 966 | /* Reset */ |
88d1aa9d MM |
967 | record_full_insn_num = 0; |
968 | record_full_insn_count = 0; | |
969 | record_full_list = &record_full_first; | |
970 | record_full_list->next = NULL; | |
d02ed0bb | 971 | |
d02ed0bb | 972 | if (core_bfd) |
88d1aa9d | 973 | record_full_core_open_1 (name, from_tty); |
d02ed0bb | 974 | else |
88d1aa9d | 975 | record_full_open_1 (name, from_tty); |
d02ed0bb MM |
976 | |
977 | /* Register extra event sources in the event loop. */ | |
88d1aa9d MM |
978 | record_full_async_inferior_event_token |
979 | = create_async_event_handler (record_full_async_inferior_event_handler, | |
db20ebdf | 980 | NULL, "record-full"); |
d02ed0bb | 981 | |
88d1aa9d | 982 | record_full_init_record_breakpoints (); |
d02ed0bb | 983 | |
76727919 | 984 | gdb::observers::record_changed.notify (current_inferior (), 1, "full", NULL); |
d02ed0bb MM |
985 | } |
986 | ||
f6ac5f3d | 987 | /* "close" target method. Close the process record target. */ |
d02ed0bb | 988 | |
f6ac5f3d PA |
989 | void |
990 | record_full_base_target::close () | |
d02ed0bb | 991 | { |
88d1aa9d | 992 | struct record_full_core_buf_entry *entry; |
d02ed0bb MM |
993 | |
994 | if (record_debug) | |
6cb06a8c | 995 | gdb_printf (gdb_stdlog, "Process record: record_full_close\n"); |
d02ed0bb | 996 | |
88d1aa9d | 997 | record_full_list_release (record_full_list); |
d02ed0bb | 998 | |
88d1aa9d MM |
999 | /* Release record_full_core_regbuf. */ |
1000 | if (record_full_core_regbuf) | |
d02ed0bb | 1001 | { |
c8ec2f33 | 1002 | delete record_full_core_regbuf; |
88d1aa9d | 1003 | record_full_core_regbuf = NULL; |
d02ed0bb MM |
1004 | } |
1005 | ||
88d1aa9d | 1006 | /* Release record_full_core_buf_list. */ |
ec70d8db | 1007 | while (record_full_core_buf_list) |
d02ed0bb | 1008 | { |
ec70d8db PW |
1009 | entry = record_full_core_buf_list; |
1010 | record_full_core_buf_list = record_full_core_buf_list->prev; | |
1011 | xfree (entry); | |
d02ed0bb MM |
1012 | } |
1013 | ||
88d1aa9d MM |
1014 | if (record_full_async_inferior_event_token) |
1015 | delete_async_event_handler (&record_full_async_inferior_event_token); | |
d02ed0bb MM |
1016 | } |
1017 | ||
f6ac5f3d | 1018 | /* "async" target method. */ |
b7d2e916 | 1019 | |
f6ac5f3d | 1020 | void |
4a570176 | 1021 | record_full_base_target::async (bool enable) |
b7d2e916 | 1022 | { |
6a3753b3 | 1023 | if (enable) |
b7d2e916 PA |
1024 | mark_async_event_handler (record_full_async_inferior_event_token); |
1025 | else | |
1026 | clear_async_event_handler (record_full_async_inferior_event_token); | |
1027 | ||
b6a8c27b | 1028 | beneath ()->async (enable); |
b7d2e916 PA |
1029 | } |
1030 | ||
ec506636 PA |
1031 | /* The PTID and STEP arguments last passed to |
1032 | record_full_target::resume. */ | |
1033 | static ptid_t record_full_resume_ptid = null_ptid; | |
88d1aa9d | 1034 | static int record_full_resume_step = 0; |
d02ed0bb | 1035 | |
88d1aa9d MM |
1036 | /* True if we've been resumed, and so each record_full_wait call should |
1037 | advance execution. If this is false, record_full_wait will return a | |
d02ed0bb | 1038 | TARGET_WAITKIND_IGNORE. */ |
88d1aa9d | 1039 | static int record_full_resumed = 0; |
d02ed0bb MM |
1040 | |
1041 | /* The execution direction of the last resume we got. This is | |
1042 | necessary for async mode. Vis (order is not strictly accurate): | |
1043 | ||
1044 | 1. user has the global execution direction set to forward | |
1045 | 2. user does a reverse-step command | |
88d1aa9d | 1046 | 3. record_full_resume is called with global execution direction |
d02ed0bb MM |
1047 | temporarily switched to reverse |
1048 | 4. GDB's execution direction is reverted back to forward | |
1049 | 5. target record notifies event loop there's an event to handle | |
1050 | 6. infrun asks the target which direction was it going, and switches | |
1051 | the global execution direction accordingly (to reverse) | |
1052 | 7. infrun polls an event out of the record target, and handles it | |
1053 | 8. GDB goes back to the event loop, and goto #4. | |
1054 | */ | |
88d1aa9d | 1055 | static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD; |
d02ed0bb | 1056 | |
f6ac5f3d | 1057 | /* "resume" target method. Resume the process record target. */ |
d02ed0bb | 1058 | |
f6ac5f3d PA |
1059 | void |
1060 | record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal) | |
d02ed0bb | 1061 | { |
ec506636 | 1062 | record_full_resume_ptid = inferior_ptid; |
88d1aa9d MM |
1063 | record_full_resume_step = step; |
1064 | record_full_resumed = 1; | |
f6ac5f3d | 1065 | record_full_execution_dir = ::execution_direction; |
d02ed0bb | 1066 | |
88d1aa9d | 1067 | if (!RECORD_FULL_IS_REPLAY) |
d02ed0bb MM |
1068 | { |
1069 | struct gdbarch *gdbarch = target_thread_architecture (ptid); | |
1070 | ||
88d1aa9d | 1071 | record_full_message (get_current_regcache (), signal); |
d02ed0bb MM |
1072 | |
1073 | if (!step) | |
dda83cd7 SM |
1074 | { |
1075 | /* This is not hard single step. */ | |
1076 | if (!gdbarch_software_single_step_p (gdbarch)) | |
1077 | { | |
1078 | /* This is a normal continue. */ | |
1079 | step = 1; | |
1080 | } | |
1081 | else | |
1082 | { | |
1083 | /* This arch supports soft single step. */ | |
1084 | if (thread_has_single_step_breakpoints_set (inferior_thread ())) | |
1085 | { | |
1086 | /* This is a soft single step. */ | |
1087 | record_full_resume_step = 1; | |
1088 | } | |
1089 | else | |
93f9a11f | 1090 | step = !insert_single_step_breakpoints (gdbarch); |
dda83cd7 SM |
1091 | } |
1092 | } | |
d02ed0bb MM |
1093 | |
1094 | /* Make sure the target beneath reports all signals. */ | |
adc6a863 | 1095 | target_pass_signals ({}); |
d02ed0bb | 1096 | |
b6a8c27b | 1097 | this->beneath ()->resume (ptid, step, signal); |
d02ed0bb | 1098 | } |
d02ed0bb MM |
1099 | } |
1100 | ||
88d1aa9d | 1101 | static int record_full_get_sig = 0; |
d02ed0bb | 1102 | |
f6ac5f3d | 1103 | /* SIGINT signal handler, registered by "wait" method. */ |
d02ed0bb MM |
1104 | |
1105 | static void | |
88d1aa9d | 1106 | record_full_sig_handler (int signo) |
d02ed0bb MM |
1107 | { |
1108 | if (record_debug) | |
6cb06a8c | 1109 | gdb_printf (gdb_stdlog, "Process record: get a signal\n"); |
d02ed0bb MM |
1110 | |
1111 | /* It will break the running inferior in replay mode. */ | |
88d1aa9d | 1112 | record_full_resume_step = 1; |
d02ed0bb | 1113 | |
88d1aa9d | 1114 | /* It will let record_full_wait set inferior status to get the signal |
d02ed0bb | 1115 | SIGINT. */ |
88d1aa9d | 1116 | record_full_get_sig = 1; |
d02ed0bb MM |
1117 | } |
1118 | ||
f6ac5f3d | 1119 | /* "wait" target method for process record target. |
d02ed0bb MM |
1120 | |
1121 | In record mode, the target is always run in singlestep mode | |
f6ac5f3d | 1122 | (even when gdb says to continue). The wait method intercepts |
d02ed0bb MM |
1123 | the stop events and determines which ones are to be passed on to |
1124 | gdb. Most stop events are just singlestep events that gdb is not | |
f6ac5f3d | 1125 | to know about, so the wait method just records them and keeps |
d02ed0bb MM |
1126 | singlestepping. |
1127 | ||
1128 | In replay mode, this function emulates the recorded execution log, | |
1129 | one instruction at a time (forward or backward), and determines | |
1130 | where to stop. */ | |
1131 | ||
1132 | static ptid_t | |
88d1aa9d MM |
1133 | record_full_wait_1 (struct target_ops *ops, |
1134 | ptid_t ptid, struct target_waitstatus *status, | |
b60cea74 | 1135 | target_wait_flags options) |
d02ed0bb | 1136 | { |
07036511 TT |
1137 | scoped_restore restore_operation_disable |
1138 | = record_full_gdb_operation_disable_set (); | |
d02ed0bb MM |
1139 | |
1140 | if (record_debug) | |
6cb06a8c TT |
1141 | gdb_printf (gdb_stdlog, |
1142 | "Process record: record_full_wait " | |
1143 | "record_full_resume_step = %d, " | |
1144 | "record_full_resumed = %d, direction=%s\n", | |
1145 | record_full_resume_step, record_full_resumed, | |
1146 | record_full_execution_dir == EXEC_FORWARD | |
1147 | ? "forward" : "reverse"); | |
88d1aa9d MM |
1148 | |
1149 | if (!record_full_resumed) | |
d02ed0bb MM |
1150 | { |
1151 | gdb_assert ((options & TARGET_WNOHANG) != 0); | |
1152 | ||
1153 | /* No interesting event. */ | |
183be222 | 1154 | status->set_ignore (); |
d02ed0bb MM |
1155 | return minus_one_ptid; |
1156 | } | |
1157 | ||
88d1aa9d MM |
1158 | record_full_get_sig = 0; |
1159 | signal (SIGINT, record_full_sig_handler); | |
d02ed0bb | 1160 | |
9e8915c6 PA |
1161 | record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON; |
1162 | ||
88d1aa9d | 1163 | if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops) |
d02ed0bb | 1164 | { |
88d1aa9d | 1165 | if (record_full_resume_step) |
d02ed0bb MM |
1166 | { |
1167 | /* This is a single step. */ | |
b6a8c27b | 1168 | return ops->beneath ()->wait (ptid, status, options); |
d02ed0bb MM |
1169 | } |
1170 | else | |
1171 | { | |
1172 | /* This is not a single step. */ | |
1173 | ptid_t ret; | |
1174 | CORE_ADDR tmp_pc; | |
ec506636 PA |
1175 | struct gdbarch *gdbarch |
1176 | = target_thread_architecture (record_full_resume_ptid); | |
d02ed0bb MM |
1177 | |
1178 | while (1) | |
1179 | { | |
b6a8c27b | 1180 | ret = ops->beneath ()->wait (ptid, status, options); |
183be222 | 1181 | if (status->kind () == TARGET_WAITKIND_IGNORE) |
d02ed0bb MM |
1182 | { |
1183 | if (record_debug) | |
6cb06a8c TT |
1184 | gdb_printf (gdb_stdlog, |
1185 | "Process record: record_full_wait " | |
1186 | "target beneath not done yet\n"); | |
d02ed0bb MM |
1187 | return ret; |
1188 | } | |
1189 | ||
08036331 | 1190 | for (thread_info *tp : all_non_exited_threads ()) |
dda83cd7 | 1191 | delete_single_step_breakpoints (tp); |
d02ed0bb | 1192 | |
88d1aa9d | 1193 | if (record_full_resume_step) |
d02ed0bb MM |
1194 | return ret; |
1195 | ||
1196 | /* Is this a SIGTRAP? */ | |
183be222 SM |
1197 | if (status->kind () == TARGET_WAITKIND_STOPPED |
1198 | && status->sig () == GDB_SIGNAL_TRAP) | |
d02ed0bb MM |
1199 | { |
1200 | struct regcache *regcache; | |
9e8915c6 PA |
1201 | enum target_stop_reason *stop_reason_p |
1202 | = &record_full_stop_reason; | |
d02ed0bb MM |
1203 | |
1204 | /* Yes -- this is likely our single-step finishing, | |
1205 | but check if there's any reason the core would be | |
1206 | interested in the event. */ | |
1207 | ||
1208 | registers_changed (); | |
5b6d1e4f PA |
1209 | switch_to_thread (current_inferior ()->process_target (), |
1210 | ret); | |
d02ed0bb MM |
1211 | regcache = get_current_regcache (); |
1212 | tmp_pc = regcache_read_pc (regcache); | |
8b86c959 | 1213 | const struct address_space *aspace = regcache->aspace (); |
d02ed0bb MM |
1214 | |
1215 | if (target_stopped_by_watchpoint ()) | |
1216 | { | |
1217 | /* Always interested in watchpoints. */ | |
1218 | } | |
9e8915c6 PA |
1219 | else if (record_check_stopped_by_breakpoint (aspace, tmp_pc, |
1220 | stop_reason_p)) | |
d02ed0bb MM |
1221 | { |
1222 | /* There is a breakpoint here. Let the core | |
1223 | handle it. */ | |
d02ed0bb MM |
1224 | } |
1225 | else | |
1226 | { | |
1227 | /* This is a single-step trap. Record the | |
dda83cd7 SM |
1228 | insn and issue another step. |
1229 | FIXME: this part can be a random SIGTRAP too. | |
1230 | But GDB cannot handle it. */ | |
1231 | int step = 1; | |
d02ed0bb | 1232 | |
88d1aa9d MM |
1233 | if (!record_full_message_wrapper_safe (regcache, |
1234 | GDB_SIGNAL_0)) | |
24b21115 | 1235 | { |
183be222 | 1236 | status->set_stopped (GDB_SIGNAL_0); |
dda83cd7 | 1237 | break; |
24b21115 | 1238 | } |
d02ed0bb | 1239 | |
1192f124 SM |
1240 | process_stratum_target *proc_target |
1241 | = current_inferior ()->process_target (); | |
1242 | ||
dda83cd7 | 1243 | if (gdbarch_software_single_step_p (gdbarch)) |
d02ed0bb MM |
1244 | { |
1245 | /* Try to insert the software single step breakpoint. | |
1246 | If insert success, set step to 0. */ | |
719546c4 | 1247 | set_executing (proc_target, inferior_ptid, false); |
391c90ee AB |
1248 | SCOPE_EXIT |
1249 | { | |
1250 | set_executing (proc_target, inferior_ptid, true); | |
1251 | }; | |
93f9a11f | 1252 | |
391c90ee | 1253 | reinit_frame_cache (); |
93f9a11f | 1254 | step = !insert_single_step_breakpoints (gdbarch); |
d02ed0bb MM |
1255 | } |
1256 | ||
1257 | if (record_debug) | |
6cb06a8c TT |
1258 | gdb_printf (gdb_stdlog, |
1259 | "Process record: record_full_wait " | |
1260 | "issuing one more step in the " | |
1261 | "target beneath\n"); | |
b6a8c27b | 1262 | ops->beneath ()->resume (ptid, step, GDB_SIGNAL_0); |
1192f124 SM |
1263 | proc_target->commit_resumed_state = true; |
1264 | proc_target->commit_resumed (); | |
1265 | proc_target->commit_resumed_state = false; | |
d02ed0bb MM |
1266 | continue; |
1267 | } | |
1268 | } | |
1269 | ||
1270 | /* The inferior is broken by a breakpoint or a signal. */ | |
1271 | break; | |
1272 | } | |
1273 | ||
1274 | return ret; | |
1275 | } | |
1276 | } | |
1277 | else | |
1278 | { | |
5b6d1e4f PA |
1279 | switch_to_thread (current_inferior ()->process_target (), |
1280 | record_full_resume_ptid); | |
d02ed0bb | 1281 | struct regcache *regcache = get_current_regcache (); |
ac7936df | 1282 | struct gdbarch *gdbarch = regcache->arch (); |
8b86c959 | 1283 | const struct address_space *aspace = regcache->aspace (); |
d02ed0bb | 1284 | int continue_flag = 1; |
88d1aa9d | 1285 | int first_record_full_end = 1; |
d02ed0bb | 1286 | |
a70b8144 | 1287 | try |
d02ed0bb | 1288 | { |
1ddbba9d | 1289 | CORE_ADDR tmp_pc; |
d02ed0bb | 1290 | |
1ddbba9d | 1291 | record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON; |
183be222 | 1292 | status->set_stopped (GDB_SIGNAL_0); |
d02ed0bb | 1293 | |
1ddbba9d TT |
1294 | /* Check breakpoint when forward execute. */ |
1295 | if (execution_direction == EXEC_FORWARD) | |
d02ed0bb | 1296 | { |
1ddbba9d TT |
1297 | tmp_pc = regcache_read_pc (regcache); |
1298 | if (record_check_stopped_by_breakpoint (aspace, tmp_pc, | |
1299 | &record_full_stop_reason)) | |
1300 | { | |
1301 | if (record_debug) | |
6cb06a8c TT |
1302 | gdb_printf (gdb_stdlog, |
1303 | "Process record: break at %s.\n", | |
1304 | paddress (gdbarch, tmp_pc)); | |
1ddbba9d TT |
1305 | goto replay_out; |
1306 | } | |
d02ed0bb MM |
1307 | } |
1308 | ||
1ddbba9d TT |
1309 | /* If GDB is in terminal_inferior mode, it will not get the |
1310 | signal. And in GDB replay mode, GDB doesn't need to be | |
1311 | in terminal_inferior mode, because inferior will not | |
1312 | executed. Then set it to terminal_ours to make GDB get | |
1313 | the signal. */ | |
1314 | target_terminal::ours (); | |
1315 | ||
1316 | /* In EXEC_FORWARD mode, record_full_list points to the tail of prev | |
1317 | instruction. */ | |
1318 | if (execution_direction == EXEC_FORWARD && record_full_list->next) | |
1319 | record_full_list = record_full_list->next; | |
1320 | ||
1321 | /* Loop over the record_full_list, looking for the next place to | |
1322 | stop. */ | |
1323 | do | |
d02ed0bb | 1324 | { |
1ddbba9d TT |
1325 | /* Check for beginning and end of log. */ |
1326 | if (execution_direction == EXEC_REVERSE | |
1327 | && record_full_list == &record_full_first) | |
d02ed0bb | 1328 | { |
1ddbba9d | 1329 | /* Hit beginning of record log in reverse. */ |
183be222 | 1330 | status->set_no_history (); |
1ddbba9d | 1331 | break; |
d02ed0bb | 1332 | } |
1ddbba9d TT |
1333 | if (execution_direction != EXEC_REVERSE |
1334 | && !record_full_list->next) | |
1335 | { | |
1336 | /* Hit end of record log going forward. */ | |
183be222 | 1337 | status->set_no_history (); |
1ddbba9d TT |
1338 | break; |
1339 | } | |
1340 | ||
1341 | record_full_exec_insn (regcache, gdbarch, record_full_list); | |
1342 | ||
1343 | if (record_full_list->type == record_full_end) | |
d02ed0bb | 1344 | { |
1ddbba9d | 1345 | if (record_debug > 1) |
6cb06a8c | 1346 | gdb_printf |
1ddbba9d TT |
1347 | (gdb_stdlog, |
1348 | "Process record: record_full_end %s to " | |
1349 | "inferior.\n", | |
1350 | host_address_to_string (record_full_list)); | |
1351 | ||
1352 | if (first_record_full_end | |
1353 | && execution_direction == EXEC_REVERSE) | |
d02ed0bb | 1354 | { |
85102364 | 1355 | /* When reverse execute, the first |
1ddbba9d TT |
1356 | record_full_end is the part of current |
1357 | instruction. */ | |
1358 | first_record_full_end = 0; | |
d02ed0bb | 1359 | } |
1ddbba9d | 1360 | else |
d02ed0bb | 1361 | { |
1ddbba9d TT |
1362 | /* In EXEC_REVERSE mode, this is the |
1363 | record_full_end of prev instruction. In | |
1364 | EXEC_FORWARD mode, this is the | |
1365 | record_full_end of current instruction. */ | |
1366 | /* step */ | |
1367 | if (record_full_resume_step) | |
1368 | { | |
1369 | if (record_debug > 1) | |
6cb06a8c TT |
1370 | gdb_printf (gdb_stdlog, |
1371 | "Process record: step.\n"); | |
1ddbba9d TT |
1372 | continue_flag = 0; |
1373 | } | |
9e8915c6 | 1374 | |
1ddbba9d TT |
1375 | /* check breakpoint */ |
1376 | tmp_pc = regcache_read_pc (regcache); | |
1377 | if (record_check_stopped_by_breakpoint | |
1378 | (aspace, tmp_pc, &record_full_stop_reason)) | |
1379 | { | |
1380 | if (record_debug) | |
6cb06a8c TT |
1381 | gdb_printf (gdb_stdlog, |
1382 | "Process record: break " | |
1383 | "at %s.\n", | |
1384 | paddress (gdbarch, tmp_pc)); | |
d02ed0bb | 1385 | |
1ddbba9d TT |
1386 | continue_flag = 0; |
1387 | } | |
1388 | ||
1389 | if (record_full_stop_reason | |
1390 | == TARGET_STOPPED_BY_WATCHPOINT) | |
1391 | { | |
1392 | if (record_debug) | |
6cb06a8c TT |
1393 | gdb_printf (gdb_stdlog, |
1394 | "Process record: hit hw " | |
1395 | "watchpoint.\n"); | |
1ddbba9d TT |
1396 | continue_flag = 0; |
1397 | } | |
1398 | /* Check target signal */ | |
1399 | if (record_full_list->u.end.sigval != GDB_SIGNAL_0) | |
1400 | /* FIXME: better way to check */ | |
1401 | continue_flag = 0; | |
d02ed0bb | 1402 | } |
d02ed0bb | 1403 | } |
d02ed0bb | 1404 | |
1ddbba9d | 1405 | if (continue_flag) |
d02ed0bb | 1406 | { |
1ddbba9d TT |
1407 | if (execution_direction == EXEC_REVERSE) |
1408 | { | |
1409 | if (record_full_list->prev) | |
1410 | record_full_list = record_full_list->prev; | |
1411 | } | |
1412 | else | |
1413 | { | |
1414 | if (record_full_list->next) | |
1415 | record_full_list = record_full_list->next; | |
1416 | } | |
d02ed0bb MM |
1417 | } |
1418 | } | |
1ddbba9d TT |
1419 | while (continue_flag); |
1420 | ||
1421 | replay_out: | |
183be222 SM |
1422 | if (status->kind () == TARGET_WAITKIND_STOPPED) |
1423 | { | |
1424 | if (record_full_get_sig) | |
1425 | status->set_stopped (GDB_SIGNAL_INT); | |
1426 | else if (record_full_list->u.end.sigval != GDB_SIGNAL_0) | |
1427 | /* FIXME: better way to check */ | |
1428 | status->set_stopped (record_full_list->u.end.sigval); | |
1429 | else | |
1430 | status->set_stopped (GDB_SIGNAL_TRAP); | |
1431 | } | |
d02ed0bb | 1432 | } |
230d2906 | 1433 | catch (const gdb_exception &ex) |
1ddbba9d TT |
1434 | { |
1435 | if (execution_direction == EXEC_REVERSE) | |
1436 | { | |
1437 | if (record_full_list->next) | |
1438 | record_full_list = record_full_list->next; | |
1439 | } | |
1440 | else | |
1441 | record_full_list = record_full_list->prev; | |
d02ed0bb | 1442 | |
eedc3f4f | 1443 | throw; |
1ddbba9d | 1444 | } |
d02ed0bb MM |
1445 | } |
1446 | ||
1447 | signal (SIGINT, handle_sigint); | |
1448 | ||
d02ed0bb MM |
1449 | return inferior_ptid; |
1450 | } | |
1451 | ||
f6ac5f3d PA |
1452 | ptid_t |
1453 | record_full_base_target::wait (ptid_t ptid, struct target_waitstatus *status, | |
b60cea74 | 1454 | target_wait_flags options) |
d02ed0bb MM |
1455 | { |
1456 | ptid_t return_ptid; | |
1457 | ||
fdbc5215 SM |
1458 | clear_async_event_handler (record_full_async_inferior_event_token); |
1459 | ||
f6ac5f3d | 1460 | return_ptid = record_full_wait_1 (this, ptid, status, options); |
183be222 | 1461 | if (status->kind () != TARGET_WAITKIND_IGNORE) |
d02ed0bb MM |
1462 | { |
1463 | /* We're reporting a stop. Make sure any spurious | |
1464 | target_wait(WNOHANG) doesn't advance the target until the | |
1465 | core wants us resumed again. */ | |
88d1aa9d | 1466 | record_full_resumed = 0; |
d02ed0bb MM |
1467 | } |
1468 | return return_ptid; | |
1469 | } | |
1470 | ||
57810aa7 | 1471 | bool |
f6ac5f3d | 1472 | record_full_base_target::stopped_by_watchpoint () |
d02ed0bb | 1473 | { |
88d1aa9d | 1474 | if (RECORD_FULL_IS_REPLAY) |
9e8915c6 | 1475 | return record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT; |
d02ed0bb | 1476 | else |
b6a8c27b | 1477 | return beneath ()->stopped_by_watchpoint (); |
d02ed0bb MM |
1478 | } |
1479 | ||
57810aa7 | 1480 | bool |
f6ac5f3d | 1481 | record_full_base_target::stopped_data_address (CORE_ADDR *addr_p) |
d02ed0bb | 1482 | { |
88d1aa9d | 1483 | if (RECORD_FULL_IS_REPLAY) |
57810aa7 | 1484 | return false; |
d02ed0bb | 1485 | else |
b6a8c27b | 1486 | return this->beneath ()->stopped_data_address (addr_p); |
d02ed0bb MM |
1487 | } |
1488 | ||
f6ac5f3d | 1489 | /* The stopped_by_sw_breakpoint method of target record-full. */ |
9e8915c6 | 1490 | |
57810aa7 | 1491 | bool |
f6ac5f3d | 1492 | record_full_base_target::stopped_by_sw_breakpoint () |
9e8915c6 PA |
1493 | { |
1494 | return record_full_stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT; | |
1495 | } | |
1496 | ||
f6ac5f3d | 1497 | /* The supports_stopped_by_sw_breakpoint method of target |
9e8915c6 PA |
1498 | record-full. */ |
1499 | ||
57810aa7 | 1500 | bool |
f6ac5f3d | 1501 | record_full_base_target::supports_stopped_by_sw_breakpoint () |
9e8915c6 | 1502 | { |
57810aa7 | 1503 | return true; |
9e8915c6 PA |
1504 | } |
1505 | ||
f6ac5f3d | 1506 | /* The stopped_by_hw_breakpoint method of target record-full. */ |
9e8915c6 | 1507 | |
57810aa7 | 1508 | bool |
f6ac5f3d | 1509 | record_full_base_target::stopped_by_hw_breakpoint () |
9e8915c6 PA |
1510 | { |
1511 | return record_full_stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT; | |
1512 | } | |
1513 | ||
f6ac5f3d | 1514 | /* The supports_stopped_by_sw_breakpoint method of target |
9e8915c6 PA |
1515 | record-full. */ |
1516 | ||
57810aa7 | 1517 | bool |
f6ac5f3d | 1518 | record_full_base_target::supports_stopped_by_hw_breakpoint () |
9e8915c6 | 1519 | { |
57810aa7 | 1520 | return true; |
9e8915c6 PA |
1521 | } |
1522 | ||
d02ed0bb MM |
1523 | /* Record registers change (by user or by GDB) to list as an instruction. */ |
1524 | ||
1525 | static void | |
88d1aa9d | 1526 | record_full_registers_change (struct regcache *regcache, int regnum) |
d02ed0bb | 1527 | { |
88d1aa9d | 1528 | /* Check record_full_insn_num. */ |
651ce16a | 1529 | record_full_check_insn_num (); |
d02ed0bb | 1530 | |
88d1aa9d MM |
1531 | record_full_arch_list_head = NULL; |
1532 | record_full_arch_list_tail = NULL; | |
d02ed0bb MM |
1533 | |
1534 | if (regnum < 0) | |
1535 | { | |
1536 | int i; | |
1537 | ||
ac7936df | 1538 | for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++) |
d02ed0bb | 1539 | { |
25ea693b | 1540 | if (record_full_arch_list_add_reg (regcache, i)) |
d02ed0bb | 1541 | { |
88d1aa9d | 1542 | record_full_list_release (record_full_arch_list_tail); |
d02ed0bb MM |
1543 | error (_("Process record: failed to record execution log.")); |
1544 | } | |
1545 | } | |
1546 | } | |
1547 | else | |
1548 | { | |
25ea693b | 1549 | if (record_full_arch_list_add_reg (regcache, regnum)) |
d02ed0bb | 1550 | { |
88d1aa9d | 1551 | record_full_list_release (record_full_arch_list_tail); |
d02ed0bb MM |
1552 | error (_("Process record: failed to record execution log.")); |
1553 | } | |
1554 | } | |
25ea693b | 1555 | if (record_full_arch_list_add_end ()) |
d02ed0bb | 1556 | { |
88d1aa9d | 1557 | record_full_list_release (record_full_arch_list_tail); |
d02ed0bb MM |
1558 | error (_("Process record: failed to record execution log.")); |
1559 | } | |
88d1aa9d MM |
1560 | record_full_list->next = record_full_arch_list_head; |
1561 | record_full_arch_list_head->prev = record_full_list; | |
1562 | record_full_list = record_full_arch_list_tail; | |
d02ed0bb | 1563 | |
7ee70bf5 | 1564 | if (record_full_insn_num == record_full_insn_max_num) |
88d1aa9d | 1565 | record_full_list_release_first (); |
d02ed0bb | 1566 | else |
88d1aa9d | 1567 | record_full_insn_num++; |
d02ed0bb MM |
1568 | } |
1569 | ||
f6ac5f3d | 1570 | /* "store_registers" method for process record target. */ |
d02ed0bb | 1571 | |
f6ac5f3d PA |
1572 | void |
1573 | record_full_target::store_registers (struct regcache *regcache, int regno) | |
d02ed0bb | 1574 | { |
88d1aa9d | 1575 | if (!record_full_gdb_operation_disable) |
d02ed0bb | 1576 | { |
88d1aa9d | 1577 | if (RECORD_FULL_IS_REPLAY) |
d02ed0bb MM |
1578 | { |
1579 | int n; | |
1580 | ||
1581 | /* Let user choose if he wants to write register or not. */ | |
1582 | if (regno < 0) | |
1583 | n = | |
1584 | query (_("Because GDB is in replay mode, changing the " | |
1585 | "value of a register will make the execution " | |
1586 | "log unusable from this point onward. " | |
1587 | "Change all registers?")); | |
1588 | else | |
1589 | n = | |
1590 | query (_("Because GDB is in replay mode, changing the value " | |
1591 | "of a register will make the execution log unusable " | |
1592 | "from this point onward. Change register %s?"), | |
ac7936df | 1593 | gdbarch_register_name (regcache->arch (), |
d02ed0bb MM |
1594 | regno)); |
1595 | ||
1596 | if (!n) | |
1597 | { | |
1598 | /* Invalidate the value of regcache that was set in function | |
dda83cd7 | 1599 | "regcache_raw_write". */ |
d02ed0bb MM |
1600 | if (regno < 0) |
1601 | { | |
1602 | int i; | |
1603 | ||
1604 | for (i = 0; | |
ac7936df | 1605 | i < gdbarch_num_regs (regcache->arch ()); |
d02ed0bb | 1606 | i++) |
6aa7d724 | 1607 | regcache->invalidate (i); |
d02ed0bb MM |
1608 | } |
1609 | else | |
6aa7d724 | 1610 | regcache->invalidate (regno); |
d02ed0bb MM |
1611 | |
1612 | error (_("Process record canceled the operation.")); | |
1613 | } | |
1614 | ||
1615 | /* Destroy the record from here forward. */ | |
88d1aa9d | 1616 | record_full_list_release_following (record_full_list); |
d02ed0bb MM |
1617 | } |
1618 | ||
88d1aa9d | 1619 | record_full_registers_change (regcache, regno); |
d02ed0bb | 1620 | } |
b6a8c27b | 1621 | this->beneath ()->store_registers (regcache, regno); |
d02ed0bb MM |
1622 | } |
1623 | ||
f6ac5f3d | 1624 | /* "xfer_partial" method. Behavior is conditional on |
88d1aa9d | 1625 | RECORD_FULL_IS_REPLAY. |
d02ed0bb MM |
1626 | In replay mode, we cannot write memory unles we are willing to |
1627 | invalidate the record/replay log from this point forward. */ | |
1628 | ||
f6ac5f3d PA |
1629 | enum target_xfer_status |
1630 | record_full_target::xfer_partial (enum target_object object, | |
1631 | const char *annex, gdb_byte *readbuf, | |
1632 | const gdb_byte *writebuf, ULONGEST offset, | |
1633 | ULONGEST len, ULONGEST *xfered_len) | |
d02ed0bb | 1634 | { |
88d1aa9d | 1635 | if (!record_full_gdb_operation_disable |
d02ed0bb MM |
1636 | && (object == TARGET_OBJECT_MEMORY |
1637 | || object == TARGET_OBJECT_RAW_MEMORY) && writebuf) | |
1638 | { | |
88d1aa9d | 1639 | if (RECORD_FULL_IS_REPLAY) |
d02ed0bb MM |
1640 | { |
1641 | /* Let user choose if he wants to write memory or not. */ | |
1642 | if (!query (_("Because GDB is in replay mode, writing to memory " | |
dda83cd7 SM |
1643 | "will make the execution log unusable from this " |
1644 | "point onward. Write memory at address %s?"), | |
d02ed0bb MM |
1645 | paddress (target_gdbarch (), offset))) |
1646 | error (_("Process record canceled the operation.")); | |
1647 | ||
1648 | /* Destroy the record from here forward. */ | |
88d1aa9d | 1649 | record_full_list_release_following (record_full_list); |
d02ed0bb MM |
1650 | } |
1651 | ||
88d1aa9d | 1652 | /* Check record_full_insn_num */ |
651ce16a | 1653 | record_full_check_insn_num (); |
d02ed0bb MM |
1654 | |
1655 | /* Record registers change to list as an instruction. */ | |
88d1aa9d MM |
1656 | record_full_arch_list_head = NULL; |
1657 | record_full_arch_list_tail = NULL; | |
25ea693b | 1658 | if (record_full_arch_list_add_mem (offset, len)) |
d02ed0bb | 1659 | { |
88d1aa9d | 1660 | record_full_list_release (record_full_arch_list_tail); |
d02ed0bb | 1661 | if (record_debug) |
6cb06a8c TT |
1662 | gdb_printf (gdb_stdlog, |
1663 | "Process record: failed to record " | |
1664 | "execution log."); | |
2ed4b548 | 1665 | return TARGET_XFER_E_IO; |
d02ed0bb | 1666 | } |
25ea693b | 1667 | if (record_full_arch_list_add_end ()) |
d02ed0bb | 1668 | { |
88d1aa9d | 1669 | record_full_list_release (record_full_arch_list_tail); |
d02ed0bb | 1670 | if (record_debug) |
6cb06a8c TT |
1671 | gdb_printf (gdb_stdlog, |
1672 | "Process record: failed to record " | |
1673 | "execution log."); | |
2ed4b548 | 1674 | return TARGET_XFER_E_IO; |
d02ed0bb | 1675 | } |
88d1aa9d MM |
1676 | record_full_list->next = record_full_arch_list_head; |
1677 | record_full_arch_list_head->prev = record_full_list; | |
1678 | record_full_list = record_full_arch_list_tail; | |
d02ed0bb | 1679 | |
7ee70bf5 | 1680 | if (record_full_insn_num == record_full_insn_max_num) |
88d1aa9d | 1681 | record_full_list_release_first (); |
d02ed0bb | 1682 | else |
88d1aa9d | 1683 | record_full_insn_num++; |
d02ed0bb MM |
1684 | } |
1685 | ||
b6a8c27b PA |
1686 | return this->beneath ()->xfer_partial (object, annex, readbuf, writebuf, |
1687 | offset, len, xfered_len); | |
d02ed0bb MM |
1688 | } |
1689 | ||
1690 | /* This structure represents a breakpoint inserted while the record | |
1691 | target is active. We use this to know when to install/remove | |
1692 | breakpoints in/from the target beneath. For example, a breakpoint | |
1693 | may be inserted while recording, but removed when not replaying nor | |
1694 | recording. In that case, the breakpoint had not been inserted on | |
1695 | the target beneath, so we should not try to remove it there. */ | |
1696 | ||
88d1aa9d | 1697 | struct record_full_breakpoint |
d02ed0bb | 1698 | { |
219605fd TT |
1699 | record_full_breakpoint (struct address_space *address_space_, |
1700 | CORE_ADDR addr_, | |
1701 | bool in_target_beneath_) | |
1702 | : address_space (address_space_), | |
1703 | addr (addr_), | |
1704 | in_target_beneath (in_target_beneath_) | |
1705 | { | |
1706 | } | |
1707 | ||
d02ed0bb MM |
1708 | /* The address and address space the breakpoint was set at. */ |
1709 | struct address_space *address_space; | |
1710 | CORE_ADDR addr; | |
1711 | ||
1712 | /* True when the breakpoint has been also installed in the target | |
1713 | beneath. This will be false for breakpoints set during replay or | |
1714 | when recording. */ | |
219605fd | 1715 | bool in_target_beneath; |
d02ed0bb MM |
1716 | }; |
1717 | ||
d02ed0bb MM |
1718 | /* The list of breakpoints inserted while the record target is |
1719 | active. */ | |
219605fd | 1720 | static std::vector<record_full_breakpoint> record_full_breakpoints; |
d02ed0bb | 1721 | |
88d1aa9d | 1722 | /* Sync existing breakpoints to record_full_breakpoints. */ |
d02ed0bb MM |
1723 | |
1724 | static void | |
88d1aa9d | 1725 | record_full_init_record_breakpoints (void) |
d02ed0bb | 1726 | { |
219605fd | 1727 | record_full_breakpoints.clear (); |
d02ed0bb | 1728 | |
055c879f SM |
1729 | for (bp_location *loc : all_bp_locations ()) |
1730 | { | |
1731 | if (loc->loc_type != bp_loc_software_breakpoint) | |
1732 | continue; | |
1733 | ||
1734 | if (loc->inserted) | |
1735 | record_full_breakpoints.emplace_back | |
1736 | (loc->target_info.placed_address_space, | |
1737 | loc->target_info.placed_address, 1); | |
1738 | } | |
d02ed0bb MM |
1739 | } |
1740 | ||
88d1aa9d | 1741 | /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually |
d02ed0bb MM |
1742 | insert or remove breakpoints in the real target when replaying, nor |
1743 | when recording. */ | |
1744 | ||
f6ac5f3d PA |
1745 | int |
1746 | record_full_target::insert_breakpoint (struct gdbarch *gdbarch, | |
1747 | struct bp_target_info *bp_tgt) | |
d02ed0bb | 1748 | { |
219605fd | 1749 | bool in_target_beneath = false; |
d02ed0bb | 1750 | |
88d1aa9d | 1751 | if (!RECORD_FULL_IS_REPLAY) |
d02ed0bb MM |
1752 | { |
1753 | /* When recording, we currently always single-step, so we don't | |
1754 | really need to install regular breakpoints in the inferior. | |
1755 | However, we do have to insert software single-step | |
1756 | breakpoints, in case the target can't hardware step. To keep | |
f99bd5f2 | 1757 | things simple, we always insert. */ |
d02ed0bb | 1758 | |
07036511 TT |
1759 | scoped_restore restore_operation_disable |
1760 | = record_full_gdb_operation_disable_set (); | |
d02ed0bb | 1761 | |
b6a8c27b | 1762 | int ret = this->beneath ()->insert_breakpoint (gdbarch, bp_tgt); |
d02ed0bb MM |
1763 | if (ret != 0) |
1764 | return ret; | |
1765 | ||
219605fd | 1766 | in_target_beneath = true; |
d02ed0bb MM |
1767 | } |
1768 | ||
e390720b YQ |
1769 | /* Use the existing entries if found in order to avoid duplication |
1770 | in record_full_breakpoints. */ | |
1771 | ||
19f3f25f | 1772 | for (const record_full_breakpoint &bp : record_full_breakpoints) |
e390720b | 1773 | { |
219605fd TT |
1774 | if (bp.addr == bp_tgt->placed_address |
1775 | && bp.address_space == bp_tgt->placed_address_space) | |
e390720b | 1776 | { |
219605fd | 1777 | gdb_assert (bp.in_target_beneath == in_target_beneath); |
e390720b YQ |
1778 | return 0; |
1779 | } | |
1780 | } | |
1781 | ||
219605fd TT |
1782 | record_full_breakpoints.emplace_back (bp_tgt->placed_address_space, |
1783 | bp_tgt->placed_address, | |
1784 | in_target_beneath); | |
d02ed0bb MM |
1785 | return 0; |
1786 | } | |
1787 | ||
f6ac5f3d | 1788 | /* "remove_breakpoint" method for process record target. */ |
d02ed0bb | 1789 | |
f6ac5f3d PA |
1790 | int |
1791 | record_full_target::remove_breakpoint (struct gdbarch *gdbarch, | |
1792 | struct bp_target_info *bp_tgt, | |
1793 | enum remove_bp_reason reason) | |
d02ed0bb | 1794 | { |
219605fd TT |
1795 | for (auto iter = record_full_breakpoints.begin (); |
1796 | iter != record_full_breakpoints.end (); | |
1797 | ++iter) | |
d02ed0bb | 1798 | { |
219605fd TT |
1799 | struct record_full_breakpoint &bp = *iter; |
1800 | ||
1801 | if (bp.addr == bp_tgt->placed_address | |
1802 | && bp.address_space == bp_tgt->placed_address_space) | |
d02ed0bb | 1803 | { |
219605fd | 1804 | if (bp.in_target_beneath) |
d02ed0bb | 1805 | { |
07036511 TT |
1806 | scoped_restore restore_operation_disable |
1807 | = record_full_gdb_operation_disable_set (); | |
f6ac5f3d | 1808 | |
b6a8c27b PA |
1809 | int ret = this->beneath ()->remove_breakpoint (gdbarch, bp_tgt, |
1810 | reason); | |
d02ed0bb MM |
1811 | if (ret != 0) |
1812 | return ret; | |
1813 | } | |
1814 | ||
01d3dedf | 1815 | if (reason == REMOVE_BREAKPOINT) |
219605fd | 1816 | unordered_remove (record_full_breakpoints, iter); |
d02ed0bb MM |
1817 | return 0; |
1818 | } | |
1819 | } | |
1820 | ||
1821 | gdb_assert_not_reached ("removing unknown breakpoint"); | |
1822 | } | |
1823 | ||
f6ac5f3d | 1824 | /* "can_execute_reverse" method for process record target. */ |
d02ed0bb | 1825 | |
57810aa7 | 1826 | bool |
f6ac5f3d | 1827 | record_full_base_target::can_execute_reverse () |
d02ed0bb | 1828 | { |
57810aa7 | 1829 | return true; |
d02ed0bb MM |
1830 | } |
1831 | ||
f6ac5f3d | 1832 | /* "get_bookmark" method for process record and prec over core. */ |
d02ed0bb | 1833 | |
f6ac5f3d PA |
1834 | gdb_byte * |
1835 | record_full_base_target::get_bookmark (const char *args, int from_tty) | |
d02ed0bb | 1836 | { |
0f928d68 | 1837 | char *ret = NULL; |
d02ed0bb MM |
1838 | |
1839 | /* Return stringified form of instruction count. */ | |
88d1aa9d MM |
1840 | if (record_full_list && record_full_list->type == record_full_end) |
1841 | ret = xstrdup (pulongest (record_full_list->u.end.insn_num)); | |
d02ed0bb MM |
1842 | |
1843 | if (record_debug) | |
1844 | { | |
1845 | if (ret) | |
6cb06a8c TT |
1846 | gdb_printf (gdb_stdlog, |
1847 | "record_full_get_bookmark returns %s\n", ret); | |
d02ed0bb | 1848 | else |
6cb06a8c TT |
1849 | gdb_printf (gdb_stdlog, |
1850 | "record_full_get_bookmark returns NULL\n"); | |
d02ed0bb | 1851 | } |
0f928d68 | 1852 | return (gdb_byte *) ret; |
d02ed0bb MM |
1853 | } |
1854 | ||
f6ac5f3d | 1855 | /* "goto_bookmark" method for process record and prec over core. */ |
d02ed0bb | 1856 | |
f6ac5f3d PA |
1857 | void |
1858 | record_full_base_target::goto_bookmark (const gdb_byte *raw_bookmark, | |
1859 | int from_tty) | |
d02ed0bb | 1860 | { |
c2bcbb1d | 1861 | const char *bookmark = (const char *) raw_bookmark; |
0f928d68 | 1862 | |
d02ed0bb | 1863 | if (record_debug) |
6cb06a8c TT |
1864 | gdb_printf (gdb_stdlog, |
1865 | "record_full_goto_bookmark receives %s\n", bookmark); | |
d02ed0bb | 1866 | |
a2b2bc12 | 1867 | std::string name_holder; |
d02ed0bb MM |
1868 | if (bookmark[0] == '\'' || bookmark[0] == '\"') |
1869 | { | |
1870 | if (bookmark[strlen (bookmark) - 1] != bookmark[0]) | |
1871 | error (_("Unbalanced quotes: %s"), bookmark); | |
1872 | ||
a2b2bc12 TT |
1873 | name_holder = std::string (bookmark + 1, strlen (bookmark) - 2); |
1874 | bookmark = name_holder.c_str (); | |
d02ed0bb MM |
1875 | } |
1876 | ||
c2bcbb1d | 1877 | record_goto (bookmark); |
d02ed0bb MM |
1878 | } |
1879 | ||
f6ac5f3d PA |
1880 | enum exec_direction_kind |
1881 | record_full_base_target::execution_direction () | |
d02ed0bb | 1882 | { |
88d1aa9d | 1883 | return record_full_execution_dir; |
d02ed0bb MM |
1884 | } |
1885 | ||
f6ac5f3d | 1886 | /* The record_method method of target record-full. */ |
b158a20f TW |
1887 | |
1888 | enum record_method | |
f6ac5f3d | 1889 | record_full_base_target::record_method (ptid_t ptid) |
b158a20f TW |
1890 | { |
1891 | return RECORD_METHOD_FULL; | |
1892 | } | |
1893 | ||
f6ac5f3d PA |
1894 | void |
1895 | record_full_base_target::info_record () | |
d02ed0bb | 1896 | { |
88d1aa9d | 1897 | struct record_full_entry *p; |
d02ed0bb | 1898 | |
88d1aa9d | 1899 | if (RECORD_FULL_IS_REPLAY) |
6cb06a8c | 1900 | gdb_printf (_("Replay mode:\n")); |
d02ed0bb | 1901 | else |
6cb06a8c | 1902 | gdb_printf (_("Record mode:\n")); |
d02ed0bb MM |
1903 | |
1904 | /* Find entry for first actual instruction in the log. */ | |
88d1aa9d MM |
1905 | for (p = record_full_first.next; |
1906 | p != NULL && p->type != record_full_end; | |
d02ed0bb MM |
1907 | p = p->next) |
1908 | ; | |
1909 | ||
1910 | /* Do we have a log at all? */ | |
88d1aa9d | 1911 | if (p != NULL && p->type == record_full_end) |
d02ed0bb MM |
1912 | { |
1913 | /* Display instruction number for first instruction in the log. */ | |
6cb06a8c TT |
1914 | gdb_printf (_("Lowest recorded instruction number is %s.\n"), |
1915 | pulongest (p->u.end.insn_num)); | |
d02ed0bb MM |
1916 | |
1917 | /* If in replay mode, display where we are in the log. */ | |
88d1aa9d | 1918 | if (RECORD_FULL_IS_REPLAY) |
6cb06a8c TT |
1919 | gdb_printf (_("Current instruction number is %s.\n"), |
1920 | pulongest (record_full_list->u.end.insn_num)); | |
d02ed0bb MM |
1921 | |
1922 | /* Display instruction number for last instruction in the log. */ | |
6cb06a8c TT |
1923 | gdb_printf (_("Highest recorded instruction number is %s.\n"), |
1924 | pulongest (record_full_insn_count)); | |
d02ed0bb MM |
1925 | |
1926 | /* Display log count. */ | |
6cb06a8c TT |
1927 | gdb_printf (_("Log contains %u instructions.\n"), |
1928 | record_full_insn_num); | |
d02ed0bb MM |
1929 | } |
1930 | else | |
6cb06a8c | 1931 | gdb_printf (_("No instructions have been logged.\n")); |
d02ed0bb MM |
1932 | |
1933 | /* Display max log size. */ | |
6cb06a8c TT |
1934 | gdb_printf (_("Max logged instructions is %u.\n"), |
1935 | record_full_insn_max_num); | |
d02ed0bb MM |
1936 | } |
1937 | ||
f6ac5f3d PA |
1938 | bool |
1939 | record_full_base_target::supports_delete_record () | |
1940 | { | |
1941 | return true; | |
1942 | } | |
d02ed0bb | 1943 | |
f6ac5f3d PA |
1944 | /* The "delete_record" target method. */ |
1945 | ||
1946 | void | |
1947 | record_full_base_target::delete_record () | |
d02ed0bb | 1948 | { |
88d1aa9d | 1949 | record_full_list_release_following (record_full_list); |
d02ed0bb MM |
1950 | } |
1951 | ||
f6ac5f3d | 1952 | /* The "record_is_replaying" target method. */ |
d02ed0bb | 1953 | |
57810aa7 | 1954 | bool |
f6ac5f3d | 1955 | record_full_base_target::record_is_replaying (ptid_t ptid) |
d02ed0bb | 1956 | { |
88d1aa9d | 1957 | return RECORD_FULL_IS_REPLAY; |
d02ed0bb MM |
1958 | } |
1959 | ||
f6ac5f3d | 1960 | /* The "record_will_replay" target method. */ |
7ff27e9b | 1961 | |
57810aa7 | 1962 | bool |
f6ac5f3d | 1963 | record_full_base_target::record_will_replay (ptid_t ptid, int dir) |
7ff27e9b MM |
1964 | { |
1965 | /* We can currently only record when executing forwards. Should we be able | |
1966 | to record when executing backwards on targets that support reverse | |
1967 | execution, this needs to be changed. */ | |
1968 | ||
1969 | return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE; | |
1970 | } | |
1971 | ||
d02ed0bb MM |
1972 | /* Go to a specific entry. */ |
1973 | ||
1974 | static void | |
88d1aa9d | 1975 | record_full_goto_entry (struct record_full_entry *p) |
d02ed0bb MM |
1976 | { |
1977 | if (p == NULL) | |
1978 | error (_("Target insn not found.")); | |
88d1aa9d | 1979 | else if (p == record_full_list) |
d02ed0bb | 1980 | error (_("Already at target insn.")); |
88d1aa9d | 1981 | else if (p->u.end.insn_num > record_full_list->u.end.insn_num) |
d02ed0bb | 1982 | { |
6cb06a8c TT |
1983 | gdb_printf (_("Go forward to insn number %s\n"), |
1984 | pulongest (p->u.end.insn_num)); | |
88d1aa9d | 1985 | record_full_goto_insn (p, EXEC_FORWARD); |
d02ed0bb MM |
1986 | } |
1987 | else | |
1988 | { | |
6cb06a8c TT |
1989 | gdb_printf (_("Go backward to insn number %s\n"), |
1990 | pulongest (p->u.end.insn_num)); | |
88d1aa9d | 1991 | record_full_goto_insn (p, EXEC_REVERSE); |
d02ed0bb MM |
1992 | } |
1993 | ||
1994 | registers_changed (); | |
1995 | reinit_frame_cache (); | |
1edb66d8 | 1996 | inferior_thread ()->set_stop_pc (regcache_read_pc (get_current_regcache ())); |
08d72866 | 1997 | print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); |
d02ed0bb MM |
1998 | } |
1999 | ||
f6ac5f3d | 2000 | /* The "goto_record_begin" target method. */ |
d02ed0bb | 2001 | |
f6ac5f3d PA |
2002 | void |
2003 | record_full_base_target::goto_record_begin () | |
d02ed0bb | 2004 | { |
88d1aa9d | 2005 | struct record_full_entry *p = NULL; |
d02ed0bb | 2006 | |
88d1aa9d MM |
2007 | for (p = &record_full_first; p != NULL; p = p->next) |
2008 | if (p->type == record_full_end) | |
d02ed0bb MM |
2009 | break; |
2010 | ||
88d1aa9d | 2011 | record_full_goto_entry (p); |
d02ed0bb MM |
2012 | } |
2013 | ||
f6ac5f3d | 2014 | /* The "goto_record_end" target method. */ |
d02ed0bb | 2015 | |
f6ac5f3d PA |
2016 | void |
2017 | record_full_base_target::goto_record_end () | |
d02ed0bb | 2018 | { |
88d1aa9d | 2019 | struct record_full_entry *p = NULL; |
d02ed0bb | 2020 | |
88d1aa9d | 2021 | for (p = record_full_list; p->next != NULL; p = p->next) |
d02ed0bb MM |
2022 | ; |
2023 | for (; p!= NULL; p = p->prev) | |
88d1aa9d | 2024 | if (p->type == record_full_end) |
d02ed0bb MM |
2025 | break; |
2026 | ||
88d1aa9d | 2027 | record_full_goto_entry (p); |
d02ed0bb MM |
2028 | } |
2029 | ||
f6ac5f3d | 2030 | /* The "goto_record" target method. */ |
d02ed0bb | 2031 | |
f6ac5f3d PA |
2032 | void |
2033 | record_full_base_target::goto_record (ULONGEST target_insn) | |
d02ed0bb | 2034 | { |
88d1aa9d | 2035 | struct record_full_entry *p = NULL; |
d02ed0bb | 2036 | |
88d1aa9d MM |
2037 | for (p = &record_full_first; p != NULL; p = p->next) |
2038 | if (p->type == record_full_end && p->u.end.insn_num == target_insn) | |
d02ed0bb MM |
2039 | break; |
2040 | ||
88d1aa9d | 2041 | record_full_goto_entry (p); |
d02ed0bb MM |
2042 | } |
2043 | ||
f6ac5f3d | 2044 | /* The "record_stop_replaying" target method. */ |
797094dd | 2045 | |
f6ac5f3d PA |
2046 | void |
2047 | record_full_base_target::record_stop_replaying () | |
797094dd | 2048 | { |
f6ac5f3d | 2049 | goto_record_end (); |
797094dd MM |
2050 | } |
2051 | ||
f6ac5f3d | 2052 | /* "resume" method for prec over corefile. */ |
d02ed0bb | 2053 | |
f6ac5f3d PA |
2054 | void |
2055 | record_full_core_target::resume (ptid_t ptid, int step, | |
2056 | enum gdb_signal signal) | |
d02ed0bb | 2057 | { |
88d1aa9d MM |
2058 | record_full_resume_step = step; |
2059 | record_full_resumed = 1; | |
f6ac5f3d | 2060 | record_full_execution_dir = ::execution_direction; |
d02ed0bb MM |
2061 | } |
2062 | ||
f6ac5f3d | 2063 | /* "kill" method for prec over corefile. */ |
d02ed0bb | 2064 | |
f6ac5f3d PA |
2065 | void |
2066 | record_full_core_target::kill () | |
d02ed0bb MM |
2067 | { |
2068 | if (record_debug) | |
6cb06a8c | 2069 | gdb_printf (gdb_stdlog, "Process record: record_full_core_kill\n"); |
d02ed0bb | 2070 | |
fadf6add | 2071 | current_inferior ()->unpush_target (this); |
d02ed0bb MM |
2072 | } |
2073 | ||
f6ac5f3d | 2074 | /* "fetch_registers" method for prec over corefile. */ |
d02ed0bb | 2075 | |
f6ac5f3d PA |
2076 | void |
2077 | record_full_core_target::fetch_registers (struct regcache *regcache, | |
2078 | int regno) | |
d02ed0bb MM |
2079 | { |
2080 | if (regno < 0) | |
2081 | { | |
ac7936df | 2082 | int num = gdbarch_num_regs (regcache->arch ()); |
d02ed0bb MM |
2083 | int i; |
2084 | ||
2085 | for (i = 0; i < num; i ++) | |
c8ec2f33 | 2086 | regcache->raw_supply (i, *record_full_core_regbuf); |
d02ed0bb MM |
2087 | } |
2088 | else | |
c8ec2f33 | 2089 | regcache->raw_supply (regno, *record_full_core_regbuf); |
d02ed0bb MM |
2090 | } |
2091 | ||
f6ac5f3d | 2092 | /* "prepare_to_store" method for prec over corefile. */ |
d02ed0bb | 2093 | |
f6ac5f3d PA |
2094 | void |
2095 | record_full_core_target::prepare_to_store (struct regcache *regcache) | |
d02ed0bb MM |
2096 | { |
2097 | } | |
2098 | ||
f6ac5f3d | 2099 | /* "store_registers" method for prec over corefile. */ |
d02ed0bb | 2100 | |
f6ac5f3d PA |
2101 | void |
2102 | record_full_core_target::store_registers (struct regcache *regcache, | |
2103 | int regno) | |
d02ed0bb | 2104 | { |
88d1aa9d | 2105 | if (record_full_gdb_operation_disable) |
c8ec2f33 | 2106 | record_full_core_regbuf->raw_supply (regno, *regcache); |
d02ed0bb MM |
2107 | else |
2108 | error (_("You can't do that without a process to debug.")); | |
2109 | } | |
2110 | ||
f6ac5f3d | 2111 | /* "xfer_partial" method for prec over corefile. */ |
d02ed0bb | 2112 | |
f6ac5f3d PA |
2113 | enum target_xfer_status |
2114 | record_full_core_target::xfer_partial (enum target_object object, | |
2115 | const char *annex, gdb_byte *readbuf, | |
2116 | const gdb_byte *writebuf, ULONGEST offset, | |
2117 | ULONGEST len, ULONGEST *xfered_len) | |
d02ed0bb MM |
2118 | { |
2119 | if (object == TARGET_OBJECT_MEMORY) | |
2120 | { | |
88d1aa9d | 2121 | if (record_full_gdb_operation_disable || !writebuf) |
d02ed0bb | 2122 | { |
d7a78e5c | 2123 | for (target_section &p : record_full_core_sections) |
d02ed0bb | 2124 | { |
bb2a6777 | 2125 | if (offset >= p.addr) |
d02ed0bb | 2126 | { |
88d1aa9d | 2127 | struct record_full_core_buf_entry *entry; |
d02ed0bb MM |
2128 | ULONGEST sec_offset; |
2129 | ||
bb2a6777 | 2130 | if (offset >= p.endaddr) |
d02ed0bb MM |
2131 | continue; |
2132 | ||
bb2a6777 TT |
2133 | if (offset + len > p.endaddr) |
2134 | len = p.endaddr - offset; | |
d02ed0bb | 2135 | |
bb2a6777 | 2136 | sec_offset = offset - p.addr; |
d02ed0bb MM |
2137 | |
2138 | /* Read readbuf or write writebuf p, offset, len. */ | |
2139 | /* Check flags. */ | |
bb2a6777 TT |
2140 | if (p.the_bfd_section->flags & SEC_CONSTRUCTOR |
2141 | || (p.the_bfd_section->flags & SEC_HAS_CONTENTS) == 0) | |
d02ed0bb MM |
2142 | { |
2143 | if (readbuf) | |
2144 | memset (readbuf, 0, len); | |
9b409511 YQ |
2145 | |
2146 | *xfered_len = len; | |
2147 | return TARGET_XFER_OK; | |
d02ed0bb | 2148 | } |
88d1aa9d MM |
2149 | /* Get record_full_core_buf_entry. */ |
2150 | for (entry = record_full_core_buf_list; entry; | |
d02ed0bb | 2151 | entry = entry->prev) |
bb2a6777 | 2152 | if (entry->p == &p) |
d02ed0bb MM |
2153 | break; |
2154 | if (writebuf) | |
2155 | { | |
2156 | if (!entry) | |
2157 | { | |
2158 | /* Add a new entry. */ | |
8d749320 | 2159 | entry = XNEW (struct record_full_core_buf_entry); |
bb2a6777 | 2160 | entry->p = &p; |
2b2848e2 | 2161 | if (!bfd_malloc_and_get_section |
dda83cd7 | 2162 | (p.the_bfd_section->owner, |
bb2a6777 | 2163 | p.the_bfd_section, |
2b2848e2 | 2164 | &entry->buf)) |
d02ed0bb MM |
2165 | { |
2166 | xfree (entry); | |
9b409511 | 2167 | return TARGET_XFER_EOF; |
d02ed0bb | 2168 | } |
88d1aa9d MM |
2169 | entry->prev = record_full_core_buf_list; |
2170 | record_full_core_buf_list = entry; | |
d02ed0bb MM |
2171 | } |
2172 | ||
2173 | memcpy (entry->buf + sec_offset, writebuf, | |
2174 | (size_t) len); | |
2175 | } | |
2176 | else | |
2177 | { | |
2178 | if (!entry) | |
b6a8c27b PA |
2179 | return this->beneath ()->xfer_partial (object, annex, |
2180 | readbuf, writebuf, | |
2181 | offset, len, | |
2182 | xfered_len); | |
d02ed0bb MM |
2183 | |
2184 | memcpy (readbuf, entry->buf + sec_offset, | |
2185 | (size_t) len); | |
2186 | } | |
2187 | ||
9b409511 YQ |
2188 | *xfered_len = len; |
2189 | return TARGET_XFER_OK; | |
d02ed0bb MM |
2190 | } |
2191 | } | |
2192 | ||
2ed4b548 | 2193 | return TARGET_XFER_E_IO; |
d02ed0bb MM |
2194 | } |
2195 | else | |
2196 | error (_("You can't do that without a process to debug.")); | |
2197 | } | |
2198 | ||
b6a8c27b PA |
2199 | return this->beneath ()->xfer_partial (object, annex, |
2200 | readbuf, writebuf, offset, len, | |
2201 | xfered_len); | |
d02ed0bb MM |
2202 | } |
2203 | ||
f6ac5f3d | 2204 | /* "insert_breakpoint" method for prec over corefile. */ |
d02ed0bb | 2205 | |
f6ac5f3d PA |
2206 | int |
2207 | record_full_core_target::insert_breakpoint (struct gdbarch *gdbarch, | |
2208 | struct bp_target_info *bp_tgt) | |
d02ed0bb MM |
2209 | { |
2210 | return 0; | |
2211 | } | |
2212 | ||
f6ac5f3d | 2213 | /* "remove_breakpoint" method for prec over corefile. */ |
d02ed0bb | 2214 | |
f6ac5f3d PA |
2215 | int |
2216 | record_full_core_target::remove_breakpoint (struct gdbarch *gdbarch, | |
2217 | struct bp_target_info *bp_tgt, | |
2218 | enum remove_bp_reason reason) | |
d02ed0bb MM |
2219 | { |
2220 | return 0; | |
2221 | } | |
2222 | ||
f6ac5f3d | 2223 | /* "has_execution" method for prec over corefile. */ |
d02ed0bb | 2224 | |
57810aa7 | 2225 | bool |
5018ce90 | 2226 | record_full_core_target::has_execution (inferior *inf) |
d02ed0bb | 2227 | { |
57810aa7 | 2228 | return true; |
d02ed0bb MM |
2229 | } |
2230 | ||
d02ed0bb MM |
2231 | /* Record log save-file format |
2232 | Version 1 (never released) | |
2233 | ||
2234 | Header: | |
2235 | 4 bytes: magic number htonl(0x20090829). | |
2236 | NOTE: be sure to change whenever this file format changes! | |
2237 | ||
2238 | Records: | |
88d1aa9d MM |
2239 | record_full_end: |
2240 | 1 byte: record type (record_full_end, see enum record_full_type). | |
2241 | record_full_reg: | |
2242 | 1 byte: record type (record_full_reg, see enum record_full_type). | |
d02ed0bb MM |
2243 | 8 bytes: register id (network byte order). |
2244 | MAX_REGISTER_SIZE bytes: register value. | |
88d1aa9d MM |
2245 | record_full_mem: |
2246 | 1 byte: record type (record_full_mem, see enum record_full_type). | |
d02ed0bb MM |
2247 | 8 bytes: memory length (network byte order). |
2248 | 8 bytes: memory address (network byte order). | |
2249 | n bytes: memory value (n == memory length). | |
2250 | ||
2251 | Version 2 | |
2252 | 4 bytes: magic number netorder32(0x20091016). | |
2253 | NOTE: be sure to change whenever this file format changes! | |
2254 | ||
2255 | Records: | |
88d1aa9d MM |
2256 | record_full_end: |
2257 | 1 byte: record type (record_full_end, see enum record_full_type). | |
d02ed0bb MM |
2258 | 4 bytes: signal |
2259 | 4 bytes: instruction count | |
88d1aa9d MM |
2260 | record_full_reg: |
2261 | 1 byte: record type (record_full_reg, see enum record_full_type). | |
d02ed0bb MM |
2262 | 4 bytes: register id (network byte order). |
2263 | n bytes: register value (n == actual register size). | |
dda83cd7 | 2264 | (eg. 4 bytes for x86 general registers). |
88d1aa9d MM |
2265 | record_full_mem: |
2266 | 1 byte: record type (record_full_mem, see enum record_full_type). | |
d02ed0bb MM |
2267 | 4 bytes: memory length (network byte order). |
2268 | 8 bytes: memory address (network byte order). | |
2269 | n bytes: memory value (n == memory length). | |
2270 | ||
2271 | */ | |
2272 | ||
2273 | /* bfdcore_read -- read bytes from a core file section. */ | |
2274 | ||
2275 | static inline void | |
2276 | bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset) | |
2277 | { | |
2278 | int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len); | |
2279 | ||
2280 | if (ret) | |
2281 | *offset += len; | |
2282 | else | |
2283 | error (_("Failed to read %d bytes from core file %s ('%s')."), | |
2284 | len, bfd_get_filename (obfd), | |
2285 | bfd_errmsg (bfd_get_error ())); | |
2286 | } | |
2287 | ||
2288 | static inline uint64_t | |
2289 | netorder64 (uint64_t input) | |
2290 | { | |
2291 | uint64_t ret; | |
2292 | ||
2293 | store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret), | |
2294 | BFD_ENDIAN_BIG, input); | |
2295 | return ret; | |
2296 | } | |
2297 | ||
2298 | static inline uint32_t | |
2299 | netorder32 (uint32_t input) | |
2300 | { | |
2301 | uint32_t ret; | |
2302 | ||
d02ed0bb MM |
2303 | store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret), |
2304 | BFD_ENDIAN_BIG, input); | |
2305 | return ret; | |
2306 | } | |
2307 | ||
2308 | /* Restore the execution log from a core_bfd file. */ | |
2309 | static void | |
88d1aa9d | 2310 | record_full_restore (void) |
d02ed0bb MM |
2311 | { |
2312 | uint32_t magic; | |
88d1aa9d | 2313 | struct record_full_entry *rec; |
d02ed0bb MM |
2314 | asection *osec; |
2315 | uint32_t osec_size; | |
2316 | int bfd_offset = 0; | |
2317 | struct regcache *regcache; | |
2318 | ||
2319 | /* We restore the execution log from the open core bfd, | |
2320 | if there is one. */ | |
2321 | if (core_bfd == NULL) | |
2322 | return; | |
2323 | ||
88d1aa9d MM |
2324 | /* "record_full_restore" can only be called when record list is empty. */ |
2325 | gdb_assert (record_full_first.next == NULL); | |
d02ed0bb MM |
2326 | |
2327 | if (record_debug) | |
6cb06a8c | 2328 | gdb_printf (gdb_stdlog, "Restoring recording from core file.\n"); |
d02ed0bb MM |
2329 | |
2330 | /* Now need to find our special note section. */ | |
2331 | osec = bfd_get_section_by_name (core_bfd, "null0"); | |
2332 | if (record_debug) | |
6cb06a8c TT |
2333 | gdb_printf (gdb_stdlog, "Find precord section %s.\n", |
2334 | osec ? "succeeded" : "failed"); | |
d02ed0bb MM |
2335 | if (osec == NULL) |
2336 | return; | |
fd361982 | 2337 | osec_size = bfd_section_size (osec); |
d02ed0bb | 2338 | if (record_debug) |
6cb06a8c | 2339 | gdb_printf (gdb_stdlog, "%s", bfd_section_name (osec)); |
d02ed0bb MM |
2340 | |
2341 | /* Check the magic code. */ | |
2342 | bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset); | |
88d1aa9d | 2343 | if (magic != RECORD_FULL_FILE_MAGIC) |
d02ed0bb MM |
2344 | error (_("Version mis-match or file format error in core file %s."), |
2345 | bfd_get_filename (core_bfd)); | |
2346 | if (record_debug) | |
6cb06a8c TT |
2347 | gdb_printf (gdb_stdlog, |
2348 | " Reading 4-byte magic cookie " | |
2349 | "RECORD_FULL_FILE_MAGIC (0x%s)\n", | |
2350 | phex_nz (netorder32 (magic), 4)); | |
d02ed0bb | 2351 | |
88d1aa9d MM |
2352 | /* Restore the entries in recfd into record_full_arch_list_head and |
2353 | record_full_arch_list_tail. */ | |
2354 | record_full_arch_list_head = NULL; | |
2355 | record_full_arch_list_tail = NULL; | |
2356 | record_full_insn_num = 0; | |
d02ed0bb | 2357 | |
a70b8144 | 2358 | try |
d02ed0bb | 2359 | { |
1ddbba9d TT |
2360 | regcache = get_current_regcache (); |
2361 | ||
2362 | while (1) | |
2363 | { | |
2364 | uint8_t rectype; | |
2365 | uint32_t regnum, len, signal, count; | |
2366 | uint64_t addr; | |
d02ed0bb | 2367 | |
1ddbba9d TT |
2368 | /* We are finished when offset reaches osec_size. */ |
2369 | if (bfd_offset >= osec_size) | |
2370 | break; | |
2371 | bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset); | |
d02ed0bb | 2372 | |
1ddbba9d TT |
2373 | switch (rectype) |
2374 | { | |
2375 | case record_full_reg: /* reg */ | |
2376 | /* Get register number to regnum. */ | |
2377 | bfdcore_read (core_bfd, osec, ®num, | |
2378 | sizeof (regnum), &bfd_offset); | |
2379 | regnum = netorder32 (regnum); | |
d02ed0bb | 2380 | |
1ddbba9d | 2381 | rec = record_full_reg_alloc (regcache, regnum); |
d02ed0bb | 2382 | |
1ddbba9d TT |
2383 | /* Get val. */ |
2384 | bfdcore_read (core_bfd, osec, record_full_get_loc (rec), | |
2385 | rec->u.reg.len, &bfd_offset); | |
d02ed0bb | 2386 | |
1ddbba9d | 2387 | if (record_debug) |
6cb06a8c TT |
2388 | gdb_printf (gdb_stdlog, |
2389 | " Reading register %d (1 " | |
2390 | "plus %lu plus %d bytes)\n", | |
2391 | rec->u.reg.num, | |
2392 | (unsigned long) sizeof (regnum), | |
2393 | rec->u.reg.len); | |
1ddbba9d | 2394 | break; |
d02ed0bb | 2395 | |
1ddbba9d TT |
2396 | case record_full_mem: /* mem */ |
2397 | /* Get len. */ | |
2398 | bfdcore_read (core_bfd, osec, &len, | |
2399 | sizeof (len), &bfd_offset); | |
2400 | len = netorder32 (len); | |
d02ed0bb | 2401 | |
1ddbba9d TT |
2402 | /* Get addr. */ |
2403 | bfdcore_read (core_bfd, osec, &addr, | |
2404 | sizeof (addr), &bfd_offset); | |
2405 | addr = netorder64 (addr); | |
2406 | ||
2407 | rec = record_full_mem_alloc (addr, len); | |
2408 | ||
2409 | /* Get val. */ | |
2410 | bfdcore_read (core_bfd, osec, record_full_get_loc (rec), | |
2411 | rec->u.mem.len, &bfd_offset); | |
2412 | ||
2413 | if (record_debug) | |
6cb06a8c TT |
2414 | gdb_printf (gdb_stdlog, |
2415 | " Reading memory %s (1 plus " | |
2416 | "%lu plus %lu plus %d bytes)\n", | |
2417 | paddress (get_current_arch (), | |
2418 | rec->u.mem.addr), | |
2419 | (unsigned long) sizeof (addr), | |
2420 | (unsigned long) sizeof (len), | |
2421 | rec->u.mem.len); | |
1ddbba9d TT |
2422 | break; |
2423 | ||
2424 | case record_full_end: /* end */ | |
2425 | rec = record_full_end_alloc (); | |
2426 | record_full_insn_num ++; | |
2427 | ||
2428 | /* Get signal value. */ | |
2429 | bfdcore_read (core_bfd, osec, &signal, | |
2430 | sizeof (signal), &bfd_offset); | |
2431 | signal = netorder32 (signal); | |
2432 | rec->u.end.sigval = (enum gdb_signal) signal; | |
2433 | ||
2434 | /* Get insn count. */ | |
2435 | bfdcore_read (core_bfd, osec, &count, | |
2436 | sizeof (count), &bfd_offset); | |
2437 | count = netorder32 (count); | |
2438 | rec->u.end.insn_num = count; | |
2439 | record_full_insn_count = count + 1; | |
2440 | if (record_debug) | |
6cb06a8c TT |
2441 | gdb_printf (gdb_stdlog, |
2442 | " Reading record_full_end (1 + " | |
2443 | "%lu + %lu bytes), offset == %s\n", | |
2444 | (unsigned long) sizeof (signal), | |
2445 | (unsigned long) sizeof (count), | |
2446 | paddress (get_current_arch (), | |
2447 | bfd_offset)); | |
1ddbba9d TT |
2448 | break; |
2449 | ||
2450 | default: | |
2451 | error (_("Bad entry type in core file %s."), | |
2452 | bfd_get_filename (core_bfd)); | |
2453 | break; | |
2454 | } | |
d02ed0bb | 2455 | |
1ddbba9d TT |
2456 | /* Add rec to record arch list. */ |
2457 | record_full_arch_list_add (rec); | |
2458 | } | |
2459 | } | |
230d2906 | 2460 | catch (const gdb_exception &ex) |
1ddbba9d TT |
2461 | { |
2462 | record_full_list_release (record_full_arch_list_tail); | |
eedc3f4f | 2463 | throw; |
1ddbba9d | 2464 | } |
d02ed0bb | 2465 | |
88d1aa9d MM |
2466 | /* Add record_full_arch_list_head to the end of record list. */ |
2467 | record_full_first.next = record_full_arch_list_head; | |
2468 | record_full_arch_list_head->prev = &record_full_first; | |
2469 | record_full_arch_list_tail->next = NULL; | |
2470 | record_full_list = &record_full_first; | |
d02ed0bb | 2471 | |
88d1aa9d MM |
2472 | /* Update record_full_insn_max_num. */ |
2473 | if (record_full_insn_num > record_full_insn_max_num) | |
d02ed0bb | 2474 | { |
88d1aa9d | 2475 | record_full_insn_max_num = record_full_insn_num; |
7ee70bf5 | 2476 | warning (_("Auto increase record/replay buffer limit to %u."), |
dda83cd7 | 2477 | record_full_insn_max_num); |
d02ed0bb MM |
2478 | } |
2479 | ||
2480 | /* Succeeded. */ | |
6cb06a8c TT |
2481 | gdb_printf (_("Restored records from core file %s.\n"), |
2482 | bfd_get_filename (core_bfd)); | |
d02ed0bb | 2483 | |
08d72866 | 2484 | print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); |
d02ed0bb MM |
2485 | } |
2486 | ||
2487 | /* bfdcore_write -- write bytes into a core file section. */ | |
2488 | ||
2489 | static inline void | |
2490 | bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset) | |
2491 | { | |
2492 | int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len); | |
2493 | ||
2494 | if (ret) | |
2495 | *offset += len; | |
2496 | else | |
2497 | error (_("Failed to write %d bytes to core file %s ('%s')."), | |
2498 | len, bfd_get_filename (obfd), | |
2499 | bfd_errmsg (bfd_get_error ())); | |
2500 | } | |
2501 | ||
2502 | /* Restore the execution log from a file. We use a modified elf | |
2503 | corefile format, with an extra section for our data. */ | |
2504 | ||
2505 | static void | |
41243651 | 2506 | cmd_record_full_restore (const char *args, int from_tty) |
d02ed0bb MM |
2507 | { |
2508 | core_file_command (args, from_tty); | |
d9f719f1 | 2509 | record_full_open (args, from_tty); |
d02ed0bb MM |
2510 | } |
2511 | ||
d02ed0bb MM |
2512 | /* Save the execution log to a file. We use a modified elf corefile |
2513 | format, with an extra section for our data. */ | |
2514 | ||
f6ac5f3d PA |
2515 | void |
2516 | record_full_base_target::save_record (const char *recfilename) | |
d02ed0bb | 2517 | { |
88d1aa9d | 2518 | struct record_full_entry *cur_record_full_list; |
d02ed0bb MM |
2519 | uint32_t magic; |
2520 | struct regcache *regcache; | |
2521 | struct gdbarch *gdbarch; | |
d02ed0bb MM |
2522 | int save_size = 0; |
2523 | asection *osec = NULL; | |
2524 | int bfd_offset = 0; | |
2525 | ||
2526 | /* Open the save file. */ | |
2527 | if (record_debug) | |
6cb06a8c TT |
2528 | gdb_printf (gdb_stdlog, "Saving execution log to core file '%s'\n", |
2529 | recfilename); | |
d02ed0bb MM |
2530 | |
2531 | /* Open the output file. */ | |
bef155c3 TT |
2532 | gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename)); |
2533 | ||
2534 | /* Arrange to remove the output file on failure. */ | |
2535 | gdb::unlinker unlink_file (recfilename); | |
d02ed0bb | 2536 | |
88d1aa9d MM |
2537 | /* Save the current record entry to "cur_record_full_list". */ |
2538 | cur_record_full_list = record_full_list; | |
d02ed0bb MM |
2539 | |
2540 | /* Get the values of regcache and gdbarch. */ | |
2541 | regcache = get_current_regcache (); | |
ac7936df | 2542 | gdbarch = regcache->arch (); |
d02ed0bb MM |
2543 | |
2544 | /* Disable the GDB operation record. */ | |
07036511 TT |
2545 | scoped_restore restore_operation_disable |
2546 | = record_full_gdb_operation_disable_set (); | |
d02ed0bb MM |
2547 | |
2548 | /* Reverse execute to the begin of record list. */ | |
2549 | while (1) | |
2550 | { | |
2551 | /* Check for beginning and end of log. */ | |
88d1aa9d | 2552 | if (record_full_list == &record_full_first) |
dda83cd7 | 2553 | break; |
d02ed0bb | 2554 | |
88d1aa9d | 2555 | record_full_exec_insn (regcache, gdbarch, record_full_list); |
d02ed0bb | 2556 | |
88d1aa9d | 2557 | if (record_full_list->prev) |
dda83cd7 | 2558 | record_full_list = record_full_list->prev; |
d02ed0bb MM |
2559 | } |
2560 | ||
2561 | /* Compute the size needed for the extra bfd section. */ | |
2562 | save_size = 4; /* magic cookie */ | |
88d1aa9d MM |
2563 | for (record_full_list = record_full_first.next; record_full_list; |
2564 | record_full_list = record_full_list->next) | |
2565 | switch (record_full_list->type) | |
d02ed0bb | 2566 | { |
88d1aa9d | 2567 | case record_full_end: |
d02ed0bb MM |
2568 | save_size += 1 + 4 + 4; |
2569 | break; | |
88d1aa9d MM |
2570 | case record_full_reg: |
2571 | save_size += 1 + 4 + record_full_list->u.reg.len; | |
d02ed0bb | 2572 | break; |
88d1aa9d MM |
2573 | case record_full_mem: |
2574 | save_size += 1 + 4 + 8 + record_full_list->u.mem.len; | |
d02ed0bb MM |
2575 | break; |
2576 | } | |
2577 | ||
2578 | /* Make the new bfd section. */ | |
bef155c3 | 2579 | osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord", |
dda83cd7 SM |
2580 | SEC_HAS_CONTENTS |
2581 | | SEC_READONLY); | |
d02ed0bb MM |
2582 | if (osec == NULL) |
2583 | error (_("Failed to create 'precord' section for corefile %s: %s"), | |
2584 | recfilename, | |
dda83cd7 | 2585 | bfd_errmsg (bfd_get_error ())); |
fd361982 AM |
2586 | bfd_set_section_size (osec, save_size); |
2587 | bfd_set_section_vma (osec, 0); | |
2588 | bfd_set_section_alignment (osec, 0); | |
d02ed0bb MM |
2589 | |
2590 | /* Save corefile state. */ | |
bef155c3 | 2591 | write_gcore_file (obfd.get ()); |
d02ed0bb MM |
2592 | |
2593 | /* Write out the record log. */ | |
2594 | /* Write the magic code. */ | |
88d1aa9d | 2595 | magic = RECORD_FULL_FILE_MAGIC; |
d02ed0bb | 2596 | if (record_debug) |
6cb06a8c TT |
2597 | gdb_printf (gdb_stdlog, |
2598 | " Writing 4-byte magic cookie " | |
2599 | "RECORD_FULL_FILE_MAGIC (0x%s)\n", | |
2600 | phex_nz (magic, 4)); | |
bef155c3 | 2601 | bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset); |
d02ed0bb MM |
2602 | |
2603 | /* Save the entries to recfd and forward execute to the end of | |
2604 | record list. */ | |
88d1aa9d | 2605 | record_full_list = &record_full_first; |
d02ed0bb MM |
2606 | while (1) |
2607 | { | |
2608 | /* Save entry. */ | |
88d1aa9d | 2609 | if (record_full_list != &record_full_first) |
dda83cd7 | 2610 | { |
d02ed0bb MM |
2611 | uint8_t type; |
2612 | uint32_t regnum, len, signal, count; | |
dda83cd7 | 2613 | uint64_t addr; |
d02ed0bb | 2614 | |
88d1aa9d | 2615 | type = record_full_list->type; |
dda83cd7 | 2616 | bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset); |
d02ed0bb | 2617 | |
dda83cd7 SM |
2618 | switch (record_full_list->type) |
2619 | { | |
2620 | case record_full_reg: /* reg */ | |
d02ed0bb | 2621 | if (record_debug) |
6cb06a8c TT |
2622 | gdb_printf (gdb_stdlog, |
2623 | " Writing register %d (1 " | |
2624 | "plus %lu plus %d bytes)\n", | |
2625 | record_full_list->u.reg.num, | |
2626 | (unsigned long) sizeof (regnum), | |
2627 | record_full_list->u.reg.len); | |
d02ed0bb | 2628 | |
dda83cd7 SM |
2629 | /* Write regnum. */ |
2630 | regnum = netorder32 (record_full_list->u.reg.num); | |
2631 | bfdcore_write (obfd.get (), osec, ®num, | |
d02ed0bb MM |
2632 | sizeof (regnum), &bfd_offset); |
2633 | ||
dda83cd7 SM |
2634 | /* Write regval. */ |
2635 | bfdcore_write (obfd.get (), osec, | |
88d1aa9d MM |
2636 | record_full_get_loc (record_full_list), |
2637 | record_full_list->u.reg.len, &bfd_offset); | |
dda83cd7 | 2638 | break; |
d02ed0bb | 2639 | |
dda83cd7 | 2640 | case record_full_mem: /* mem */ |
d02ed0bb | 2641 | if (record_debug) |
6cb06a8c TT |
2642 | gdb_printf (gdb_stdlog, |
2643 | " Writing memory %s (1 plus " | |
2644 | "%lu plus %lu plus %d bytes)\n", | |
2645 | paddress (gdbarch, | |
2646 | record_full_list->u.mem.addr), | |
2647 | (unsigned long) sizeof (addr), | |
2648 | (unsigned long) sizeof (len), | |
2649 | record_full_list->u.mem.len); | |
d02ed0bb MM |
2650 | |
2651 | /* Write memlen. */ | |
88d1aa9d | 2652 | len = netorder32 (record_full_list->u.mem.len); |
bef155c3 TT |
2653 | bfdcore_write (obfd.get (), osec, &len, sizeof (len), |
2654 | &bfd_offset); | |
d02ed0bb MM |
2655 | |
2656 | /* Write memaddr. */ | |
88d1aa9d | 2657 | addr = netorder64 (record_full_list->u.mem.addr); |
bef155c3 | 2658 | bfdcore_write (obfd.get (), osec, &addr, |
d02ed0bb MM |
2659 | sizeof (addr), &bfd_offset); |
2660 | ||
2661 | /* Write memval. */ | |
bef155c3 | 2662 | bfdcore_write (obfd.get (), osec, |
88d1aa9d MM |
2663 | record_full_get_loc (record_full_list), |
2664 | record_full_list->u.mem.len, &bfd_offset); | |
dda83cd7 | 2665 | break; |
d02ed0bb | 2666 | |
dda83cd7 | 2667 | case record_full_end: |
d02ed0bb | 2668 | if (record_debug) |
6cb06a8c TT |
2669 | gdb_printf (gdb_stdlog, |
2670 | " Writing record_full_end (1 + " | |
2671 | "%lu + %lu bytes)\n", | |
2672 | (unsigned long) sizeof (signal), | |
2673 | (unsigned long) sizeof (count)); | |
d02ed0bb | 2674 | /* Write signal value. */ |
88d1aa9d | 2675 | signal = netorder32 (record_full_list->u.end.sigval); |
bef155c3 | 2676 | bfdcore_write (obfd.get (), osec, &signal, |
d02ed0bb MM |
2677 | sizeof (signal), &bfd_offset); |
2678 | ||
2679 | /* Write insn count. */ | |
88d1aa9d | 2680 | count = netorder32 (record_full_list->u.end.insn_num); |
bef155c3 | 2681 | bfdcore_write (obfd.get (), osec, &count, |
d02ed0bb | 2682 | sizeof (count), &bfd_offset); |
dda83cd7 SM |
2683 | break; |
2684 | } | |
2685 | } | |
d02ed0bb MM |
2686 | |
2687 | /* Execute entry. */ | |
88d1aa9d | 2688 | record_full_exec_insn (regcache, gdbarch, record_full_list); |
d02ed0bb | 2689 | |
88d1aa9d | 2690 | if (record_full_list->next) |
dda83cd7 | 2691 | record_full_list = record_full_list->next; |
d02ed0bb | 2692 | else |
dda83cd7 | 2693 | break; |
d02ed0bb MM |
2694 | } |
2695 | ||
88d1aa9d | 2696 | /* Reverse execute to cur_record_full_list. */ |
d02ed0bb MM |
2697 | while (1) |
2698 | { | |
2699 | /* Check for beginning and end of log. */ | |
88d1aa9d | 2700 | if (record_full_list == cur_record_full_list) |
dda83cd7 | 2701 | break; |
d02ed0bb | 2702 | |
88d1aa9d | 2703 | record_full_exec_insn (regcache, gdbarch, record_full_list); |
d02ed0bb | 2704 | |
88d1aa9d | 2705 | if (record_full_list->prev) |
dda83cd7 | 2706 | record_full_list = record_full_list->prev; |
d02ed0bb MM |
2707 | } |
2708 | ||
bef155c3 | 2709 | unlink_file.keep (); |
d02ed0bb MM |
2710 | |
2711 | /* Succeeded. */ | |
6cb06a8c TT |
2712 | gdb_printf (_("Saved core file %s with execution log.\n"), |
2713 | recfilename); | |
d02ed0bb MM |
2714 | } |
2715 | ||
88d1aa9d | 2716 | /* record_full_goto_insn -- rewind the record log (forward or backward, |
d02ed0bb MM |
2717 | depending on DIR) to the given entry, changing the program state |
2718 | correspondingly. */ | |
2719 | ||
2720 | static void | |
88d1aa9d MM |
2721 | record_full_goto_insn (struct record_full_entry *entry, |
2722 | enum exec_direction_kind dir) | |
d02ed0bb | 2723 | { |
07036511 TT |
2724 | scoped_restore restore_operation_disable |
2725 | = record_full_gdb_operation_disable_set (); | |
d02ed0bb | 2726 | struct regcache *regcache = get_current_regcache (); |
ac7936df | 2727 | struct gdbarch *gdbarch = regcache->arch (); |
d02ed0bb MM |
2728 | |
2729 | /* Assume everything is valid: we will hit the entry, | |
2730 | and we will not hit the end of the recording. */ | |
2731 | ||
2732 | if (dir == EXEC_FORWARD) | |
88d1aa9d | 2733 | record_full_list = record_full_list->next; |
d02ed0bb MM |
2734 | |
2735 | do | |
2736 | { | |
88d1aa9d | 2737 | record_full_exec_insn (regcache, gdbarch, record_full_list); |
d02ed0bb | 2738 | if (dir == EXEC_REVERSE) |
88d1aa9d | 2739 | record_full_list = record_full_list->prev; |
d02ed0bb | 2740 | else |
88d1aa9d MM |
2741 | record_full_list = record_full_list->next; |
2742 | } while (record_full_list != entry); | |
d02ed0bb MM |
2743 | } |
2744 | ||
2745 | /* Alias for "target record-full". */ | |
2746 | ||
2747 | static void | |
981a3fb3 | 2748 | cmd_record_full_start (const char *args, int from_tty) |
d02ed0bb | 2749 | { |
95a6b0a1 | 2750 | execute_command ("target record-full", from_tty); |
d02ed0bb MM |
2751 | } |
2752 | ||
2753 | static void | |
eb4c3f4a | 2754 | set_record_full_insn_max_num (const char *args, int from_tty, |
88d1aa9d | 2755 | struct cmd_list_element *c) |
d02ed0bb | 2756 | { |
7ee70bf5 | 2757 | if (record_full_insn_num > record_full_insn_max_num) |
d02ed0bb | 2758 | { |
88d1aa9d MM |
2759 | /* Count down record_full_insn_num while releasing records from list. */ |
2760 | while (record_full_insn_num > record_full_insn_max_num) | |
d02ed0bb | 2761 | { |
dda83cd7 SM |
2762 | record_full_list_release_first (); |
2763 | record_full_insn_num--; | |
d02ed0bb MM |
2764 | } |
2765 | } | |
2766 | } | |
2767 | ||
e24d337e BL |
2768 | /* Implement the 'maintenance print record-instruction' command. */ |
2769 | ||
2770 | static void | |
2771 | maintenance_print_record_instruction (const char *args, int from_tty) | |
2772 | { | |
2773 | struct record_full_entry *to_print = record_full_list; | |
2774 | ||
2775 | if (args != nullptr) | |
2776 | { | |
2777 | int offset = value_as_long (parse_and_eval (args)); | |
2778 | if (offset > 0) | |
2779 | { | |
2780 | /* Move forward OFFSET instructions. We know we found the | |
2781 | end of an instruction when to_print->type is record_full_end. */ | |
2782 | while (to_print->next != nullptr && offset > 0) | |
2783 | { | |
2784 | to_print = to_print->next; | |
2785 | if (to_print->type == record_full_end) | |
2786 | offset--; | |
2787 | } | |
2788 | if (offset != 0) | |
2789 | error (_("Not enough recorded history")); | |
2790 | } | |
2791 | else | |
2792 | { | |
2793 | while (to_print->prev != nullptr && offset < 0) | |
2794 | { | |
2795 | to_print = to_print->prev; | |
2796 | if (to_print->type == record_full_end) | |
2797 | offset++; | |
2798 | } | |
2799 | if (offset != 0) | |
2800 | error (_("Not enough recorded history")); | |
2801 | } | |
2802 | } | |
2803 | gdb_assert (to_print != nullptr); | |
2804 | ||
2805 | /* Go back to the start of the instruction. */ | |
2806 | while (to_print->prev != nullptr && to_print->prev->type != record_full_end) | |
2807 | to_print = to_print->prev; | |
2808 | ||
2809 | /* if we're in the first record, there are no actual instructions | |
2810 | recorded. Warn the user and leave. */ | |
2811 | if (to_print == &record_full_first) | |
2812 | error (_("Not enough recorded history")); | |
2813 | ||
2814 | while (to_print->type != record_full_end) | |
2815 | { | |
2816 | switch (to_print->type) | |
2817 | { | |
2818 | case record_full_reg: | |
2819 | { | |
2820 | type *regtype = gdbarch_register_type (target_gdbarch (), | |
2821 | to_print->u.reg.num); | |
2822 | value *val | |
2823 | = value_from_contents (regtype, | |
2824 | record_full_get_loc (to_print)); | |
2825 | gdb_printf ("Register %s changed: ", | |
2826 | gdbarch_register_name (target_gdbarch (), | |
2827 | to_print->u.reg.num)); | |
2828 | struct value_print_options opts; | |
2829 | get_user_print_options (&opts); | |
2830 | opts.raw = true; | |
2831 | value_print (val, gdb_stdout, &opts); | |
2832 | gdb_printf ("\n"); | |
2833 | break; | |
2834 | } | |
2835 | case record_full_mem: | |
2836 | { | |
2837 | gdb_byte *b = record_full_get_loc (to_print); | |
2838 | gdb_printf ("%d bytes of memory at address %s changed from:", | |
2839 | to_print->u.mem.len, | |
2840 | print_core_address (target_gdbarch (), | |
2841 | to_print->u.mem.addr)); | |
2842 | for (int i = 0; i < to_print->u.mem.len; i++) | |
2843 | gdb_printf (" %02x", b[i]); | |
2844 | gdb_printf ("\n"); | |
2845 | break; | |
2846 | } | |
2847 | } | |
2848 | to_print = to_print->next; | |
2849 | } | |
2850 | } | |
2851 | ||
6c265988 | 2852 | void _initialize_record_full (); |
d02ed0bb | 2853 | void |
6c265988 | 2854 | _initialize_record_full () |
d02ed0bb MM |
2855 | { |
2856 | struct cmd_list_element *c; | |
2857 | ||
88d1aa9d MM |
2858 | /* Init record_full_first. */ |
2859 | record_full_first.prev = NULL; | |
2860 | record_full_first.next = NULL; | |
2861 | record_full_first.type = record_full_end; | |
d02ed0bb | 2862 | |
d9f719f1 PA |
2863 | add_target (record_full_target_info, record_full_open); |
2864 | add_deprecated_target_alias (record_full_target_info, "record"); | |
2865 | add_target (record_full_core_target_info, record_full_open); | |
d02ed0bb | 2866 | |
88d1aa9d | 2867 | add_prefix_cmd ("full", class_obscure, cmd_record_full_start, |
d02ed0bb | 2868 | _("Start full execution recording."), &record_full_cmdlist, |
2f822da5 | 2869 | 0, &record_cmdlist); |
d02ed0bb | 2870 | |
5e84b7ee SM |
2871 | cmd_list_element *record_full_restore_cmd |
2872 | = add_cmd ("restore", class_obscure, cmd_record_full_restore, | |
d02ed0bb MM |
2873 | _("Restore the execution log from a file.\n\ |
2874 | Argument is filename. File must be created with 'record save'."), | |
2875 | &record_full_cmdlist); | |
5e84b7ee | 2876 | set_cmd_completer (record_full_restore_cmd, filename_completer); |
d02ed0bb MM |
2877 | |
2878 | /* Deprecate the old version without "full" prefix. */ | |
5e84b7ee | 2879 | c = add_alias_cmd ("restore", record_full_restore_cmd, class_obscure, 1, |
d02ed0bb MM |
2880 | &record_cmdlist); |
2881 | set_cmd_completer (c, filename_completer); | |
2882 | deprecate_cmd (c, "record full restore"); | |
2883 | ||
f54bdb6d SM |
2884 | add_setshow_prefix_cmd ("full", class_support, |
2885 | _("Set record options."), | |
2886 | _("Show record options."), | |
2887 | &set_record_full_cmdlist, | |
2888 | &show_record_full_cmdlist, | |
2889 | &set_record_cmdlist, | |
2890 | &show_record_cmdlist); | |
d02ed0bb MM |
2891 | |
2892 | /* Record instructions number limit command. */ | |
5e84b7ee SM |
2893 | set_show_commands set_record_full_stop_at_limit_cmds |
2894 | = add_setshow_boolean_cmd ("stop-at-limit", no_class, | |
2895 | &record_full_stop_at_limit, _("\ | |
d02ed0bb MM |
2896 | Set whether record/replay stops when record/replay buffer becomes full."), _("\ |
2897 | Show whether record/replay stops when record/replay buffer becomes full."), | |
2898 | _("Default is ON.\n\ | |
2899 | When ON, if the record/replay buffer becomes full, ask user what to do.\n\ | |
2900 | When OFF, if the record/replay buffer becomes full,\n\ | |
2901 | delete the oldest recorded instruction to make room for each new one."), | |
5e84b7ee SM |
2902 | NULL, NULL, |
2903 | &set_record_full_cmdlist, | |
2904 | &show_record_full_cmdlist); | |
d02ed0bb | 2905 | |
5e84b7ee SM |
2906 | c = add_alias_cmd ("stop-at-limit", |
2907 | set_record_full_stop_at_limit_cmds.set, no_class, 1, | |
d02ed0bb MM |
2908 | &set_record_cmdlist); |
2909 | deprecate_cmd (c, "set record full stop-at-limit"); | |
2910 | ||
5e84b7ee SM |
2911 | c = add_alias_cmd ("stop-at-limit", |
2912 | set_record_full_stop_at_limit_cmds.show, no_class, 1, | |
d02ed0bb MM |
2913 | &show_record_cmdlist); |
2914 | deprecate_cmd (c, "show record full stop-at-limit"); | |
2915 | ||
5e84b7ee SM |
2916 | set_show_commands record_full_insn_number_max_cmds |
2917 | = add_setshow_uinteger_cmd ("insn-number-max", no_class, | |
2918 | &record_full_insn_max_num, | |
2919 | _("Set record/replay buffer limit."), | |
2920 | _("Show record/replay buffer limit."), _("\ | |
d02ed0bb | 2921 | Set the maximum number of instructions to be stored in the\n\ |
f81d1120 PA |
2922 | record/replay buffer. A value of either \"unlimited\" or zero means no\n\ |
2923 | limit. Default is 200000."), | |
5e84b7ee SM |
2924 | set_record_full_insn_max_num, |
2925 | NULL, &set_record_full_cmdlist, | |
2926 | &show_record_full_cmdlist); | |
d02ed0bb | 2927 | |
5e84b7ee SM |
2928 | c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.set, |
2929 | no_class, 1, &set_record_cmdlist); | |
d02ed0bb MM |
2930 | deprecate_cmd (c, "set record full insn-number-max"); |
2931 | ||
5e84b7ee SM |
2932 | c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.show, |
2933 | no_class, 1, &show_record_cmdlist); | |
d02ed0bb MM |
2934 | deprecate_cmd (c, "show record full insn-number-max"); |
2935 | ||
5e84b7ee SM |
2936 | set_show_commands record_full_memory_query_cmds |
2937 | = add_setshow_boolean_cmd ("memory-query", no_class, | |
2938 | &record_full_memory_query, _("\ | |
d02ed0bb | 2939 | Set whether query if PREC cannot record memory change of next instruction."), |
5e84b7ee | 2940 | _("\ |
d02ed0bb | 2941 | Show whether query if PREC cannot record memory change of next instruction."), |
5e84b7ee | 2942 | _("\ |
d02ed0bb MM |
2943 | Default is OFF.\n\ |
2944 | When ON, query if PREC cannot record memory change of next instruction."), | |
5e84b7ee SM |
2945 | NULL, NULL, |
2946 | &set_record_full_cmdlist, | |
2947 | &show_record_full_cmdlist); | |
d02ed0bb | 2948 | |
5e84b7ee SM |
2949 | c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.set, |
2950 | no_class, 1, &set_record_cmdlist); | |
d02ed0bb MM |
2951 | deprecate_cmd (c, "set record full memory-query"); |
2952 | ||
5e84b7ee SM |
2953 | c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.show, |
2954 | no_class, 1,&show_record_cmdlist); | |
d02ed0bb | 2955 | deprecate_cmd (c, "show record full memory-query"); |
e24d337e BL |
2956 | |
2957 | add_cmd ("record-instruction", class_maintenance, | |
2958 | maintenance_print_record_instruction, | |
2959 | _("\ | |
2960 | Print a recorded instruction.\n\ | |
2961 | If no argument is provided, print the last instruction recorded.\n\ | |
2962 | If a negative argument is given, prints how the nth previous \ | |
2963 | instruction will be undone.\n\ | |
2964 | If a positive argument is given, prints \ | |
2965 | how the nth following instruction will be redone."), &maintenanceprintlist); | |
d02ed0bb | 2966 | } |