From fc0cdca948f16bcf7590e057878fca1d4ce1ed6e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 13 Dec 2014 16:07:36 +0100 Subject: mds-kbdc: dump call-stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/call-stack.c | 34 ++++++++++++++++++++++++++++++++++ src/mds-kbdc/call-stack.h | 15 +++++++++++++++ src/mds-kbdc/compile-layout.c | 11 ++++++++--- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/mds-kbdc/call-stack.c b/src/mds-kbdc/call-stack.c index cd77b15..642988a 100644 --- a/src/mds-kbdc/call-stack.c +++ b/src/mds-kbdc/call-stack.c @@ -90,6 +90,40 @@ static size_t calls_ptr = 0; +/** + * Add “called from here”-notes + * + * @return Zero on success, -1 on error + */ +int mds_kbdc_call_stack_dump(void) +{ + char* old_pathname = result->pathname; + mds_kbdc_source_code_t* old_source_code = result->source_code; + size_t ptr = calls_ptr, iptr; + mds_kbdc_call_t* restrict call; + mds_kbdc_include_stack_t* restrict includes; + + while (ptr--) + { + call = calls + ptr; + includes = call->include_stack; + iptr = includes->ptr; + result->pathname = iptr ? includes->stack[iptr - 1]->filename : original_pathname; + result->source_code = iptr ? includes->stack[iptr - 1]->source_code : original_source_code; + NEW_ERROR_(result, NOTE, 1, call->tree->loc_line, call->start, call->end, 1, "called from here"); + DUMP_INCLUDE_STACK(iptr); + } + + result->pathname = old_pathname; + result->source_code = old_source_code; + return 0; + fail: + result->pathname = old_pathname; + result->source_code = old_source_code; + return -1; +} + + /** * Prepare for usage of call-stacks * diff --git a/src/mds-kbdc/call-stack.h b/src/mds-kbdc/call-stack.h index aa206b3..3c010cf 100644 --- a/src/mds-kbdc/call-stack.h +++ b/src/mds-kbdc/call-stack.h @@ -24,6 +24,21 @@ +/** + * Add “called from here”-notes + */ +#define DUMP_CALL_STACK \ + fail_if (mds_kbdc_call_stack_dump()) + + + +/** + * Add “called from here”-notes + * + * @return Zero on success, -1 on error + */ +int mds_kbdc_call_stack_dump(void); + /** * Prepare for usage of call-stacks * diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c index b2cd5e0..89f507f 100644 --- a/src/mds-kbdc/compile-layout.c +++ b/src/mds-kbdc/compile-layout.c @@ -17,7 +17,7 @@ */ #include "compile-layout.h" /* XXX fix so that for-loops do not generate the same errors/warnings in all iterations [loopy_error]. */ -/* XXX add pragma support */ +/* XXX add pragma support: mark as shadowable, stop warnings, print variable value */ #include "call-stack.h" #include "builtin-functions.h" @@ -49,8 +49,13 @@ * @param ...:const char*, ... Error description format string and arguments * @scope error:mds_kbdc_parse_error_t* Variable where the new error will be stored */ -#define NEW_ERROR(NODE, SEVERITY, ...) \ - NEW_ERROR_WITH_INCLUDES(NODE, includes_ptr, SEVERITY, __VA_ARGS__) +#define NEW_ERROR(NODE, SEVERITY, ...) \ + do \ + { \ + NEW_ERROR_WITH_INCLUDES(NODE, includes_ptr, SEVERITY, __VA_ARGS__); \ + DUMP_CALL_STACK; \ + } \ + while (0) /** * Beginning of failure clause -- cgit v1.2.3-70-g09d2