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 <robh@xxxxxxxxxx> --- checks.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/checks.c b/checks.c index 32e0d7aed8f8..4dfdf485ea87 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 : "<stdout>", - (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, "<stdout>"); + } 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); } -- 2.19.1