forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord-full.c
2887 lines (2402 loc) · 83.8 KB
/
record-full.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Process record and replay target for GDB, the GNU debugger.
Copyright (C) 2013-2015 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "gdbcmd.h"
#include "regcache.h"
#include "gdbthread.h"
#include "event-top.h"
#include "completer.h"
#include "arch-utils.h"
#include "gdbcore.h"
#include "exec.h"
#include "record.h"
#include "record-full.h"
#include "elf-bfd.h"
#include "gcore.h"
#include "event-loop.h"
#include "inf-loop.h"
#include "gdb_bfd.h"
#include "observer.h"
#include "infrun.h"
#include <signal.h>
/* This module implements "target record-full", also known as "process
record and replay". This target sits on top of a "normal" target
(a target that "has execution"), and provides a record and replay
functionality, including reverse debugging.
Target record has two modes: recording, and replaying.
In record mode, we intercept the to_resume and to_wait methods.
Whenever gdb resumes the target, we run the target in single step
mode, and we build up an execution log in which, for each executed
instruction, we record all changes in memory and register state.
This is invisible to the user, to whom it just looks like an
ordinary debugging session (except for performance degredation).
In replay mode, instead of actually letting the inferior run as a
process, we simulate its execution by playing back the recorded
execution log. For each instruction in the log, we simulate the
instruction's side effects by duplicating the changes that it would
have made on memory and registers. */
#define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
#define RECORD_FULL_IS_REPLAY \
(record_full_list->next || execution_direction == EXEC_REVERSE)
#define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
/* These are the core structs of the process record functionality.
A record_full_entry is a record of the value change of a register
("record_full_reg") or a part of memory ("record_full_mem"). And each
instruction must have a struct record_full_entry ("record_full_end")
that indicates that this is the last struct record_full_entry of this
instruction.
Each struct record_full_entry is linked to "record_full_list" by "prev"
and "next" pointers. */
struct record_full_mem_entry
{
CORE_ADDR addr;
int len;
/* Set this flag if target memory for this entry
can no longer be accessed. */
int mem_entry_not_accessible;
union
{
gdb_byte *ptr;
gdb_byte buf[sizeof (gdb_byte *)];
} u;
};
struct record_full_reg_entry
{
unsigned short num;
unsigned short len;
union
{
gdb_byte *ptr;
gdb_byte buf[2 * sizeof (gdb_byte *)];
} u;
};
struct record_full_end_entry
{
enum gdb_signal sigval;
ULONGEST insn_num;
};
enum record_full_type
{
record_full_end = 0,
record_full_reg,
record_full_mem
};
/* This is the data structure that makes up the execution log.
The execution log consists of a single linked list of entries
of type "struct record_full_entry". It is doubly linked so that it
can be traversed in either direction.
The start of the list is anchored by a struct called
"record_full_first". The pointer "record_full_list" either points
to the last entry that was added to the list (in record mode), or to
the next entry in the list that will be executed (in replay mode).
Each list element (struct record_full_entry), in addition to next
and prev pointers, consists of a union of three entry types: mem,
reg, and end. A field called "type" determines which entry type is
represented by a given list element.
Each instruction that is added to the execution log is represented
by a variable number of list elements ('entries'). The instruction
will have one "reg" entry for each register that is changed by
executing the instruction (including the PC in every case). It
will also have one "mem" entry for each memory change. Finally,
each instruction will have an "end" entry that separates it from
the changes associated with the next instruction. */
struct record_full_entry
{
struct record_full_entry *prev;
struct record_full_entry *next;
enum record_full_type type;
union
{
/* reg */
struct record_full_reg_entry reg;
/* mem */
struct record_full_mem_entry mem;
/* end */
struct record_full_end_entry end;
} u;
};
/* If true, query if PREC cannot record memory
change of next instruction. */
int record_full_memory_query = 0;
struct record_full_core_buf_entry
{
struct record_full_core_buf_entry *prev;
struct target_section *p;
bfd_byte *buf;
};
/* Record buf with core target. */
static gdb_byte *record_full_core_regbuf = NULL;
static struct target_section *record_full_core_start;
static struct target_section *record_full_core_end;
static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
/* The following variables are used for managing the linked list that
represents the execution log.
record_full_first is the anchor that holds down the beginning of
the list.
record_full_list serves two functions:
1) In record mode, it anchors the end of the list.
2) In replay mode, it traverses the list and points to
the next instruction that must be emulated.
record_full_arch_list_head and record_full_arch_list_tail are used
to manage a separate list, which is used to build up the change
elements of the currently executing instruction during record mode.
When this instruction has been completely annotated in the "arch
list", it will be appended to the main execution log. */
static struct record_full_entry record_full_first;
static struct record_full_entry *record_full_list = &record_full_first;
static struct record_full_entry *record_full_arch_list_head = NULL;
static struct record_full_entry *record_full_arch_list_tail = NULL;
/* 1 ask user. 0 auto delete the last struct record_full_entry. */
static int record_full_stop_at_limit = 1;
/* Maximum allowed number of insns in execution log. */
static unsigned int record_full_insn_max_num
= DEFAULT_RECORD_FULL_INSN_MAX_NUM;
/* Actual count of insns presently in execution log. */
static unsigned int record_full_insn_num = 0;
/* Count of insns logged so far (may be larger
than count of insns presently in execution log). */
static ULONGEST record_full_insn_count;
/* The target_ops of process record. */
static struct target_ops record_full_ops;
static struct target_ops record_full_core_ops;
/* See record-full.h. */
int
record_full_is_used (void)
{
struct target_ops *t;
t = find_record_target ();
return (t == &record_full_ops
|| t == &record_full_core_ops);
}
/* Command lists for "set/show record full". */
static struct cmd_list_element *set_record_full_cmdlist;
static struct cmd_list_element *show_record_full_cmdlist;
/* Command list for "record full". */
static struct cmd_list_element *record_full_cmdlist;
static void record_full_goto_insn (struct record_full_entry *entry,
enum exec_direction_kind dir);
static void record_full_save (struct target_ops *self,
const char *recfilename);
/* Alloc and free functions for record_full_reg, record_full_mem, and
record_full_end entries. */
/* Alloc a record_full_reg record entry. */
static inline struct record_full_entry *
record_full_reg_alloc (struct regcache *regcache, int regnum)
{
struct record_full_entry *rec;
struct gdbarch *gdbarch = get_regcache_arch (regcache);
rec = XCNEW (struct record_full_entry);
rec->type = record_full_reg;
rec->u.reg.num = regnum;
rec->u.reg.len = register_size (gdbarch, regnum);
if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
return rec;
}
/* Free a record_full_reg record entry. */
static inline void
record_full_reg_release (struct record_full_entry *rec)
{
gdb_assert (rec->type == record_full_reg);
if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
xfree (rec->u.reg.u.ptr);
xfree (rec);
}
/* Alloc a record_full_mem record entry. */
static inline struct record_full_entry *
record_full_mem_alloc (CORE_ADDR addr, int len)
{
struct record_full_entry *rec;
rec = XCNEW (struct record_full_entry);
rec->type = record_full_mem;
rec->u.mem.addr = addr;
rec->u.mem.len = len;
if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
return rec;
}
/* Free a record_full_mem record entry. */
static inline void
record_full_mem_release (struct record_full_entry *rec)
{
gdb_assert (rec->type == record_full_mem);
if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
xfree (rec->u.mem.u.ptr);
xfree (rec);
}
/* Alloc a record_full_end record entry. */
static inline struct record_full_entry *
record_full_end_alloc (void)
{
struct record_full_entry *rec;
rec = XCNEW (struct record_full_entry);
rec->type = record_full_end;
return rec;
}
/* Free a record_full_end record entry. */
static inline void
record_full_end_release (struct record_full_entry *rec)
{
xfree (rec);
}
/* Free one record entry, any type.
Return entry->type, in case caller wants to know. */
static inline enum record_full_type
record_full_entry_release (struct record_full_entry *rec)
{
enum record_full_type type = rec->type;
switch (type) {
case record_full_reg:
record_full_reg_release (rec);
break;
case record_full_mem:
record_full_mem_release (rec);
break;
case record_full_end:
record_full_end_release (rec);
break;
}
return type;
}
/* Free all record entries in list pointed to by REC. */
static void
record_full_list_release (struct record_full_entry *rec)
{
if (!rec)
return;
while (rec->next)
rec = rec->next;
while (rec->prev)
{
rec = rec->prev;
record_full_entry_release (rec->next);
}
if (rec == &record_full_first)
{
record_full_insn_num = 0;
record_full_first.next = NULL;
}
else
record_full_entry_release (rec);
}
/* Free all record entries forward of the given list position. */
static void
record_full_list_release_following (struct record_full_entry *rec)
{
struct record_full_entry *tmp = rec->next;
rec->next = NULL;
while (tmp)
{
rec = tmp->next;
if (record_full_entry_release (tmp) == record_full_end)
{
record_full_insn_num--;
record_full_insn_count--;
}
tmp = rec;
}
}
/* Delete the first instruction from the beginning of the log, to make
room for adding a new instruction at the end of the log.
Note -- this function does not modify record_full_insn_num. */
static void
record_full_list_release_first (void)
{
struct record_full_entry *tmp;
if (!record_full_first.next)
return;
/* Loop until a record_full_end. */
while (1)
{
/* Cut record_full_first.next out of the linked list. */
tmp = record_full_first.next;
record_full_first.next = tmp->next;
tmp->next->prev = &record_full_first;
/* tmp is now isolated, and can be deleted. */
if (record_full_entry_release (tmp) == record_full_end)
break; /* End loop at first record_full_end. */
if (!record_full_first.next)
{
gdb_assert (record_full_insn_num == 1);
break; /* End loop when list is empty. */
}
}
}
/* Add a struct record_full_entry to record_full_arch_list. */
static void
record_full_arch_list_add (struct record_full_entry *rec)
{
if (record_debug > 1)
fprintf_unfiltered (gdb_stdlog,
"Process record: record_full_arch_list_add %s.\n",
host_address_to_string (rec));
if (record_full_arch_list_tail)
{
record_full_arch_list_tail->next = rec;
rec->prev = record_full_arch_list_tail;
record_full_arch_list_tail = rec;
}
else
{
record_full_arch_list_head = rec;
record_full_arch_list_tail = rec;
}
}
/* Return the value storage location of a record entry. */
static inline gdb_byte *
record_full_get_loc (struct record_full_entry *rec)
{
switch (rec->type) {
case record_full_mem:
if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
return rec->u.mem.u.ptr;
else
return rec->u.mem.u.buf;
case record_full_reg:
if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
return rec->u.reg.u.ptr;
else
return rec->u.reg.u.buf;
case record_full_end:
default:
gdb_assert_not_reached ("unexpected record_full_entry type");
return NULL;
}
}
/* Record the value of a register NUM to record_full_arch_list. */
int
record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
{
struct record_full_entry *rec;
if (record_debug > 1)
fprintf_unfiltered (gdb_stdlog,
"Process record: add register num = %d to "
"record list.\n",
regnum);
rec = record_full_reg_alloc (regcache, regnum);
regcache_raw_read (regcache, regnum, record_full_get_loc (rec));
record_full_arch_list_add (rec);
return 0;
}
/* Record the value of a region of memory whose address is ADDR and
length is LEN to record_full_arch_list. */
int
record_full_arch_list_add_mem (CORE_ADDR addr, int len)
{
struct record_full_entry *rec;
if (record_debug > 1)
fprintf_unfiltered (gdb_stdlog,
"Process record: add mem addr = %s len = %d to "
"record list.\n",
paddress (target_gdbarch (), addr), len);
if (!addr) /* FIXME: Why? Some arch must permit it... */
return 0;
rec = record_full_mem_alloc (addr, len);
if (record_read_memory (target_gdbarch (), addr,
record_full_get_loc (rec), len))
{
record_full_mem_release (rec);
return -1;
}
record_full_arch_list_add (rec);
return 0;
}
/* Add a record_full_end type struct record_full_entry to
record_full_arch_list. */
int
record_full_arch_list_add_end (void)
{
struct record_full_entry *rec;
if (record_debug > 1)
fprintf_unfiltered (gdb_stdlog,
"Process record: add end to arch list.\n");
rec = record_full_end_alloc ();
rec->u.end.sigval = GDB_SIGNAL_0;
rec->u.end.insn_num = ++record_full_insn_count;
record_full_arch_list_add (rec);
return 0;
}
static void
record_full_check_insn_num (int set_terminal)
{
if (record_full_insn_num == record_full_insn_max_num)
{
/* Ask user what to do. */
if (record_full_stop_at_limit)
{
int q;
if (set_terminal)
target_terminal_ours ();
q = yquery (_("Do you want to auto delete previous execution "
"log entries when record/replay buffer becomes "
"full (record full stop-at-limit)?"));
if (set_terminal)
target_terminal_inferior ();
if (q)
record_full_stop_at_limit = 0;
else
error (_("Process record: stopped by user."));
}
}
}
static void
record_full_arch_list_cleanups (void *ignore)
{
record_full_list_release (record_full_arch_list_tail);
}
/* Before inferior step (when GDB record the running message, inferior
only can step), GDB will call this function to record the values to
record_full_list. This function will call gdbarch_process_record to
record the running message of inferior and set them to
record_full_arch_list, and add it to record_full_list. */
static int
record_full_message (struct regcache *regcache, enum gdb_signal signal)
{
int ret;
struct gdbarch *gdbarch = get_regcache_arch (regcache);
struct cleanup *old_cleanups
= make_cleanup (record_full_arch_list_cleanups, 0);
record_full_arch_list_head = NULL;
record_full_arch_list_tail = NULL;
/* Check record_full_insn_num. */
record_full_check_insn_num (1);
/* If gdb sends a signal value to target_resume,
save it in the 'end' field of the previous instruction.
Maybe process record should record what really happened,
rather than what gdb pretends has happened.
So if Linux delivered the signal to the child process during
the record mode, we will record it and deliver it again in
the replay mode.
If user says "ignore this signal" during the record mode, then
it will be ignored again during the replay mode (no matter if
the user says something different, like "deliver this signal"
during the replay mode).
User should understand that nothing he does during the replay
mode will change the behavior of the child. If he tries,
then that is a user error.
But we should still deliver the signal to gdb during the replay,
if we delivered it during the recording. Therefore we should
record the signal during record_full_wait, not
record_full_resume. */
if (record_full_list != &record_full_first) /* FIXME better way to check */
{
gdb_assert (record_full_list->type == record_full_end);
record_full_list->u.end.sigval = signal;
}
if (signal == GDB_SIGNAL_0
|| !gdbarch_process_record_signal_p (gdbarch))
ret = gdbarch_process_record (gdbarch,
regcache,
regcache_read_pc (regcache));
else
ret = gdbarch_process_record_signal (gdbarch,
regcache,
signal);
if (ret > 0)
error (_("Process record: inferior program stopped."));
if (ret < 0)
error (_("Process record: failed to record execution log."));
discard_cleanups (old_cleanups);
record_full_list->next = record_full_arch_list_head;
record_full_arch_list_head->prev = record_full_list;
record_full_list = record_full_arch_list_tail;
if (record_full_insn_num == record_full_insn_max_num)
record_full_list_release_first ();
else
record_full_insn_num++;
return 1;
}
struct record_full_message_args {
struct regcache *regcache;
enum gdb_signal signal;
};
static int
record_full_message_wrapper (void *args)
{
struct record_full_message_args *record_full_args = args;
return record_full_message (record_full_args->regcache,
record_full_args->signal);
}
static int
record_full_message_wrapper_safe (struct regcache *regcache,
enum gdb_signal signal)
{
struct record_full_message_args args;
args.regcache = regcache;
args.signal = signal;
return catch_errors (record_full_message_wrapper, &args, NULL,
RETURN_MASK_ALL);
}
/* Set to 1 if record_full_store_registers and record_full_xfer_partial
doesn't need record. */
static int record_full_gdb_operation_disable = 0;
struct cleanup *
record_full_gdb_operation_disable_set (void)
{
struct cleanup *old_cleanups = NULL;
old_cleanups =
make_cleanup_restore_integer (&record_full_gdb_operation_disable);
record_full_gdb_operation_disable = 1;
return old_cleanups;
}
/* Flag set to TRUE for target_stopped_by_watchpoint. */
static enum target_stop_reason record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON;
/* Execute one instruction from the record log. Each instruction in
the log will be represented by an arbitrary sequence of register
entries and memory entries, followed by an 'end' entry. */
static inline void
record_full_exec_insn (struct regcache *regcache,
struct gdbarch *gdbarch,
struct record_full_entry *entry)
{
switch (entry->type)
{
case record_full_reg: /* reg */
{
gdb_byte reg[MAX_REGISTER_SIZE];
if (record_debug > 1)
fprintf_unfiltered (gdb_stdlog,
"Process record: record_full_reg %s to "
"inferior num = %d.\n",
host_address_to_string (entry),
entry->u.reg.num);
regcache_cooked_read (regcache, entry->u.reg.num, reg);
regcache_cooked_write (regcache, entry->u.reg.num,
record_full_get_loc (entry));
memcpy (record_full_get_loc (entry), reg, entry->u.reg.len);
}
break;
case record_full_mem: /* mem */
{
/* Nothing to do if the entry is flagged not_accessible. */
if (!entry->u.mem.mem_entry_not_accessible)
{
gdb_byte *mem = alloca (entry->u.mem.len);
if (record_debug > 1)
fprintf_unfiltered (gdb_stdlog,
"Process record: record_full_mem %s to "
"inferior addr = %s len = %d.\n",
host_address_to_string (entry),
paddress (gdbarch, entry->u.mem.addr),
entry->u.mem.len);
if (record_read_memory (gdbarch,
entry->u.mem.addr, mem, entry->u.mem.len))
entry->u.mem.mem_entry_not_accessible = 1;
else
{
if (target_write_memory (entry->u.mem.addr,
record_full_get_loc (entry),
entry->u.mem.len))
{
entry->u.mem.mem_entry_not_accessible = 1;
if (record_debug)
warning (_("Process record: error writing memory at "
"addr = %s len = %d."),
paddress (gdbarch, entry->u.mem.addr),
entry->u.mem.len);
}
else
{
memcpy (record_full_get_loc (entry), mem,
entry->u.mem.len);
/* We've changed memory --- check if a hardware
watchpoint should trap. Note that this
presently assumes the target beneath supports
continuable watchpoints. On non-continuable
watchpoints target, we'll want to check this
_before_ actually doing the memory change, and
not doing the change at all if the watchpoint
traps. */
if (hardware_watchpoint_inserted_in_range
(get_regcache_aspace (regcache),
entry->u.mem.addr, entry->u.mem.len))
record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
}
}
}
}
break;
}
}
static void record_full_restore (void);
/* Asynchronous signal handle registered as event loop source for when
we have pending events ready to be passed to the core. */
static struct async_event_handler *record_full_async_inferior_event_token;
static void
record_full_async_inferior_event_handler (gdb_client_data data)
{
inferior_event_handler (INF_REG_EVENT, NULL);
}
/* Open the process record target. */
static void
record_full_core_open_1 (const char *name, int from_tty)
{
struct regcache *regcache = get_current_regcache ();
int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
int i;
/* Get record_full_core_regbuf. */
target_fetch_registers (regcache, -1);
record_full_core_regbuf = xmalloc (MAX_REGISTER_SIZE * regnum);
for (i = 0; i < regnum; i ++)
regcache_raw_collect (regcache, i,
record_full_core_regbuf + MAX_REGISTER_SIZE * i);
/* Get record_full_core_start and record_full_core_end. */
if (build_section_table (core_bfd, &record_full_core_start,
&record_full_core_end))
{
xfree (record_full_core_regbuf);
record_full_core_regbuf = NULL;
error (_("\"%s\": Can't find sections: %s"),
bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
}
push_target (&record_full_core_ops);
record_full_restore ();
}
/* "to_open" target method for 'live' processes. */
static void
record_full_open_1 (const char *name, int from_tty)
{
if (record_debug)
fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
/* check exec */
if (!target_has_execution)
error (_("Process record: the program is not being run."));
if (non_stop)
error (_("Process record target can't debug inferior in non-stop mode "
"(non-stop)."));
if (!gdbarch_process_record_p (target_gdbarch ()))
error (_("Process record: the current architecture doesn't support "
"record function."));
push_target (&record_full_ops);
}
static void record_full_init_record_breakpoints (void);
/* "to_open" target method. Open the process record target. */
static void
record_full_open (const char *name, int from_tty)
{
struct target_ops *t;
if (record_debug)
fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
record_preopen ();
/* Reset */
record_full_insn_num = 0;
record_full_insn_count = 0;
record_full_list = &record_full_first;
record_full_list->next = NULL;
if (core_bfd)
record_full_core_open_1 (name, from_tty);
else
record_full_open_1 (name, from_tty);
/* Register extra event sources in the event loop. */
record_full_async_inferior_event_token
= create_async_event_handler (record_full_async_inferior_event_handler,
NULL);
record_full_init_record_breakpoints ();
observer_notify_record_changed (current_inferior (), 1);
}
/* "to_close" target method. Close the process record target. */
static void
record_full_close (struct target_ops *self)
{
struct record_full_core_buf_entry *entry;
if (record_debug)
fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
record_full_list_release (record_full_list);
/* Release record_full_core_regbuf. */
if (record_full_core_regbuf)
{
xfree (record_full_core_regbuf);
record_full_core_regbuf = NULL;
}
/* Release record_full_core_buf_list. */
if (record_full_core_buf_list)
{
for (entry = record_full_core_buf_list->prev; entry;
entry = entry->prev)
{
xfree (record_full_core_buf_list);
record_full_core_buf_list = entry;
}
record_full_core_buf_list = NULL;
}
if (record_full_async_inferior_event_token)
delete_async_event_handler (&record_full_async_inferior_event_token);
}
/* "to_async" target method. */
static void
record_full_async (struct target_ops *ops, int enable)
{
if (enable)
mark_async_event_handler (record_full_async_inferior_event_token);
else
clear_async_event_handler (record_full_async_inferior_event_token);
ops->beneath->to_async (ops->beneath, enable);
}
static int record_full_resume_step = 0;
/* True if we've been resumed, and so each record_full_wait call should
advance execution. If this is false, record_full_wait will return a
TARGET_WAITKIND_IGNORE. */
static int record_full_resumed = 0;
/* The execution direction of the last resume we got. This is
necessary for async mode. Vis (order is not strictly accurate):
1. user has the global execution direction set to forward
2. user does a reverse-step command
3. record_full_resume is called with global execution direction
temporarily switched to reverse
4. GDB's execution direction is reverted back to forward
5. target record notifies event loop there's an event to handle
6. infrun asks the target which direction was it going, and switches
the global execution direction accordingly (to reverse)
7. infrun polls an event out of the record target, and handles it
8. GDB goes back to the event loop, and goto #4.
*/
static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
/* "to_resume" target method. Resume the process record target. */
static void
record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
enum gdb_signal signal)
{
record_full_resume_step = step;
record_full_resumed = 1;
record_full_execution_dir = execution_direction;
if (!RECORD_FULL_IS_REPLAY)
{
struct gdbarch *gdbarch = target_thread_architecture (ptid);
record_full_message (get_current_regcache (), signal);
if (!step)
{
/* This is not hard single step. */
if (!gdbarch_software_single_step_p (gdbarch))
{
/* This is a normal continue. */
step = 1;
}
else
{
/* This arch support soft sigle step. */
if (thread_has_single_step_breakpoints_set (inferior_thread ()))
{
/* This is a soft single step. */
record_full_resume_step = 1;
}
else
{
/* This is a continue.
Try to insert a soft single step breakpoint. */
if (!gdbarch_software_single_step (gdbarch,
get_current_frame ()))
{
/* This system don't want use soft single step.
Use hard sigle step. */
step = 1;
}
}
}
}
/* Make sure the target beneath reports all signals. */
target_pass_signals (0, NULL);
ops->beneath->to_resume (ops->beneath, ptid, step, signal);