* Question about getting GNU Cobol work with GDB
[not found] <525328B4.3020405@web.de>
@ 2013-10-09 22:31 ` Simon Sobisch
2013-10-10 8:03 ` Madan Teodor-TEMADAN1
2013-10-10 15:30 ` Tom Tromey
0 siblings, 2 replies; 3+ messages in thread
From: Simon Sobisch @ 2013-10-09 22:31 UTC (permalink / raw)
To: gdb
[-- Attachment #1: Type: text/plain, Size: 2483 bytes --]
[posted before to gdb@gnu.org]
Hi co-hackers,
GNU Cobol (formerly OpenCOBOL) translates COBOL to C (compiling it with GCC later on).
We try to use GDB as debugging frontend but are unsure how some points can be reached without actually patching the GDB (if it's possible at all).
As one of the maintainers of GNU Cobol I write to you with the hope that we can get as far as possible.
A sample is attached, snippets:
HELLO.cob:
INSPECT user-input REPLACING TRAILING SPACES BY LOW-VALUE
MOVE SPACES TO output-msg
STRING 'Hello "' DELIMITED BY SIZE
user-input DELIMITED BY LOW-VALUE
'"!' DELIMITED BY SIZE
INTO output-msg
END-STRING
HELLO.c[h,l.h]
static cob_field f_6 = {80, b_6, &a_1}; /* output-msg */
static cob_field f_7 = {50, NULL, &a_1}; /* user-input */
static int
HELLO_ (const int entry)
// [...]
unsigned char *b_7 = NULL; /* user-input */
// [...]
/* HELLO.cob:23: INSPECT */
cob_set_location ("HELLO", "HELLO.cob", 23, "MAIN SECTION", "MAIN PARAGRAPH", "INSPECT");
{
cob_inspect_init ((f_7.data = b_7, &f_7), 1);
cob_inspect_start ();
cob_inspect_trailing (&cob_low, &cob_space);
cob_inspect_finish ();
}
/* HELLO.cob:24: MOVE */
cob_set_location ("HELLO", "HELLO.cob", 24, "MAIN SECTION", "MAIN PARAGRAPH", "MOVE");
{
memset (b_6, 32, 80);
}
/* HELLO.cob:25: STRING */
cob_set_location ("HELLO", "HELLO.cob", 25, "MAIN SECTION", "MAIN PARAGRAPH", "STRING");
{
cob_string_init (&f_6, 0);
cob_string_delimited (0);
cob_string_append (&c_3);
cob_string_delimited (&cob_low);
cob_string_append ((f_7.data = b_7, &f_7));
cob_string_delimited (0);
cob_string_append (&c_4);
cob_string_finish ();
}
// [...]
}
Not clear is how to
- let the programmer see only the COBOL source, not the C source, while stepping
- let the programmer view/change/... COBOL variables (there is a mapping like you can see above)
- set breakpoints within the COBOL source
We're free to add directives and other necessary stuff into the generated C files, even performing "stuff" at runtime, if this helps.
Thank you for your answers,
Simon Sobisch
[-- Attachment #2: HELLO.c.h --]
[-- Type: text/plain, Size: 1374 bytes --]
/* Generated by cobc 1.1.0 */
/* Generated from HELLO.cob */
/* Generated at Okt 07 2013 23:18:42 CEST */
/* OpenCOBOL build date Apr 20 2013 02:29:02 */
/* OpenCOBOL package date Feb 06 2009 10:30:55 CET */
/* Compile command cobc -g -debug -x --save-temps HELLO.cob */
/* Frame stack declaration */
struct cob_frame {
int perform_through;
void *return_address;
};
/* Union for CALL statement */
union cob_call_union {
void *(*funcptr)();
int (*funcint)();
void *func_void;
};
union cob_call_union cob_unifunc;
/* Data storage */
/* PROGRAM-ID : HELLO */
static unsigned char b_1[4] __attribute__((aligned)); /* RETURN-CODE */
static unsigned char b_6[80] __attribute__((aligned)); /* output-msg */
/* End of data storage */
/* Attributes */
static const cob_field_attr a_1 = {33, 0, 0, 0, NULL};
/* Fields */
/* PROGRAM-ID : HELLO */
static cob_field f_6 = {80, b_6, &a_1}; /* output-msg */
static cob_field f_7 = {50, NULL, &a_1}; /* user-input */
static cob_field f_8 = {1, NULL, &a_1}; /* dummy-var */
/* End of fields */
/* Constants */
static cob_field c_1 = {21, (unsigned char *)"Input name to greet: ", &a_1};
static cob_field c_2 = {12, (unsigned char *)"Hello World!", &a_1};
static cob_field c_3 = {7, (unsigned char *)"Hello \"", &a_1};
static cob_field c_4 = {2, (unsigned char *)"\"!", &a_1};
[-- Attachment #3: HELLO.c.l.h --]
[-- Type: text/plain, Size: 537 bytes --]
/* Generated by cobc 1.1.0 */
/* Generated from HELLO.cob */
/* Generated at Okt 07 2013 23:18:42 CEST */
/* OpenCOBOL build date Apr 20 2013 02:29:02 */
/* OpenCOBOL package date Feb 06 2009 10:30:55 CET */
/* Compile command cobc -g -debug -x --save-temps HELLO.cob */
/* Define perform frame stack */
struct cob_frame *frame_overflow;
struct cob_frame *frame_ptr;
struct cob_frame frame_stack[255];
unsigned char *b_7 = NULL; /* user-input */
unsigned char *b_8 = NULL; /* dummy-var */
[-- Attachment #4: HELLO.cob --]
[-- Type: text/plain, Size: 1091 bytes --]
* Sample COBOL program
IDENTIFICATION DIVISION.
PROGRAM-ID. 'HELLO'.
DATA DIVISION.
*
WORKING-STORAGE SECTION.
78 input-msg value 'Input name to greet: '.
77 output-msg pic x(80).
*
LOCAL-STORAGE SECTION.
77 user-input pic x(50).
77 dummy-var pic x(01).
*
PROCEDURE DIVISION.
DISPLAY input-msg
END-DISPLAY
ACCEPT user-input
END-ACCEPT
IF user-input = SPACES
DISPLAY "Hello World!"
END-DISPLAY
ELSE
INSPECT user-input REPLACING TRAILING SPACES BY LOW-VALUE
MOVE SPACES TO output-msg
STRING 'Hello "' DELIMITED BY SIZE
user-input DELIMITED BY LOW-VALUE
'"!' DELIMITED BY SIZE
INTO output-msg
END-STRING
DISPLAY FUNCTION TRIM (output-msg)
END-DISPLAY
END-IF
*
ACCEPT dummy-var END-ACCEPT
*
STOP RUN.
[-- Attachment #5: HELLO.c --]
[-- Type: text/plain, Size: 4796 bytes --]
/* Generated by cobc 1.1.0 */
/* Generated from HELLO.cob */
/* Generated at Okt 07 2013 23:18:42 CEST */
/* OpenCOBOL build date Apr 20 2013 02:29:02 */
/* OpenCOBOL package date Feb 06 2009 10:30:55 CET */
/* Compile command cobc -g -debug -x --save-temps HELLO.cob */
#define __USE_STRING_INLINES 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <libcob.h>
#define COB_SOURCE_FILE "HELLO.cob"
#define COB_PACKAGE_VERSION "1.1"
#define COB_PATCH_LEVEL 0
/* Global variables */
#include "HELLO.c.h"
/* Function prototypes */
int HELLO ();
static int HELLO_ (const int);
/* Main function */
int
main (int argc, char **argv)
{
cob_init (argc, argv);
cob_stop_run (HELLO ());
}
/* Functions */
int
HELLO ()
{
return HELLO_ (0);
}
static int
HELLO_ (const int entry)
{
/* Local variables */
#include "HELLO.c.l.h"
static int initialized = 0;
static cob_field *cob_user_parameters[COB_MAX_FIELD_PARAMS];
static struct cob_module module = { NULL, NULL, NULL, NULL, cob_user_parameters, 0, '.', '$', ',', 1, 1, 1, 0 };
/* Start of function code */
/* CANCEL callback handling */
if (unlikely(entry < 0)) {
if (!initialized) {
return 0;
}
initialized = 0;
return 0;
}
/* Initialize frame stack */
frame_ptr = &frame_stack[0];
frame_ptr->perform_through = 0;
frame_overflow = &frame_stack[COB_STACK_SIZE - 1];
/* Push module stack */
module.next = cob_current_module;
cob_current_module = &module;
/* Initialize program */
if (unlikely(initialized == 0))
{
if (!cob_initialized) {
cob_fatal_error (COB_FERROR_INITIALIZED);
}
cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL);
(*(int *) (b_1)) = 0;
memset (b_6, 32, 80);
initialized = 1;
}
/* Allocate LOCAL storage */
b_7 = cob_malloc (50);
b_8 = cob_malloc (1);
/* Initialialize LOCAL storage */
memset (b_7, 32, 50);
*(unsigned char *)(b_8) = 32;
cob_save_call_params = cob_call_params;
/* Entry dispatch */
goto l_2;
/* PROCEDURE DIVISION */
/* Entry HELLO */
l_2:;
/* MAIN SECTION */
/* MAIN PARAGRAPH */
/* HELLO.cob:15: DISPLAY */
cob_set_location ("HELLO", "HELLO.cob", 15, "MAIN SECTION", "MAIN PARAGRAPH", "DISPLAY");
{
cob_display (0, 1, 1, &c_1);
}
/* HELLO.cob:17: ACCEPT */
cob_set_location ("HELLO", "HELLO.cob", 17, "MAIN SECTION", "MAIN PARAGRAPH", "ACCEPT");
{
cob_accept ((f_7.data = b_7, &f_7));
}
/* HELLO.cob:19: IF */
cob_set_location ("HELLO", "HELLO.cob", 19, "MAIN SECTION", "MAIN PARAGRAPH", "IF");
{
if (((int)cob_cmp ((f_7.data = b_7, &f_7), &cob_space) == 0))
{
/* HELLO.cob:20: DISPLAY */
cob_set_location ("HELLO", "HELLO.cob", 20, "MAIN SECTION", "MAIN PARAGRAPH", "DISPLAY");
{
cob_display (0, 1, 1, &c_2);
}
}
else
{
/* HELLO.cob:23: INSPECT */
cob_set_location ("HELLO", "HELLO.cob", 23, "MAIN SECTION", "MAIN PARAGRAPH", "INSPECT");
{
cob_inspect_init ((f_7.data = b_7, &f_7), 1);
cob_inspect_start ();
cob_inspect_trailing (&cob_low, &cob_space);
cob_inspect_finish ();
}
/* HELLO.cob:24: MOVE */
cob_set_location ("HELLO", "HELLO.cob", 24, "MAIN SECTION", "MAIN PARAGRAPH", "MOVE");
{
memset (b_6, 32, 80);
}
/* HELLO.cob:25: STRING */
cob_set_location ("HELLO", "HELLO.cob", 25, "MAIN SECTION", "MAIN PARAGRAPH", "STRING");
{
cob_string_init (&f_6, 0);
cob_string_delimited (0);
cob_string_append (&c_3);
cob_string_delimited (&cob_low);
cob_string_append ((f_7.data = b_7, &f_7));
cob_string_delimited (0);
cob_string_append (&c_4);
cob_string_finish ();
}
/* HELLO.cob:30: DISPLAY */
cob_set_location ("HELLO", "HELLO.cob", 30, "MAIN SECTION", "MAIN PARAGRAPH", "DISPLAY");
{
cob_display (0, 1, 1, cob_intr_trim (0, 0, &f_6, 0));
}
}
}
/* HELLO.cob:34: ACCEPT */
cob_set_location ("HELLO", "HELLO.cob", 34, "MAIN SECTION", "MAIN PARAGRAPH", "ACCEPT");
{
cob_accept ((f_8.data = b_8, &f_8));
}
/* HELLO.cob:36: STOP */
cob_set_location ("HELLO", "HELLO.cob", 36, "MAIN SECTION", "MAIN PARAGRAPH", "STOP");
{
cob_stop_run ((*(int *) (b_1)));
}
/* Program exit */
/* Deallocate LOCAL storage */
if (b_8) {
free (b_8);
b_8 = NULL;
}
if (b_7) {
free (b_7);
b_7 = NULL;
}
/* Pop module stack */
cob_current_module = cob_current_module->next;
/* Program return */
return (*(int *) (b_1));
}
/* End functions */
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: Question about getting GNU Cobol work with GDB
2013-10-09 22:31 ` Question about getting GNU Cobol work with GDB Simon Sobisch
@ 2013-10-10 8:03 ` Madan Teodor-TEMADAN1
2013-10-10 15:30 ` Tom Tromey
1 sibling, 0 replies; 3+ messages in thread
From: Madan Teodor-TEMADAN1 @ 2013-10-10 8:03 UTC (permalink / raw)
To: Simon Sobisch, gdb
To see COBOL sources instead of generated C, you could emit #line pragma in the generated source. That should cover setting breakpoints as well.
See http://gcc.gnu.org/onlinedocs/cpp/Line-Control.html
Teodor Madan
-----Original Message-----
From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behalf Of Simon Sobisch
Sent: Thursday, October 10, 2013 01:31
To: gdb@sourceware.org
Subject: Question about getting GNU Cobol work with GDB
[posted before to gdb@gnu.org]
Hi co-hackers,
GNU Cobol (formerly OpenCOBOL) translates COBOL to C (compiling it with GCC later on).
We try to use GDB as debugging frontend but are unsure how some points can be reached without actually patching the GDB (if it's possible at all).
As one of the maintainers of GNU Cobol I write to you with the hope that we can get as far as possible.
A sample is attached, snippets:
HELLO.cob:
INSPECT user-input REPLACING TRAILING SPACES BY LOW-VALUE
MOVE SPACES TO output-msg
STRING 'Hello "' DELIMITED BY SIZE
user-input DELIMITED BY LOW-VALUE
'"!' DELIMITED BY SIZE
INTO output-msg
END-STRING
HELLO.c[h,l.h]
static cob_field f_6 = {80, b_6, &a_1}; /* output-msg */
static cob_field f_7 = {50, NULL, &a_1}; /* user-input */
static int
HELLO_ (const int entry)
// [...]
unsigned char *b_7 = NULL; /* user-input */
// [...]
/* HELLO.cob:23: INSPECT */
cob_set_location ("HELLO", "HELLO.cob", 23, "MAIN SECTION", "MAIN PARAGRAPH", "INSPECT");
{
cob_inspect_init ((f_7.data = b_7, &f_7), 1);
cob_inspect_start ();
cob_inspect_trailing (&cob_low, &cob_space);
cob_inspect_finish ();
}
/* HELLO.cob:24: MOVE */
cob_set_location ("HELLO", "HELLO.cob", 24, "MAIN SECTION", "MAIN PARAGRAPH", "MOVE");
{
memset (b_6, 32, 80);
}
/* HELLO.cob:25: STRING */
cob_set_location ("HELLO", "HELLO.cob", 25, "MAIN SECTION", "MAIN PARAGRAPH", "STRING");
{
cob_string_init (&f_6, 0);
cob_string_delimited (0);
cob_string_append (&c_3);
cob_string_delimited (&cob_low);
cob_string_append ((f_7.data = b_7, &f_7));
cob_string_delimited (0);
cob_string_append (&c_4);
cob_string_finish ();
}
// [...]
}
Not clear is how to
- let the programmer see only the COBOL source, not the C source, while stepping
- let the programmer view/change/... COBOL variables (there is a mapping like you can see above)
- set breakpoints within the COBOL source
We're free to add directives and other necessary stuff into the generated C files, even performing "stuff" at runtime, if this helps.
Thank you for your answers,
Simon Sobisch
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question about getting GNU Cobol work with GDB
2013-10-09 22:31 ` Question about getting GNU Cobol work with GDB Simon Sobisch
2013-10-10 8:03 ` Madan Teodor-TEMADAN1
@ 2013-10-10 15:30 ` Tom Tromey
1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2013-10-10 15:30 UTC (permalink / raw)
To: Simon Sobisch; +Cc: gdb
>>>>> "Simon" == Simon Sobisch <simonsobisch@web.de> writes:
Simon> GNU Cobol (formerly OpenCOBOL) translates COBOL to C (compiling
Simon> it with GCC later on). We try to use GDB as debugging frontend
Simon> but are unsure how some points can be reached without actually
Simon> patching the GDB (if it's possible at all).
Simon> - let the programmer see only the COBOL source, not the C source,
Simon> while stepping
I agree with the other poster who suggested #line.
Simon> - let the programmer view/change/... COBOL variables (there is a
Simon> mapping like you can see above)
I don't think this is doable with your current translation approach.
The simplest way to get this information into gdb is to write out DWARF
from your compiler. DWARF lets you specify the names of variables and
where they live.
However, I think there's no good way to write out DWARF in the C code
your front end generates. *Maybe* it can be done in a gross way by
emitting lots of 'asm' statements, but I am not sure whether this can be
made to work without a lot of exertion.
This sort of thing is one reason that it is generally better to write a
GCC front end than to write a translator. This is easier than it
sounds, but of course you probably have reasons for wanting to do C
translation.
At that point you'll want to write the gdb language support...
Simon> - set breakpoints within the COBOL source
I think #line may help here as well, at least for "file:line"
breakpoints.
I don't remember enough COBOL to know whether there are named
procedures. If there are then those will face the same conceptual
problem as variables: if the COBOL->C name mapping requires some
transformation, then users won't have a way to use to the name from
their COBOL source.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-10-10 15:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <525328B4.3020405@web.de>
2013-10-09 22:31 ` Question about getting GNU Cobol work with GDB Simon Sobisch
2013-10-10 8:03 ` Madan Teodor-TEMADAN1
2013-10-10 15:30 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox