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