Meaning of this=<optimized out> in GDB

740 views Asked by At

I understand the general concept of using optimization flags like -O2 and ending up having had things optimized out, makes sense. But what does it mean for the 'this' function parameter in a gdb frame to be optimized out? Does it mean the use of an Object was determined to be entirely pointless, and that it, and the following function call was elided from existence? Is it indicative of a function having been inlined? Is it indicative of the function call having been elided?

How would I go about investigating further? This occurs with both -O0 and -Og.

If it makes any difference, this is with an ARM process. I'm doing remote debugging using GNU gdbserver (GDB) 7.12.1.20170417-git and 'gdb-multiarch' GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1.

1

There are 1 answers

1
Employed Russian On

But what does it mean for the 'this' function parameter in a gdb frame to be optimized out?

It means that GDB doesn't have sufficient debug info to understand the current value of this.

It could happen for two reasons:

  1. the compiler failed to emit relevant debug info
  2. the info is there, but GDB failed to understand it

GCC used to do (1) a lot with -O2 and higher optimization levels, but that has been significantly improved around 2015-2016. I have never seen <optimized out> with GCC at -O0.

Clang still does (1) with -O2 and above on x86_64 in 2022, but again I've never seen it do that at -O0.

How would I go about investigating further?

You can run readelf --debug-dump ./a.out and see what info is present in the binary. Beware -- there is a lot of info, and making sense of it requires understanding of what's supposed to be there.

Or you could file a bugzilla issue with exact compiler and debugger versions and compilation command, attach a small binary, and hope that someone will look.

But first make sure you still get this behavior from the latest released version of GCC and GDB (or the current tip-of-trunk versions if you can build them).