diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index e4e6eb37ed..cff26c69ad 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -138,10 +138,10 @@ public: static cmListFileContext FromListFilePath(std::string const& filePath) { - // We are entering a file-level scope but have not yet reached - // any specific line or command invocation within it. This context - // is useful to print when it is at the top but otherwise can be - // skipped during call stack printing. + // We are entering a file-level scope but have not yet reached any specific + // line or command invocation within it. This context is useful to print + // when it is at the top, but otherwise can be skipped during call stack + // printing if preceded by a more specific entry. cmListFileContext lfc; lfc.FilePath = filePath; return lfc; diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index 15833534d5..bbdc697780 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -116,6 +116,7 @@ void PrintCallStack(std::ostream& out, cmListFileBacktrace bt, if (bt.Empty()) { return; } + std::string lastFilePath = bt.Top().FilePath; bt = bt.Pop(); if (bt.Empty()) { return; @@ -125,15 +126,19 @@ void PrintCallStack(std::ostream& out, cmListFileBacktrace bt, for (; !bt.Empty(); bt = bt.Pop()) { cmListFileContext lfc = bt.Top(); if (lfc.Name.empty() && - lfc.Line != cmListFileContext::DeferPlaceholderLine) { - // Skip this whole-file scope. When we get here we already will - // have printed a more-specific context within the file. + lfc.Line != cmListFileContext::DeferPlaceholderLine && + lfc.FilePath == lastFilePath) { + // An entry with no function name is frequently preceded (in the stack) + // by a more specific entry. When this happens (as verified by the + // preceding entry referencing the same file path), skip the less + // specific entry, as we have already printed the more specific one. continue; } if (first) { first = false; out << "Call Stack (most recent call first):\n"; } + lastFilePath = lfc.FilePath; if (topSource) { lfc.FilePath = cmSystemTools::RelativeIfUnder(*topSource, lfc.FilePath); }