Ada Bare Bones: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
Line 49: Line 49:
done
done
</source>
</source>


===Exception handling===

I have based my knowledge of this kind of work on GNAT's High Integrity Edition manual, in which is hints that at this level of work, a programmer should be able to declare their own exceptions and be able to raise them. I have had it confirmed via a [http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53684 bug I filed] that this is not the case. Any attempt to do this requests that a package from the RTS called Ada.Exceptions be present, I have experimented by creating a version of this package:

<source lang="ada">
with System;

package Ada.Exceptions is
pragma Preelaborate (Exceptions);

type Exception_Id is private;
pragma Preelaborable_Initialization (Exception_Id);

Null_Id : constant Exception_Id;

procedure Raise_Exception
(E : Exception_Id;
Message : String := "");
pragma No_Return (Raise_Exception);
private
type Exception_Id is new Natural;

Null_Id : constant Exception_Id := Exception_Id'First;
end Ada.Exceptions;

with GNAT.Source_Info;
with Last_Chance_Handler;

package body Ada.Exceptions is
procedure Raise_Exception
(E : Exception_Id;
Message : String := "") is
pragma Unreferenced (E);
pragma Unreferenced (Message);
File : String := GNAT.Source_Info.File;
Line : Positive := GNAT.Source_Info.Line;
Source_Location : String := GNAT.Source_Info.Source_Location;
Enclosing_Entity : String := GNAT.Source_Info.Enclosing_Entity;
pragma Unreferenced (File, Line, Source_Location, Enclosing_Entity);
begin
Last_Chance_Handler (System.Null_Address, 0);

loop
null;
end loop;
end Raise_Exception;
end Ada.Exceptions;
</source>

This seemed to work until I tried to catch the exception inside bare_bones.adb at which point the compiler threw up a number of warnings, resulting in a compile failure:

<pre>
bare_bones.adb:23:17: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:23:17: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:30:07: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:30:07: warning: Last_Chance_Handler will be called on exception
bare_bones.adb:33:17: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:33:17: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:38:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:38:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:44:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:44:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:50:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:50:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:56:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:56:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:61:42: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:61:42: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:86:21: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:86:21: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:86:30: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:86:30: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:86:39: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:86:39: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:89:26: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:89:26: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:97:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:97:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:104:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:104:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:110:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:110:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:124:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:124:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:130:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:130:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:136:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:136:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:142:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:142:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:148:20: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:148:20: warning: "Constraint_Error" may call Last_Chance_Handler
bare_bones.adb:151:04: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:151:04: warning: Last_Chance_Handler will be called on exception
bare_bones.adb:160:04: warning: pragma Restrictions (No_Exception_Propagation) in effect
bare_bones.adb:160:04: warning: this handler can never be entered, and has been removed
bare_bones.adb:160:09: violation of restriction "No_Exception_Propagation" at ../gnat.adc:10
gnatmake: "/home/laguest/src/mine/bare_bones/src/bare_bones.adb" compilation error
make: *** [disk/boot/bare_bones] Error 4
</pre>

So the net effect of this is to not bother with this package and only use the language defined exceptions for bare metal programming.


==Files==
==Files==