Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify stack trace collection code in C++ #3110

Merged
merged 16 commits into from
Nov 12, 2024

Conversation

bernardnormier
Copy link
Member

@bernardnormier bernardnormier commented Nov 8, 2024

This PR simplifies the stack trace collection code in C++, and moves the initialization to a static function on Ice::Exception.

It also fixes #3048.

Copy link
Member

@pepone pepone left a comment

Choose a reason for hiding this comment

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

Looks good, not clear why this is faster.

cpp/include/Ice/Exception.h Outdated Show resolved Hide resolved
@bernardnormier bernardnormier marked this pull request as draft November 9, 2024 14:55
#elif defined(ICE_BACKTRACE)
backTraceEnabled = true;
#endif
return collectStackTraces();
Copy link
Member

Choose a reason for hiding this comment

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

If I read this correctly ICE_LIBBACKTRACE is the only case where collectStackTraces has the possibility to return false (aside from when there is no library support). ICE_BACKTRACE is always true and ICE_DBGHELP will throw an exception.

I think we should just throw if bstate == NULL and have this function return void. Returning a bool here doesn't make much sense. If it returns false you have no idea why or what you're supposed to do.

The few places we're call it we don't even check the return value.

Copy link
Member Author

Choose a reason for hiding this comment

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

We check the return value in the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. It now returns void and the test assumes stack trace collection is available for the current platform/build.

@@ -539,6 +466,59 @@ Ice::Exception::ice_stackTrace() const
return getStackTrace(*_stackFrames);
}

bool
Ice::Exception::ice_enableStackTraceCollection()
Copy link
Member

Choose a reason for hiding this comment

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

Is the ice_ prefix really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

We use this ice_ prefix for all other member functions. No ice_ prefix would be inconsistent.

}
};

Init init;
#endif

inline bool collectStackTraces() noexcept
Copy link
Member

Choose a reason for hiding this comment

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

Should we be using a memory barrier to access these global variables. Isn't there a chance they'll be stale otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added mutex lock.

if (!bstate)
{
// Leaked, as libbacktrace does not provide an API to free this state.
bstate = backtrace_create_state(0, 1, ignoreErrorCallback, 0);
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to get an error message out of the callback if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's unrelated to this PR and it's not clear where we'd send this error message.

@bernardnormier bernardnormier marked this pull request as ready for review November 11, 2024 20:25
cpp/src/Ice/Exception.cpp Show resolved Hide resolved
cpp/src/IceBox/ServiceManagerI.cpp Outdated Show resolved Hide resolved
@bernardnormier bernardnormier merged commit c7a7cc7 into zeroc-ice:main Nov 12, 2024
19 checks passed
@bernardnormier bernardnormier deleted the win32-stack branch December 9, 2024 17:10
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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.

cpp/Ice/timeout failure (Windows)
3 participants