Skip to content

Commit 8a95dd9

Browse files
committed
Add a motivating sample with stacktrace print
It is copied from http://boostorg.github.io/stacktrace/stacktrace/getting_started.html#stacktrace.getting_started.better_asserts Also fix minor bug (SG6->SG14)
1 parent 7fc257b commit 8a95dd9

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

stacktrace.html

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<h1>A Proposal to add stack trace library</h1>
3434

3535
<span class='changed-added'>Significant changes to <a href="http://github.com/leha-bot/cpp-stacktrace-proposal">P????R?</a> are marked with blue.</span> <button onclick="show_hide_deleted()">Show/Hide deleted lines from P????R?</button>
36-
<p class='notes'>Green lines are notes for the <b>editor</b> or for the <b>SG6</b> that must not be treated as part of the wording.</p>
36+
<p class='notes'>Green lines are notes for the <b>editor</b> or for the <b>SG14</b> that must not be treated as part of the wording.</p>
3737
<h2>I. Motivation</h2>
3838
<p>At this time there is no standard solution to get the calls sequence that results in unhandled exception, std::terminate or assertion failure. That sequence is widely used in another programming languages (like Java, C#, Python) for debugging and post mortem debugging.
3939
</p>
@@ -44,6 +44,20 @@ <h2>I. Motivation</h2>
4444
Aborted (core dumped)</code>
4545
</p>
4646
<p>This assert can be in any translation unit including the <code>boost/array.hpp</code> header.</p>
47+
<p>With adding of the proposed classes you may see the following message:
48+
<pre>
49+
Expression 'i < N' is false in function 'T& boost::array<T, N>::operator[](boost::array<T, N>::size_type) [with T = int; long unsigned int N = 5ul; boost::array<T, N>::reference = int&; boost::array<T, N>::size_type = long unsigned int]': out of range.
50+
Backtrace:
51+
0# boost::assertion_failed_msg(char const*, char const*, char const*, char const*, long) at ../example/assert_handler.cpp:39
52+
1# boost::array<int, 5ul>::operator[](unsigned long) at ../../../boost/array.hpp:124
53+
2# bar(int) at ../example/assert_handler.cpp:17
54+
3# foo(int) at ../example/assert_handler.cpp:25
55+
4# bar(int) at ../example/assert_handler.cpp:17
56+
5# foo(int) at ../example/assert_handler.cpp:25
57+
6# main at ../example/assert_handler.cpp:54
58+
7# 0x00007F991FD69F45 in /lib/x86_64-linux-gnu/libc.so.6
59+
8# 0x0000000000401139
60+
</pre>
4761
<p>We propose two headers (<code>&lt;stacktrace&gt;</code> and <code>&lt;frame&gt;</code>), two classes (<code>template &lt;typename Allocator&gt;class basic_stacktrace</code> and <code>class frame</code>) and several functions for safe stack frames dump.</p>
4862

4963
<!--<p>Current compilers can print a stack trace while debugging or crash dump for debugging purposes. The compiler's users also can get a stack trace via implementation-defined API. But there is no cross-platform solution (except Boost.Stacktrace on which this Proposal is based of).</p>
@@ -82,36 +96,36 @@ <h3>Header &lt;stacktrace&gt;</h3>
8296
namespace stacktrace {
8397
template&lt;typename Allocator&gt; class basic_stacktrace;
8498

85-
typedef basic_stacktrace stacktrace; // This is the typedef to use unless you'd like to provide a specific allocator to boost::stacktrace::basic_stacktrace.
86-
template&lt;typename Allocator1, typename Allocator2&gt;
87-
bool operator&lt;(const basic_stacktrace&lt; Allocator1 &gt; &,
99+
typedef basic_stacktrace stacktrace; // This is the typedef to use unless you'd like to provide a specific allocator to boost::stacktrace::basic_stacktrace.
100+
template&lt;typename Allocator1, typename Allocator2&gt;
101+
bool operator&lt;(const basic_stacktrace&lt; Allocator1 &gt; &,
88102
const basic_stacktrace&lt; Allocator2 &gt; &);
89-
template&lt;typename Allocator1, typename Allocator2&gt;
90-
bool operator==(const basic_stacktrace&lt; Allocator1 &gt; &,
103+
template&lt;typename Allocator1, typename Allocator2&gt;
104+
bool operator==(const basic_stacktrace&lt; Allocator1 &gt; &,
91105
const basic_stacktrace&lt; Allocator2 &gt; &);
92106

93-
// Comparison operators that provide platform dependant ordering and have amortized O(1) complexity; O(size()) worst case complexity; are Async-Handler-Safe.
94-
template&lt;typename Allocator1, typename Allocator2&gt;
95-
bool operator&gt;(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
107+
// Comparison operators that provide platform dependant ordering and have amortized O(1) complexity; O(size()) worst case complexity; are Async-Handler-Safe.
108+
template&lt;typename Allocator1, typename Allocator2&gt;
109+
bool operator&gt;(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
96110
const basic_stacktrace&lt; Allocator2 &gt; & rhs);
97-
template&lt;typename Allocator1, typename Allocator2&gt;
98-
bool operator&lt;=(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
111+
template&lt;typename Allocator1, typename Allocator2&gt;
112+
bool operator&lt;=(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
99113
const basic_stacktrace&lt; Allocator2 &gt; & rhs);
100-
template&lt;typename Allocator1, typename Allocator2&gt;
101-
bool operator&gt;=(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
114+
template&lt;typename Allocator1, typename Allocator2&gt;
115+
bool operator&gt;=(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
102116
const basic_stacktrace&lt; Allocator2 &gt; & rhs);
103-
template&lt;typename Allocator1, typename Allocator2&gt;
104-
bool operator!=(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
117+
template&lt;typename Allocator1, typename Allocator2&gt;
118+
bool operator!=(const basic_stacktrace&lt; Allocator1 &gt; & lhs,
105119
const basic_stacktrace&lt; Allocator2 &gt; & rhs);
106120

107-
// Fast hashing support, O(st.size()) complexity; Async-Handler-Safe.
108-
template&lt;typename Allocator&gt;
121+
// Fast hashing support, O(st.size()) complexity; Async-Handler-Safe.
122+
template&lt;typename Allocator&gt;
109123
std::size_t hash_value(const basic_stacktrace&lt; Allocator &gt; & st);
110124

111-
// Outputs stacktrace in a human readable format to output stream; unsafe to use in async handlers.
112-
template&lt;typename CharT, typename TraitsT, typename Allocator&gt;
113-
std::basic_ostream&lt; CharT, TraitsT &gt; &
114-
operator&lt;&lt;(std::basic_ostream&lt; CharT, TraitsT &gt; & os,
125+
// Outputs stacktrace in a human readable format to output stream; unsafe to use in async handlers.
126+
template&lt;typename CharT, typename TraitsT, typename Allocator&gt;
127+
std::basic_ostream&lt; CharT, TraitsT &gt; &
128+
operator&lt;&lt;(std::basic_ostream&lt; CharT, TraitsT &gt; & os,
115129
const basic_stacktrace&lt; Allocator &gt; & bt);
116130
}
117131
}
@@ -121,23 +135,23 @@ <h3> Header &lt;frame&gt;</h3>
121135
namespace boost {
122136
namespace stacktrace {
123137

124-
// Comparison operators that provide platform dependant ordering and have O(1) complexity; are Async-Handler-Safe.
138+
// Comparison operators that provide platform dependant ordering and have O(1) complexity; are Async-Handler-Safe.
125139
constexpr bool operator&lt;(const frame & lhs, const frame & rhs);
126140
constexpr bool operator&gt;(const frame & lhs, const frame & rhs);
127141
constexpr bool operator&lt;=(const frame & lhs, const frame & rhs);
128142
constexpr bool operator&gt;=(const frame & lhs, const frame & rhs);
129143
constexpr bool operator==(const frame & lhs, const frame & rhs);
130144
constexpr bool operator!=(const frame & lhs, const frame & rhs);
131145

132-
// Fast hashing support, O(1) complexity; Async-Handler-Safe.
146+
// Fast hashing support, O(1) complexity; Async-Handler-Safe.
133147
std::size_t hash_value(const frame & f);
134148

135-
// Outputs stacktrace::frame in a human readable format to string; unsafe to use in async handlers.
149+
// Outputs stacktrace::frame in a human readable format to string; unsafe to use in async handlers.
136150
std::string to_string(const frame & f);
137151

138-
// Outputs stacktrace::frame in a human readable format to output stream; unsafe to use in async handlers.
139-
template&lt;typename CharT, typename TraitsT&gt;
140-
std::basic_ostream&lt; CharT, TraitsT &gt; &
152+
// Outputs stacktrace::frame in a human readable format to output stream; unsafe to use in async handlers.
153+
template&lt;typename CharT, typename TraitsT&gt;
154+
std::basic_ostream&lt; CharT, TraitsT &gt; &
141155
operator&lt;&lt;(std::basic_ostream&lt; CharT, TraitsT &gt; & os, const frame & f);
142156
}
143157
}

0 commit comments

Comments
 (0)