[mlpack-git] master: Print backtrace after newline in fatal message. (78f53da)
gitdub at mlpack.org
gitdub at mlpack.org
Tue Apr 12 11:09:28 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/8d77f4231046703d5c0c05ed4795458f98267968...78f53daf5a91e221432c93ea43fbdc9de2ec2f15
>---------------------------------------------------------------
commit 78f53daf5a91e221432c93ea43fbdc9de2ec2f15
Author: Ryan Curtin <ryan at ratml.org>
Date: Tue Apr 12 11:08:57 2016 -0400
Print backtrace after newline in fatal message.
This cleans up the output when backtraces are available.
>---------------------------------------------------------------
78f53daf5a91e221432c93ea43fbdc9de2ec2f15
src/mlpack/core/util/prefixedoutstream_impl.hpp | 49 +++++++++++++------------
1 file changed, 25 insertions(+), 24 deletions(-)
diff --git a/src/mlpack/core/util/prefixedoutstream_impl.hpp b/src/mlpack/core/util/prefixedoutstream_impl.hpp
index 8c6ccda..a0f1965 100644
--- a/src/mlpack/core/util/prefixedoutstream_impl.hpp
+++ b/src/mlpack/core/util/prefixedoutstream_impl.hpp
@@ -66,32 +66,9 @@ void PrefixedOutStream::BaseLogic(const T& val)
return;
}
- // Now, we need to check for newlines in retrieved backtrace.
- //If we find one, output up until the newline, then output the newline
- //and the prefix and continue looking.
+ // Now, we need to check for newlines in the output and print it.
size_t nl;
size_t pos = 0;
-#ifdef HAS_BFD_DL
- if(fatal)
- {
- Backtrace bt;
- std::string btLine = bt.ToString();
- while ((nl = btLine.find('\n', pos)) != std::string::npos)
- {
- PrefixIfNeeded();
-
- destination << btLine.substr(pos, nl - pos);
- destination << std::endl;
- newlined = true;
-
- carriageReturned = true; // Regardless of whether or not we display it.
-
- pos = nl + 1;
- }
- pos = 0;
- }
-#endif
- //The same logic like above, but this time for 'line'.
while ((nl = line.find('\n', pos)) != std::string::npos)
{
PrefixIfNeeded();
@@ -121,6 +98,30 @@ void PrefixedOutStream::BaseLogic(const T& val)
if (fatal && newlined)
{
std::cout << std::endl;
+
+ // Print a backtrace, if we can.
+#ifdef HAS_BFD_DL
+ if (fatal)
+ {
+ size_t nl;
+ size_t pos = 0;
+
+ Backtrace bt;
+ std::string btLine = bt.ToString();
+ while ((nl = btLine.find('\n', pos)) != std::string::npos)
+ {
+ PrefixIfNeeded();
+
+ destination << btLine.substr(pos, nl - pos);
+ destination << std::endl;
+
+ carriageReturned = true; // Regardless of whether or not we display it.
+
+ pos = nl + 1;
+ }
+ }
+#endif
+
throw std::runtime_error("fatal error; see Log::Fatal output");
}
}
More information about the mlpack-git
mailing list