Commit 61dddae4 by Robert Dewar Committed by Arnaud Charlet

debug.adb: Eliminate numeric switches for binder/gnatmake

2006-02-13  Robert Dewar  <dewar@adacore.com>
	    Vincent Celier  <celier@adacore.com>

	* debug.adb: Eliminate numeric switches for binder/gnatmake

	* switch-m.adb (Normalize_Compiler_Switches): Record numeric debug
	switches for the compiler.
	(Scan_Make_Switches): Do not allow numeric debug switches for gnatmake
	(Scan_Make_Switches): When failing with an illegal switch, output an
	error message with the full switch.
	Eliminate numeric switches for binder/gnatmake

	* switch.ads, switch.adb (Bad_Switch): New procedure

	* switch-b.adb (Scan_Binder_Switches): Do not accept combined switches.
	Remove 0-9 as debug flag character possibilities
	-d is now controlling the primary stack size when its value is a
	positive. Also add checks against invalid values, and support for kb,
	mb. Ditto for -D switch.

From-SVN: r111053
parent 86ac5e79
...@@ -159,16 +159,6 @@ package body Debug is ...@@ -159,16 +159,6 @@ package body Debug is
-- dy -- dy
-- dz -- dz
-- d1
-- d2
-- d3
-- d4
-- d5
-- d6
-- d7
-- d8
-- d9
-- Debug flags used in package Make and its clients (e.g. GNATMAKE) -- Debug flags used in package Make and its clients (e.g. GNATMAKE)
-- da -- da
...@@ -198,16 +188,6 @@ package body Debug is ...@@ -198,16 +188,6 @@ package body Debug is
-- dy -- dy
-- dz -- dz
-- d1
-- d2
-- d3
-- d4
-- d5
-- d6
-- d7
-- d8
-- d9
-------------------------------------------- --------------------------------------------
-- Documentation for Compiler Debug Flags -- -- Documentation for Compiler Debug Flags --
-------------------------------------------- --------------------------------------------
......
...@@ -41,11 +41,60 @@ package body Switch.B is ...@@ -41,11 +41,60 @@ package body Switch.B is
Ptr : Integer := Switch_Chars'First; Ptr : Integer := Switch_Chars'First;
C : Character := ' '; C : Character := ' ';
function Get_Stack_Size (S : Character) return Int;
-- Used for -d and -D to scan stack size including handling k/m.
-- S is set to 'd' or 'D' to indicate the switch being scanned.
--------------------
-- Get_Stack_Size --
--------------------
function Get_Stack_Size (S : Character) return Int is
Result : Int;
begin
Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
-- In the following code, we enable overflow checking since the
-- multiplication by K or M may cause overflow, which is an error.
declare
pragma Unsuppress (Overflow_Check);
begin
-- Check for additional character 'k' (for kilobytes) or 'm'
-- (for Megabytes), but only if we have not reached the end
-- of the switch string. Note that if this appears before the
-- end of the string we will get an error when we test to make
-- sure that the string is exhausted (at the end of the case).
if Ptr <= Max then
if Switch_Chars (Ptr) = 'k' then
Result := Result * 1024;
Ptr := Ptr + 1;
elsif Switch_Chars (Ptr) = 'm' then
Result := Result * (1024 * 1024);
Ptr := Ptr + 1;
end if;
end if;
exception
when Constraint_Error =>
Osint.Fail
("numeric value out of range for switch: ", (1 => S));
end;
return Result;
end Get_Stack_Size;
-- Start of processing for Scan_Binder_Switches
begin begin
-- Skip past the initial character (must be the switch character) -- Skip past the initial character (must be the switch character)
if Ptr = Max then if Ptr = Max then
Bad_Switch (C); Bad_Switch (Switch_Chars);
else else
Ptr := Ptr + 1; Ptr := Ptr + 1;
end if; end if;
...@@ -62,7 +111,7 @@ package body Switch.B is ...@@ -62,7 +111,7 @@ package body Switch.B is
-- Loop to scan through switches given in switch string -- Loop to scan through switches given in switch string
while Ptr <= Max loop Check_Switch : begin
C := Switch_Chars (Ptr); C := Switch_Chars (Ptr);
case C is case C is
...@@ -103,37 +152,55 @@ package body Switch.B is ...@@ -103,37 +152,55 @@ package body Switch.B is
when 'd' => when 'd' =>
-- Note: for the debug switch, the remaining characters in this if Ptr = Max then
-- switch field must all be debug flags, since all valid switch Bad_Switch (Switch_Chars);
-- characters are also valid debug characters. This switch is not end if;
-- documented on purpose because it is only used by the
-- implementors.
-- Loop to scan out debug flags Ptr := Ptr + 1;
C := Switch_Chars (Ptr);
while Ptr < Max loop -- Case where character after -d is a digit (default stack size)
Ptr := Ptr + 1;
C := Switch_Chars (Ptr);
exit when C = ASCII.NUL or else C = '/' or else C = '-';
if C in '1' .. '9' or else if C in '0' .. '9' then
C in 'a' .. 'z' or else
C in 'A' .. 'Z' -- In this case, we process the default primary stack size
then
Set_Debug_Flag (C); Default_Stack_Size := Get_Stack_Size ('d');
else
Bad_Switch (C); -- Case where character after -d is not digit (debug flags)
end if;
end loop; else
-- Note: for the debug switch, the remaining characters in this
-- switch field must all be debug flags, since all valid switch
-- characters are also valid debug characters. This switch is
-- not documented on purpose because it is only used by the
-- implementors.
-- Loop to scan out debug flags
loop
C := Switch_Chars (Ptr);
return; if C in 'a' .. 'z' or else C in 'A' .. 'Z' then
Set_Debug_Flag (C);
else
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1;
exit when Ptr > Max;
end loop;
end if;
-- Processing for D switch -- Processing for D switch
when 'D' => when 'D' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
Scan_Pos Default_Sec_Stack_Size := Get_Stack_Size ('D');
(Switch_Chars, Max, Ptr, Default_Sec_Stack_Size, C);
-- Processing for e switch -- Processing for e switch
...@@ -182,7 +249,7 @@ package body Switch.B is ...@@ -182,7 +249,7 @@ package body Switch.B is
when 'i' => when 'i' =>
if Ptr = Max then if Ptr = Max then
Bad_Switch (C); Bad_Switch (Switch_Chars);
end if; end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
...@@ -198,7 +265,7 @@ package body Switch.B is ...@@ -198,7 +265,7 @@ package body Switch.B is
Identifier_Character_Set := C; Identifier_Character_Set := C;
Ptr := Ptr + 1; Ptr := Ptr + 1;
else else
Bad_Switch (C); Bad_Switch (Switch_Chars);
end if; end if;
-- Processing for K switch -- Processing for K switch
...@@ -216,6 +283,10 @@ package body Switch.B is ...@@ -216,6 +283,10 @@ package body Switch.B is
-- Processing for m switch -- Processing for m switch
when 'm' => when 'm' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors, C); Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors, C);
...@@ -281,6 +352,10 @@ package body Switch.B is ...@@ -281,6 +352,10 @@ package body Switch.B is
-- Processing for T switch -- Processing for T switch
when 'T' => when 'T' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
Time_Slice_Set := True; Time_Slice_Set := True;
Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C); Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
...@@ -289,6 +364,10 @@ package body Switch.B is ...@@ -289,6 +364,10 @@ package body Switch.B is
-- Processing for u switch -- Processing for u switch
when 'u' => when 'u' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
Dynamic_Stack_Measurement := True; Dynamic_Stack_Measurement := True;
Scan_Nat Scan_Nat
...@@ -307,6 +386,9 @@ package body Switch.B is ...@@ -307,6 +386,9 @@ package body Switch.B is
-- Processing for w switch -- Processing for w switch
when 'w' => when 'w' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
-- For the binder we only allow suppress/error cases -- For the binder we only allow suppress/error cases
...@@ -321,7 +403,7 @@ package body Switch.B is ...@@ -321,7 +403,7 @@ package body Switch.B is
Warning_Mode := Suppress; Warning_Mode := Suppress;
when others => when others =>
Bad_Switch (C); Bad_Switch (Switch_Chars);
end case; end case;
Ptr := Ptr + 1; Ptr := Ptr + 1;
...@@ -329,6 +411,10 @@ package body Switch.B is ...@@ -329,6 +411,10 @@ package body Switch.B is
-- Processing for W switch -- Processing for W switch
when 'W' => when 'W' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
for J in WC_Encoding_Method loop for J in WC_Encoding_Method loop
...@@ -337,7 +423,7 @@ package body Switch.B is ...@@ -337,7 +423,7 @@ package body Switch.B is
exit; exit;
elsif J = WC_Encoding_Method'Last then elsif J = WC_Encoding_Method'Last then
Bad_Switch (C); Bad_Switch (Switch_Chars);
end if; end if;
end loop; end loop;
...@@ -357,6 +443,10 @@ package body Switch.B is ...@@ -357,6 +443,10 @@ package body Switch.B is
-- Processing for X switch -- Processing for X switch
when 'X' => when 'X' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C); Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
...@@ -366,29 +456,21 @@ package body Switch.B is ...@@ -366,29 +456,21 @@ package body Switch.B is
Ptr := Ptr + 1; Ptr := Ptr + 1;
No_Main_Subprogram := True; No_Main_Subprogram := True;
-- Ignore extra switch character -- Processing for --RTS
when '/' =>
Ptr := Ptr + 1;
-- Ignore '-' extra switch caracter, only if it isn't followed by
-- 'RTS'. If it is, then we must process the 'RTS' switch
when '-' => when '-' =>
if Ptr + 3 <= Max and then if Ptr + 4 <= Max and then
Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS" Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
then then
Ptr := Ptr + 1; Ptr := Ptr + 4;
if Switch_Chars (Ptr + 3) /= '=' or else if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
(Switch_Chars (Ptr + 3) = '='
and then Ptr + 4 > Max)
then
Osint.Fail ("missing path for --RTS"); Osint.Fail ("missing path for --RTS");
else
else
-- valid --RTS switch -- valid --RTS switch
Opt.No_Stdinc := True; Opt.No_Stdinc := True;
Opt.RTS_Switch := True; Opt.RTS_Switch := True;
...@@ -396,12 +478,12 @@ package body Switch.B is ...@@ -396,12 +478,12 @@ package body Switch.B is
Src_Path_Name : constant String_Ptr := Src_Path_Name : constant String_Ptr :=
Get_RTS_Search_Dir Get_RTS_Search_Dir
(Switch_Chars (Switch_Chars
(Ptr + 4 .. Switch_Chars'Last), (Ptr + 1 .. Switch_Chars'Last),
Include); Include);
Lib_Path_Name : constant String_Ptr := Lib_Path_Name : constant String_Ptr :=
Get_RTS_Search_Dir Get_RTS_Search_Dir
(Switch_Chars (Switch_Chars
(Ptr + 4 .. Switch_Chars'Last), (Ptr + 1 .. Switch_Chars'Last),
Objects); Objects);
begin begin
...@@ -415,10 +497,7 @@ package body Switch.B is ...@@ -415,10 +497,7 @@ package body Switch.B is
RTS_Src_Path_Name := Src_Path_Name; RTS_Src_Path_Name := Src_Path_Name;
RTS_Lib_Path_Name := Lib_Path_Name; RTS_Lib_Path_Name := Lib_Path_Name;
-- We can exit as there cannot be another switch Ptr := Max + 1;
-- after --RTS
exit;
elsif Src_Path_Name = null elsif Src_Path_Name = null
and then Lib_Path_Name = null and then Lib_Path_Name = null
...@@ -436,15 +515,19 @@ package body Switch.B is ...@@ -436,15 +515,19 @@ package body Switch.B is
end if; end if;
else else
Ptr := Ptr + 1; Bad_Switch (Switch_Chars);
end if; end if;
-- Anything else is an error (illegal switch character) -- Anything else is an error (illegal switch character)
when others => when others =>
Bad_Switch (C); Bad_Switch (Switch_Chars);
end case; end case;
end loop;
if Ptr <= Max then
Bad_Switch (Switch_Chars);
end if;
end Check_Switch;
end Scan_Binder_Switches; end Scan_Binder_Switches;
end Switch.B; end Switch.B;
...@@ -491,7 +491,7 @@ package body Switch.M is ...@@ -491,7 +491,7 @@ package body Switch.M is
-- Skip past the initial character (must be the switch character) -- Skip past the initial character (must be the switch character)
if Ptr = Max then if Ptr = Max then
Bad_Switch (C); Bad_Switch (Switch_Chars);
else else
Ptr := Ptr + 1; Ptr := Ptr + 1;
...@@ -573,15 +573,11 @@ package body Switch.M is ...@@ -573,15 +573,11 @@ package body Switch.M is
while Ptr < Max loop while Ptr < Max loop
Ptr := Ptr + 1; Ptr := Ptr + 1;
C := Switch_Chars (Ptr); C := Switch_Chars (Ptr);
exit when C = ASCII.NUL or else C = '/' or else C = '-';
if C in '1' .. '9' or else if C in 'a' .. 'z' or else C in 'A' .. 'Z' then
C in 'a' .. 'z' or else
C in 'A' .. 'Z'
then
Set_Debug_Flag (C); Set_Debug_Flag (C);
else else
Bad_Switch (C); Bad_Switch (Switch_Chars);
end if; end if;
end loop; end loop;
...@@ -593,7 +589,7 @@ package body Switch.M is ...@@ -593,7 +589,7 @@ package body Switch.M is
Ptr := Ptr + 1; Ptr := Ptr + 1;
if Ptr > Max then if Ptr > Max then
Bad_Switch (C); Bad_Switch (Switch_Chars);
end if; end if;
case Switch_Chars (Ptr) is case Switch_Chars (Ptr) is
...@@ -611,7 +607,7 @@ package body Switch.M is ...@@ -611,7 +607,7 @@ package body Switch.M is
Follow_Links := True; Follow_Links := True;
when others => when others =>
Bad_Switch (C); Bad_Switch (Switch_Chars);
end case; end case;
-- Processing for f switch -- Processing for f switch
...@@ -641,6 +637,10 @@ package body Switch.M is ...@@ -641,6 +637,10 @@ package body Switch.M is
-- Processing for j switch -- Processing for j switch
when 'j' => when 'j' =>
if Ptr = Max then
Bad_Switch (Switch_Chars);
end if;
Ptr := Ptr + 1; Ptr := Ptr + 1;
declare declare
...@@ -721,7 +721,7 @@ package body Switch.M is ...@@ -721,7 +721,7 @@ package body Switch.M is
Verbosity_Level := Opt.High; Verbosity_Level := Opt.High;
when others => when others =>
Osint.Fail ("invalid switch: ", Switch_Chars); Bad_Switch (Switch_Chars);
end case; end case;
Ptr := Ptr + 1; Ptr := Ptr + 1;
...@@ -739,20 +739,15 @@ package body Switch.M is ...@@ -739,20 +739,15 @@ package body Switch.M is
Ptr := Ptr + 1; Ptr := Ptr + 1;
No_Main_Subprogram := True; No_Main_Subprogram := True;
-- Ignore extra switch character
when '/' | '-' =>
Ptr := Ptr + 1;
-- Anything else is an error (illegal switch character) -- Anything else is an error (illegal switch character)
when others => when others =>
Bad_Switch (C); Bad_Switch (Switch_Chars);
end case; end case;
if Ptr <= Max then if Ptr <= Max then
Osint.Fail ("invalid switch: ", Switch_Chars); Bad_Switch (Switch_Chars);
end if; end if;
end Check_Switch; end Check_Switch;
......
...@@ -37,6 +37,11 @@ package body Switch is ...@@ -37,6 +37,11 @@ package body Switch is
Osint.Fail ("invalid switch: ", (1 => Switch)); Osint.Fail ("invalid switch: ", (1 => Switch));
end Bad_Switch; end Bad_Switch;
procedure Bad_Switch (Switch : String) is
begin
Osint.Fail ("invalid switch: ", Switch);
end Bad_Switch;
------------------------- -------------------------
-- Is_Front_End_Switch -- -- Is_Front_End_Switch --
------------------------- -------------------------
...@@ -63,7 +68,6 @@ package body Switch is ...@@ -63,7 +68,6 @@ package body Switch is
and then Switch_Chars (Switch_Chars'First) = '-'; and then Switch_Chars (Switch_Chars'First) = '-';
end Is_Switch; end Is_Switch;
------------------------
-------------- --------------
-- Scan_Nat -- -- Scan_Nat --
-------------- --------------
......
...@@ -86,6 +86,7 @@ private ...@@ -86,6 +86,7 @@ private
-- digit of the integer value. -- digit of the integer value.
procedure Bad_Switch (Switch : Character); procedure Bad_Switch (Switch : Character);
procedure Bad_Switch (Switch : String);
-- Fail with an appropriate message when a switch is not recognized -- Fail with an appropriate message when a switch is not recognized
end Switch; end Switch;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment