Skip to content

Commit 2cc71d5

Browse files
committed
Various cleanup, corrections, clarification, etc
1 parent 644515c commit 2cc71d5

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,10 @@ namespace cpptrace {
479479

480480
### Logging
481481

482-
Cpptrace attempts to gracefully recover from any internal errors. By default, cpptrace doesn't log anything to the
483-
console in order to avoid interfering with user programs. However, there are a couple configurations that can be used
484-
to set a custom logging behavior or enable logging to stderr.
482+
Cpptrace attempts to gracefully recover from any internal errors in order to provide the best information it can and not
483+
interfere with user applications. However, sometimes it's important to see what's going wrong inside cpptrace if
484+
anything does go wrong. To facilitate this, cpptrace has an internal logger. By default it doesn't log anything out. The
485+
following configurations that can be used to set a custom logging callback or enable logging to stderr:
485486

486487
```cpp
487488
namespace cpptrace {
@@ -577,23 +578,23 @@ CPPTRACE_TRY {
577578
}
578579
```
579580

580-
> [!CAUTION]
581-
> There is a footgun with `return` statements in these try/catch macros: The implementation on Windows requires wrapping
582-
> the try body in an immediately-invoked lambda and and as such `return` statements return from the lambda not the
583-
> enclosing function. If you're writing code that will be compiled on windows, it's important to not write `return`
584-
> statements within CPPTRACE_TRY. E.g., this does not work as expected on windows:
581+
> [!WARNING]
582+
> There is an unfortunate limitation with `return` statements in these try/catch macros: The implementation on Windows
583+
> requires wrapping the try body in an immediately-invoked lambda and and as such `return` statements would return from
584+
> the lambda not the enclosing function. Cpptrace guards against misleading `return`s compiling by requiring the lambdas
585+
> to return a special internal type, but, if you're writing code that will be compiled on windows it's important to not
586+
> write `return` statements within CPPTRACE_TRY. For example, this is invalid:
585587
> ```cpp
586588
> CPPTRACE_TRY {
587-
> if(condition) return 40; // does not return from the enclosing function on windows
589+
> if(condition) return 40; // error, type int doesn't match cpptrace::detail::dont_return_from_try_catch_macros
588590
> } CPPTRACE_CATCH(const std::exception& e) {
589591
> ...
590592
> }
591-
> return 20;
592593
> ```
593594
594595
> [!WARNING]
595-
> There is one other footgun which is mainly relevant for code that was written on an older version of cpptrace: It's
596-
> possible to write the following without getting errors
596+
> There is a footgun which is mainly relevant for code that was written on an older version of cpptrace: It's possible
597+
> to write the following without getting errors
597598
> ```cpp
598599
> CPPTRACE_TRY {
599600
> ...
@@ -603,9 +604,9 @@ CPPTRACE_TRY {
603604
> ...
604605
> }
605606
> ```
606-
> This code will compile and in some sense work as expected as the second catch handler will work, however, cpptrace
607-
> won't know about the handler and as such it would be able to correctly collect a trace on a non-`std::runtime_error`
608-
> that is thrown. No run-time errors will occur, however, `from_current_exception` may report a misleading trace.
607+
> This code will compile and the second catch handler will work, however, cpptrace won't know about the handler and as
608+
> such it won't be able to correctly collect a trace when a type that does not match `std::runtime_error` is thrown. No
609+
> run-time errors will occur, however, `from_current_exception` will report a misleading trace.
609610
610611
### Removing the `CPPTRACE_` prefix
611612

src/platform/exception_type.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace detail {
1717
inline std::string exception_type_name() {
1818
#if defined(CPPTRACE_HAS_CXX_EXCEPTION_TYPE) && (IS_LIBSTDCXX || IS_LIBCXX)
1919
const std::type_info* t = abi::__cxa_current_exception_type();
20-
return t ? demangle(t->name(), false) : "<unknown>";
20+
return t ? detail::demangle(t->name(), false) : "<unknown>";
2121
#else
2222
return "<unknown>";
2323
#endif

src/utils.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
#include <unistd.h>
1515
#endif
1616

17-
CPPTRACE_BEGIN_NAMESPACE
18-
namespace detail {
19-
const formatter& get_terminate_formatter() {
20-
static formatter the_formatter = formatter{}
21-
.header("Stack trace to reach terminate handler (most recent call first):");
22-
return the_formatter;
23-
}
24-
}
25-
CPPTRACE_END_NAMESPACE
26-
2717
CPPTRACE_BEGIN_NAMESPACE
2818
std::string demangle(const std::string& name) {
2919
return detail::demangle(name, false);
@@ -47,6 +37,14 @@ CPPTRACE_BEGIN_NAMESPACE
4737
extern const int stderr_fileno = STDERR_FILENO;
4838
#endif
4939

40+
namespace detail {
41+
const formatter& get_terminate_formatter() {
42+
static formatter the_formatter = formatter{}
43+
.header("Stack trace to reach terminate handler (most recent call first):");
44+
return the_formatter;
45+
}
46+
}
47+
5048
CPPTRACE_FORCE_NO_INLINE void print_terminate_trace() {
5149
try { // try/catch can never be hit but it's needed to prevent TCO
5250
detail::get_terminate_formatter().print(std::cerr, generate_trace(1));

src/utils/result.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ namespace detail {
7171
return *this;
7272
}
7373
Result& operator=(Result&& other)
74-
noexcept(std::is_nothrow_move_assignable<value_type>::value && std::is_nothrow_move_constructible<value_type>::value)
74+
noexcept(
75+
std::is_nothrow_move_constructible<value_type>::value && std::is_nothrow_move_constructible<E>::value
76+
)
7577
{
7678
if (this != &other) {
7779
destroy();

test/link_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ int main() {
8585
cpptrace::experimental::set_dwarf_resolver_line_table_cache_size(100);
8686
cpptrace::experimental::set_dwarf_resolver_disable_aranges(true);
8787

88+
cpptrace::detail::lazy_trace_holder lh;
89+
lh.is_resolved();
90+
8891
cpptrace::basename("");
8992
cpptrace::prettify_symbol("");
93+
cpptrace::prune_symbol("");
9094
}

0 commit comments

Comments
 (0)