I have to port some legacy software written in ADA from Windows to Linux. The program compiles fine, but terminates with a segmentation fault when executed.
The segfault occurs when the program tries to open a file (the file exists ;). Strange to say, the program succeeds in opening another file earlier in the execution without an error. Both files are binary files.
Stepping through the program with gdb, I could track down the last line executed to
DIO.Open (FP (File), To_FCB (Mode), Name, Form);
which is defined in a-direio.adb, line 167.
How can I further investigate the cause of the fault? The values of the parameters to DIO.Open look OK (they are the same as for the previous successful call to DIO.Open, except for the file name). Any hints are appreciated.
Here is the code that eventually calls DIO.Open:
procedure Open
(The_File : in out File_Type;
The_Mode : in A_DB_Mode := DBS_Database_Types.InOut_DB;
The_Name : in String;
The_Form : in String := "") is
begin
Ada_File_IO.Open
(File => The_File,
Mode => DB_Mode_To_File_Mode(The_Mode),
Name => The_Name,
Form => The_Form);
exception
when Ada_File_IO.Status_Error => raise Status_Error;
when Ada_File_IO.Name_Error => raise Name_Error;
when Ada_File_IO.Use_Error => raise Use_Error;
end Open;
where ADA_File_IO is declared as
package Ada_File_IO is
new Ada.Direct_IO(Element_Type => GNL_Universal_Representation.An_Item);
GNL_Universal_Representation.An_Item resolves to
subtype An_Item is GNL_Basic_Types.A_Byte;
type A_Byte is mod 2**Byte_Size;
and DB_Mode_To_File_Mode(The_Mode) resolves to Ada_File_IO.In_File.
This is the gdb output with some filenames (as suggested by Brian)
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb563db40 (LWP 9887)]
0x081053af in system.file_io.open ()
(gdb) bt
#0 0x081053af in system.file_io.open ()
#1 0x080fd447 in system.direct_io.open ()
#2 0x08066182 in dbs_file.ada_file_io.open (file=0x0, mode=in_file, name=...,
form=...)
at /media/chmiwah/ADA/lib/gcc/i686-pc-linux-gnu/4.7.4/adainclude/a-direio.adb:167
#3 0x080665cc in dbs_file.open (the_file=0x0, the_mode=in_db, the_name=...,
the_form=...)
at /media/chmiwah/GISMO/bbp-benchmark/code/rebsys/src/dbs/ntv/bdy/dbs_file.adb:108
#4 0x080631b0 in dbs_database.open (the_database=0xb5500468, the_mode=in_db,
the_name=..., the_form=..., using_the_definition=0xb5646008)
at /media/chmiwah/GISMO/bbp-benchmark/code/rebsys/src/dbs/gnc/bdy/dbs_database.adb:363
I see you are using a multi-threaded program. When using gdb, note that 'bt' will not be terribly useful, as it only shows one thread (I can't rememeber if this is the main thread or the current thread).
Instead, using the following:
thread apply all bt
or
thread apply all bt full
Also, using strace -f -e trace=file your_program args
will be useful to determine if the fault comes before or after the system call to open.
It would be quite useful to know what version of the compiler you are using, and what options were used to build it (esp. if any warnings were disabled).
Are the filename encoding anything more or less than US-ASCII?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With