1

Consider a type like

#include <type_traits>
template<typename T>
struct Foo {
    std::remove_cv_t<T> m;
};

which uses a type trait to deduce the type of one of its members from a template parameter. This type may then be used as follows:

Foo<const int> f;
f.m = 42;          // type of f.m is std::remove_cv_t<const int>,
                   // which resolves to int; break on this line

When trying to inspect the type of f.m wit gdb's Python API, it seems I only get incomplete information.

(gdb) python-interactive
>>> print(gdb.parse_and_eval('f')['m'].type)
std::remove_cv_t

This is not very helpful. It does not tell me what template arguments remove_cv_t was instantiated with, nor which underlying type the instantiated trait resolves to.

How can I determine through the Python API that the resolved type of f.m in this case is int?

1 Answer 1

3

The API function you are looking for is strip_typedefs():

Function: Type.strip_typedefs ()

Return a new gdb.Type that represents the real type, after removing all layers of typedefs.

(gdb) python-interactive
>>> print(gdb.parse_and_eval('f')['m'].type.strip_typedefs())
int
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.