Skip to content

Fix symbolizer empty stack frame names - #68

Merged
vadimskipin merged 1 commit into
ClickHouse:mainfrom
Maximus5:users/maximus5/fix-symbolizer
Jun 12, 2026
Merged

vadimskipin merged 1 commit into
ClickHouse:mainfrom
Maximus5:users/maximus5/fix-symbolizer

Conversation

@Maximus5

@Maximus5 Maximus5 commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Notes

In some projects the root stack frame started with (anonymous namespace)::. Also this may appear in the middle of demangled result and even in arguments.

So the result became just an empty string and this stack frame became <process>+0x12345 in result svg.

Testing

../../bb test -R Symbolizer
2026-06-12 15:55:43.118 [INFO ] bb:1970: command=test preset=debug
[0/2] Re-checking globbed directories...
ninja: no work to do.
Test project /home/moisiuk/git/silk/build/debug
    Start 284: Symbolizer.ResolveKnownFunction
    Start 286: Symbolizer.CacheReturnsSameReference
    Start 288: Symbolizer.DemangleResults
    Start 287: Symbolizer.DemangleOptions
    Start 283: Symbolizer.ReadMappingsSucceeds
    Start 285: Symbolizer.ResolveUnmappedAddressReturnsHex
1/6 Test #288: Symbolizer.DemangleResults ....................   Passed    0.00 sec
2/6 Test #287: Symbolizer.DemangleOptions ....................   Passed    0.00 sec
3/6 Test #283: Symbolizer.ReadMappingsSucceeds ...............   Passed    0.00 sec
4/6 Test #285: Symbolizer.ResolveUnmappedAddressReturnsHex ...   Passed    0.00 sec
5/6 Test #286: Symbolizer.CacheReturnsSameReference ..........   Passed    0.22 sec
6/6 Test #284: Symbolizer.ResolveKnownFunction ...............   Passed    0.22 sec

100% tests passed, 0 tests failed out of 6

@Maximus5 Maximus5 changed the title Fix symbolizer causing stacks loss Fix symbolizer empty stack frames Jun 12, 2026
@Maximus5 Maximus5 changed the title Fix symbolizer empty stack frames Fix symbolizer empty stack frame names Jun 12, 2026
@vadimskipin
vadimskipin requested a review from Copilot June 12, 2026 12:02
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from 34b7a14 to ddad77d Compare June 12, 2026 12:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses cases where demangled C++ symbols contain (anonymous namespace):: (including inside argument types), which previously caused the profiler/assert symbol printing to strip from the wrong ( and produce empty/truncated frame names (leading to ...+0x... frames in the output).

Changes:

  • Switch stack-trace printing in assert.cpp from first ( to last ( when splitting name vs args.
  • Introduce Symbolizer::demangle(..., SymbolizerDemangleOptions) with support for stripping anonymous namespaces and/or arguments, and use it in Symbolizer::resolve.
  • Add a dedicated Symbolizer.Demangle unit test with a variety of mangled symbols.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/util/assert.cpp Adjusts stack-trace demangle formatting to avoid empty names when (anonymous namespace):: is present.
src/profiler/symbolizer.h Adds demangling options enum and a new Symbolizer::demangle API.
src/profiler/symbolizer.cpp Centralizes demangling/stripping logic and updates resolve() to use it.
src/profiler/tests/symbolizer-test.cpp Adds unit tests for demangling and stripping behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/profiler/symbolizer.cpp Resolved
Comment thread src/util/assert.cpp Resolved
Comment thread src/profiler/tests/symbolizer-test.cpp Resolved
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from ddad77d to a550dc8 Compare June 12, 2026 12:24
@Maximus5
Maximus5 requested a review from Copilot June 12, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/profiler/symbolizer.h Resolved
Comment thread src/profiler/symbolizer.cpp Resolved
Comment thread src/profiler/tests/symbolizer-test.cpp Resolved
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from a550dc8 to 5675fdc Compare June 12, 2026 12:48
@Maximus5
Maximus5 requested a review from Copilot June 12, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread src/util/assert.cpp Resolved
Comment thread src/profiler/symbolizer.cpp Resolved
Comment thread src/profiler/symbolizer.h Resolved
Comment thread src/profiler/tests/symbolizer-test.cpp Resolved
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from 5675fdc to b834f73 Compare June 12, 2026 13:55
@Maximus5
Maximus5 requested a review from Copilot June 12, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/util/assert.cpp Resolved
Comment thread src/profiler/symbolizer.h Resolved
Comment thread src/profiler/symbolizer.cpp Resolved
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from b834f73 to 9353bf0 Compare June 12, 2026 14:08
@Maximus5
Maximus5 requested a review from Copilot June 12, 2026 14:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/util/assert.cpp Resolved
Comment thread src/profiler/symbolizer.h Resolved
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from 9353bf0 to 2345dda Compare June 12, 2026 14:18
@Maximus5
Maximus5 requested a review from Copilot June 12, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread src/util/assert.cpp Resolved
Comment thread src/profiler/symbolizer.h Resolved
Comment thread src/profiler/symbolizer.cpp Resolved
Comment thread src/profiler/symbolizer.cpp Resolved
Comment thread src/profiler/tests/symbolizer-test.cpp Resolved
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from 2345dda to ebc7c6e Compare June 12, 2026 14:43
@Maximus5
Maximus5 requested a review from Copilot June 12, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread src/profiler/symbolizer.cpp Resolved
Comment thread src/profiler/tests/symbolizer-test.cpp Resolved
Comment thread src/profiler/tests/symbolizer-test.cpp Resolved
Comment thread src/profiler/symbolizer.h Resolved
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from ebc7c6e to 2a0cbd0 Compare June 12, 2026 15:00
@Maximus5
Maximus5 requested a review from Copilot June 12, 2026 15:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/util/assert.cpp
Comment on lines +47 to 50
const char * paren = std::strrchr(demangled, '(');
if (paren)
{
std::fwrite(demangled, 1, static_cast<size_t>(paren - demangled), stderr);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep this part in assert.cpp as simple as possible.

Even if we find a wrong start position (quite rare cases), worst thing that happens - incorrect coloring of the arguments part.

Comment thread src/profiler/symbolizer.h Outdated
const std::string & resolve(uint64_t addr);

// Demangle a C++ symbol and optionally strip anonymous namespaces and/or arguments.
static std::string demangle(const std::string & mangled, SymbolizerDemangleOptions options);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the function we use .c_str(), so string_view is not acceptable.

Comment thread src/profiler/symbolizer.cpp Outdated
Comment on lines +266 to +270
if ((options & SymbolizerDemangleOptions::StripAnonymousNamespace) == SymbolizerDemangleOptions::StripAnonymousNamespace)
{
constexpr std::string_view anonymousNamespace = "(anonymous namespace)::";
if (size_t pos = result.find(anonymousNamespace); pos != std::string::npos)
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just two places. Introducing hasFlag helper triggers infinite loop with Copilit unhappy.

In some projects the root stack frame started with `(anonymous namespace)::`.
Also this may appear in the middle of demangled result and even in arguments.

So the result became just an empty string and this stack frame became
`<process>+0x12345` in result svg.
@Maximus5
Maximus5 force-pushed the users/maximus5/fix-symbolizer branch from 2a0cbd0 to ae1c006 Compare June 12, 2026 15:26
@vadimskipin
vadimskipin merged commit e51e507 into ClickHouse:main Jun 12, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants