debug origin lines

This commit is contained in:
Lev Walkin 2017-11-19 23:39:59 -08:00
parent 4215c51ca3
commit 840fb8e37b
6 changed files with 35 additions and 8 deletions

View File

@ -101,6 +101,9 @@ main(int ac, char **av) {
strdup(optarg + 17); strdup(optarg + 17);
debug_type_names[debug_type_names_count] = NULL; debug_type_names[debug_type_names_count] = NULL;
break; break;
} else if(strcmp(optarg, "ebug-output-origin-lines") == 0) {
asn1_compiler_flags |= A1C_DEBUG_OUTPUT_ORIGIN_LINES;
break;
} }
usage(av[0]); usage(av[0]);
case 'E': case 'E':

View File

@ -2026,7 +2026,7 @@ emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alpha
OUT("{ APC_CONSTRAINED%s,%s% d, % d, ", OUT("{ APC_CONSTRAINED%s,%s% d, % d, ",
range->extensible range->extensible
? " | APC_EXTENSIBLE" : "", ? " | APC_EXTENSIBLE" : "",
range->extensible ? " " : "\t", rbits, ebits); range->extensible ? " " : "\t", (int)rbits, (int)ebits);
if(alphabetsize) { if(alphabetsize) {
asn1c_integer_t lv = range->left.value; asn1c_integer_t lv = range->left.value;

View File

@ -175,10 +175,10 @@ emit_ioc_value(arg_t *arg, struct asn1p_ioc_cell_s *cell) {
asn1c_integer_t v = expr_value->value->value.v_integer; asn1c_integer_t v = expr_value->value->value.v_integer;
if(v >= 0) { if(v >= 0) {
if(v <= 127) { if(v <= 127) {
OUT("\"\\x%02x\", 1", v); OUT("\"\\x%02x\", 1", (int)v);
break; break;
} else if(v <= 32767) { } else if(v <= 32767) {
OUT("\"\\x%02x\\x%02x\", 2", (v >> 8), (v & 0xff)); OUT("\"\\x%02x\\x%02x\", 2", (int)(v >> 8), (int)(v & 0xff));
break; break;
} }
} }

View File

@ -6,7 +6,8 @@
* into appropriate output stream. * into appropriate output stream.
*/ */
int int
asn1c_compiled_output(arg_t *arg, const char *fmt, ...) { asn1c_compiled_output(arg_t *arg, const char *source, int lineno, const char *func, const char *fmt,
...) {
struct compiler_stream_destination_s *dst; struct compiler_stream_destination_s *dst;
const char *p; const char *p;
int lf_found; int lf_found;
@ -45,13 +46,19 @@ asn1c_compiled_output(arg_t *arg, const char *fmt, ...) {
} }
dst->indented = 1; dst->indented = 1;
while(i--) { while(i--) {
ret = asn1c_compiled_output(arg, "\t"); ret = asn1c_compiled_output(arg, source, lineno, func, "\t");
if(ret == -1) return -1; if(ret == -1) return -1;
} }
} }
if(lf_found) if(lf_found)
dst->indented = 0; dst->indented = 0;
size_t debug_reserve_size = 0;
if(lf_found && (arg->flags & A1C_DEBUG_OUTPUT_ORIGIN_LINES)) {
debug_reserve_size =
sizeof("\t// :100000 ()") + strlen(source) + strlen(func);
}
/* /*
* Allocate buffer. * Allocate buffer.
*/ */
@ -62,7 +69,7 @@ asn1c_compiled_output(arg_t *arg, const char *fmt, ...) {
do { do {
void *tmp; void *tmp;
m->len <<= 2; m->len <<= 2;
tmp = realloc(m->buf, m->len); tmp = realloc(m->buf, m->len + debug_reserve_size);
if(tmp) { if(tmp) {
m->buf = (char *)tmp; m->buf = (char *)tmp;
} else { } else {
@ -77,6 +84,15 @@ asn1c_compiled_output(arg_t *arg, const char *fmt, ...) {
m->len = ret; m->len = ret;
/* Print out the origin of the lines */
if(lf_found && (arg->flags & A1C_DEBUG_OUTPUT_ORIGIN_LINES)) {
assert(m->buf[m->len - 1] == '\n');
ret = snprintf(m->buf + m->len - 1, debug_reserve_size,
"\t// %s:%03d %s()\n", source, lineno, func);
assert(ret > 0 && (size_t)ret < debug_reserve_size);
m->len = m->len - 1 + ret;
}
if(arg->target->target == OT_INCLUDES if(arg->target->target == OT_INCLUDES
|| arg->target->target == OT_FWD_DECLS || arg->target->target == OT_FWD_DECLS
|| arg->target->target == OT_POST_INCLUDE) { || arg->target->target == OT_POST_INCLUDE) {

View File

@ -39,7 +39,9 @@ typedef struct compiler_streams {
static char *_compiler_stream2str[] __attribute__ ((unused)) static char *_compiler_stream2str[] __attribute__ ((unused))
= { "IGNORE", "INCLUDES", "DEPS", "FWD-DECLS", "FWD-DEFS", "TYPE-DECLS", "FUNC-DECLS", "POST-INCLUDE", "IOC-TABLES", "CTABLES", "CODE", "CTDEFS", "STAT-DEFS" }; = { "IGNORE", "INCLUDES", "DEPS", "FWD-DECLS", "FWD-DEFS", "TYPE-DECLS", "FUNC-DECLS", "POST-INCLUDE", "IOC-TABLES", "CTABLES", "CODE", "CTDEFS", "STAT-DEFS" };
int asn1c_compiled_output(arg_t *arg, const char *fmt, ...); int asn1c_compiled_output(arg_t *arg, const char *file, int lineno,
const char *func, const char *fmt, ...)
__attribute__((format(printf, 5, 6)));
/***************************************************************** /*****************************************************************
@ -80,7 +82,8 @@ int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
} while(0) } while(0)
/* Output a piece of text into a default stream */ /* Output a piece of text into a default stream */
#define OUT(fmt, args...) asn1c_compiled_output(arg, fmt, ##args) #define OUT(fmt, args...) \
asn1c_compiled_output(arg, __FILE__, __LINE__, __func__, fmt, ##args)
#define OUT_NOINDENT(fmt, args...) do { \ #define OUT_NOINDENT(fmt, args...) do { \
int _saved_indent = INDENT_LEVEL; \ int _saved_indent = INDENT_LEVEL; \
INDENT_LEVEL = 0; \ INDENT_LEVEL = 0; \

View File

@ -92,6 +92,11 @@ enum asn1c_flags {
* Generate top-level configure.ac and Makefile.am * Generate top-level configure.ac and Makefile.am
*/ */
A1C_GEN_AUTOTOOLS_EXAMPLE = 0x200000, A1C_GEN_AUTOTOOLS_EXAMPLE = 0x200000,
/*
* Print the source of generated lines.
* -debug-output-origin-lines
*/
A1C_DEBUG_OUTPUT_ORIGIN_LINES = 0x400000,
}; };
/* /*