From a4f289109a3e02bcf1185acd80f4c36c7f5eca5f Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 9 Sep 2025 14:27:27 +0200 Subject: [PATCH] fixed #13926 - `ErrorMessage::FileLocation::mOrigFileName` was not stored in the XML --- lib/errorlogger.cpp | 12 ++++++++++-- test/testerrorlogger.cpp | 10 ++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 9fe160364e9..47157f7a504 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -196,16 +196,20 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) for (const tinyxml2::XMLElement *e = errmsg->FirstChildElement(); e; e = e->NextSiblingElement()) { const char* name = e->Name(); if (std::strcmp(name,"location")==0) { + const char *strorigfile = e->Attribute("origfile"); const char *strfile = e->Attribute("file"); const char *strinfo = e->Attribute("info"); const char *strline = e->Attribute("line"); const char *strcolumn = e->Attribute("column"); const char *file = strfile ? strfile : unknown; + const char *origfile = strorigfile ? strorigfile : file; const char *info = strinfo ? strinfo : ""; const int line = strline ? strToInt(strline) : 0; const int column = strcolumn ? strToInt(strcolumn) : 0; - callStack.emplace_front(file, info, line, column); + callStack.emplace_front(origfile, info, line, column); + if (strorigfile) + callStack.front().setfile(file); } else if (std::strcmp(name,"symbol")==0) { mSymbolNames += e->GetText(); } @@ -508,7 +512,11 @@ std::string ErrorMessage::toXML() const for (auto it = callStack.crbegin(); it != callStack.crend(); ++it) { printer.OpenElement("location", false); - printer.PushAttribute("file", it->getfile(false).c_str()); + const std::string origfile = it->getOrigFile(false); + const std::string file = it->getfile(false); + if (origfile != file) + printer.PushAttribute("origfile", origfile.c_str()); + printer.PushAttribute("file", file.c_str()); printer.PushAttribute("line", std::max(it->line,0)); printer.PushAttribute("column", it->column); if (!it->getinfo().empty()) diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index aa4d2f3e223..ca036b90ea5 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -409,9 +409,9 @@ class TestErrorLogger : public TestFixture { message += " \n"; message += " \n"; message += " \n"; - message += " \n"; - message += " \n"; - message += " \n"; + message += " \n"; + message += " \n"; + message += " \n"; message += " "; ASSERT_EQUALS(message, msg.toXML()); } @@ -443,7 +443,7 @@ class TestErrorLogger : public TestFixture { " hash=\"456\"" ">\n" " \n" - " \n" + " \n" ""; tinyxml2::XMLDocument doc; ASSERT(doc.Parse(xmldata, sizeof(xmldata)) == tinyxml2::XML_SUCCESS); @@ -458,9 +458,11 @@ class TestErrorLogger : public TestFixture { ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS(456u, msg.hash); ASSERT_EQUALS(2u, msg.callStack.size()); + ASSERT_EQUALS("proj/foo.cpp", msg.callStack.front().getOrigFile(false)); ASSERT_EQUALS("foo.cpp", msg.callStack.front().getfile(false)); ASSERT_EQUALS(5, msg.callStack.front().line); ASSERT_EQUALS(2u, msg.callStack.front().column); + ASSERT_EQUALS("bar.cpp", msg.callStack.back().getOrigFile(false)); ASSERT_EQUALS("bar.cpp", msg.callStack.back().getfile(false)); ASSERT_EQUALS(8, msg.callStack.back().line); ASSERT_EQUALS(1u, msg.callStack.back().column);