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

Move type info into hpx::debug namespace and add print helper functions #3192

Merged
merged 5 commits into from Oct 16, 2018

Conversation

biddisco
Copy link
Contributor

Proposed Changes

Adds an extra couple of type info print helpers and moves the demangler into the debug namespace.
Might not compile on all platforms because we had some problems with it in the past, so wanting to see what pycicle gives after a build/test of this PR.

@@ -36,6 +41,7 @@ namespace hpx { namespace util
private:
char* demangled_;
};

Copy link
Member

Choose a reason for hiding this comment

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

The same structure below needs to be moved into hpx::debug as well

template <typename T=void>
inline std::string print_type(const char *delim="")
{
return std::string(debug::type_id<T>::typeid_.type_id());;
Copy link
Member

Choose a reason for hiding this comment

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

Superfluous ';'

@msimberg
Copy link
Contributor

Should these be moved to an hpx/debug folder to match the namespace?

@hkaiser
Copy link
Member

hkaiser commented Feb 26, 2018

Should these be moved to an hpx/debug folder to match the namespace?

Good point!

@msimberg msimberg removed this from the 1.1.0 milestone Mar 22, 2018
@biddisco
Copy link
Contributor Author

biddisco commented Oct 8, 2018

would hpx/util/debug be acceptable, or would people prefer hpx/debug

@hkaiser
Copy link
Member

hkaiser commented Oct 10, 2018

would hpx/util/debug be acceptable, or would people prefer hpx/debug

I'd vote for hpx/util/debug/.


// disable the code specific to gcc for now as this causes problems
// (see #811: simple_central_tuplespace_client run error)
#if 0 // defined(__GNUC__)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Am I right in thinking that the reason why the code was #ifdefed out here is because the demangle_helper uses abi::__cxa_demangle(typeid(T).name(), 0, 0, 0) which returns a char * and this char * is deleted when the helper goes out of scope - but the char * is held onto by the (serialization) code that uses it.

If this is the case, is there anything we can do to make the serialization code keep the memory alive?
For debugging, the demangled version is very useful, in the debug::print(...) code, the char * is copied into a string, so no memory violations occur. Perhaps we should just use the undemangled version in the serialization, and keep the demangled one for debug stuff?

Copy link
Member

Choose a reason for hiding this comment

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

for that, we'd just need to implement proper resource management. std::string, std::shared_ptr<char> or std::vector<char> are available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I played with this some more and something very odd is going on. The code segfaults in function registration of pointers when the debug mangler is used, but it's not caused by the pointer being invalid AFAICT. the test any_serialization_test_exe fails if the GNU cxxabi demangler is used and I'm baffled as to what is going wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'll leave the serialization code using the standard typeid stuff and enable the demangler for debugging and printing types, it is very useful to me and worth having, but I'll just provide two types and use one for debug and the other for serialization. Unless someone has a clue as to why the cxxabi demangler causes problems

Unfortunately, the cxxabi demangler utility causes an error in
the serialization code. Until that is resolved (see also issue #811)
use the normal typeid string for serialization and cxxabi
for debug printing.
@biddisco
Copy link
Contributor Author

I have made 2 versions of the debug mangler
serialization code always uses plain typeid for safety, until we understand why the code fails when using the cxxabi version. The cxxabi version is enabled for debug printing on systems that support it.

I'd like this to go into 1.2 release if possible.


~cxxabi_demangle_helper()
{
free(demangled_);
Copy link
Member

Choose a reason for hiding this comment

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

Due to this, the class can't be copied. I think it would make sense to use proper memory management here. As I suggested previously, using either std::vector<char>, std::unique_ptr<char, deleter> or even std::string might help here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to clarify - the code in question was copied directly from the old implementation and used only in one place to initialize a static var that is used for the symbol translation (so copying is not planned or supported for this class). I will however use a unique_ptr if that makes you happy.

Copy link
Contributor

@msimberg msimberg left a comment

Choose a reason for hiding this comment

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

This looks good to go as soon as pycicle finishes with gcc 4.9.

@biddisco biddisco merged commit b90ec00 into master Oct 16, 2018
@biddisco biddisco deleted the demangle_helper branch October 16, 2018 14:41
@msimberg msimberg added this to the 1.4.0 milestone Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants