@@ -307,7 +307,7 @@ into `std::string`.
307307
308308`cpptrace::prune_symbol` is a helper for custom formatters that prunes demangled symbols by removing return types,
309309template arguments, and function parameters. It also does some minimal normalization. For example, it prunes
310- `ns::S<int, float>::~S()` to `ns::S::~S`.
310+ `ns::S<int, float>::~S()` to `ns::S::~S`. If cpptrace is unable to parse the symbol it will return the original symbol.
311311
312312`cpptrace::get_snippet` gets a text snippet, if possible, from for the given source file for +/- `context_size` lines
313313around `line`.
@@ -370,7 +370,8 @@ namespace cpptrace {
370370 formatter& snippets(bool);
371371 formatter& snippet_context(int);
372372 formatter& columns(bool);
373- formatter& prettify_symbols(bool);
373+ enum class symbol_mode { full, pretty, pruned };
374+ formatter& symbols(symbol_mode);
374375 formatter& filtered_frame_placeholders(bool);
375376 formatter& filter(std::function<bool(const stacktrace_frame&)>);
376377 formatter& transform(std::function<stacktrace_frame(stacktrace_frame)>);
@@ -399,28 +400,32 @@ namespace cpptrace {
399400```
400401
401402Options:
402- | Setting | Description | Default |
403- | ----------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------ |
404- | `header` | Header line printed before the trace | `Stack trace (most recent call first):` |
405- | `colors` | Default color mode for the trace | `automatic`, which attempts to detect if the target stream is a terminal |
406- | `addresses` | Raw addresses, object addresses, or no addresses | `raw` |
407- | `paths` | Full paths or just filenames | `full` |
408- | `snippets` | Whether to include source code snippets | `false` |
409- | `snippet_context` | How many lines of source context to show in a snippet | `2` |
410- | `columns` | Whether to include column numbers if present | `true` |
411- | `prettify_symbols ` | Whether to attempt to clean up long symbol names | `false` |
412- | `filtered_frame_placeholders` | Whether to still print filtered frames as just `#n (filtered)` | `true` |
413- | `filter` | A predicate to filter frames with | None |
414- | `transform` | A transformer which takes a stacktrace frame and modifies it | None |
403+ | Setting | Description | Default |
404+ | ----------------------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------ |
405+ | `header` | Header line printed before the trace | `Stack trace (most recent call first):` |
406+ | `colors` | Default color mode for the trace | `automatic`, which attempts to detect if the target stream is a terminal |
407+ | `addresses` | Raw addresses, object addresses, or no addresses | `raw` |
408+ | `paths` | Full paths or just filenames | `full` |
409+ | `snippets` | Whether to include source code snippets | `false` |
410+ | `snippet_context` | How many lines of source context to show in a snippet | `2` |
411+ | `columns` | Whether to include column numbers if present | `true` |
412+ | `symbols ` | Full demangled symbols, pruned symbol names, or prettified symbols | `full` |
413+ | `filtered_frame_placeholders` | Whether to still print filtered frames as just `#n (filtered)` | `true` |
414+ | `filter` | A predicate to filter frames with | None |
415+ | `transform` | A transformer which takes a stacktrace frame and modifies it | None |
415416
416417The `automatic` color mode attempts to detect if a stream that may be attached to a terminal. As such, it will not use
417418colors for the `formatter::format` method and it may not be able to detect if some ostreams correspond to terminals or
418419not. For this reason, `formatter::format` and `formatter::print` methods have overloads taking a color parameter. This
419420color parameter will override configured color mode.
420421
421- The `prettify_symbols` option applies a number of simple rewrite rules to symbols in an attempt to clean them up, e.g.
422- it rewrites `foo(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >)`
423- as `foo(std::vector<std::string>)`.
422+ The `symbols` option provides a few settings for pretty-printing symbol names. By default the full name is printed.
423+ - `symbol_mode::pretty` applies a number of transformations to clean up long symbol names. For example, it turns
424+ `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >` into `std::string`. This is
425+ equivalent to `cpptrace::prettify_symbol`.
426+ - `symbol_mode::prune` prunes demangled symbols by removing return types, template arguments, and function parameters.
427+ It also does some minimal normalization. For example, it prunes `ns::S<int, float>::~S()` to `ns::S::~S`. If cpptrace
428+ is unable to parse the symbol it will uses the full symbol. This is equivalent to `cpptrace::prune_symbol`.
424429
425430Recommended practice with formatters: It's generally preferable to create formatters objects that are long-lived rather
426431than to create them on the fly every time a trace needs to be formatted.
0 commit comments