我的程序在包详细说明部分出现段错误。我在正文的一个块中声明了一堆变量。它们都是带有 QLOCK、First ID Number、Last ID Number 和数据数组的记录。所有不同的类型,因为每条记录的数据和 ID 范围略有不同。
这些类型都在同一个包规范 (SMO_Types) 中定义,但只有其中一个会导致段错误。
Ada 捕获此段错误并引发存储错误,因此输出如下所示
引发 STORAGE_ERROR : s-intman.adb:136 显式引发
我试图通过放置 Elaborate_All(SMO_Types); 来强制制定顺序;
它在运行时仍然存在段错误。
当我注释掉该声明和该单个变量的任何用途时,它工作正常。
begin -- Package Body
EX1_Access := EX_PKG.Object_Access(Read_Only => False);
EX2_Access := EX_PKG.Object_Access(Read_Only => False);
EX3_Access := EX_PKG.Object_Access(Read_Only => False);
IPC_API.Qlock.Init(Lock => EX1_Access.QLock, Name => "EX1_Access.QLock");
IPC_API.Qlock.Init(Lock => EX2_Access.QLock, Name => "EX2_Access.QLock");
IPC_API.Qlock.Init(Lock => EX3_Access.QLock, Name => "EX3_Access.QLock");
declare
EX1 : constant SMO_Types.EX1_Type
:= (QLock => EX1_Access.QLock,
First => ACT.EX1_ID_Type'first,
Last => ACT.EX1_ID_Type'last,
Data => (others => (EX_File => EX_API_Types.NOT_DEFINED)));
--The following EX2_Type causes the elaboration issue, if I comment this
--declaration/init and it's use the code works.
--If I make a random variable of EX2_Type without making it a constant
--and initializing it there is still a seg fault. Therefor it seems
--likely that the issue lies with the EX2_Type.
EX2 : constant SMO_Types.EX2_Type
:= (QLock => EX2_Access.QLock,
First => ACT.EX2_ID_Type'first,
Last => ACT.EX2_ID_Type'last,
Data => (others => (EX_File => EX_API_Types.NOT_DEFINED)));
EX3 : constant SMO_Types.EX3_Type
:= (QLock => EX3_Access.QLock,
First => ACT.EX3_ID_Type'first,
Last => ACT.EX3_ID_Type'last,
Data => (others => (EX_File => EX_API_Types.NOT_DEFINED)));
begin
EX1_Access.all := EX1;
EX2_Access.all := EX2;
EX3_Access.all := EX3;
end Example_Package;
*** 编辑:这里是类型(忽略 EX1 与 EX2 与 EX3 的奇怪顺序,这不是重新输入错字。这是它们在旧代码中的样子)
MAX_EX_COUNT : constant := 36367;
MAX_EX1_COUNT : constant := 18947;
MAX_EX2_COUNT : constant := 1000;
MAX_EX3_COUNT : constant := 1000;
type EX_ID_Type is range -1 .. MAX_EX_COUNT;
for EX_ID_Type'size use 4*8;
subtype EX2_ID_Type is ID_Type
range 1 .. MAX_EX2_COUNT;
subtype EX1_ID_Type is ID_Type
range EX2_ID_Type'Last+1 .. EX2_ID_Type'Last+MAX_EX1_COUNT;
subtype EX3_ID_Type is ID_Type
range EX1_ID_Type'Last+1 .. EX1_ID_Type'Last+MAX_EX3_COUNT;
type Data_Array_Type is array (EX_ID_Type range <>)
of EX_API_Types.EX_Data_Type;
type EX_Record_Type (First, Last : EX_ID_Type) is
record
Qlock : IPC_API.Qlock.Qlock_Type;
Data : Data_Array_Type(First .. Last);
end record;
subtype EX1_Type is
EX_Record_Type(First => EX1_ID_Type'first,
Last => EX1_ID_Type'last);
subtype EX2_Type is
EX_Record_Type(First => EX2_ID_Type'first,
Last => EX2_ID_Type'last);
subtype EX3_Type is
EX_Record_Type(First => EX3_ID_Type'first,
Last => EX3_ID_Type'last);