cmListFileBacktrace: Implement in terms of cmState::Snapshot.

Avoid copying many strings into each backtrace object.
This commit is contained in:
Stephen Kelly 2015-05-29 22:37:59 +02:00 committed by Brad King
parent 238aac2351
commit d2475bb5c4
5 changed files with 37 additions and 52 deletions

View File

@ -115,10 +115,7 @@ IsFunctionBlocked(const cmListFileFunction& lff,
{ {
std::string err = cmIfCommandError(expandedArguments); std::string err = cmIfCommandError(expandedArguments);
err += errorString; err += errorString;
cmListFileContext lfc = cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
cmListFileContext::FromCommandContext(
this->Functions[c], this->GetStartingContext().FilePath);
cmListFileBacktrace bt = mf.GetBacktrace(lfc);
mf.GetCMakeInstance()->IssueMessage(messType, err, bt); mf.GetCMakeInstance()->IssueMessage(messType, err, bt);
if (messType == cmake::FATAL_ERROR) if (messType == cmake::FATAL_ERROR)
{ {

View File

@ -398,40 +398,50 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
} }
} }
void cmListFileBacktrace::Append(cmListFileContext const& context)
{
this->push_back(context);
}
void cmListFileBacktrace::PrintTitle(std::ostream& out) void cmListFileBacktrace::PrintTitle(std::ostream& out)
{ {
if (this->empty()) if (!this->Snapshot.IsValid())
{ {
return; return;
} }
cmOutputConverter converter(this->Snapshot); cmOutputConverter converter(this->Snapshot);
cmListFileContext lfc = this->front(); cmListFileContext lfc =
cmListFileContext::FromCommandContext(
this->Context, this->Snapshot.GetExecutionListFile());
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
out << (lfc.Line ? " at " : " in ") << lfc; out << (lfc.Line ? " at " : " in ") << lfc;
} }
void cmListFileBacktrace::PrintCallStack(std::ostream& out) void cmListFileBacktrace::PrintCallStack(std::ostream& out)
{ {
if (size() <= 1) if (!this->Snapshot.IsValid())
{
return;
}
cmState::Snapshot parent = this->Snapshot.GetCallStackParent();
if (!parent.IsValid() || parent.GetExecutionListFile().empty())
{ {
return; return;
} }
cmOutputConverter converter(this->Snapshot); cmOutputConverter converter(this->Snapshot);
const_iterator i = this->begin() + 1; std::string commandName = this->Snapshot.GetEntryPointCommand();
long commandLine = this->Snapshot.GetEntryPointLine();
out << "Call Stack (most recent call first):\n"; out << "Call Stack (most recent call first):\n";
while(i != this->end()) while(parent.IsValid())
{ {
cmListFileContext lfc = *i; cmListFileContext lfc;
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); lfc.Name = commandName;
lfc.Line = commandLine;
lfc.FilePath = converter.Convert(parent.GetExecutionListFile(),
cmOutputConverter::HOME);
out << " " << lfc << "\n"; out << " " << lfc << "\n";
++i;
commandName = parent.GetEntryPointCommand();
commandLine = parent.GetEntryPointLine();
parent = parent.GetCallStackParent();
} }
} }

View File

@ -86,19 +86,19 @@ struct cmListFileFunction: public cmCommandContext
std::vector<cmListFileArgument> Arguments; std::vector<cmListFileArgument> Arguments;
}; };
class cmListFileBacktrace: private std::vector<cmListFileContext> class cmListFileBacktrace
{ {
public: public:
cmListFileBacktrace(cmState::Snapshot snapshot = cmState::Snapshot()) cmListFileBacktrace(cmState::Snapshot snapshot = cmState::Snapshot(),
: Snapshot(snapshot) cmCommandContext const& cc = cmCommandContext())
: Context(cc), Snapshot(snapshot)
{ {
} }
void Append(cmListFileContext const& context);
void PrintTitle(std::ostream& out); void PrintTitle(std::ostream& out);
void PrintCallStack(std::ostream& out); void PrintCallStack(std::ostream& out);
private: private:
cmCommandContext Context;
cmState::Snapshot Snapshot; cmState::Snapshot Snapshot;
}; };

View File

@ -275,43 +275,21 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmListFileBacktrace cmMakefile::GetBacktrace() const cmListFileBacktrace cmMakefile::GetBacktrace() const
{ {
cmListFileBacktrace backtrace(this->StateSnapshot); cmListFileBacktrace backtrace;
cmState::Snapshot snp = this->StateSnapshot; if (!this->ContextStack.empty())
for(std::vector<cmCommandContext const*>::const_reverse_iterator
i = this->ContextStack.rbegin();
i != this->ContextStack.rend();
++i, snp = snp.GetCallStackParent())
{ {
assert(snp.IsValid()); backtrace = cmListFileBacktrace(this->StateSnapshot,
cmListFileContext frame = *this->ContextStack.back());
cmListFileContext::FromCommandContext(*(*i),
snp.GetExecutionListFile());
backtrace.Append(frame);
} }
return backtrace; return backtrace;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmListFileBacktrace cmListFileBacktrace
cmMakefile::GetBacktrace(cmListFileContext const& lfc) const cmMakefile::GetBacktrace(cmCommandContext const& cc) const
{ {
cmListFileBacktrace backtrace(this->StateSnapshot);
backtrace.Append(lfc);
cmState::Snapshot snp = this->StateSnapshot; cmState::Snapshot snp = this->StateSnapshot;
assert(snp.GetExecutionListFile() == lfc.FilePath); return cmListFileBacktrace(snp, cc);
snp = snp.GetCallStackParent();
for(std::vector<cmCommandContext const*>::const_reverse_iterator
i = this->ContextStack.rbegin();
i != this->ContextStack.rend();
++i, snp = snp.GetCallStackParent())
{
assert(snp.IsValid());
cmListFileContext frame =
cmListFileContext::FromCommandContext(*(*i),
snp.GetExecutionListFile());
backtrace.Append(frame);
}
return backtrace;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -547,7 +547,7 @@ public:
* Get the current context backtrace. * Get the current context backtrace.
*/ */
cmListFileBacktrace GetBacktrace() const; cmListFileBacktrace GetBacktrace() const;
cmListFileBacktrace GetBacktrace(cmListFileContext const& lfc) const; cmListFileBacktrace GetBacktrace(cmCommandContext const& lfc) const;
cmListFileContext GetExecutionContext() const; cmListFileContext GetExecutionContext() const;
/** /**