Daniel Walker
Daniel Walker

Reputation: 6760

gdb declares size of 0 for class field

I loaded up a C++ library in gdb, started the built-in Python interpreter, and ran

import gdb

t = gdb.lookup_type('Some::Type')
field = t.fields()[0]
print(field.bitpos)
print(field.bitsize)

The output is

0
0

What does it mean for a field to have a size of 0?

I've run gdb.lookup_type on the class of the field and it's not empty. I think it's a virtual class because all it has is a vtable.

Upvotes: 0

Views: 67

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 120049

bitsize is only meaningful for bit fields or packed fields. For regular fields, the size is given by the type. Use

t.fields()[0].type.sizeof

to access the size.

Upvotes: 1

Related Questions