Getting a process core dump with OpenCOBOL

Below is a copy of a post to the forum on http://opencobol.org. If you ever need to analyze a crashing OpenCOBOL (or any, for that matter) program, GNU/Linux may be able to help with a core dump. …

Well met,

Below is a post to the forum on http://opencobol.org. If you ever need to analyze a crashing OpenCOBOL (or any, for that matter) program, GNU/Linux may be able to help with a core dump. A core dump is disk copy of the program's process space when the operating system detects shenanigans.


It might be more than you need sajjar, but if you are on GNU/Linux, look into ulimit, in particular ulimit -c unlimited. Most of the time, people don't care about core dumps, so most distro's ship with coredump limit set to 0 blocks, meaning don't write any core. ulimit -a will show your current process settings.

Global control is from /etc/security/limits.conf
and you'll likely see a line like


* soft core 0

Meaning all domains, soft (versus hard), core limit, 0 blocks.

Tread lightly here and do not make changes to this file until you've read up.

After that, there are a plethora of ways to get a core dump. Signals are a great way.
On Fedora, man 7 signal and look for those listed as 'core'.

Mine looks like


Signal Value Action Comment
──────────────────────────────────────────────────────────────────────
SIGHUP 1 Term Hangup detected on controlling terminal
or death of controlling process
SIGINT 2 Term Interrupt from keyboard
SIGQUIT 3 Core Quit from keyboard
SIGILL 4 Core Illegal Instruction
SIGABRT 6 Core Abort signal from abort(3)
SIGFPE 8 Core Floating point exception
SIGKILL 9 Term Kill signal
SIGSEGV 11 Core Invalid memory reference
SIGPIPE 13 Term Broken pipe: write to pipe with no
readers
SIGALRM 14 Term Timer signal from alarm(2)
SIGTERM 15 Term Termination signal
SIGUSR1 30,10,16 Term User-defined signal 1
SIGUSR2 31,12,17 Term User-defined signal 2
SIGCHLD 20,17,18 Ign Child stopped or terminated
SIGCONT 19,18,25 Cont Continue if stopped
SIGSTOP 17,19,23 Stop Stop process
SIGTSTP 18,20,24 Stop Stop typed at tty
SIGTTIN 21,21,26 Stop tty input for background process
SIGTTOU 22,22,27 Stop tty output for background process

So, a quit (Ctrl-backslash / SysRq) will actually cause a core dump, as would


01 SOME-VAR PIC X BASED.

DISPLAY SOME-VAR END-DISPLAY *> with no allocate

Trying to access an unallocated SOME-VAR will cause a SIGSEGV. Dirty pool, and you can get who knows what bad mojo side effects, but usually it's a core dump. So, only for use at home while no one is watching.

Or far better


>>D CALL "abort" END-CALL

compile with cobc -fdebugging-line, the code will SIGABRT and you get a core, compile without debug lines and you'll get a normal run. A very cool feature of OpenCOBOL and cobc is that we get all the libc6 functions 'for free', with no need to modify tectonics.

Then good old gdb and EXAMINE can be used to look through the entire program space (assuming coredump limit is an appropriate value). See Richard Stallman's notes at http://www.unknownroad.com/rtfm/gdbtut/gdbadvanced.html for some details.

For a less geeky solution, see human's latest CBL_OC_DUMP utility listed at http://opencobol.add1tocobol.com/#what-is-cbl-oc-dump (listed twice, with the second one the latest). Set the variable to dump from the top of WORKING-STORAGE and give it an appropriate size. As long as it's contiguous space, all should be well. If you go past working store, it'll be garbage and maybe a SIGSEGV, in which case, hey, core. 😉

If you are looking for something along the lines of SNOBOL and Icon's &dump, end of run dump setting, then you'll need to write it, as human suggested.

Cheers,

Brian


And once again, http://opencobol.add1tocobol.com/ for the FAQ.

Cheers,

Brian

Leave a Reply

Your email address will not be published. Required fields are marked *