-
Notifications
You must be signed in to change notification settings - Fork 9
/
checkpoints.adb
1612 lines (1344 loc) · 43.9 KB
/
checkpoints.adb
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
------------------------------------------------------------------------------
-- --
-- GNATcoverage --
-- --
-- Copyright (C) 2009-2024, AdaCore --
-- --
-- GNATcoverage is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 3, or (at your option) any later --
-- version. This software is distributed in the hope that it will be useful --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY 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 distributed with this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Unchecked_Deallocation;
pragma Warnings (Off, "* is an internal GNAT unit");
with Ada.Strings.Unbounded.Aux; use Ada.Strings.Unbounded.Aux;
pragma Warnings (On, "* is an internal GNAT unit");
with Interfaces; use Interfaces;
with Coverage.Source;
with Coverage_Options; use Coverage_Options;
with Instrument.Checkpoints;
with Outputs; use Outputs;
with Traces_Files; use Traces_Files;
with Traces_Files_Registry;
package body Checkpoints is
Checkpoint_Magic : constant String := "GNATcov checkpoint" & ASCII.NUL;
procedure Free is new Ada.Unchecked_Deallocation
(SFI_Map_Array, SFI_Map_Acc);
procedure Free is new Ada.Unchecked_Deallocation
(CU_Id_Map_Array, CU_Id_Map_Acc);
procedure Free is new Ada.Unchecked_Deallocation
(Inst_Id_Map_Array, Inst_Id_Map_Acc);
procedure Free is new Ada.Unchecked_Deallocation
(BDD_Node_Id_Map_Array, BDD_Node_Id_Map_Acc);
procedure Free is new Ada.Unchecked_Deallocation
(SCO_Id_Map_Array, SCO_Id_Map_Acc);
procedure Free is new Ada.Unchecked_Deallocation
(SFI_Ignored_Map_Array, SFI_Ignored_Map_Access);
procedure Free is new Ada.Unchecked_Deallocation
(CU_Id_Ignored_Map_Array, CU_Id_Ignored_Access);
procedure Free is new Ada.Unchecked_Deallocation
(SCO_Ignored_Map_Array, SCO_Ignored_Map_Access);
type Binary_Traces_Bits is (Undetermined, Bits_32, Bits_64);
-- Describe the nature of binary traces that contributed to create a
-- checkpoint.
--
-- Undetermined
--
-- No binary trace was used (as far as gnatcov knows).
--
-- Bits_32
--
-- Only 32-bit traces were used.
--
-- Bits_64
--
-- Only 64-bit traces were used.
--
-- Remember that it is invalid to mix 32-bit and 64-bit traces.
subtype Determined_Binary_Traces_Bits is
Binary_Traces_Bits range Bits_32 .. Bits_64;
Supported_Bits : constant Determined_Binary_Traces_Bits :=
(if Pc_Type_Size = 4 then Bits_32 else Bits_64);
-- Kind of binary traces that this instance of gnatcov can read
function Image (Bits : Determined_Binary_Traces_Bits) return String
is (case Bits is
when Bits_32 => "32-bit traces",
when Bits_64 => "64-bit traces");
-- Helper to format error messages about binary traces bits. Return the
-- name of the kind of traces described by Bits.
-----------------------
-- Allocate_SFI_Maps --
-----------------------
procedure Allocate_SFI_Maps
(Relocs : in out Checkpoint_Relocations;
First, Last : Source_File_Index)
is
begin
pragma Assert
(Relocs.SFI_Map = null and then Relocs.Ignored_SFIs = null);
Relocs.SFI_Map :=
new SFI_Map_Array'(First .. Last => No_Source_File);
Relocs.Ignored_SFIs :=
new SFI_Ignored_Map_Array'(First .. Last => False);
Relocs.SFI_Simple_Filenames :=
new SFI_Simple_Name_Map_Array'(First .. Last => <>);
end Allocate_SFI_Maps;
-------------------------
-- Allocate_CU_Id_Maps --
-------------------------
procedure Allocate_CU_Id_Maps
(Relocs : in out Checkpoint_Relocations;
First, Last : CU_Id)
is
begin
pragma Assert (Relocs.CU_Map = null and then Relocs.Ignored_CUs = null);
Relocs.CU_Map :=
new CU_Id_Map_Array'(First .. Last => No_CU_Id);
Relocs.Ignored_CUs :=
new CU_Id_Ignored_Map_Array'(First .. Last => False);
end Allocate_CU_Id_Maps;
---------------------------
-- Allocate_Inst_Id_Maps --
---------------------------
procedure Allocate_Inst_Id_Map
(Relocs : in out Checkpoint_Relocations;
First, Last : Inst_Id)
is
begin
pragma Assert (Relocs.Inst_Map = null);
Relocs.Inst_Map :=
new Inst_Id_Map_Array'(First .. Last => No_Inst_Id);
end Allocate_Inst_Id_Map;
-------------------------------
-- Allocate_BDD_Node_Id_Maps --
-------------------------------
procedure Allocate_BDD_Node_Id_Map
(Relocs : in out Checkpoint_Relocations;
First, Last : BDD_Node_Id)
is
begin
pragma Assert (Relocs.BDD_Map = null);
Relocs.BDD_Map :=
new BDD_Node_Id_Map_Array'(First .. Last => No_BDD_Node_Id);
end Allocate_BDD_Node_Id_Map;
--------------------------
-- Allocate_SCO_Id_Maps --
--------------------------
procedure Allocate_SCO_Id_Map
(Relocs : in out Checkpoint_Relocations;
First, Last : SCO_Id)
is
begin
pragma Assert
(Relocs.SCO_Map = null and then Relocs.Ignored_SCOs = null);
Relocs.SCO_Map :=
new SCO_Id_Map_Array'(First .. Last => No_SCO_Id);
Relocs.Ignored_SCOs :=
new SCO_Ignored_Map_Array'(First .. Last => False);
end Allocate_SCO_Id_Map;
---------------------
-- Get_Simple_Name --
---------------------
function Get_Simple_Name
(Relocs : Checkpoint_Relocations;
CP_SFI : Valid_Source_File_Index) return Unbounded_String
is
begin
return Relocs.SFI_Simple_Filenames.all (CP_SFI);
end Get_Simple_Name;
----------------
-- Ignore_SFI --
----------------
procedure Ignore_SFI
(Relocs : in out Checkpoint_Relocations;
CP_SFI : Source_File_Index)
is
begin
pragma Assert (Relocs.SFI_Map (CP_SFI) = No_Source_File);
Relocs.Ignored_SFIs (CP_SFI) := True;
end Ignore_SFI;
------------------
-- Ignore_CU_Id --
------------------
procedure Ignore_CU_Id
(Relocs : in out Checkpoint_Relocations;
CP_CU_Id : CU_Id)
is
begin
pragma Assert (Relocs.CU_Map (CP_CU_Id) = No_CU_Id);
Relocs.Ignored_CUs (CP_CU_Id) := True;
end Ignore_CU_Id;
----------------
-- Ignore_SCO --
----------------
procedure Ignore_SCO
(Relocs : in out Checkpoint_Relocations;
CP_SCO_Id : SCO_Id)
is
begin
pragma Assert (Relocs.SCO_Map (CP_SCO_Id) = No_SCO_Id);
Relocs.Ignored_SCOs (CP_SCO_Id) := True;
end Ignore_SCO;
-----------------
-- SFI_Ignored --
-----------------
function SFI_Ignored
(Relocs : Checkpoint_Relocations;
CP_SFI : Source_File_Index) return Boolean
is
begin
return CP_SFI /= No_Source_File and then Relocs.Ignored_SFIs (CP_SFI);
end SFI_Ignored;
-------------------
-- CU_Id_Ignored --
-------------------
function CU_Id_Ignored
(Relocs : Checkpoint_Relocations;
CP_CU_Id : CU_Id) return Boolean
is
begin
return CP_CU_Id /= No_CU_Id and then Relocs.Ignored_CUs (CP_CU_Id);
end CU_Id_Ignored;
-----------------
-- SCO_Ignored --
-----------------
function SCO_Ignored
(Relocs : Checkpoint_Relocations;
CP_SCO_Id : SCO_Id) return Boolean
is
begin
return CP_SCO_Id /= No_SCO_Id and then Relocs.Ignored_SCOs (CP_SCO_Id);
end SCO_Ignored;
-----------------
-- Set_SFI_Map --
-----------------
procedure Set_SFI_Map
(Relocs : in out Checkpoint_Relocations;
Source_SFI, Target_SFI : Valid_Source_File_Index)
is
begin
Relocs.SFI_Map (Source_SFI) := Target_SFI;
end Set_SFI_Map;
-------------------------
-- Set_SFI_Simple_Name --
-------------------------
procedure Set_SFI_Simple_Name
(Relocs : in out Checkpoint_Relocations;
SFI : Valid_Source_File_Index;
Simple_Name : Unbounded_String)
is
begin
Relocs.SFI_Simple_Filenames.all (SFI) := Simple_Name;
end Set_SFI_Simple_Name;
-------------------
-- Set_CU_Id_Map --
-------------------
procedure Set_CU_Id_Map
(Relocs : in out Checkpoint_Relocations;
Source_CU_Id, Target_CU_Id : Valid_CU_Id)
is
begin
Relocs.CU_Map (Source_CU_Id) := Target_CU_Id;
end Set_CU_Id_Map;
---------------------
-- Set_Inst_Id_Map --
---------------------
procedure Set_Inst_Id_Map
(Relocs : in out Checkpoint_Relocations;
Source_Inst_Id, Target_Inst_Id : Valid_Inst_Id)
is
begin
Relocs.Inst_Map (Source_Inst_Id) := Target_Inst_Id;
end Set_Inst_Id_Map;
-------------------------
-- Set_BDD_Node_Id_Map --
-------------------------
procedure Set_BDD_Node_Id_Map
(Relocs : in out Checkpoint_Relocations;
Source_BDD_Node_Id, Target_BDD_Node_Id : Valid_BDD_Node_Id)
is
begin
Relocs.BDD_Map (Source_BDD_Node_Id) := Target_BDD_Node_Id;
end Set_BDD_Node_Id_Map;
--------------------
-- Set_SCO_Id_Map --
--------------------
procedure Set_SCO_Id_Map
(Relocs : in out Checkpoint_Relocations;
Source_SCO_Id, Target_SCO_Id : Valid_SCO_Id)
is
begin
Relocs.SCO_Map (Source_SCO_Id) := Target_SCO_Id;
end Set_SCO_Id_Map;
---------------
-- Remap_SFI --
---------------
procedure Remap_SFI
(Relocs : Checkpoint_Relocations;
CP_SFI : in out Source_File_Index)
is
begin
if CP_SFI /= No_Source_File then
CP_SFI := Relocs.SFI_Map (CP_SFI);
pragma Assert (CP_SFI /= No_Source_File);
end if;
end Remap_SFI;
---------------
-- Remap_SFI --
---------------
function Remap_SFI
(Relocs : Checkpoint_Relocations;
CP_SFI : Source_File_Index) return Source_File_Index
is
begin
if CP_SFI /= No_Source_File then
pragma Assert (Relocs.SFI_Map (CP_SFI) /= No_Source_File);
return Relocs.SFI_Map (CP_SFI);
end if;
return CP_SFI;
end Remap_SFI;
-----------------
-- Remap_CU_Id --
-----------------
function Remap_CU_Id
(Relocs : Checkpoint_Relocations;
CP_CU_Id : CU_Id) return CU_Id
is
begin
if CP_CU_Id /= No_CU_Id then
pragma Assert (Relocs.CU_Map (CP_CU_Id) /= No_CU_Id);
return Relocs.CU_Map (CP_CU_Id);
end if;
return CP_CU_Id;
end Remap_CU_Id;
-------------------
-- Remap_Inst_Id --
-------------------
function Remap_Inst_Id
(Relocs : Checkpoint_Relocations;
CP_Inst_Id : Inst_Id) return Inst_Id
is
begin
if CP_Inst_Id /= No_Inst_Id then
pragma Assert (Relocs.Inst_Map (CP_Inst_Id) /= No_Inst_Id);
return Relocs.Inst_Map (CP_Inst_Id);
end if;
return CP_Inst_Id;
end Remap_Inst_Id;
-----------------------
-- Remap_BDD_Node_Id --
-----------------------
function Remap_BDD_Node_Id
(Relocs : Checkpoint_Relocations;
CP_BDD_Node_Id : BDD_Node_Id) return BDD_Node_Id
is
begin
if CP_BDD_Node_Id /= No_BDD_Node_Id then
pragma Assert (Relocs.BDD_Map (CP_BDD_Node_Id) /= No_BDD_Node_Id);
return Relocs.BDD_Map (CP_BDD_Node_Id);
end if;
return CP_BDD_Node_Id;
end Remap_BDD_Node_Id;
------------------
-- Remap_SCO_Id --
------------------
function Remap_SCO_Id
(Relocs : Checkpoint_Relocations;
CP_SCO_Id : SCO_Id) return SCO_Id
is
begin
if CP_SCO_Id /= No_SCO_Id then
pragma Assert (Relocs.SCO_Map (CP_SCO_Id) /= No_SCO_Id);
return Relocs.SCO_Map (CP_SCO_Id);
end if;
return CP_SCO_Id;
end Remap_SCO_Id;
---------------------------
-- Remap_ALI_Annotations --
---------------------------
procedure Remap_ALI_Annotations
(Relocs : Checkpoint_Relocations;
CP_ALI_Annotations : in out ALI_Annotation_Maps.Map)
is
use ALI_Annotation_Maps;
Result : Map;
begin
for Cur in CP_ALI_Annotations.Iterate loop
declare
Sloc : Source_Location := Key (Cur);
begin
Remap_SFI (Relocs, Sloc.Source_File);
if Sloc.Source_File /= No_Source_File then
Result.Include (Sloc, Element (Cur));
end if;
end;
end loop;
CP_ALI_Annotations := Result;
end Remap_ALI_Annotations;
procedure Checkpoint_Load
(Filename : String;
Purpose : Checkpoint_Purpose;
Ignored_Source_Files : access GNAT.Regexp.Regexp) with
Pre => Purpose = Instrumentation or else Ignored_Source_Files = null;
-- Common implementation for SID_Load and Checkpoint_Load
---------------------
-- Checkpoint_Save --
---------------------
procedure Checkpoint_Save
(Filename : String;
Context : access Coverage.Context;
Purpose : Checkpoint_Purpose)
is
SF : Ada.Streams.Stream_IO.File_Type;
begin
Create (SF, Out_File, Filename);
declare
use Coverage;
CSS : aliased Checkpoint_Save_State :=
(Root_Stream_Type with
Stream => Stream (SF),
Filename => +Filename,
Purpose => Purpose);
Supported_Levels : Levels_Type := Current_Levels;
begin
-- Write the checkpoint header: magic, version and purpose
CSS.Write (Checkpoint_Magic);
CSS.Write_U32 (Checkpoint_Version'Last);
CSS.Write_U8 (Checkpoint_Purpose'Pos (Purpose));
-- Describe the binary traces (if any) that contributed to the
-- creation of this checkpoint.
declare
Bits : constant Binary_Traces_Bits :=
(case Currently_Accepted_Trace_Kind is
when Unknown | Source_Trace_File => Undetermined,
when Binary_Trace_File | All_Trace_Files => Supported_Bits);
begin
CSS.Write_U8 (Binary_Traces_Bits'Pos (Bits));
end;
-- Instrumentation is the same for all MC/DC variants, so a
-- checkpoint generated for any of them supports all of them.
-- Instrumentation for MC/DC also provides everything needed
-- for decision coverage analysis.
if Purpose = Instrumentation and then MCDC_Coverage_Enabled then
Supported_Levels (MCDC_Coverage_Level'Range) := (others => True);
Supported_Levels (Decision) := True;
end if;
for Level in Insn .. Fun_Call loop
CSS.Write (Supported_Levels (Level));
end loop;
CSS.Write_U8
(Traces_Files.Any_Accepted_Trace_Kind'Pos
(Traces_Files.Currently_Accepted_Trace_Kind));
Files_Table.Checkpoint_Save (CSS'Access);
SC_Obligations.Checkpoint_Save (CSS'Access);
Instrument.Checkpoints.Checkpoint_Save (CSS'Access);
Coverage.Source.Checkpoint_Save (CSS'Access);
Traces_Files_Registry.Checkpoint_Save (CSS'Access, Context);
end;
Close (SF);
end Checkpoint_Save;
----------------------
-- Checkpoint_Clear --
----------------------
procedure Checkpoint_Clear is
begin
Files_Table.Checkpoint_Clear;
SC_Obligations.Checkpoint_Clear;
Instrument.Checkpoints.Checkpoint_Clear;
Coverage.Source.Checkpoint_Clear;
Traces_Files_Registry.Checkpoint_Clear;
end Checkpoint_Clear;
--------------
-- SID_Load --
--------------
procedure SID_Load
(Filename : String;
Ignored_Source_Files : access GNAT.Regexp.Regexp)
is
SID_Re : constant GNAT.Regexp.Regexp := GNAT.Regexp.Compile (".*\.sid");
begin
if not GNAT.Regexp.Match (Filename, SID_Re) then
Fatal_Error ("invalid "
& Purpose_Name (Instrumentation)
& " file "
& Filename
& ", name of file should have .sid extension");
end if;
Checkpoint_Load (Filename, Instrumentation, Ignored_Source_Files);
end SID_Load;
---------------------
-- Checkpoint_Load --
---------------------
procedure Checkpoint_Load (Filename : String) is
begin
Checkpoint_Load (Filename, Consolidation, null);
end Checkpoint_Load;
---------------------
-- Checkpoint_Load --
---------------------
procedure Checkpoint_Load
(Filename : String;
Purpose : Checkpoint_Purpose;
Ignored_Source_Files : access GNAT.Regexp.Regexp)
is
Dummy : constant Context_Handle :=
Create_Context ("Loading " & Filename);
SF : Ada.Streams.Stream_IO.File_Type;
begin
Open (SF, In_File, Filename);
-- If requested, create an artificial internal error when loading
-- checkpoints.
Raise_Stub_Internal_Error_For (Load_Checkpoint);
declare
CLS : Checkpoint_Load_State :=
(Root_Stream_Type with
Stream => Stream (SF),
Filename => +Filename,
Purpose => Purpose,
others => <>);
Magic : String (Checkpoint_Magic'Range);
begin
CLS.Read (Magic);
if Magic /= Checkpoint_Magic then
Fatal_Error ("invalid checkpoint file " & Filename);
end if;
CLS.Version := CLS.Read_U32;
if CLS.Version /= Checkpoint_Version'Last then
Fatal_Error ("invalid checkpoint version" & CLS.Version'Img);
end if;
-- Check that we are loading the kind of checkpoint we are
-- expecting (Purpose).
declare
CP_Purpose : constant Checkpoint_Purpose :=
Checkpoint_Purpose'Val (CLS.Read_U8);
begin
if CP_Purpose /= Purpose then
Fatal_Error
(Filename & " is a " & Purpose_Name (CP_Purpose)
& " while a " & Purpose_Name (Purpose)
& " was expected");
end if;
end;
-- Check the kind of binary traces that were used to create this
-- checkpoint.
declare
Bits : constant Binary_Traces_Bits :=
Binary_Traces_Bits'Val (CLS.Read_U8);
begin
if Bits not in Undetermined | Supported_Bits then
Fatal_Error
(Filename & " was created with " & Image (Bits)
& " whereas the selected target requires "
& Image (Supported_Bits));
end if;
end;
-- Check that the checkpoint to load covers all the coverage levels
-- that are selected for this run.
--
-- See the note on checkpoint version compatibility for the tedious
-- reading code.
declare
CP_Levels : U8_Array (1 .. 9);
Levels : Levels_Type;
begin
CLS.Read (CP_Levels);
Levels :=
(Insn => Boolean'Val (CP_Levels (1)),
Branch => Boolean'Val (CP_Levels (2)),
Stmt => Boolean'Val (CP_Levels (3)),
Decision => Boolean'Val (CP_Levels (4)),
MCDC => Boolean'Val (CP_Levels (5)),
UC_MCDC => Boolean'Val (CP_Levels (6)),
ATC => Boolean'Val (CP_Levels (7)),
ATCC => Boolean'Val (CP_Levels (8)),
Fun_Call => Boolean'Val (CP_Levels (9)));
declare
Error_Msg : constant String :=
Coverage.Is_Load_Allowed (Filename, Levels);
begin
if Error_Msg'Length > 0 then
Fatal_Error (Error_Msg);
end if;
end;
end;
Update_Current_Trace_Kind
(Any_Accepted_Trace_Kind'Val (CLS.Read_U8));
Files_Table.Checkpoint_Load (CLS, Ignored_Source_Files);
SC_Obligations.Checkpoint_Load (CLS);
Instrument.Checkpoints.Checkpoint_Load (CLS);
Coverage.Source.Checkpoint_Load (CLS);
Traces_Files_Registry.Checkpoint_Load (CLS);
Free (CLS.Relocations);
end;
Close (SF);
end Checkpoint_Load;
----------
-- Read --
----------
procedure Read
(Stream : in out Stateful_Stream;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset)
is
begin
Stream.Stream.Read (Item, Last);
end Read;
----------
-- Free --
----------
procedure Free (Relocs : in out Checkpoint_Relocations) is
begin
Free (Relocs.SFI_Map);
Free (Relocs.CU_Map);
Free (Relocs.Inst_Map);
Free (Relocs.BDD_Map);
Free (Relocs.SCO_Map);
Free (Relocs.Ignored_SFIs);
Free (Relocs.Ignored_CUs);
Free (Relocs.Ignored_SCOs);
end Free;
-----------
-- Write --
-----------
procedure Write
(Stream : in out Stateful_Stream;
Item : Stream_Element_Array)
is
begin
Stream.Stream.Write (Item);
end Write;
-- Note for the Read* procedures below: using stream attributes for
-- well-defined elementary data types (String, Unsigned_*) can be
-- considered stable enough that it will preserve backwards and platform
-- compatibility, except maybe for endianity. For now, gnatcov is supported
-- on little-endian platforms only, so we should be fine.
-------------------
-- Read_BDD_Node --
-------------------
function Read_BDD_Node
(Self : in out Checkpoint_Load_State) return BDD_Node_Id is
begin
return BDD_Node_Id (Self.Read_I32);
end Read_BDD_Node;
-----------------
-- Read_Bit_Id --
-----------------
function Read_Bit_Id
(Self : in out Checkpoint_Load_State) return Any_Bit_Id
is
begin
return Any_Bit_Id (Self.Read_I32);
end Read_Bit_Id;
------------------
-- Read_Boolean --
------------------
function Read_Boolean (Self : in out Checkpoint_Load_State) return Boolean
is
begin
return Boolean'Val (Self.Read_U8);
end Read_Boolean;
-------------
-- Read_CU --
-------------
function Read_CU (Self : in out Checkpoint_Load_State) return CU_Id is
begin
return CU_Id (Self.Read_I32);
end Read_CU;
---------------------------
-- Read_Compilation_Unit --
---------------------------
function Read_Compilation_Unit
(Self : in out Checkpoint_Load_State) return Compilation_Unit
is
Language : constant Supported_Language_Kind := Self.Read_Language_Kind;
begin
return (Language => Language, Unit_Name => Self.Read_Unbounded_String);
end Read_Compilation_Unit;
--------------------
-- Read_Condition --
--------------------
function Read_Condition
(Self : in out Checkpoint_Load_State) return Any_Condition_Index is
begin
return Any_Condition_Index (Self.Read_I32);
end Read_Condition;
----------------------
-- Read_Fingerprint --
----------------------
function Read_Fingerprint
(Self : in out Checkpoint_Load_State)
return SC_Obligations.Fingerprint_Type
is
Buffer : String (1 .. SC_Obligations.Fingerprint_Type'Length);
I : Positive := 1;
begin
Self.Read (Buffer);
return Result : SC_Obligations.Fingerprint_Type do
for Digit of Result loop
Digit := Character'Pos (Buffer (I));
I := I + 1;
end loop;
end return;
end Read_Fingerprint;
--------------
-- Read_I32 --
--------------
function Read_I32
(Self : in out Checkpoint_Load_State) return Interfaces.Integer_32 is
begin
return Interfaces.Integer_32'Input (Self.Stream);
end Read_I32;
------------------
-- Read_Integer --
------------------
function Read_Integer (Self : in out Checkpoint_Load_State) return Integer
is
begin
return Integer (Self.Read_I32);
end Read_Integer;
---------------
-- Read_Inst --
---------------
function Read_Inst (Self : in out Checkpoint_Load_State) return Inst_Id is
begin
return Inst_Id (Self.Read_I32);
end Read_Inst;
------------------------
-- Read_Language_Kind --
------------------------
function Read_Language_Kind
(Self : in out Checkpoint_Load_State) return Supported_Language_Kind is
begin
return Supported_Language_Kind'Val (Self.Read_U32);
end Read_Language_Kind;
---------------------
-- Read_Line_State --
---------------------
function Read_Line_State
(Self : in out Checkpoint_Load_State) return Any_Line_State is
begin
return Any_Line_State'Val (Self.Read_U8);
end Read_Line_State;
--------------------------------
-- Read_Local_Source_Location --
--------------------------------
function Read_Local_Source_Location
(Self : in out Checkpoint_Load_State) return Local_Source_Location
is
Line : constant Natural := Self.Read_Integer;
Column : constant Integer := Self.Read_Integer;
begin
return (Line, Column);
end Read_Local_Source_Location;
--------------------------------------
-- Read_Local_Source_Location_Range --
--------------------------------------
function Read_Local_Source_Location_Range
(Self : in out Checkpoint_Load_State) return Local_Source_Location_Range
is
First : constant Local_Source_Location :=
Self.Read_Local_Source_Location;
Last : constant Local_Source_Location :=
Self.Read_Local_Source_Location;
begin
return (First, Last);
end Read_Local_Source_Location_Range;
-------------
-- Read_PC --
-------------
function Read_PC (Self : in out Checkpoint_Load_State) return Pc_Type is
begin
case Pc_Type'Size is
when 32 =>
return Pc_Type (Self.Read_U32);
when 64 =>
return Pc_Type (Self.Read_U64);
when others =>
raise Program_Error;
end case;
end Read_PC;
--------------
-- Read_SCO --
--------------
function Read_SCO (Self : in out Checkpoint_Load_State) return SCO_Id is
begin
return SCO_Id (Self.Read_I32);
end Read_SCO;
--------------
-- Read_SFI --
--------------
function Read_SFI
(Self : in out Checkpoint_Load_State) return Source_File_Index is
begin
return Source_File_Index (Self.Read_I32);
end Read_SFI;
--------------------------
-- Read_Source_Location --
--------------------------
function Read_Source_Location
(Self : in out Checkpoint_Load_State) return Source_Location
is
begin
return Result : Source_Location do
Self.Read (Result);
end return;
end Read_Source_Location;
--------------------------------
-- Read_Source_Location_Range --
--------------------------------
function Read_Source_Location_Range
(Self : in out Checkpoint_Load_State) return Source_Location_Range is
begin
return Result : Source_Location_Range do
Result.Source_File := Self.Read_SFI;
Result.L := Self.Read_Local_Source_Location_Range;
end return;
end Read_Source_Location_Range;
-----------------
-- Read_String --
-----------------
function Read_String (Self : in out Checkpoint_Load_State) return String is
First : constant Positive := Self.Read_Integer;
Last : constant Natural := Self.Read_Integer;
begin
return Result : String (First .. Last) do
Self.Read (Result);
end return;
end Read_String;
-------------------
-- Read_Tristate --
-------------------
function Read_Tristate
(Self : in out Checkpoint_Load_State) return Tristate is
begin
return Tristate'Val (Self.Read_U8);
end Read_Tristate;
-------------
-- Read_U8 --
-------------
function Read_U8
(Self : in out Checkpoint_Load_State) return Interfaces.Unsigned_8 is
begin
return Interfaces.Unsigned_8'Input (Self.Stream);
end Read_U8;
--------------
-- Read_U16 --
--------------
function Read_U16
(Self : in out Checkpoint_Load_State) return Interfaces.Unsigned_16 is
begin
return Interfaces.Unsigned_16'Input (Self.Stream);
end Read_U16;
--------------
-- Read_U32 --
--------------
function Read_U32
(Self : in out Checkpoint_Load_State) return Interfaces.Unsigned_32 is
begin
return Interfaces.Unsigned_32'Input (Self.Stream);