New submission from STINNER Victor <vstin...@python.org>:
In Python 2.7, when using ./configure --with-pydebug, Python is built using -O0 compiler optimization level: disable all optimizations. The comment is quite explicit: "Optimization messes up debuggers, so turn it off for debug builds". if test "$Py_DEBUG" = 'true' ; then # Optimization messes up debuggers, so turn it off for # debug builds. OPT="-g -O0 -Wall $STRICT_PROTO" else OPT="-g $WRAP -O3 -Wall $STRICT_PROTO" fi In Python 3, -Og is preferred over -O0 for pydebug, if -Og is available: if test "$Py_DEBUG" = 'true' ; then # 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 else OPT="-g $WRAP -O3 -Wall" fi Problem: in my experience, gdb traceback doesn't make sense sometimes, and gdb fails to inspect some function arguments and some variables which are displayed as <optimized out>. See a very concrete example with a test_gdb failure on x86-64 when Python is compiled using gcc -Og: https://bugzilla.redhat.com/show_bug.cgi?id=1734327#c22 My colleague who is working on gdb suggests to use -O0: https://bugzilla.redhat.com/show_bug.cgi?id=1734327#c27 Since I started contributing to Python, I always forced gcc -O0 because any other optimization level caused me many issues in gdb. I'm using -O0 for 10 years with sucess. The GCC documentation says "It is a better choice than -O0 for producing debuggable code because some compiler passes that collect debug information are disabled at -O0." But my experience says the opposite. Note: instead of -g, we could use -g3 to include debug information for macros and defines. -- I'm proposing to change the *default* compiler flags from -Og to -O0. Obviously, Linux distributions and developers are free to override the compiler optimization level. For example: ./configure --with-pydebug CFLAGS="-Og" ensures that Python is always built using -Og. I propose to modify 3.7, 3.8 and master branches. ---------- components: Build messages: 353746 nosy: vstinner priority: normal severity: normal status: open title: ./configure --with-pydebug should use -O0 rather than -Og versions: Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38350> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com