LynxOS and LynxOS-178 Topics

This appendix presents information specific to GNAT for LynxOS and LynxOS-178 cross configurations.

LynxOS Topics

This section describes topics that are specific to the GNAT for LynxOS cross configurations.

Getting Started with GNAT on LynxOS

This section is a starting point for using GNAT to develop and execute Ada programs for LynuxWorks’ LynxOS target environment from a Unix host environment. We assume that you know how to use GNAT in a native environment and how to start a telnet or other login session to connect to your LynxOS board.

To compile code for a LynxOS system running on a PowerPC board, the basic compiler command is powerpc-elf-lynxos-gcc.

In order to find the target libraries, GNAT requires the ENV_PREFIX variable to be defined. Please consult your LynxOS documentation for more information about this environment variable.

With GNAT, the easiest way to build the basic Hello World program is with gnatmake. For the LynxOS PowerPC target this would look like:

$ powerpc-elf-lynxos5-gnatmake hello
powerpc-elf-lynxos5-gcc -c hello.adb
powerpc-elf-lynxos5-gnatbind -x hello.ali
powerpc-elf-lynxos5-gnatlink hello.ali

(The first line is the command entered by the user – the subsequent three are the programs run by gnatmake.)

This creates the executable hello, which you then need to load on the board (using ftp or an NFS directory for example) to run it.

Kernel Configuration for LynxOS

The appropriate configuration for your LynxOS kernel depends on the target system and the requirements of your application. GNAT itself adds no additional demands; however in some situations it may be appropriate to increase the conservative resource assumptions made by the default configuration.

Kernel parameters limiting the maximum number of file descriptors, kernel and user threads, synchronization objects, etc., may be set in the file uparam.h. You may also wish to modify the file /etc/starttab, which places limits on data, stack, and core file size. See the documentation provided by LynuxWorks for more information.

Debugging Issues for LynxOS

GNAT’s debugger is based on the same GNU gdb technology as the debugger provided by LynxOS, though with a great number of extensions and enhancements to support the Ada language and GNAT. The LynxOS documentation is relevant to understanding how to get the debugger started if you run into difficulties.

Cross Debugging on PPC LynxOS

The procedure for cross debugging on LynxOS is similar, but requires two additional steps. First, the executable must be launched on the target under the utility gdbserver, and then the cross debugger must be started on the host and attached to it.

To demonstrate a debugging session, we will use a slightly more complex program called demo1.adb, which can be found in the examples directory of the GNAT distribution. This program is compiled with debugging information as follows:

$ powerpc-elf-lynxos5-gnatmake -g demo1
powerpc-elf-lynxos5-gcc -c -g demo1.adb
powerpc-elf-lynxos5-gcc -c -g gen_list.adb
powerpc-elf-lynxos5-gcc -c -g instr.adb
powerpc-elf-lynxos5-gnatbind -x demo1.ali
powerpc-elf-lynxos5-gnatlink -g demo1.ali

Once the executable is created, copy it to your working directory on the board. In this directory, you will have to launch the gdb server and choose a free port number on your TCP/IP socket. Presuming the Internet hostname of the board is myboard and the port chosen is 2345, issue the following command:

myboard> gdbserver myboard:2345 demo1

Then return to your host environment.

Next, attach from gdb:

(gdb) file my_program
(gdb) target remote myboard:2345

To run the cross debugger from the command line without the visual interface use the command powerpc-elf-lynxos5-gdb.

You will see something like:

GNU gdb 4.17.gnat.3.14a1
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.  There is absolutely no warranty
for GDB.  Type "show warranty" for details.  This GDB was configured as
"--host=sparc-sun-solaris2.5.1 --target=powerpc-elf-lynxos".
(gdb)

where (gdb) is the debugger’s prompt. The first thing to do at the prompt from within gdb is to load the symbol table from the executable:

(gdb) file demo1
Reading symbols from demo1...done.
(gdb)

You then have to attach to the server running on the board. Issue the command:

(gdb) target remote myboard:2345

After the server has been started and attached from the host, the program is running on the target but has halted execution at the very beginning. The following commands set a breakpoint and continue execution:

(gdb) break demo1.adb:37
Breakpoint 1 at 0x100064d0: file demo1.adb, line 37.
(gdb) cont
Continuing.

Breakpoint 1, demo1 () at demo1.adb:37
37         Set_Name (Fuel, "Fuel");
(gdb)

Here the execution has stopped at the breakpoint set above. Now you can use the standard gdb commands to examine the stack and program variables.

Note that once execution has completed, the server on the board must be restarted before a new debugging session may begin.

An Example Cross Debugging Session for LynxOS

Carrying on a little further with the debugging session, the following example illustrates some of the usual debugging commands for moving around and seeing where you are:

(gdb) next
38         Set_Name (Water, "Water");
(gdb) bt
#0  demo1 () at demo1.adb:38
#1  0x10001218 in main (argc=1, argv=2147483640, envp=2147483520) at
b~demo1.adb:118
#2  0x10017538 in runmainthread ()
#3  0x10001048 in __start ()
(gdb) up
#1  0x10001218 in main (argc=1, argv=2147483640, envp=2147483520) at
b~demo1.adb:118
118       Ada_Main_Program;
(gdb) down
#0  demo1 () at demo1.adb:38
38         Set_Name (Water, "Water");
(gdb)

To examine and modify variables (of a tagged type here):

(gdb) print speed
$1 = (name => "Speed         ", value => -286331154)
(gdb) ptype speed
type = new instr.instrument with record
    value: instr.speed;
end record
(gdb) speed.value := 3
$2 = 3
(gdb) print speed
$3 = (name => "Speed         ", value => 3)
(gdb) info local
speed = (name => "Speed         ", value => 3)
fuel = (name => "Fuel          ", value => -286331154)
oil = (name => ' ' <repeats 14 times>, value => -286331154, size => 20,
  fill => 42 '*', empty => 46 '.')
water = (name => ' ' <repeats 14 times>, value => -286331154, size => 20,
  fill => 42 '*', empty => 46 '.')
time = (name => ' ' <repeats 14 times>, seconds => 0, minutes => 0, hours =>
0)
chrono = (name => ' ' <repeats 14 times>, seconds => 0, minutes => 0,
  hours => 0)
db = (access demo1.dash_board.internal) 0x0
(gdb)

And finally letting the program it run to completion:

(gdb) c
Continuing.

Program exited normally.
(gdb)

Issues Linking on LynxOS

On PPC Lynx, certain system libraries contain 24 bit PC relative jump instructions. For very large applications it may be impossible for the linker resolve some relocations at link time.

In this case you will see an error like the following:

<object file> : relocation truncated to fit: R_PPC_REL24 exit
collect2: ld returned 1 exit status

One solution to this problem is to reduce the size of your binary. There are several approaches you can try, for instance:

  • Turn off run time checks. (-gnatp)
  • Optimize for space rather than time. (-Os)
  • Disable stack checking (remove option -fstack-check)
  • Disable inlining. (-fno-inline)

If these workarounds are not sufficient to link your application, please contact AdaCore support for additional help.

LynxOS-178 2.2.4 Topics

This section describes topics that are specific to the GNAT for LynxOS-178 2.2.4 cross configurations.

Getting Started with GNAT on LynxOS-178 2.2.4

This section is a starting point for using GNAT to develop and execute Ada programs for LynuxWorks’ LynxOS-178 2.2.4 target environment. We assume that you know how to use GNAT in a native environment and how to start a telnet or other login session to connect to your board running LynxOS-178 2.2.4.

To compile code for a LynxOS-178 2.2.4 system running on a PowerPC board, the basic compiler command is powerpc-elf-lynxos178e-gcc.

In order to find the target libraries, GNAT requires the ENV_PREFIX variable to be defined. Please consult your LynxOS-178 2.2.4 documentation for more information about this environment variable.

With GNAT, the easiest way to build the basic Hello World program is with gnatmake. For the LynxOS-178 2.2.4 PowerPC target this would look like:

$ powerpc-elf-lynxos178e-gnatmake hello
powerpc-elf-lynxos178e-gcc -c hello.adb
powerpc-elf-lynxos178e-gnatbind -x hello.ali
powerpc-elf-lynxos178e-gnatlink hello.ali

(The first line is the command entered by the user – the subsequent three are the programs run by gnatmake.)

This creates the executable hello, which you then need to load on the board (using ftp or an NFS directory for example) to run it. You can also include the binary in your KDI.

Kernel Configuration for LynxOS-178 2.2.4

The appropriate configuration for your LynxOS-178 2.2.4 kernel depends on the target system and the requirements of your application. GNAT itself adds no additional demands; however in some situations it may be appropriate to increase the conservative resource assumptions made by the default configuration.

Resource limits may be set in the file uparam.h for VM0, and in your VCT file for other partitions. See the documentation provided by LynuxWorks for more information.

Debugging Issues for LynxOS-178 2.2.4

GNAT’s debugger is based on the same GNU gdb technology as the debugger provided by LynxOS-178 2.2.4, though with a great number of extensions and enhancements to support the Ada language and GNAT. The LynxOS-178 2.2.4 documentation is relevant to understanding how to get the debugger started if you run into difficulties.

The procedure for cross debugging on LynxOS-178 2.2.4 requires that the executable is first launched on the target under the utility gdbserver, and then the cross debugger is started on the host and attached to it. It is recommended that you include the powerpc-elf-lynxos178e-gdbserver binary in your KDI so it’s always available for debugging.

To demonstrate a debugging session, we will use a slightly more complex program called demo1.adb, which can be found in the examples directory of the GNAT distribution. This program is compiled with debugging information as follows:

$ powerpc-elf-lynxos178e-gnatmake -g demo1
powerpc-elf-lynxos178e-gcc -c -g demo1.adb
powerpc-elf-lynxos178e-gcc -c -g gen_list.adb
powerpc-elf-lynxos178e-gcc -c -g instr.adb
powerpc-elf-lynxos178e-gnatbind -x demo1.ali
powerpc-elf-lynxos178e-gnatlink -g demo1.ali

Once the executable is created, copy it to your working directory on the board. In this directory, you will have to launch the gdb server and choose a free port number on your TCP/IP socket. Presuming the Internet hostname of the board is myboard and the port chosen is 2345, issue the following command:

myboard> powerpc-elf-lynxos178e-gdbserver :2345 demo1

Then return to your host environment and run the debugger. To run the cross debugger from the command line without the visual interface use the command powerpc-elf-lynxos178e-gdb.

The first thing to do at the (gdb) prompt from within gdb is to load the symbol table from the executable:

(gdb) file demo1
Reading symbols from demo1...done.
(gdb)

You then have to attach to the server running on the board. Issue the command:

(gdb) target remote myboard:2345

After the server has been started and attached from the host, the program is running on the target but has halted execution at the very beginning. The following commands set a breakpoint and continue execution:

(gdb) break demo1.adb:37
Breakpoint 1 at 0x100064d0: file demo1.adb, line 37.
(gdb) cont
Continuing.

Breakpoint 1, demo1 () at demo1.adb:37
37         Set_Name (Fuel, "Fuel");
(gdb)

Here the execution has stopped at the breakpoint set above. Now you can use the standard gdb commands to examine the stack and program variables.

Note that once execution has completed, the server on the board must be restarted before a new debugging session may begin.

An Example Cross Debugging Session for LynxOS-178 2.2.4

Carrying on a little further with the debugging session, the following example illustrates some of the usual debugging commands for moving around and seeing where you are:

(gdb) next
38         Set_Name (Water, "Water");
(gdb) bt
#0  demo1 () at demo1.adb:38
#1  0x10001218 in main (argc=1, argv=2147483640, envp=2147483520) at
b~demo1.adb:118
#2  0x10017538 in runmainthread ()
#3  0x10001048 in __start ()
(gdb) up
#1  0x10001218 in main (argc=1, argv=2147483640, envp=2147483520) at
b~demo1.adb:118
118       Ada_Main_Program;
(gdb) down
#0  demo1 () at demo1.adb:38
38         Set_Name (Water, "Water");
(gdb)

To examine and modify variables (of a tagged type here):

(gdb) print speed
$1 = (name => "Speed         ", value => -286331154)
(gdb) ptype speed
type = new instr.instrument with record
    value: instr.speed;
end record
(gdb) speed.value := 3
$2 = 3
(gdb) print speed
$3 = (name => "Speed         ", value => 3)
(gdb) info local
speed = (name => "Speed         ", value => 3)
fuel = (name => "Fuel          ", value => -286331154)
oil = (name => ' ' <repeats 14 times>, value => -286331154, size => 20,
  fill => 42 '*', empty => 46 '.')
water = (name => ' ' <repeats 14 times>, value => -286331154, size => 20,
  fill => 42 '*', empty => 46 '.')
time = (name => ' ' <repeats 14 times>, seconds => 0, minutes => 0, hours =>
0)
chrono = (name => ' ' <repeats 14 times>, seconds => 0, minutes => 0,
  hours => 0)
db = (access demo1.dash_board.internal) 0x0
(gdb)

And finally letting the program it run to completion:

(gdb) c
Continuing.

Program exited normally.
(gdb)