Follow

Compiling & Running Applications on Raspberry Pi

Using the Command Line

Elastic COBOL has many options to manage compiler and runtime options, but it also comes with a "Simple-Style" menu which provides an easy way to compile & run applications with the most common options already set:

$ ecc -h
Elastic COBOL 14.11.8 (Build Nov 8 2014 20:22:19)
Copyright (C) 2010-2014 Heirloom Computing

Elastic COBOL Simple-Style Compiler Options
Use -help or -help:old for expanded list

usage: ecc [ -option [ param ] ] file(s)

-d Produce listing file & runtime trace info
-p Set COPY library path to parameter
-x Compile and execute (first program in list)
-c Check COBOL syntax (no output)
-t Compile EXEC TRANSACTION constructs
-w Suppress info/warning messages
-v Verbose compilation

 

Compiling an Application

$ cd $HOME/ec4rpi/samples/helloworld/cobol_source
$ ecc hello
Elastic COBOL V14.11.8 Copyright (C) 2010-2014 Heirloom Computing

LOC: 40 (0 variables in 0 records)
Warnings: 0
Errors: 0
Result: Compilation SUCCESSFUL
Building: Class files

 

Running an Application

$ ecr hello
Hello World from Raspberry Pi! 

 

A More Complex Example

$ cd $HOME/ec4rpi/samples/calljava/cobol_source
$ ecc calljava ../java_source/ShowParams.java
Elastic COBOL V14.11.8 Copyright (C) 2010-2014 Heirloom Computing

LOC: 49 (10 variables in 6 records)
Warnings: 0
Errors: 0
Result: Compilation SUCCESSFUL
Building: Class files

The default class path needs to be overridden because we have classes in a different directory to the main program:

  • . = current directory (where calljava is)
  • ../java_source = directory where the called Java program is
  • $HOME/ec4rpi = directory where the Elastic COBOL runtime is
$ ecr -cp .:../java_source:$HOME/ec4rpi/ecobol.jar calljava
Parameter 0: (passed by reference)
Datatype: text='hello ', type='TEXT SIGN-NONE'

Parameter 1: (passed by reference)
Datatype: text='12345', type='ZONED SIGN-NONE JUSTIFIED'

Parameter 2: (passed by reference)
Datatype: text=' ', type='TEXT SIGN-NONE JUSTIFIED'

Parameter 3: (passed by reference)
Datatype: text='in group ', type='TEXT SIGN-NONE'
Datatype: text='3.141', type='FLOAT SIGN-TRAILING JUSTIFIED'
Datatype: text='987', type='ZONED SIGN-NONE JUSTIFIED'

Parameter 4: (passed by reference)
Datatype: text='a ', type='GROUP SIGN-NONE'
Datatype: text='b ', type='GROUP SIGN-NONE'
Datatype: text='c ', type='GROUP SIGN-NONE'
Datatype: text='d ', type='GROUP SIGN-NONE'
Datatype: text='e ', type='GROUP SIGN-NONE'
Datatype: text='f ', type='GROUP SIGN-NONE'
Datatype: text='g ', type='GROUP SIGN-NONE'
Datatype: text='h ', type='GROUP SIGN-NONE'
Datatype: text='i ', type='GROUP SIGN-NONE'
Datatype: text='j ', type='GROUP SIGN-NONE'

Parameter 5: (passed by content)
Datatype: text='Java Object', type='TEXT SIGN-NONE'

Parameter 6: (passed by reference)
Datatype: text='0000000765-', type='BINARY SIGN-TRAILING JUSTIFIED'

Returned from Java. Program terminated.

 

Debugging

Elastic COBOL does not have a command-line debugger. Debugging is usually done in Eclipse, and although it is possible to run Eclipse on the Raspberry Pi, the performance makes it extremely difficult to use productively.

However, Elastic COBOL does provide execution tracing and other information that can be useful to isolate the cause of a bug.

Isolating Exceptions 

Use the programs attached to this article (call.cbl & bug.cbl) and create copies of them on your system. We are going to use the '-d' (debug) compiler directive to turn on trace debugging features.

$ ecc -d call bug
Elastic COBOL V14.11.8 Copyright (C) 2010-2014 Heirloom Computing

LOC: 9 (2 variables in 2 records)
Warnings: 0
Errors: 0
Result: Compilation SUCCESSFUL
Building: Class files
$ export SMAP_DIR=`pwd`

SMAP_DIR is an environment variable that locates debug files output by the compiler.
$ ecr call
PROG=[call] PARA=[CALL-MAIN-PARA OF CALL-MAIN] SOURCE=[call.cbl]
PROG=[call] CALL=[bug:literal] USING=[(null)]
PROG=[bug] PARA=[MAIN OF MAINLOGIC] SOURCE=[bug.cbl]
----
COBOL STACK TRACE
----
==>bug.cbl::12::./bug.cbl
==>call.cbl::6::./call.cbl
----
java.lang.ArrayIndexOutOfBoundsException: 20
at bug.main_OF_mainlogic(bug.java:164)

[...snip...]

The output above presents a COBOL stack trace (in blue) for the program (as well as a Java stack trace, which has been snipped from view). This immediately tells us that the cause of the exception is on line 12 of bug.cbl (and that bug.cbl was called by call.cbl at line 6):

move "a" to item-element(20)

In bug.cbl we can see the definition of "item-element" is within an array that occurs 3 times. Attempting to reference the 20th element of that array is what caused the exception.

Tracing Execution Flow

The other aspect of the output above is runtime tracing of things like paragraphs, calls etc. You can find more detailed information about how to use all the features of runtime tracing here.

Use the programs attached to this article (a.cbl, b.cbl & c.cbl) and create copies of them on your system.

Note in the example below we are also using "-x" to immediately execute the application after compilation. It is important to note that the first program specified is the "main" program and will be executed first.

$ ecc -d -x a b c
Elastic COBOL V14.11.8 Copyright (C) 2010-2014 Heirloom Computing
LOC: 53 (11 variables in 8 records)
Warnings: 0
Errors: 0
Result: Compilation SUCCESSFUL
Building: Class files
Running: a

PROG=[a] SECT=[A-SECTION] SOURCE=[a.cbl]
PROG=[a] PARA=[A-PARA OF A-SECTION] SOURCE=[a.cbl]
PROG=[a]*CALL=[b:literal] USING=[(null)]
PROG=[b] SECT=[B-SECTION] SOURCE=[b.cbl]
PROG=[b] PARA=[B-PARA OF B-SECTION] SOURCE=[b.cbl]
PROG=[b] SECT=[B-EXTENDED] SOURCE=[b.cbl]
PROG=[b] PARA=[B1-PARA OF B-EXTENDED] SOURCE=[b.cbl]
PROG=[b] PARA=[B2-PARA OF B-EXTENDED] SOURCE=[b.cbl]
PROG=[b]*CALL=[c:literal] USING=[lnk.b_item]
PROG=[c] SECT=[C-SECTION] SOURCE=[c.cbl]
PROG=[c] PARA=[C-PARA OF C-SECTION] SOURCE=[c.cbl]
PROG=[a]*CALL=[b:wrk.b_name] USING=[wrk.a_item,wrk.b_item] GIVING=[wrk.x_item]
PROG=[b] SECT=[B-SECTION] SOURCE=[b.cbl]
PROG=[b] PARA=[B-PARA OF B-SECTION] SOURCE=[b.cbl]
PROG=[b] SECT=[B-EXTENDED] SOURCE=[b.cbl]
PROG=[b] PARA=[B1-PARA OF B-EXTENDED] SOURCE=[b.cbl]
PROG=[b] PARA=[B2-PARA OF B-EXTENDED] SOURCE=[b.cbl]
PROG=[b]*CALL=[c:literal] USING=[lnk.b_item]
PROG=[c] SECT=[C-SECTION] SOURCE=[c.cbl]
PROG=[c] PARA=[C-PARA OF C-SECTION] SOURCE=[c.cbl]
PROG=[a]*CALL=[c:literal] USING=["fred","bill","jane"]
PROG=[c] SECT=[C-SECTION] SOURCE=[c.cbl]
PROG=[c] PARA=[C-PARA OF C-SECTION] SOURCE=[c.cbl]
PROG=[a]*CALL=[b:wrk.c_name] USING=["123","456","78.9"]
PROG=[b] SECT=[B-SECTION] SOURCE=[b.cbl]
PROG=[b] PARA=[B-PARA OF B-SECTION] SOURCE=[b.cbl]
PROG=[b] SECT=[B-EXTENDED] SOURCE=[b.cbl]
PROG=[b] PARA=[B1-PARA OF B-EXTENDED] SOURCE=[b.cbl]
PROG=[b] PARA=[B2-PARA OF B-EXTENDED] SOURCE=[b.cbl]
PROG=[b]*CALL=[c:literal] USING=[lnk.b_item]
PROG=[c] SECT=[C-SECTION] SOURCE=[c.cbl]
PROG=[c] PARA=[C-PARA OF C-SECTION] SOURCE=[c.cbl]
PROG=[a]*CALL=[c:wrk.c_name] USING=[wrk.x_item,"STRING"]
PROG=[c] SECT=[C-SECTION] SOURCE=[c.cbl]
PROG=[c] PARA=[C-PARA OF C-SECTION] SOURCE=[c.cbl]
PROG=[a] PARA=[A-EXIT OF A-SECTION] SOURCE=[a.cbl]
PROG=[a]*CALL=[M$ALLOC:literal] USING=["1048576",wrk.p_item]

Next Step

Click here to see how to compile and run a GUI application.

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk