Commit 300bad0e authored by rdubner's avatar rdubner
Browse files

Version 2.2. Works with Windows10/MSYS2/GDB-9

parent 74e73fd3
......@@ -37,6 +37,7 @@ ifdef DESTDIR
mkdir -p $(DESTDIR)/bin/
install cobcd $(DESTDIR)/bin/
else
mkdir -p /usr/local/bin/
install cobcd /usr/local/bin/
endif
$(MAKE) -C cobst install
......
......@@ -39,21 +39,25 @@ set +e ## This kind of needs to be +e in order to make sure intermediate files
unset COB_SWITCH_1
if grep -q debian /etc/os-release ; then
os_name=debian
fi
if grep -q centos /etc/os-release ; then
os_name=centos
fi
if uname -a | grep -q x86_64 ; then
if uname -a | grep -q x86_64 ; then
platform=x86_64
fi
if uname -a | grep -q arm ; then
if uname -a | grep -q arm ; then
platform=arm
fi
if grep -qs debian /etc/os-release ; then
os_name=debian
fi
if grep -qs centos /etc/os-release ; then
os_name=centos
fi
if uname | grep -q MINGW64_NT ; then
os_name=MINGW64_NT
fi
# Courtesy of stackoverflow, a script to find the directory of the script
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do # resolve $SOURCE until the file is no longer a symlink
......@@ -222,9 +226,11 @@ TRUEBASENAME=$BASENAME
TRUESOURCEFILE=$SOURCEFILE
SOURCEFILE=$(echo $SOURCEFILE | sed "s/$TRUEBASENAME/$TRUEBASENAME$TEMPEST/")
BASENAME=$(echo $BASENAME | sed "s/$TRUEBASENAME/$TRUEBASENAME$TEMPEST/")
#cp $TRUESOURCEFILE $SOURCEFILE ## This is part of the failed "compile elsewhere" effort
#cp $TRUESOURCEFILE $SOURCEFILE ## This is part of the failed "compile elsewhere" effort
if test X$ECHO != X"" ; then
echo platform $platform
echo os_name $os_name
echo GCC $GCC
echo CC1 $CC1
echo ASSEMBLER $ASSEMBLER
......@@ -269,14 +275,32 @@ if test X$result = X"0" ; then
if test X$result = X"0" ; then
if test X$BASENAME = X"" ; then
echo "There doesn't seem to be a source file specified."
echo "We can't proceed the the debug-capable build."
echo "We can't proceed with the debug-capable build."
exit 1
fi
fi
## In this step, we do a partial compilation that ends with the creation
## of the .s assembly language file:
if test X$result = X"0" ; then
if test X$ECHO != X"" ; then
echo COB_CFLAGS="-Wa,-L,-anchls=$BASENAME.lst" $COBC $COBCDFLAGS -S $COBCDXM -d -g \
--fgen-c-line-directives --fgen-c-labels \
-T $BASENAME.cbl.lst --tlines=0 --tsymbols $PREOPTIONS $SOURCEFILE
fi
COB_CFLAGS="-Wa,-L,-anchls=$BASENAME.lst" $COBC $COBCDFLAGS -S $COBCDXM -d -g \
--fgen-c-line-directives --fgen-c-labels \
-T $BASENAME.cbl.lst --tlines=0 --tsymbols $PREOPTIONS $SOURCEFILE
result=$?
fi
## In this step, we do a partial compilation that ends with the creation
## of the BASENAME.lst mixed-language C/Assember output file. It's just
## like previous step, except that the -S switch is replaced with a -c switch
if test X$result = X"0" ; then
# This first step builds the intermediate files that COBST needs. Those files
# include the .h files, the mixed-language
if test X$ECHO != X"" ; then
echo COB_CFLAGS="-Wa,-L,-anchls=$BASENAME.lst" $COBC $COBCDFLAGS -c $COBCDXM -d -g \
--fgen-c-line-directives --fgen-c-labels \
......@@ -288,49 +312,34 @@ if test X$result = X"0" ; then
result=$?
fi
## Remove the .o file that was created in the -c step, just in order to avoid
## any possible confusion.
rm $BASENAME.o
## In this step, we run the COBST program, which combines information
## from BASENAME.lst and the .h files to create BASENAME.sym.c
if test X$result = X"0" ; then
## Build the BASENAME.sym.c file
if test X$ECHO != X"" ; then
echo $COBST -q $BASENAME
fi
$COBST -q $BASENAME
result=$?
fi
## In this step, we compile the BASENAME.sym.c, creating BASENAME.sym.o
## It contains the VARIABLE_STRING and the cprint.py script
if test X$result = X"0" ; then
# Compile the .sym.c file, creating a .sym.o file containing the
# .debug_gdb_scripts section with the VARIABLE_STRING and cprint.py script
if test X$ECHO != X"" ; then
echo $GCC -c -o $BASENAME.sym.o $BASENAME.sym.c
fi
$GCC -c -o $BASENAME.sym.o $BASENAME.sym.c
result=$?
fi
if test X$result = X"0" ; then
# Create the .s file from the .c file
if test X$platform = Xx86_64 ; then
if test X$ECHO != X"" ; then
echo $CC1 -quiet -imultiarch x86_64-linux-gnu \
-D PIC $BASENAME.c -quiet -mtune=generic -march=x86-64 -g -fPIC \
-fstack-protector-strong -Wformat -Wformat-security -o $BASENAME.s
fi
$CC1 -quiet -imultiarch x86_64-linux-gnu \
-D PIC $BASENAME.c -quiet -mtune=generic -march=x86-64 -g -fPIC \
-fstack-protector-strong -Wformat -Wformat-security -o $BASENAME.s
result=$?
fi
fi
if test X$result = X"0" ; then
if test X$platform = Xarm ; then
# This worked on a Raspberry Pi 3 running buster
$CC1 -quiet -imultilib . -imultiarch arm-linux-gnueabihf \
$BASENAME.c -quiet -mfloat-abi=hard -mfpu=vfp -mtls-dialect=gnu \
-marm -march=armv6+fp -g -fPIC -o $BASENAME.s
result=$?
fi
fi
## In this step, we modify the .s file we created earlier. The SFIX
## program removes all .loc references to BASENAME.C and to any .h
## files.
if test X$result = X"0" ; then
# Modify the .s file, removing all .loc references to
......@@ -341,29 +350,22 @@ if test X$result = X"0" ; then
$SFIX -q $BASENAME.s $BASENAME-2.s $BASENAME.c $SOURCEFILE
result=$?
fi
## In this step, we invoke COBC to run the assembler on the modified BASENAME-2.s
## in order to create BASENAME-2.o file
if test X$result = X"0" ; then
# Assemble the modified .s file into a replacement .o file:
if test X$platform = Xx86_64 ; then
if test X$ECHO != X"" ; then
echo $ASSEMBLER --64 -L -anchls=$BASENAME-2.lst \
-o $BASENAME-2.o $BASENAME-2.s
echo COB_CFLAGS="-Wa,-L,-anchls=$BASENAME-2.lst" $COBC -c -o $BASENAME-2.o $BASENAME-2.s
fi
$ASSEMBLER --64 -L -anchls=$BASENAME-2.lst \
-o $BASENAME-2.o $BASENAME-2.s
result=$?
fi
fi
if test X$result = X"0" ; then
if test X$platform = Xarm ; then
# This worked on a Raspberry Pi 3 running buster
$ASSEMBLER -march=armv6 -mfloat-abi=hard -mfpu=vfp -meabi=5 \
-o $BASENAME-2.o $BASENAME-2.s
COB_CFLAGS="-Wa,-L,-anchls=$BASENAME-2.lst" $COBC -c -o $BASENAME-2.o $BASENAME-2.s
result=$?
fi
fi
## In this step, we combine the two .o files to create the executable
if test X$result = X"0" ; then
# Combine the two .o files to create the executable
# Stay in the original directory so that $TARGET, if relative, ends up in
......@@ -379,31 +381,115 @@ if test X$result = X"0" ; then
echo $GCC -shared -o $TARGET $BASENAME-2.o $BASENAME.sym.o -lcob $POSTOPTIONS
fi
$GCC -shared -o $TARGET $BASENAME-2.o $BASENAME.sym.o -lcob $POSTOPTIONS
if test X$os_name = X"MINGW64_NT" ; then
mv $TARGET $BASENAME.dll
fi
fi
fi
# rm $SOURCEFILE ## This is part of the failed "compile elsewhere" effort
#if test X$COBCDNOCLEAN != X"" ; then
# # We are going to keep the intermediate files; give them the right names
# files=`find . -maxdepth 1 -name "$TRUEBASENAME*"`
# for file in $files ; do
# newname=$(echo $file | sed "s/$TRUEBASENAME$TEMPEST/$TRUEBASENAME/")
# if test X$file != X$newname ; then
# mv $file $newname
## In this step, we put a copy of the cprint.py into the right place,
## if it is necessary:
if test X$result = X"0" ; then
if test X$os_name = X"MINGW64_NT" ; then
if test -f $DIR/cprint.py ; then
cp $DIR/cprint.py ./$BASENAME-gdb.py
elif test -f $DIR/python/cprint.py ; then
cp $DIR/python/cprint.py ./$BASENAME-gdb.py
elif test -f /usr/local/bin/cprint.py ; then
cp /usr/local/bin/cprint.py ./$BASENAME-gdb.py
else
echo ERROR: "Couldn't find a copy of cprint.py"
fi
fi
fi
####
#### I am keeping the following comments around, because they contain
#### code known to work on both Intel and Rasperry Pi platforms.
#### Until I get a chance to try the newer script, up above, on the Pi
#if test X$result = X"0" ; then
# # Create the .s file from the .c file
# if test X$platform = Xx86_64 ; then
# if test X$ECHO != X"" ; then
# echo $CC1 -quiet -imultiarch x86_64-linux-gnu \
# -D PIC $BASENAME.c -quiet -mtune=generic -march=x86-64 -g -fPIC \
# -fstack-protector-strong -Wformat -Wformat-security -o $BASENAME.s
# fi
# $CC1 -quiet -imultiarch x86_64-linux-gnu \
# -D PIC $BASENAME.c -quiet -mtune=generic -march=x86-64 -g -fPIC \
# -fstack-protector-strong -Wformat -Wformat-security -o $BASENAME.s
# result=$?
# fi
# fi
#
#if test X$result = X"0" ; then
# if test X$platform = Xarm ; then
# # This worked on a Raspberry Pi 3 running buster
# $CC1 -quiet -imultilib . -imultiarch arm-linux-gnueabihf \
# $BASENAME.c -quiet -mfloat-abi=hard -mfpu=vfp -mtls-dialect=gnu \
# -marm -march=armv6+fp -g -fPIC -o $BASENAME.s
# result=$?
# fi
# fi
#
#if test X$result = X"0" ; then
# # Modify the .s file, removing all .loc references to
# # BASENAME.c and any .h files.
# if test X$ECHO != X"" ; then
# echo $SFIX -q $BASENAME.s $BASENAME-2.s $BASENAME.c $SOURCEFILE
# fi
# $SFIX -q $BASENAME.s $BASENAME-2.s $BASENAME.c $SOURCEFILE
# result=$?
# fi
#
#if test X$result = X"0" ; then
# # Assemble the modified .s file into a replacement .o file:
# if test X$platform = Xx86_64 ; then
# if test X$ECHO != X"" ; then
# echo $ASSEMBLER --64 -L -anchls=$BASENAME-2.lst \
# -o $BASENAME-2.o $BASENAME-2.s
# fi
# done
#else
# # They want to delete the intermediate files...
# files=`find . -maxdepth 1 -name "$TRUEBASENAME$TEMPEST*"`
# for file in $files ; do
# rm $file
# done
# $ASSEMBLER --64 -L -anchls=$BASENAME-2.lst \
# -o $BASENAME-2.o $BASENAME-2.s
# result=$?
# fi
# fi
#
#if test X$result = X"0" ; then
# if test X$platform = Xarm ; then
# # This worked on a Raspberry Pi 3 running buster
# $ASSEMBLER -march=armv6 -mfloat-abi=hard -mfpu=vfp -meabi=5 \
# -o $BASENAME-2.o $BASENAME-2.s
# result=$?
# fi
# fi
#
#if test X$result = X"0" ; then
# # Combine the two .o files to create the executable
# # Stay in the original directory so that $TARGET, if relative, ends up in
# # the right place.
#
# if test X$COBCDXM = X"-x" ; then
# if test X$ECHO != X"" ; then
# echo $COBC $COBCDXM -o $TARGET $BASENAME-2.o $BASENAME.sym.o $POSTOPTIONS
# fi
# $COBC $COBCDXM -o $TARGET $BASENAME-2.o $BASENAME.sym.o $POSTOPTIONS
# else
# if test X$ECHO != X"" ; then
# echo $GCC -shared -o $TARGET $BASENAME-2.o $BASENAME.sym.o -lcob $POSTOPTIONS
# fi
# $GCC -shared -o $TARGET $BASENAME-2.o $BASENAME.sym.o -lcob $POSTOPTIONS
# fi
# fi
if test X$COBCDNOCLEAN = X"" ; then
rm -fr = $BASENAME.c $BASENAME.s $BASENAME*.h $BASENAME.i $BASENAME.lst \
$BASENAME.cbl.lst $BASENAME.full.tab $BASENAME.tab $BASENAME.o \
$BASENAME.cbl.o $BASENAME-2.lst $BASENAME.sym.c $BASENAME.sym.o \
$BASENAME-2.s $BASENAME-2.o
fi
rm -fr = $BASENAME.c $BASENAME.s $BASENAME*.h $BASENAME.i $BASENAME.lst \
$BASENAME.cbl.lst $BASENAME.full.tab $BASENAME.tab $BASENAME.o \
$BASENAME.cbl.o $BASENAME-2.lst $BASENAME.sym.c $BASENAME.sym.o \
$BASENAME-2.s $BASENAME-2.o
fi
......@@ -33,7 +33,7 @@
#include <string>
#include <fstream>
#define VERSION "2.1"
#define VERSION "2.2"
class FILENAME
{
......
......@@ -5,7 +5,7 @@
_realname=gnucobol
pkgbase=mingw-w64-${_realname}-svn
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-svn
pkgver=.r3533
pkgver=.r3534
_specialversion=-dev
pkgrel=1
pkgdesc="GnuCOBOL, a free and modern COBOL compiler (mingw-w64)"
......
optfde01
optfde01.exe
dd_output
optfde01.tab
optfde01-gdb.py
......@@ -28,5 +28,5 @@ $(project) : $(project).cbl
.PHONY : clean
suffixes = .c *.h .i .lst .cbl.lst .full.tab .tab .o .cbl.o
clean:
@rm -f $(addprefix $(project),$(suffixes)) $(project) *.txt $(CLEAN)
@rm -f $(addprefix $(project),$(suffixes)) $(project) *.txt $(CLEAN) $(project)-gdb.py
......@@ -23,6 +23,8 @@ pregit:
#
.PHONY : install
install :
mkdir -p /usr/local/bin/
cp cprint.py /usr/local/bin/
ifeq ($(AUTO_LOAD_FOUND), 0)
echo "set auto-load safe-path /" >>~/.gdbinit
endif
......
......@@ -14,3 +14,7 @@ optfde01/optfde01
optfde01/dd_output
callabc/MAIN
bob01/bob01
*-gdb.py
*.exe
*.dll
......@@ -33,7 +33,7 @@ $(project) : $(project).cbl
suffixes = .c .s *.h .i .lst .cbl.lst .full.tab .tab .o .cbl.o .x -2.lst \
.sym.c .sym.o -2.s -2.o
clean:
@rm -f $(addprefix $(project),$(suffixes)) $(project) *.txt $(CLEAN)
@rm -f $(addprefix $(project),$(suffixes)) $(project) *.txt $(CLEAN) $(project)-gdb.py
endif
......
......@@ -11,13 +11,13 @@ COBCD=../../cobcd
.PHONY : all
all:
# mkdir -p library
cobcd -x -g -d MAIN.cbl
cobcd -m -g -d A.cbl
cobcd -m -g -d B.cbl
cobcd -m -g -d C.cbl
$(COBCD) -x -g -d MAIN.cbl
$(COBCD) -m -g -d A.cbl
$(COBCD) -m -g -d B.cbl
$(COBCD) -m -g -d C.cbl
# mv *.so library
COB_LIBRARY_PATH=./library ./MAIN
.PHONY : clean
clean:
rm -fr library *.so MAIN
rm -fr library *.so *.dll MAIN MAIN.exe *-gdb.py
......@@ -34,7 +34,7 @@
#include <fstream>
#include <vector>
#define VERSION "2.1"
#define VERSION "2.2"
class FILENAME
{
......
......@@ -28,9 +28,6 @@
#
############################################################################ */
// sfix.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <map>
#include <string.h>
......@@ -69,6 +66,7 @@ GetInputFileMappings(const VSTRING &input_file, const string &primary_file)
retval[primary_file] = -1;
for(string s : input_file) {
s = Trim(s);
if( s.find(".file ") != string::npos) {
VSTRING tokens = Split(s,"\t ");
if( tokens[0] EQ ".file" AND isdigit(tokens[1][0]) ) {
......@@ -141,8 +139,12 @@ ReadEntireFile(string filename)
char ach[16384];
while(fgets(ach,sizeof(ach),f)) {
string s = Trim(ach);
retval.push_back(s);
if(strlen(ach) AND ach[strlen(ach)-1] EQ '\n') {
ach[strlen(ach)-1] = '\0';
}
// string s = Trim(ach);
// retval.push_back(s);
retval.push_back(ach);
}
fclose(f);
return retval;
......@@ -189,11 +191,14 @@ main(int argc, char **argv)
int next_function_reference_index = 0;
size_t interject_line_number = -1;
string interject_line = "";
for( size_t i=0; i<input_file.size(); i++ ) {
// Start at 1, rather than zero; we need to get rid of the original
// " .file blah.c " line.
for( size_t i=1; i<input_file.size(); i++ ) {
if( i EQ interject_line_number ) {
ss << interject_line;
}
VSTRING tokens = Split(input_file[i]," \t");
VSTRING tokens = Split(Trim(input_file[i])," \t");
if( tokens[0] EQ ".file" ) {
// We've already taken care of all .file lines
continue;
......@@ -256,6 +261,14 @@ main(int argc, char **argv)
}
}
ss << input_file[i] << endl;
if(tokens[0] EQ "main:") {
// Starting with version 9, GDB seems to be cranky if there isn't
// a .loc entry pretty close to the entry point. The symptom was
// that entering a "L" command caused GDB to simply exit.
//
// So, I am going to force one in:
ss << "\t.loc 1 1 1" << endl;
}
}
FILE *f = fopen(params.s_output_filename.WholePath().c_str(),"w");
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>c:\temp\SM106A.s c:\temp\SM106A-2.s SM106A.c SM106A.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest.s C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest-2.s rtest.c rtest.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>c:\temp\SM106A.s c:\temp\SM106A-2.s SM106A.c SM106A.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest.s C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest-2.s rtest.c rtest.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>c:\temp\SM106A.s c:\temp\SM106A-2.s SM106A.c SM106A.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest.s C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest-2.s rtest.c rtest.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>c:\temp\SM106A.s c:\temp\SM106A-2.s SM106A.c SM106A.cbl</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest.s C:\projects\1-symas\cbl-gdb\samples\ref_test_0\rtest-2.s rtest.c rtest.cbl</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment