Can't get rid of “value has been optimized out” in GDB

醉酒当歌 提交于 2019-12-11 12:51:59

问题


I am debugging the CPython executable by GDB and can't get the value of some variables despite of disabling all GCC optimizations:

(gdb) print *co
value has been optimized out

(gdb) frame
#0  _PyEval_EvalFrameDefault (
    f=Frame 0x7ffff7f36050, for file <frozen importlib._bootstrap>, line 8, in <module> (), 
    throwflag=<optimized out>) at Python/ceval.c:1057
1057            switch (opcode) {

(gdb) info locals
stack_pointer = 0x7ffff7f361c8
next_instr = 0x555555aff422
opcode = 100
oparg = 0
fastlocals = 0x7ffff7f361c8
freevars = <optimized out>
retval = 0x0
tstate = <optimized out>
co = <optimized out>
instr_ub = -1
instr_lb = 0
instr_prev = -1
first_instr = <optimized out>
names = <optimized out>
consts = <optimized out>
... <output cropped>

OS: Ubuntu 18.04.2 LTS
CPython version: 3.8.0a
Compiled by: GCC 7.3.0 on Linux
Debugger: GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git

Firstly, I did the usual compilation with --with-pydebug option.

./configure --with-pydebug
make -s -j

It should preserve all values for debugger but it doesn't.

I have read, that the cause of this problem is the compiler optimization, so I decided to disable it completely. For this I changed relevant lines in the configure script from:

# Optimization messes up debuggers, so turn it off for
# debug builds.
        if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
            OPT="-g -Og -Wall"
        else
            OPT="-g -O0 -Wall"
        fi

to:

# Optimization messes up debuggers, so turn it off for
# debug builds.
#                if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then
#                    OPT="-g -Og -Wall"
#                else
#                    OPT="-g -O0 -Wall"
#                fi
                OPT="-g -O0 -Wall"

The resulting optimization options in the Makefile are:

$ grep -- '-O' Makefile
OPT=        -g -O0 -Wall
    $(MAKE) all CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov"
        $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
        $(PYTHON_FOR_BUILD) -Wi -OO $(DESTDIR)$(LIBDEST)/compileall.py \
        $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
        $(PYTHON_FOR_BUILD) -Wi -OO $(DESTDIR)$(LIBDEST)/compileall.py \

Also, didn't help.

The question: Why "the value has been optimized out" persists even with the compiler optimization disabled and how can I overcome this problem?

EDIT

(gdb) info sharedlibrary 
From                To                  Syms Read   Shared Object Library
0x00007ffff7dd5f10  0x00007ffff7df4b20  Yes         /lib64/ld-linux-x86-64.so.2
0x00007ffff7bbbbb0  0x00007ffff7bca0f1  Yes         /lib/x86_64-linux-gnu/libpthread.so.0
0x00007ffff79b2e50  0x00007ffff79b3bde  Yes         /lib/x86_64-linux-gnu/libdl.so.2
0x00007ffff77afe70  0x00007ffff77b093a  Yes         /lib/x86_64-linux-gnu/libutil.so.1
0x00007ffff741ca80  0x00007ffff74db2f5  Yes         /lib/x86_64-linux-gnu/libm.so.6
0x00007ffff70412d0  0x00007ffff71b9c3c  Yes         /lib/x86_64-linux-gnu/libc.so.6

来源:https://stackoverflow.com/questions/56824992/cant-get-rid-of-value-has-been-optimized-out-in-gdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!