Had the same problem earlier today,
The most suitable tool I can find is pahole. Usage example:
$ cat dummy.cpp
#include <string>
struct Dummy {
int a, b, c;
std::string d;
};
struct Dummy x; // gcc doesn't emit debug info for unused stuff
$ g++ -c dummy.cpp -ggdb3
$ pahole dummy.o
die__process_class: tag not supported (template_type_parameter)!
//trimmed structs __va_list_tag, tm and lconv
struct Dummy {
int a; /* 0 4 */
int b; /* 4 4 */
int c; /* 8 4 */
string d; /* 16 8 */
//trimmed some constructors
};
Unfortunately, it doesn't print template contents, like std::string aka std::basic_string< char>.
I also found pstruct (easier confused than pahole, doesn't accept C++ at all), Clang -cc1 -fdump-record-layouts (it gave me a pile of pointers to Clang's address space, but no offsets) and MSVC -d1reportAllClassLayout (that flag made no difference when I tried).
Or the manual method:
Memset the struct to zero, set the relevant offsets to 0xFF, print struct in gdb (use set print pretty on
so it doesn't put everything on a single huge line), grep the output for nonzeroes, and hope the STL pretty-printers don't get too confused.
Maybe I should make a GDB module to automate this, it's quite tedious no matter what I do...