Reputation: 68270
In my main()
, I have some variable (reader
) on the stack, which is of type OggReader
(some own struct
/class
). This variable is shown as <not accessible>
in the Qt Creator / GDB debugger:
Then, I call some function on this class, so that this
should point to this reader
object. But Qt Creator / GDB does not show the content of this
:
Why? How can I fix this?
This is Qt Creator 4.0.2 on Ubuntu 16.04.
I use g++ 5.4.0 with options -g -O0 -g3 -ggdb
.
I use gdb 7.11.1.
The OggReader
class:
struct OggReader {
Page buffer_page_;
std::map<uint32_t, VorbisStream> streams_;
size_t packet_counts_;
std::shared_ptr<IReader> reader_;
ParseCallbacks& callbacks_;
OggReader(ParseCallbacks& callbacks) : packet_counts_(0), callbacks_(callbacks) {}
...
};
Page
:
struct Page {
PageHeader header;
uint8_t segment_table[256]; // page_segments_num in len
uint32_t data_len;
uint8_t data[256 * 256];
...
};
PageHeader
:
struct __attribute__((packed)) PageHeader {
char capture_pattern[4]; // should be "OggS"
uint8_t stream_structure_version; // should be 0
uint8_t header_type_flag; // 0x1: continued, 0x2: first (bos), 0x4: last (eos)
int64_t absolute_granule_pos; // end PCM sample position of the last packet completed on that page
uint32_t stream_serial_num;
uint32_t page_sequence_num;
uint32_t page_crc_checksum;
uint8_t page_segments_num;
};
Maybe __attribute__((packed))
confuses GDB somehow?
Even when I explicitly do this
Page* dummy = &buffer_page_;
inside some Page
member function, it also does not show the content of this dummy
ptr (it's the same address as this
, because buffer_page_
starts at zero offset from this
).
This question is related, although I think it is not about this
(some own struct
/class
) but instead about standard types (std::string
or so). Also, all the given solutions do not have an effect, or do not apply. E.g. "Load system GDB pretty printers" was already disabled.
Upvotes: 1
Views: 1582
Reputation: 22023
The reason is that in optimized builds, you can have some variables that are optimized away or only available in registers. In these cases, there is no way for the debuggers to get the values and you would see these <not accessible>
or <optimized away>
.
Lower the optimization level, and you will start seeing more of these variables (at the cost of reduced speed).
It seems here that there is also no default display of non-standard types. char*
are displayed, because it's a C-style string, so there would be a proper display for them. Just like VS has natvis files, QtCreator support helpers, Python files that can be used to display just what you need.
If you just want to get the contant of a struct when you only have a pointer, you can also do: const auto& v = *this;
.
Upvotes: 1