Skip to content

Commit 9680ea7

Browse files
authored
Merge pull request #3 from apolukhin/ap/update2
More polishings for the paper: 1. Update date; 2. Fix typo in section "III. Design decisions"; 3. Add synopsis to "Header stacktrace" subsection; 4. Add more constexpr for the God of constexpr; 5. Fix typos in comments in header synopsis; 6. Change wording in brief functions descriptions.
2 parents 23077e7 + 08b2018 commit 9680ea7

File tree

1 file changed

+77
-57
lines changed

1 file changed

+77
-57
lines changed

stacktrace.html

+77-57
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<address>Alexey Gorgurov &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;, &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</address>
3030
<address>Antony Polukhin &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;, &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</address>
3131
<address>&nbsp;</address>
32-
<address>Date: 2018-02-09</address>
32+
<address>Date: 2018-01-23</address>
3333
<h1>A Proposal to add stack trace library</h1>
3434

3535
<!--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-->
@@ -65,12 +65,45 @@ <h2>II. Impact on the Standard</h2>
6565
<h2>III. Design Decisions</h2>
6666
<p>The design is based on the Boost.Stacktrace library, a popular library that does not depend on any non-standard library components.</p>
6767
<p><b>Note about signal safety:</b> this proposal does not attempt to provide a signal-safe solution for capturing and decoding stacktraces.
68-
Such functionality currently is not implementable on some of the popular platforms. However, the paper attempts to provide extendable solution, that may be made sygnal safe some day.</p>
68+
Such functionality currently is not implementable on some of the popular platforms. However, the paper attempts to provide extendable solution, that may be made signal safe some day.</p>
6969
<p><b>Note on performance:</b> during Boost.Stacktrace development phase many users requested a fast way to store stack trace, without decoding the function names. This functionality is preserved in the paper.</p>
7070

7171

7272
<h2>IV. Proposed Interface</h2>
73-
<h3>Header &lt;stacktrace&gt;</h3>
73+
<h3>Header &lt;stacktrace&gt; synopsis</h3>
74+
<pre>
75+
namespace std {
76+
77+
class stack_frame;
78+
79+
template&lt;typename Allocator&gt;
80+
class basic_stacktrace;
81+
82+
// free functions
83+
84+
// This is the alias to use unless you'd like to provide a specific allocator to basic_stacktrace.
85+
using stacktrace = basic_stacktrace&lt;allocator&lt;stack_frame&gt;&gt;;
86+
87+
// Outputs stacktrace in a human readable format to output stream.
88+
template&lt;typename CharT, typename TraitsT, typename Allocator&gt;
89+
basic_ostream&lt; CharT, TraitsT &gt; &amp; operator&lt;&lt;(basic_ostream&lt;CharT, TraitsT&gt;&amp; os, const basic_stacktrace&lt;Allocator&gt;&amp; bt);
90+
91+
// Outputs stacktrace in a human readable format to string.
92+
template&lt;typename Allocator&gt;
93+
string to_string(const basic_stacktrace&lt;Allocator&gt;&amp; f);
94+
95+
// Outputs frame in a human readable format to string.
96+
string to_string(const stack_frame&amp; f);
97+
98+
// Outputs frame in a human readable format to output stream.
99+
template&lt;typename CharT, typename TraitsT&gt;
100+
basic_ostream&lt; CharT, TraitsT &gt;&amp; operator&lt;&lt;(basic_ostream&lt;CharT, TraitsT&gt;&amp; os, const stack_frame&amp; f);
101+
}
102+
</pre>
103+
104+
105+
<h3>Class stack_frame</h3>
106+
<p>The stack_frame class stores a pointer to function and allows querying information about that function.</p>
74107
<pre>
75108
namespace std {
76109
class stack_frame {
@@ -82,24 +115,56 @@ <h3>Header &lt;stacktrace&gt;</h3>
82115
constexpr stack_frame(const stack_frame&amp;) noexcept = default;
83116
constexpr stack_frame&amp; operator=(const stack_frame&amp;) = default;
84117

85-
explicit stack_frame(native_frame_ptr_t f) noexcept;
118+
constexpr explicit stack_frame(native_frame_ptr_t f) noexcept;
86119
template&lt;typename T&gt; explicit stack_frame(T* address) noexcept;
87120

88121
constexpr native_frame_ptr_t address() const noexcept;
89-
constexpr bool empty() const noexcept;
122+
constexpr explicit operator bool() const noexcept;
90123

91-
strong_ordering operator &lt;=&gt;(const stack_frame&amp; rhs) = default;
124+
constexpr strong_ordering operator &lt;=&gt;(const stack_frame&amp; rhs) = default;
92125

93-
// functions that do decoding
126+
// functions that querying information about stored address
94127
string name() const;
95128
string source_file() const;
96129
size_t source_line() const;
97130

98131
private:
99-
native_frame_ptr_t data; // exposiotion only
132+
native_frame_ptr_t data; // exposition only
100133
};
134+
}
135+
</pre>
136+
137+
138+
<h3><code>stack_frame</code> constructors</h3>
139+
<pre>stack_frame() noexcept;</pre>
140+
<div class="desc">Constructs stack_frame that references nullptr address. Calls to <code>source_file()</code> and <code>source_line()</code> will return empty string. Calls to <code>source_line()</code> will return 0.</div>
141+
142+
<pre>explicit stack_frame(native_frame_ptr_t addr) noexcept;
143+
template&lt;typename T&gt; explicit stack_frame(T * addr) noexcept;</pre>
144+
<div class="desc">Constructs stack_frame that references addr and could later generate information about that address using platform specific features.</div>
145+
146+
147+
<h3><code>stack_frame</code> member functions</h3>
148+
<pre>std::string name() const;</pre>
149+
<div class="desc">Returns empty string or platform specific name of the function that the stored address is pointing to. Throws std::bad_alloc if not enough memory to construct resulting string.</div>
150+
151+
<pre>constexpr native_frame_ptr_t address() const noexcept;</pre>
152+
<div class="desc">Returns address stored by this.</div>
153+
154+
<pre>std::string source_file() const;</pre>
155+
<div class="desc">Returns empty string or path to the source file, where the function of the frame is defined. Returns empty string if this->source_line() == 0. Throws std::bad_alloc if not enough memory to construct resulting string.</div>
101156

157+
<pre>std::string source_line() const;</pre>
158+
<div class="desc">Returns 0 or code line in the source file, where the function of the stored address is defined. Throws std::bad_alloc if not enough memory to construct resulting string.</div>
159+
160+
<pre>explicit operator bool() const noexcept;</pre>
161+
<div class="desc">Returns true if this stores and address other than NULL.</div>
102162

163+
164+
<h3>Class template &lt;basic_stacktrace&gt;</h3>
165+
<p>The basic_stacktrace template class stores current call sequence on construction and provides functions for querying information about the call sequence.</p>
166+
<pre>
167+
namespace std {
103168
template&lt;typename Allocator&gt;
104169
class basic_stacktrace {
105170
public:
@@ -109,7 +174,7 @@ <h3>Header &lt;stacktrace&gt;</h3>
109174
using const_iterator = <i>implementation-defined</i>;
110175
using allocaotr_type = Allocator;
111176

112-
// functions that capture current call sequence without decoding it
177+
// functions that capture current call sequence
113178
basic_stacktrace() noexcept;
114179
explicit basic_stacktrace(const allocator_type&amp; a) noexcept;
115180
basic_stacktrace(size_type skip, size_type max_depth, const allocator_type&amp; a = allocator_type()) noexcept;
@@ -136,64 +201,19 @@ <h3>Header &lt;stacktrace&gt;</h3>
136201
vector&lt;value_type&gt; stack_frames; // exposition only
137202
};
138203

139-
// This is the alias to use unless you'd like to provide a specific allocator to basic_stacktrace.
140-
using stacktrace = basic_stacktrace&lt;allocator&lt;stack_frame&gt;&gt;;
141-
142-
// Outputs stacktrace in a human readable format to output stream; unsafe to use in async handlers.
143-
template&lt;typename CharT, typename TraitsT, typename Allocator&gt;
144-
basic_ostream&lt; CharT, TraitsT &gt; &amp; operator&lt;&lt;(basic_ostream&lt;CharT, TraitsT&gt;&amp; os, const basic_stacktrace&lt;Allocator&gt;&amp; bt);
145-
146-
// Outputs frame in a human readable format to string; unsafe to use in async handlers.
147-
string to_string(const stack_frame&amp; f);
148-
149-
// Outputs frame in a human readable format to output stream; unsafe to use in async handlers.
150-
template&lt;typename CharT, typename TraitsT&gt;
151-
basic_ostream&lt; CharT, TraitsT &gt;&amp; operator&lt;&lt;(basic_ostream&lt;CharT, TraitsT&gt;&amp; os, const stack_frame&amp; f);
152204
}
153205
</pre>
154206

155-
156-
<h3><code>stack_frame</code> constructors</h3>
157-
<pre>stack_frame() noexcept;</pre>
158-
<div class="desc">Constructs stack_frame that references NULL address. Calls to <code>source_file()</code> and <code>source_line()</code> will return empty string. Calls to <code>source_line()</code> will return 0.</div>
159-
160-
<pre>explicit stack_frame(native_frame_ptr_t addr) noexcept;
161-
template&lt;typename T&gt; explicit stack_frame(T * addr) noexcept;</pre>
162-
<div class="desc">Constructs stack_frame that references addr and could later generate information about that address using platform specific features.</div>
163-
164-
165-
<h3><code>stack_frame</code> member functions</h3>
166-
<pre>std::string name() const;</pre>
167-
<div class="desc">Returns platform specific name of the stack_frame (function name in a human readable form). Throws std::bad_alloc if not enough memory to construct resulting string.</div>
168-
169-
<pre>constexpr native_frame_ptr_t address() const noexcept;</pre>
170-
<div class="desc">Returns address of the stack_frame.</div>
171-
172-
<pre>std::string source_file() const;</pre>
173-
<div class="desc">Returns path to the source file, where the function of the frame is defined. Returns empty string if this->source_line() == 0. Throws std::bad_alloc if not enough memory to construct resulting string.</div>
174-
175-
<pre>std::string source_line() const;</pre>
176-
<div class="desc">Returns code line in the source line, where the function of the frame is defined. Throws std::bad_alloc if not enough memory to construct resulting string.</div>
177-
178-
<pre>constexpr bool empty() const;</pre>
179-
<div class="desc">Checks that stack_frame is not references NULL address.</div>
180-
181-
182-
183-
184-
185-
186-
187207
<h3><code>basic_stacktrace</code> constructors</h3>
188208
<pre>basic_stacktrace() noexcept;
189209
explicit basic_stacktrace(const allocator_type & a) noexcept;</pre>
190210

191-
<div class="desc">Stores the current function call sequence inside *this without any decoding or any other heavy platform specific operations.</div>
211+
<div class="desc">Stores the current call sequence inside *this without querying information about each call.</div>
192212
<div class="desc">Any exception raised during this operation is
193213
silently ignored. In case of exception <code>(bool)*this</code> is <code>false</code></div>
194214

195215
<pre>basic_stacktrace(size_type skip, size_type max_depth, const allocator_type&amp; a = allocator_type()) noexcept;</pre>
196-
<div class="desc">Stores [skip; skip + max_depth) of the current function call sequence inside *this without any decoding or any heavy platform specific operations.</div>
216+
<div class="desc">Stores [skip; skip + max_depth) of the current function call sequence inside *this without querying information about each call.</div>
197217
<div class="desc">Any exception raised during this operation is
198218
silently ignored. In case of exception <code>(bool)*this</code> is <code>false</code></div>
199219

@@ -203,7 +223,7 @@ <h3><code>basic_stacktrace</code> member functions</h3>
203223
<div class="desc">Parameters: <code>frame_no</code> - zero-based index of frame to return. 0 is the function index where stacktrace was constructed and index close to this->size() contains function main().</div>
204224

205225
<pre>explicit operator bool() const noexcept;</pre>
206-
<div class="desc">Allows to check that stack trace capturing was successful.</div>
226+
<div class="desc">Returns true if call sequence was successfully stored.</div>
207227

208228

209229
<h2>V. Feature-testing macro</h2>

0 commit comments

Comments
 (0)