Commit 112441d1 authored by rdubner's avatar rdubner

Modify cobcd.py to be Python 2/3 agnostic. Runs as Python2. Modify cobcd-st...

Modify cobcd.py to be Python 2/3 agnostic.  Runs as Python2.  Modify cobcd-st and cobcd to put Python script alongside executable, rather than inside
parent c2cf08bb
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
## Don't mess with it! # ## Don't mess with it! #
########################################################################### ###########################################################################
# [Version 2.9] # [Version 3.1]
# This script, nominally named cobcd, packages up the process of compiling # This script, nominally named cobcd, packages up the process of compiling
# a single COBOL source module and processing it so that gdb can be used for # a single COBOL source module and processing it so that gdb can be used for
...@@ -58,10 +58,19 @@ if uname -a | grep -q arm ; then ...@@ -58,10 +58,19 @@ if uname -a | grep -q arm ; then
if grep -qs debian /etc/os-release ; then if grep -qs debian /etc/os-release ; then
os_name=debian os_name=debian
fi fi
if grep -qs centos /etc/os-release ; then if grep -qs centos /etc/os-release ; then
os_name=centos os_name=centos
fi fi
if uname -a | grep -qs centos7 ; then
os_name=centos7
fi
if uname -a | grep -qs rhel7 ; then
os_name=rhel7
fi
if uname | grep -q MINGW32_NT ; then if uname | grep -q MINGW32_NT ; then
os_name=MINGW32_NT os_name=MINGW32_NT
fi fi
...@@ -92,9 +101,15 @@ LOADER=`$GCC --print-prog-name ld` ...@@ -92,9 +101,15 @@ LOADER=`$GCC --print-prog-name ld`
if test X"$COBCDEVEL" != X"" ; then if test X"$COBCDEVEL" != X"" ; then
COBST=$DIR/cobcd-st/cobcd-st COBST=$DIR/cobcd-st/cobcd-st
SFIX=$DIR/cobcd-sfix/cobcd-sfix SFIX=$DIR/cobcd-sfix/cobcd-sfix
PYTHON=$DIR/python/cobcd.py
else else
COBST=cobcd-st COBST=cobcd-st
SFIX=cobcd-sfix SFIX=cobcd-sfix
PYTHON=`which cobcd.py`
fi
if test X"$os_name" == X"centos7" || test X"$os_name" == X"rhel7" ; then
COBST_FLAGS=-n
fi fi
########################################################### ###########################################################
...@@ -288,27 +303,29 @@ BASENAME=$(echo $BASENAME | sed "s/$TRUEBASENAME/$TRUEBASENAME$TEMPEST/") ...@@ -288,27 +303,29 @@ 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 if test X$ECHO != X"" ; then
echo platform $platform echo platform $platform
echo os_name $os_name echo os_name $os_name
echo GCC $GCC echo GCC $GCC
echo CC1 $CC1 echo CC1 $CC1
echo ASSEMBLER $ASSEMBLER echo ASSEMBLER $ASSEMBLER
echo LOADER $LOADER echo LOADER $LOADER
echo COBC $COBC echo COBC $COBC
echo cob_cflags $cob_cflags echo cob_cflags $cob_cflags
echo COBST $COBST echo COBST $COBST
echo SFIX $SFIX echo COBST_FLAGS $COBST_FLAGS
echo COBCDEVEL $COBCDEVEL echo SFIX $SFIX
echo COBCDNOCLEAN $COBCDNOCLEAN echo PYTHON $PYTHON
echo COBCDXM $COBCDXM echo COBCDEVEL $COBCDEVEL
echo ORIGINAL $ORIGINAL echo COBCDNOCLEAN $COBCDNOCLEAN
echo PREOPTIONS $PREOPTIONS echo COBCDXM $COBCDXM
echo ORIGINAL $ORIGINAL
echo PREOPTIONS $PREOPTIONS
echo TRUESOURCEFILE $TRUESOURCEFILE echo TRUESOURCEFILE $TRUESOURCEFILE
echo TRUEBASENAME $TRUEBASENAME echo TRUEBASENAME $TRUEBASENAME
echo SOURCEFILE $SOURCEFILE echo SOURCEFILE $SOURCEFILE
echo BASENAME $BASENAME echo BASENAME $BASENAME
echo POSTOPTIONS $POSTOPTIONS echo POSTOPTIONS $POSTOPTIONS
echo TARGET $TARGET echo TARGET $TARGET
set | grep COB set | grep COB
fi fi
...@@ -361,9 +378,9 @@ if test X$result = X"0" ; then ...@@ -361,9 +378,9 @@ if test X$result = X"0" ; then
if test X$result = X"0" ; then if test X$result = X"0" ; then
if test X$ECHO != X"" ; then if test X$ECHO != X"" ; then
echo $COBST -q $BASENAME echo $COBST -q $COBST_FLAGS $BASENAME
fi fi
$COBST -q $BASENAME $COBST -q $COBST_FLAGS $BASENAME
result=$? result=$?
fi fi
...@@ -431,13 +448,14 @@ if test X$result = X"0" ; then ...@@ -431,13 +448,14 @@ if test X$result = X"0" ; then
## if it is necessary for this operating system: ## if it is necessary for this operating system:
if test X$result = X"0" ; then if test X$result = X"0" ; then
if test X$os_name = X"MINGW32_NT" || test X$os_name = X"MINGW64_NT" || test X$os_name = X"MSYS_NT" ; then if test X$os_name = X"MINGW32_NT" \
if test -f $DIR/cobcd.py ; then || test X$os_name = X"MINGW64_NT" \
cp $DIR/cobcd.py ./$BASENAME-gdb.py || test X$os_name = X"MSYS_NT" \
elif test -f $DIR/python/cobcd.py ; then || test X$os_name = X"centos7" \
cp $DIR/python/cobcd.py ./$BASENAME-gdb.py || test X$os_name = X"rhel7" \
elif test -f /usr/local/bin/cobcd.py ; then ; then
cp /usr/local/bin/cobcd.py ./$BASENAME-gdb.py if test -f $PYTHON ; then
cp $PYTHON ./$BASENAME-gdb.py
else else
echo ERROR: "Couldn't find a copy of cobcd.py" echo ERROR: "Couldn't find a copy of cobcd.py"
fi fi
......
...@@ -328,10 +328,9 @@ main(int argc, char *argv[]) ...@@ -328,10 +328,9 @@ main(int argc, char *argv[])
// Create the .sym.c file that will be compiled and linked into the // Create the .sym.c file that will be compiled and linked into the
// executable, providing the text that will become the executable's // executable, providing the text that will become the executable's
// .debug_gdb_scripts section // .debug_gdb_scripts section
bool tack_on_python = params.insert_python;
#if defined(_WIN32) #if defined(_WIN32)
bool tack_on_python = false; tack_on_python = false;
#else
bool tack_on_python = true;
#endif #endif
CreateSymc(params, CreateSymc(params,
program_labels, program_labels,
......
...@@ -203,11 +203,12 @@ static void ...@@ -203,11 +203,12 @@ static void
Usage() Usage()
{ {
cerr << "cobst: Cobol Symbol Table generator version: " << VERSION << endl; cerr << "cobst: Cobol Symbol Table generator version: " << VERSION << endl;
cerr << "cobst [-v] [-q] FileName.CBL\n"; cerr << "cobst [-v] [-q] [-n] FileName.CBL\n";
cerr << "Reads various other files with the same FileName root;\n"; cerr << "Reads various other files with the same FileName root;\n";
cerr << "Generates FileName.tab containing the symbol table data\n"; cerr << "Generates FileName.tab containing the symbol table data\n";
cerr << "-q suppresses the one-line version announcement\n"; cerr << "-q suppresses the one-line version announcement\n";
cerr << "-v generates the one-line version announcement and exits\n"; cerr << "-v generates the one-line version announcement and exits\n";
cerr << "-n suppresses the insertion of cobcb.py into SOURCE.sym.c\n";
} }
void void
...@@ -241,10 +242,11 @@ PARAMETERS::GetParameters(int argc, char *argv[]) ...@@ -241,10 +242,11 @@ PARAMETERS::GetParameters(int argc, char *argv[])
} }
quiet = false; quiet = false;
insert_python = true;
string input_parameter; string input_parameter;
int c; int c;
while ((c = getopt (argc, argv, "qv")) != -1) { while ((c = getopt (argc, argv, "qvn")) != -1) {
switch (c) { switch (c) {
case 'q': case 'q':
quiet = true; quiet = true;
...@@ -254,6 +256,9 @@ PARAMETERS::GetParameters(int argc, char *argv[]) ...@@ -254,6 +256,9 @@ PARAMETERS::GetParameters(int argc, char *argv[])
<< VERSION << endl; << VERSION << endl;
exit(0); exit(0);
break; break;
case 'n':
insert_python = false;
break;
case '?': case '?':
fprintf (stderr, "Unknown option '-%c'.\n", optopt); fprintf (stderr, "Unknown option '-%c'.\n", optopt);
exit(1); exit(1);
......
...@@ -123,6 +123,7 @@ public: ...@@ -123,6 +123,7 @@ public:
std::ofstream symc; std::ofstream symc;
bool quiet; bool quiet;
bool insert_python;
void GetParameters(int argc, char *argv[]); void GetParameters(int argc, char *argv[]);
}; };
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
::## Don't mess with it! # ::## Don't mess with it! #
::########################################################################### ::###########################################################################
:: ::
::# [Version 2.9] ::# [Version 3.1]
:: ::
@ECHO OFF @ECHO OFF
SETLOCAL SETLOCAL
......
...@@ -29,6 +29,13 @@ ...@@ -29,6 +29,13 @@
# This module implements the gdb extension commands cprint and cwatch # This module implements the gdb extension commands cprint and cwatch
#EndOfCopyright######################################################## #EndOfCopyright########################################################
from __future__ import print_function
import re
import sys
import os
import traceback
# This module implements the gdb extension commands cprint and cwatch # This module implements the gdb extension commands cprint and cwatch
# #
# This script is read by the COBST program and incorporated into a # This script is read by the COBST program and incorporated into a
...@@ -109,11 +116,6 @@ COB_FLAG_REAL_SIGN = (1 << 10) # /* 0x0400 */ ...@@ -109,11 +116,6 @@ COB_FLAG_REAL_SIGN = (1 << 10) # /* 0x0400 */
COB_FLAG_BINARY_TRUNC = (1 << 11) # /* 0x0800 */ COB_FLAG_BINARY_TRUNC = (1 << 11) # /* 0x0800 */
COB_FLAG_CONSTANT = (1 << 12) # /* 0x1000 */ COB_FLAG_CONSTANT = (1 << 12) # /* 0x1000 */
import re
import sys
import os
import traceback
def NoNulls(s) : def NoNulls(s) :
ss = "" ss = ""
for ch in s: for ch in s:
...@@ -223,7 +225,7 @@ def BlankIsZero(v) : ...@@ -223,7 +225,7 @@ def BlankIsZero(v) :
v = "0" v = "0"
return int(v) return int(v)
def GetAddressOf(variable:str) : def GetAddressOf(variable) :
if 'gdb' in sys.modules : if 'gdb' in sys.modules :
try : try :
command = "info address " + variable command = "info address " + variable
...@@ -237,7 +239,7 @@ def GetAddressOf(variable:str) : ...@@ -237,7 +239,7 @@ def GetAddressOf(variable:str) :
address_string = address_string[nfound+3:] address_string = address_string[nfound+3:]
nfound = address_string.find(' ') nfound = address_string.find(' ')
address_string = address_string[0:nfound] address_string = address_string[0:nfound]
address:int = int(address_string,16) address = int(address_string,16)
return address return address
except gdb.error: except gdb.error:
print("gdb.execute failed:",command) print("gdb.execute failed:",command)
...@@ -373,10 +375,10 @@ class VarTrie() : ...@@ -373,10 +375,10 @@ class VarTrie() :
return retval return retval
def NameMatcher(self, def NameMatcher(self,
boys:[], boys,
boy_index:int, boy_index,
trie:VarTrieNode, trie,
paths:[]) : paths) :
# Nomenclature: We have a list of lost_boys: A/B/C # Nomenclature: We have a list of lost_boys: A/B/C
# We have a forest, where some of the trees are labeled. # We have a forest, where some of the trees are labeled.
# The labels might be # The labels might be
...@@ -485,6 +487,11 @@ class VarTrie() : ...@@ -485,6 +487,11 @@ class VarTrie() :
# with bupkis. Let's start again with the very first element (if # with bupkis. Let's start again with the very first element (if
# there was more than one) and give him some options: # there was more than one) and give him some options:
if desired == '*' :
for index in range(len(self.storage_list)) :
paths.append(index)
return paths
fragment = desired.split()[0] fragment = desired.split()[0]
pattern1 = re.compile("^" + fragment) pattern1 = re.compile("^" + fragment)
...@@ -534,10 +541,10 @@ class LineList() : ...@@ -534,10 +541,10 @@ class LineList() :
self.line_list = [] # This will be a list of (int,str) tuples self.line_list = [] # This will be a list of (int,str) tuples
self.EndOfTheWorld = 10000000 self.EndOfTheWorld = 10000000
def Insert(self,line_number : int, program_id : str) : def Insert(self,line_number , program_id ) :
self.line_list.append( (line_number,program_id) ) self.line_list.append( (line_number,program_id) )
def Find(self,line_number : int) : def Find(self,line_number ) :
# returns the program-id that covers line_number # returns the program-id that covers line_number
if len(self.line_list) == 0 : if len(self.line_list) == 0 :
...@@ -788,7 +795,7 @@ class CobolVariable() : ...@@ -788,7 +795,7 @@ class CobolVariable() :
return True return True
def SetToRside(self, line_list : LineList(), rside) : def SetToRside(self, line_list , rside) :
#print( "Inside SetToRside", rside) #print( "Inside SetToRside", rside)
GotData = True GotData = True
...@@ -939,7 +946,7 @@ class CobolVariable() : ...@@ -939,7 +946,7 @@ class CobolVariable() :
else : else :
return None return None
def FetchVariableData(self, line_list : LineList(), show_failure ) : def FetchVariableData(self, line_list , show_failure ) :
data_string = None data_string = None
self.location = "" self.location = ""
self.data = [] self.data = []
...@@ -2678,10 +2685,10 @@ class TabFileInformation() : ...@@ -2678,10 +2685,10 @@ class TabFileInformation() :
def __init__(self) : def __init__(self) :
self.var_trie = VarTrie() self.var_trie = VarTrie()
self.line_list = LineList() self.line_list = LineList()
self.current_variable_string:str = "" self.current_variable_string = ""
self.current_trapped_routine:str = "" self.current_trapped_routine = ""
self.current_trapped_file:str = "" self.current_trapped_file = ""
self.current_trapped_line:int = 0 self.current_trapped_line = 0
def ProcessInfoStack(self, info_stack) : def ProcessInfoStack(self, info_stack) :
""" Figures out which routine we are currently trapped in""" """ Figures out which routine we are currently trapped in"""
...@@ -2736,7 +2743,7 @@ class TabFileInformation() : ...@@ -2736,7 +2743,7 @@ class TabFileInformation() :
self.var_trie.LoadFromLine(variable_line) self.var_trie.LoadFromLine(variable_line)
# Put a fencepost at the end of the line_list # Put a fencepost at the end of the line_list
self.line_list.Insert(self.line_list.EndOfTheWorld,"Ragnarök") self.line_list.Insert(self.line_list.EndOfTheWorld,"Ragnarok")
def ReadSymbolTableText(self) : def ReadSymbolTableText(self) :
...@@ -2838,7 +2845,7 @@ class CPrintWorker() : ...@@ -2838,7 +2845,7 @@ class CPrintWorker() :
return args return args
def FormattedDisplay(self,payload : CobolVariable()) : def FormattedDisplay(self,payload ) :
# see the comments in ProcessDisplayMode() # see the comments in ProcessDisplayMode()
if self.current_display_mode == '0' : if self.current_display_mode == '0' :
print(payload.display_body) print(payload.display_body)
...@@ -2885,7 +2892,6 @@ class CPrintWorker() : ...@@ -2885,7 +2892,6 @@ class CPrintWorker() :
pstar = True pstar = True
# If the single argument is an asterisk, then # If the single argument is an asterisk, then
# he is asking for a list of variables and values: # he is asking for a list of variables and values:
args[0] = TabFile.current_trapped_routine
elif args[0].isdigit() : elif args[0].isdigit() :
# if the single argument is a number, then he is looking # if the single argument is a number, then he is looking
...@@ -3048,7 +3054,7 @@ class CWatchWorker() : ...@@ -3048,7 +3054,7 @@ class CWatchWorker() :
return args return args
def SetTheWatchpoint(self, TabFile:TabFileInformation(), payload : CobolVariable()) : def SetTheWatchpoint(self, TabFile, payload ) :
the_address = payload.GetTheAddress(TabFile.line_list) the_address = payload.GetTheAddress(TabFile.line_list)
if not the_address and not 'gdb' in sys.modules : if not the_address and not 'gdb' in sys.modules :
...@@ -3153,7 +3159,7 @@ if 'gdb' in sys.modules : ...@@ -3153,7 +3159,7 @@ if 'gdb' in sys.modules :
## The text "Version x.x" has to appear in square brackets. # ## The text "Version x.x" has to appear in square brackets. #
## Don't mess with it! # ## Don't mess with it! #
########################################################################### ###########################################################################
print('registering CPrint (Usage is "print <COBOL identifier>") [Version 2.9]') print('registering CPrint (Usage is "print <COBOL identifier>") [Version 3.1]')
self.Worker = CPrintWorker() self.Worker = CPrintWorker()
self.TabFile = TabFileInformation(); self.TabFile = TabFileInformation();
......
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