Skip to content

Commit

Permalink
Add a feature to build a binary debug database at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Jan 10, 2024
1 parent c0d64ad commit b7ff8a3
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

2024-01-10 David Declerck <[email protected]>

* debuggen.c: implement a feature to collect and dump debug information
relevant for debugging in a debug database file in binary format
* cobc.h: export the new `debuggen` functions
* codegen.c: add calls to `debuggen` at appropriate locations
* flag.def: add a -fgen-debug-db flag to enable debug database generation
* cobc.c: ensure proper options are passed to the C compiler when
using the -fgen-debug-db flag
* Makefile.am: add `debuggen.c` to the list of source files

2023-07-26 Simon Sobisch <[email protected]>

* typeck.c (search_set_keys): improving SEARCH ALL syntax checks
Expand Down
2 changes: 1 addition & 1 deletion cobc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bin_PROGRAMS = cobc
cobc_SOURCES = cobc.c cobc.h ppparse.y pplex.c parser.y scanner.c config.c \
reserved.c error.c tree.c tree.h field.c typeck.c codegen.c help.c \
config.def flag.def warning.def codeoptim.def ppparse.def \
codeoptim.c replace.c
codeoptim.c replace.c debuggen.c

#cobc_SOURCES = cobc.c cobc.h ppparse.y pplex.l parser.y scanner.l config.c

Expand Down
9 changes: 9 additions & 0 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3327,6 +3327,15 @@ process_command_line (const int argc, char **argv)
cb_flag_stack_extended = 1; /* for extended stack output */
}

/* If generating a debug database, must also
pass the appropriate flags to the C compiler */
if (cb_flag_gen_debug_db && !cb_source_debugging) {
cb_source_debugging = 1;
#ifdef COB_DEBUG_FLAGS
COBC_ADD_STR (cobc_cflags, " ", cobc_debug_flags, NULL);
#endif
}

cob_optind = 1;
cob_opterr = 0; /* all error handling was done in the call above */
while ((c = cob_getopt_long_long (argc, argv, short_options,
Expand Down
6 changes: 6 additions & 0 deletions cobc/cobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,10 @@ extern int cb_strcasecmp (const void *, const void *);
extern unsigned char cb_toupper (const unsigned char);
extern unsigned char cb_tolower (const unsigned char);

/* debuggen.c */

extern void debuggen_init(void);
extern void debuggen_add_ref(int c_line, const char *cob_file_name, int cob_line);
extern void debuggen_finalize(const struct cb_program *prog, const char *c_file);

#endif /* CB_COBC_H */
13 changes: 13 additions & 0 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -5299,6 +5299,9 @@ output_init_comment_and_source_ref (struct cb_field *f)
output_c_info ();
}
#endif
if (cb_flag_gen_debug_db) {
debuggen_add_ref(output_line_number, f->common.source_file, f->common.source_line);
}
}

static void
Expand Down Expand Up @@ -8482,6 +8485,10 @@ output_source_reference (cb_tree tree, const enum cob_statement statement)
}
output_trace_info (tree, statement);
}

if (cb_flag_gen_debug_db) {
debuggen_add_ref(output_line_number, tree->source_file, tree->source_line);
}
}

static void
Expand Down Expand Up @@ -13618,6 +13625,9 @@ codegen (struct cb_program *prog, const char *translate_name)
const int set_xref = cb_listing_xref;
int subsequent_call = 0;
int has_global_file_level = 0 ;
if (cb_flag_gen_debug_db) {
debuggen_init();
}
codegen_init (prog, translate_name);

/* Temporarily disable cross-reference during C generation */
Expand Down Expand Up @@ -13650,6 +13660,9 @@ codegen (struct cb_program *prog, const char *translate_name)
cb_listing_xref = set_xref;

codegen_finalize ();
if (cb_flag_gen_debug_db) {
debuggen_finalize(prog, translate_name);
}
}

void
Expand Down
Loading

0 comments on commit b7ff8a3

Please sign in to comment.