From 7621f2b2775c8d95569d2b611d2404dfab67da25 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:20:59 -0500 Subject: [PATCH] A couple notes/comments/documentation tweaks --- README.md | 7 ++++--- src/from_current.cpp | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4b0421a..c8d734c 100644 --- a/README.md +++ b/README.md @@ -395,13 +395,14 @@ API functions: references to traces returned by `cpptrace::raw_trace_from_current_exception`. #### How it works + C++ does not provide any language support for collecting stack traces when exceptions are thrown, however, exception handling under both the Itanium ABI and by SEH (used to implement C++ exceptions on windows) involves unwinding the stack twice, the first unwind searches for an appropriate `catch` handler, the second actually unwinds the stack and calls destructors. Since the stack remains intact during the search phase it's possible to collect a stack trace with zero overhead when the `catch` is considered for matching the exception. -N.b.: Cpptrace uses the same mechanism proposed for use in [P2490R3][P2490R3]. +N.b.: This mechanism is also discussed in [P2490R3][P2490R3]. #### Performance @@ -413,8 +414,8 @@ nesting of handlers, either directly in code or as a result of the current call mutliple times until the appropriate handler is found. This should not matter for the vast majority applications given that performance very rarely is critical in throwing -paths, how exception handling is usually used, and the shallowness of most call stacks. However, it's an important -consideration to be aware of. +paths, how exception handling is usually used, and the shallowness of most call stacks. However, it's something to be +aware of. To put the scale of this performance consideration into perspective: In my benchmarking I have found generation of raw traces to take on the order of `75ns` per frame. Thus, even if there were 100 non-matching handlers before a matching diff --git a/src/from_current.cpp b/src/from_current.cpp index 8805fb9..e7fbef6 100644 --- a/src/from_current.cpp +++ b/src/from_current.cpp @@ -132,7 +132,7 @@ namespace cpptrace { uintptr_t start; uintptr_t stop; stream>>start; - stream.ignore(1); + stream.ignore(1); // dash stream>>stop; if(stream.eof()) { break; @@ -141,8 +141,8 @@ namespace cpptrace { throw std::runtime_error("Failure reading /proc/self/maps"); } if(page_addr >= start && page_addr < stop) { - stream.ignore(1); - char r, w, x; + stream.ignore(1); // space + char r, w, x; // there's a private/shared flag after these but we don't need it stream>>r>>w>>x; if(stream.fail() || stream.eof()) { throw std::runtime_error("Failure reading /proc/self/maps");