Skip to content

Commit fd2d2a7

Browse files
committed
Add verbose output to show the scope entities structure
This will help understand what scope entities are created for input sources, for debugging purposes.
1 parent 434d99f commit fd2d2a7

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

tools/gnatcov/gnatcov_bits_specific.adb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ procedure GNATcov_Bits_Specific is
418418
Create_Matcher (Ignored_Source_Files, Matcher, Has_Matcher);
419419
Inputs.Iterate (SID_Inputs, SID_Load_Wrapper'Access);
420420

421+
-- Now that all the scope entities that can be referenced by
422+
-- --subprograms are known, dump them in verbose mode.
423+
424+
if Verbose then
425+
for CU in 1 .. Last_CU loop
426+
Put_Line ("Scopes for " & Image (CU) & ":");
427+
Dump (Get_Scope_Entities (CU), Line_Prefix => "| ");
428+
end loop;
429+
end if;
430+
421431
-- Parse the listed subprograms of interest
422432

423433
Copy_Arg_List (Opt_Subp_Of_Interest, Subprograms_Inputs);

tools/gnatcov/sc_obligations.adb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,44 @@ package body SC_Obligations is
597597
--
598598
-- ??? Same comment as above.
599599

600+
-----------
601+
-- Image --
602+
-----------
603+
604+
function Image (SE : Scope_Entity) return String is
605+
begin
606+
return
607+
"Scope for "
608+
& Ada.Strings.Unbounded.To_String (SE.Name)
609+
& "[" & Slocs.Image (SE.Sloc)
610+
& "], identifier at "
611+
& Get_Simple_Name (SE.Identifier.Decl_SFI)
612+
& ":" & Img (SE.Identifier.Decl_Line);
613+
end Image;
614+
615+
----------
616+
-- Dump --
617+
----------
618+
619+
procedure Dump
620+
(Scope_Entities : Scope_Entities_Trees.Tree; Line_Prefix : String := "")
621+
is
622+
use Scope_Entities_Trees;
623+
begin
624+
for Cur in Scope_Entities.Iterate loop
625+
declare
626+
Prefix : constant String :=
627+
Line_Prefix & (1 .. 2 * (Natural (Depth (Cur)) - 2) => ' ');
628+
SE : Scope_Entity renames
629+
Scope_Entities.Constant_Reference (Cur);
630+
begin
631+
Put_Line (Prefix & Image (SE));
632+
Put_Line (Prefix & "... from " & Image (SE.From));
633+
Put_Line (Prefix & " to " & Image (SE.To));
634+
end;
635+
end loop;
636+
end Dump;
637+
600638
---------------------
601639
-- Scope_Traversal --
602640
---------------------
@@ -2699,6 +2737,28 @@ package body SC_Obligations is
26992737
return Sloc;
27002738
end Last_Sloc;
27012739

2740+
-----------
2741+
-- Image --
2742+
-----------
2743+
2744+
function Image (CU : CU_Id) return String is
2745+
begin
2746+
return
2747+
(if CU = No_CU_Id
2748+
then "No CU"
2749+
else "CU "
2750+
& Get_Full_Name (CU_Vector.Constant_Reference (CU).Main_Source));
2751+
end Image;
2752+
2753+
-------------
2754+
-- Last_CU --
2755+
-------------
2756+
2757+
function Last_CU return CU_Id is
2758+
begin
2759+
return CU_Vector.Last_Index;
2760+
end Last_CU;
2761+
27022762
--------------
27032763
-- Provider --
27042764
--------------

tools/gnatcov/sc_obligations.ads

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ package SC_Obligations is
108108
No_CU_Id : constant CU_Id := 0;
109109
subtype Valid_CU_Id is CU_Id range No_CU_Id + 1 .. CU_Id'Last;
110110

111+
function Image (CU : CU_Id) return String;
112+
113+
function Last_CU return CU_Id;
114+
-- Return the last compilation unit that was created so far
115+
111116
package CU_Id_Vectors is new Ada.Containers.Vectors (Positive, CU_Id);
112117

113118
function Provider (CU : CU_Id) return SCO_Provider;
@@ -203,6 +208,8 @@ package SC_Obligations is
203208
-- This information is computed by the instrumenters (that know what is
204209
-- a scope, and what is not).
205210

211+
function Image (SE : Scope_Entity) return String;
212+
206213
package Scope_Id_Sets is new Ada.Containers.Ordered_Sets
207214
(Element_Type => Scope_Entity_Identifier);
208215
subtype Scope_Id_Set is Scope_Id_Sets.Set;
@@ -211,6 +218,11 @@ package SC_Obligations is
211218
(Element_Type => Scope_Entity);
212219
subtype Scope_Entities_Tree is Scope_Entities_Trees.Tree;
213220

221+
procedure Dump
222+
(Scope_Entities : Scope_Entities_Trees.Tree; Line_Prefix : String := "");
223+
-- Debug helper: print a representation of Scope_Entities on the standard
224+
-- output. Each line that is printed has the given Line_Prefix.
225+
214226
subtype Tree_Iterator is
215227
Scope_Entities_Trees.Tree_Iterator_Interfaces.Forward_Iterator'Class;
216228
type Iterator_Acc is access Tree_Iterator;

tools/gnatcov/slocs.adb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ package body Slocs is
143143
-- Image --
144144
-----------
145145

146+
function Image (Sloc : Local_Source_Location) return String is
147+
begin
148+
return Img (Sloc.Line) & ":" & Img (Sloc.Column);
149+
end Image;
150+
146151
function Image
147152
(Sloc : Source_Location;
148153
Unique_Name : Boolean := False) return String is

tools/gnatcov/slocs.ads

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ package Slocs is
3737
function "<" (L, R : Local_Source_Location) return Boolean;
3838
function "<=" (L, R : Local_Source_Location) return Boolean;
3939

40+
function Image (Sloc : Local_Source_Location) return String;
41+
4042
No_Local_Location : constant Local_Source_Location := (0, 0);
4143

4244
type Local_Source_Location_Range is record

0 commit comments

Comments
 (0)