From 3616b9a811b66744b4b818c2930462b480ddae44 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Sat, 24 Nov 2018 14:47:56 -0600 Subject: checks: Use source position information for check failures Now that we retain source position information of nodes and properties, make that the preferred file name (and position) to print out in check failures. This will greatly simplify finding and fixing check errors because most errors are in included source .dtsi files and they get duplicated every time the source file is included. Signed-off-by: Rob Herring Signed-off-by: David Gibson --- checks.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'checks.c') diff --git a/checks.c b/checks.c index 32e0d7a..4dfdf48 100644 --- a/checks.c +++ b/checks.c @@ -19,6 +19,7 @@ */ #include "dtc.h" +#include "srcpos.h" #ifdef TRACE_CHECKS #define TRACE(c, ...) \ @@ -79,13 +80,30 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti, { va_list ap; char *str = NULL; + struct srcpos *pos = NULL; + char *file_str; if (!(c->warn && (quiet < 1)) && !(c->error && (quiet < 2))) return; - xasprintf(&str, "%s: %s (%s): ", - strcmp(dti->outname, "-") ? dti->outname : "", - (c->error) ? "ERROR" : "Warning", c->name); + if (prop && prop->srcpos) + pos = prop->srcpos; + else if (node && node->srcpos) + pos = node->srcpos; + + if (pos) { + file_str = srcpos_string(pos); + xasprintf(&str, "%s", file_str); + free(file_str); + } else if (streq(dti->outname, "-")) { + xasprintf(&str, ""); + } else { + xasprintf(&str, "%s", dti->outname); + } + + xasprintf_append(&str, ": %s (%s): ", + (c->error) ? "ERROR" : "Warning", c->name); + if (node) { if (prop) xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name); @@ -99,6 +117,17 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti, xasprintf_append(&str, "\n"); + if (!prop && pos) { + pos = node->srcpos; + while (pos->next) { + pos = pos->next; + + file_str = srcpos_string(pos); + str += xasprintf_append(&str, " also defined at %s\n", file_str); + free(file_str); + } + } + fputs(str, stderr); } -- cgit v1.1