mridoni / gixsql

GixSQL is an ESQL preprocessor and a series of runtime libraries to enable GnuCOBOL to access PostgreSQL, ODBC, MySQL, Oracle and SQLite databases.
GNU General Public License v3.0
16 stars 8 forks source link

Return code 262 parsing same cobol programs - terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 9) >= this->size() (which is 9) #178

Open sergiosa61 opened 8 months ago

sergiosa61 commented 8 months ago

In trying to process same cobol programs for our Oracle migration project, I get the following errors.

I am unable to determine the program lines that generate the errors.

I would like to know how to provide additional information to determine the cause of the error

The first program

029006     IF D-EUR-FF = "EUR"
029007     MOVE 2936 TO JJBB MOVE 013 TO D-EUR-ARR
029008     PERFORM RRTRA-O-O THRU SSTRA-O-O.
029009 RR-007008.
029010     MOVE TOTINTPG TO BB-007008.
029011     IF D-EUR-FF = "EUR"
029012     MOVE 2961 TO JJBB MOVE 013 TO D-EUR-ARR
029013     PERFORM RRTRA-O-O THRU SSTRA-O-O.
029014 RR-007010.
029015     MOVE TOTSPEPG TO
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 9) >= this->size() (which is 9)

The second

036678     MOVE TOT-IGA TO BB-012424.
036679     IF D-EUR-FF = "EUR"
036680     MOVE 0050 TO JJBB MOVE 017 TO D-EUR-ARR
036681     PERFORM RRTRA-O-O THRU SSTRA-O-O.
036682 RR-012434.
036683     MOVE TOT-ICO TO BB-012434.
036684     IF D-EUR-FF = "EUR"
036685     MOVE 0030 TO JJBB MOVE 017 TO D-EUR-ARR
036686     PERFORM RRTRA-O-O THRU SSTRA-O-O.
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 26) >= this->size() (which is 25)

The gixpp version

gixpp -V
gixpp - the ESQL preprocessor for Gix-IDE/GixSQL
Version: 1.0.20b
libgixpp version: 1.0.20b

The cobc version

cobc -V
cobc (OpenCOBOL) 2.0.0
Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida
Copyright (C) 2006-2012 Roger While
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Built     Nov 30 2023 11:35:35
Packaged  Feb 11 2012 12:36:31 UTC
C version "8.3.0"

Os Version

cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
GitMensch commented 8 months ago

Thank you for this nice bug report. If you could additional provide a minimal complete program that shows this behaviour, it would be "easy" for others to check.

Unrelated to this issue but... as noted: try to switch to GnuCOBOL, as the Gix programs were not tested against OpenCOBOL - especially 2, as far as I know (and it is only rarely used world-wide and not supported by .

I would like to know how to provide additional information to determine the cause of the error

The best way is a minimal reproducer. The second best is to ensure you have good debugging information available, for example by passing LDFLAGS=-gdb3 CFLAGS=-ggdb3 to your configure invocation, then make / make install again, then start gixpp with debugging gdb -ex run --args gixpp $youroptions and when it stops with the debugger do either core bug178.core and make a download of this - as well as your installed GixSQL binaries - available (note: this can contain any data that gixpp has read / in its environment, so make sure this is fine) and/or do backtrace then post its output (with the corefile and the binaries the developers can do it locally and inspect it further).

sergiosa61 commented 8 months ago

Hi, i execute gixpp on gdb whith

gdb -ex run --args gixpp --copypath /opt/install/share/gixsql/copy --esql --esql-preprocess-copy --infile MU057R.PCO --outfile MU057R.CBL --debug-info

the optput

Starting program: /opt/install/bin/gixpp --copypath /opt/install/share/gixsql/copy --esql --esql-preprocess-copy --infile MU057R.PCO --outfile MU057R.CBL --debug-info
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 9) >= this->size() (which is 9)

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: File o directory non esistente.

(gdb) backtrace

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff7ac1535 in __GI_abort () at abort.c:79
#2  0x00007ffff7e88983 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff7e8e8c6 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff7e8e901 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff7e8eb34 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7e8a891 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x000000000042dddc in std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_range_check (__n=<optimized out>, this=0x4dffa0) at /usr/include/c++/8/bits/basic_string.h:936
#8  std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::at (__n=<optimized out>, this=0x4dffa0) at /usr/include/c++/8/bits/stl_vector.h:981
#9  TPESQLProcessor::put_cursor_declarations (this=0x4dfd80) at TPESQLProcessor.cpp:558
#10 0x0000000000437723 in TPESQLProcessor::outputESQL (this=0x4dfd80) at TPESQLProcessor.cpp:228
#11 0x00000000004381aa in TPESQLProcessor::run (this=0x4dfd80, prev_step=...) at TPESQLProcessor.cpp:159
#12 0x0000000000423134 in GixPreProcessor::transform (this=0x7fffffffd4b0) at /usr/include/c++/8/ext/atomicity.h:96
#13 0x00000000004241fc in GixPreProcessor::process (this=this@entry=0x7fffffffd4b0) at GixPreProcessor.cpp:146
#14 0x000000000041123d in main (argc=<optimized out>, argv=<optimized out>) at main.cpp:217

The source is quite big, 29073 code rows.

Tell me what I can add to help the error analysis

Thank you

sergiosa61 commented 8 months ago

Hi, I have generated a cobol source that generates the return code 262. I have reduced the original program. I also attach the source and the core.

By removing the comments on lines 4828 to 4833, the return code does not occur. In this case gixpp generates a source with errors: the calls to the library routines use references to non-generated variables.

EPAST003.CBL: In paragraph 'APRE-FL':
EPAST003.CBL: 4965: Error: 'SQ0013' is not defined
GIXSQL 01  SQ0001.
GIXSQL     02  FILLER PIC X(0363) VALUE "SELECT SUBSTR(K_TBG , 4 , 2) "
GIXSQL  &  ", TRIM(SUBSTR(FLDTBG , 1 , 35)) , TRIM(SUBSTR(FLDTBG , 117 "
GIXSQL  &  ", 6)) , TRIM(SUBSTR(FLDTBG , 177 , 2)) , TRIM(SUBSTR(FLDTBG"
GIXSQL  &  " , 240 , 2)) , TRIM(SUBSTR(FLDTBG , 242 , 4)) , TRIM(SUBSTR"
GIXSQL  &  "(FLDTBG , 234 , 2)) , TRIM(SUBSTR(FLDTBG , 202 , 2)) , TRIM"
GIXSQL  &  "(SUBSTR(FLDTBG , 221 , 2)) , TRIM(SUBSTR(FLDTBG , 236 , 2))"
GIXSQL  &  " FROM PARSTAB WHERE K_TBG LIKE 'T01__%'".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0002.
GIXSQL     02  FILLER PIC X(0103) VALUE "SELECT K_NDG , K_PRATICA , ND"
GIXSQL  &  "GPROMOT , NDGASSOC , NDGGESTORE , NDGSEGNAL FROM PRATICHE W"
GIXSQL  &  "HERE K_ABI = $1".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0003.
GIXSQL     02  FILLER PIC X(0106) VALUE "SELECT K_NDG , NEWNFIDO , DES"
GIXSQL  &  "TINAZIONE , IMPORTO , AUTOPRAPP FROM FIDI WHERE K_ABI = $1 "
GIXSQL  &  "AND TPRECORD = 'C'".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0004.
GIXSQL     02  FILLER PIC X(0289) VALUE "SELECT K_CHIAVE , K_TIPO_INFO"
GIXSQL  &  " , DESCR , DATAINIVAL , DATAFINVAL , VALORE , DATA , TESTO "
GIXSQL  &  ", DATAINS , USERINS FROM ANXDATIVARI WHERE K_ABI = $1 AND K"
GIXSQL  &  "_TIPO_INFO IN('IMPOREVOCATO' , 'FD-TIPOPROVV' , 'FD-DTDELPR"
GIXSQL  &  "RV' , 'FD-CONTRFATT' , 'FD-AUTEROFD' , 'COR/CUP03' , 'COR/V"
GIXSQL  &  "AR03' , 'MCC-POSCHIUSE')".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0005.
GIXSQL     02  FILLER PIC X(0186) VALUE "SELECT K_CHIAVE , K_TIPO_INFO"
GIXSQL  &  " , DOMINIO , TESTO , DESCR FROM ANXDATIVARI WHERE K_ABI = $"
GIXSQL  &  "1 AND K_TIPO_INFO IN('TIPOIPA03' , 'TIPOIPB03' , 'TIPOIPC03"
GIXSQL  &  "' , 'FASCIACLASSE03') ORDER BY K_CHIAVE".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0006.
GIXSQL     02  FILLER PIC X(0189) VALUE "SELECT K_CHIAVE , K_TIPO_INFO"
GIXSQL  &  " , DOMINIO , TESTO FROM ANXDATIVARI WHERE K_ABI = $1 AND K_"
GIXSQL  &  "TIPO_INFO IN('GIUDIZIOIPA03' , 'GIUDIZIOIPB03' , 'GIUDIZIOI"
GIXSQL  &  "PC03' , 'GIUDIZIOIPD03') ORDER BY K_CHIAVE".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0007.
GIXSQL     02  FILLER PIC X(0104) VALUE "SELECT K_NDG , DATA_SOTTOSCRI"
GIXSQL  &  "ZIONE , DATAVAL , TIPO_CONSENSO FROM PRYTES WHERE K_ABI = $"
GIXSQL  &  "1 ORDER BY K_NDG".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0008.
GIXSQL     02  FILLER PIC X(0497) VALUE "SELECT max(NVL(DATACR , '0000"
GIXSQL  &  "0000')) AS DATARIF , CR , K_NDG FROM (SELECT MAX(NVL(DRIF ,"
GIXSQL  &  " '000000000')) AS DATACR , CR FROM IMPRIT GROUP BY CR UNION"
GIXSQL  &  "  MAX(DRIF) AS DATACR , CR FROM CRTBIMPO WHERE (TIMBRO , CR"
GIXSQL  &  ") IN (SELECT TIMBRO , CR FROM CRTBCOMM WHERE COMUNICAZIONE "
GIXSQL  &  "IN ('107' , '108') AND (DATA_PRODUZIONE , CR) IN (SELECT MA"
GIXSQL  &  "X(DATA_PRODUZIONE) AS DATA , CR FROM CRTBCOMM WHERE COMUNIC"
GIXSQL  &  "AZIONE IN ('107' , '108') GROUP BY CR))GROUP BY CR) LEFT JO"
GIXSQL  &  "IN DBANA ON CR = NU_CENTRALE_RISCHI GROUP BY CR , K_NDG".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0009.
GIXSQL     02  FILLER PIC X(0065) VALUE "SELECT K_NDG , K_DATA , K_DAT"
GIXSQL  &  "AVAL FROM RTGCERVED WHERE K_ABI = $1".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0010.
GIXSQL     02  FILLER PIC X(0136) VALUE "SELECT K_ABI , K_CHIAVE , K_T"
GIXSQL  &  "IPO_INFO , DOMINIO , DESCR FROM ANXDATIVARI WHERE K_ABI = $"
GIXSQL  &  "1 AND K_TIPO_INFO = 'LEGALE03' ORDER BY K_CHIAVE".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0011.
GIXSQL     02  FILLER PIC X(0017) VALUE "START TRANSACTION".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL 01  SQ0012.
GIXSQL     02  FILLER PIC X(0018) VALUE "SELECT 1 FROM DUAL".
GIXSQL     02  FILLER PIC X(1) VALUE X"00".
GIXSQL     CALL "GIXSQLExecSelectIntoOne" USING
GIXSQL         BY REFERENCE SQLCA
GIXSQL         BY REFERENCE x"00"
GIXSQL         BY VALUE 0
GIXSQL         BY REFERENCE SQ0013
GIXSQL         BY VALUE 0
GIXSQL         BY VALUE 1
GIXSQL     END-CALL
GIXSQL     CALL "GIXSQLEndSQL"
GIXSQL     END-CALL
004835     MOVE SQLCODE TO SQL-CODE

It seems that after a while the pointing to the SQnnnn variables is moved forward one or two positions

In the case below the call uses SQ0012 instead of SQ0011

GIXSQL*    EXEC SQL
GIXSQL*    START TRANSACTION
GIXSQL*    END-EXEC
GIXSQL     CALL "GIXSQLStartSQL"
GIXSQL     END-CALL
GIXSQL     CALL "GIXSQLExec" USING
GIXSQL         BY REFERENCE SQLCA
GIXSQL         BY REFERENCE x"00"
GIXSQL         BY VALUE 0
GIXSQL         BY REFERENCE SQ0012
GIXSQL     END-CALL
GIXSQL     CALL "GIXSQLEndSQL"
GIXSQL     END-CALL

I looked closely at my program to identify the cause of the bug but found nothing.

That's all for now Thank you

sergiosa61 commented 7 months ago

Hi, I generated two simple cobol sources to reproduce the error: TSQL178A.cbl and TSQL178B.cbl. The cause of the error appears to be the insertion of sub select inside the cursor (TSQL178A.cbl). The second TSQL178B.cbl does not have sub selects and works. The two programs are identical and should produce the same result. the first generates the error "terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 2)" and contains some sub select in the query. The second program does not generate any errors with gixpp and compiles correctly Bug178_source.zip