summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-05-29 20:37:59 (GMT)
committerBrad King <brad.king@kitware.com>2015-07-06 15:22:42 (GMT)
commitd2475bb5c4488a0ef6015f13ee46ddc7a2e4455b (patch)
treed590a226216dde3fad489be3170f240b40f459ee
parent238aac23514ecdae0d4edb71033e443f30e94158 (diff)
downloadCMake-d2475bb5c4488a0ef6015f13ee46ddc7a2e4455b.zip
CMake-d2475bb5c4488a0ef6015f13ee46ddc7a2e4455b.tar.gz
CMake-d2475bb5c4488a0ef6015f13ee46ddc7a2e4455b.tar.bz2
cmListFileBacktrace: Implement in terms of cmState::Snapshot.
Avoid copying many strings into each backtrace object.
-rw-r--r--Source/cmIfCommand.cxx5
-rw-r--r--Source/cmListFileCache.cxx38
-rw-r--r--Source/cmListFileCache.h10
-rw-r--r--Source/cmMakefile.cxx34
-rw-r--r--Source/cmMakefile.h2
5 files changed, 37 insertions, 52 deletions
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index cdf278c..20448c1 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -115,10 +115,7 @@ IsFunctionBlocked(const cmListFileFunction& lff,
{
std::string err = cmIfCommandError(expandedArguments);
err += errorString;
- cmListFileContext lfc =
- cmListFileContext::FromCommandContext(
- this->Functions[c], this->GetStartingContext().FilePath);
- cmListFileBacktrace bt = mf.GetBacktrace(lfc);
+ cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
mf.GetCMakeInstance()->IssueMessage(messType, err, bt);
if (messType == cmake::FATAL_ERROR)
{
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index 9141d88..1097dc2 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -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)
{
- if (this->empty())
+ if (!this->Snapshot.IsValid())
{
return;
}
-
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);
out << (lfc.Line ? " at " : " in ") << lfc;
}
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;
}
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";
- while(i != this->end())
+ while(parent.IsValid())
{
- cmListFileContext lfc = *i;
- lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
+ cmListFileContext lfc;
+ lfc.Name = commandName;
+ lfc.Line = commandLine;
+
+ lfc.FilePath = converter.Convert(parent.GetExecutionListFile(),
+ cmOutputConverter::HOME);
out << " " << lfc << "\n";
- ++i;
+
+ commandName = parent.GetEntryPointCommand();
+ commandLine = parent.GetEntryPointLine();
+ parent = parent.GetCallStackParent();
}
}
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
index 57bf253..aa8a34c 100644
--- a/Source/cmListFileCache.h
+++ b/Source/cmListFileCache.h
@@ -86,19 +86,19 @@ struct cmListFileFunction: public cmCommandContext
std::vector<cmListFileArgument> Arguments;
};
-class cmListFileBacktrace: private std::vector<cmListFileContext>
+class cmListFileBacktrace
{
public:
- cmListFileBacktrace(cmState::Snapshot snapshot = cmState::Snapshot())
- : Snapshot(snapshot)
+ cmListFileBacktrace(cmState::Snapshot snapshot = cmState::Snapshot(),
+ cmCommandContext const& cc = cmCommandContext())
+ : Context(cc), Snapshot(snapshot)
{
}
- void Append(cmListFileContext const& context);
-
void PrintTitle(std::ostream& out);
void PrintCallStack(std::ostream& out);
private:
+ cmCommandContext Context;
cmState::Snapshot Snapshot;
};
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 9f2abff..94c77e1 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -275,43 +275,21 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
//----------------------------------------------------------------------------
cmListFileBacktrace cmMakefile::GetBacktrace() const
{
- cmListFileBacktrace backtrace(this->StateSnapshot);
- cmState::Snapshot snp = this->StateSnapshot;
- for(std::vector<cmCommandContext const*>::const_reverse_iterator
- i = this->ContextStack.rbegin();
- i != this->ContextStack.rend();
- ++i, snp = snp.GetCallStackParent())
+ cmListFileBacktrace backtrace;
+ if (!this->ContextStack.empty())
{
- assert(snp.IsValid());
- cmListFileContext frame =
- cmListFileContext::FromCommandContext(*(*i),
- snp.GetExecutionListFile());
- backtrace.Append(frame);
+ backtrace = cmListFileBacktrace(this->StateSnapshot,
+ *this->ContextStack.back());
}
return backtrace;
}
//----------------------------------------------------------------------------
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;
- assert(snp.GetExecutionListFile() == lfc.FilePath);
- 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;
+ return cmListFileBacktrace(snp, cc);
}
//----------------------------------------------------------------------------
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index d3cf02e..82a2279 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -547,7 +547,7 @@ public:
* Get the current context backtrace.
*/
cmListFileBacktrace GetBacktrace() const;
- cmListFileBacktrace GetBacktrace(cmListFileContext const& lfc) const;
+ cmListFileBacktrace GetBacktrace(cmCommandContext const& lfc) const;
cmListFileContext GetExecutionContext() const;
/**