Hi co-hackers,

GNU Cobol (formerly OpenCOBOL) translates COBOL to C (compiling it with GCC).
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

/* 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};

/* 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 */
      * 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.
/* 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 */

Reply via email to