Wei You
Wei You

Reputation: 41

How to de-optimize the Linux kernel to avoid value optimized out

I am debugging Linux kernel.

I compile the kernel with -O1 optimization level. (Note that the Linux kernel cannot be compiled with -O0).
When using gdb to debug it, I found some values are optimized out. As shown in the following figure. The len, flags, and add_len arguments are all optimized out.
How can I de-optimize the Linux kernel to avoid making these variables being optimized out?

enter image description

Upvotes: 4

Views: 1254

Answers (1)

Employed Russian
Employed Russian

Reputation: 213754

Building with -Og is supposed to eliminate these problems.

I don't know whether Linux kernel can be compiled that way.

Note that often you can discover the "optimized out" value by going up or down the stack, e.g. if the caller looks like this:

udp_recvmsg(sk, foo->msg, foo->msglen, ...);

then looking at *foo in the caller will tell you the len despite it being optimized out in the udp_recvmsg itself.

Upvotes: 1

Related Questions