Summary: | Segfault in gdbpy_enter_varobj::gdbpy_enter_varobj when debugging in VS Code | ||
---|---|---|---|
Product: | gdb | Reporter: | Andrey Sotnikov <usaonmonday> |
Component: | varobj | Assignee: | Tom Tromey <tromey> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | simark, ssbssa, tromey |
Priority: | P2 | ||
Version: | HEAD | ||
Target Milestone: | 11.1 | ||
Host: | Target: | ||
Build: | Last reconfirmed: | 2021-07-30 00:00:00 |
Description
Andrey Sotnikov
2021-07-24 20:01:22 UTC
I ran a quick binary search and found the culprit commit: SHA-1: 24fd95b4cd40f0108299c02f31f2d2a129f83769 * Change varobj_dynamic::child_iter to unique_ptr This changes varobj_dynamic::child_iter to be a unique_ptr, removing some manual management. gdb/ChangeLog 2020-12-11 Tom Tromey <tom@tromey.com> * varobj.c (struct varobj_dynamic) <child_iter>: Now unique_ptr. (varobj_get_iterator): Return unique_ptr. (update_dynamic_varobj_children, install_visualizer) (varobj::~varobj): Update. * python/python-internal.h (py_varobj_get_iterator): Return unique_ptr. * python/py-varobj.c (py_varobj_get_iterator): Return unique_ptr. Adding Tom to CC. Does VSCode give you a way to see the MI traffic between it and GDB? If so, could you share that? It would make it easier to reproduce. If you can give the source of the debugged program, even better. It took a little while but I figured out how to reproduce this today. Thanks for taking care of it! The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4d0754c5f572b01cf2fe6c8ab292adba83331cbc commit 4d0754c5f572b01cf2fe6c8ab292adba83331cbc Author: Tom Tromey <tromey@adacore.com> Date: Fri Jul 30 11:18:36 2021 -0600 Avoid crash in varobj deletion PR varobj/28131 points out a crash in the varobj deletion code. It took a while to reproduce this, but essentially what happens is that a top-level varobj deletes its root object, then deletes the "dynamic" object. However, deletion of the dynamic object may cause ~py_varobj_iter to run, which in turn uses gdbpy_enter_varobj: gdbpy_enter_varobj::gdbpy_enter_varobj (const struct varobj *var) : gdbpy_enter (var->root->exp->gdbarch, var->root->exp->language_defn) { } However, because var->root has already been destroyed, this is invalid. I've added a new test case. This doesn't reliably crash, but the problem can easily be seen under valgrind (and, I presume, with ASAN, though I did not try this). Tested on x86-64 Fedora 32. I also propose putting this on the GDB 11 branch, with a suitable ChangeLog entry of course. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28131 The gdb-11-branch branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3e5ec878a43ac06624a2cc816a329d9b22b95cac commit 3e5ec878a43ac06624a2cc816a329d9b22b95cac Author: Tom Tromey <tromey@adacore.com> Date: Fri Jul 30 11:18:36 2021 -0600 Avoid crash in varobj deletion PR varobj/28131 points out a crash in the varobj deletion code. It took a while to reproduce this, but essentially what happens is that a top-level varobj deletes its root object, then deletes the "dynamic" object. However, deletion of the dynamic object may cause ~py_varobj_iter to run, which in turn uses gdbpy_enter_varobj: gdbpy_enter_varobj::gdbpy_enter_varobj (const struct varobj *var) : gdbpy_enter (var->root->exp->gdbarch, var->root->exp->language_defn) { } However, because var->root has already been destroyed, this is invalid. I've added a new test case. This doesn't reliably crash, but the problem can easily be seen under valgrind (and, I presume, with ASAN, though I did not try this). Tested on x86-64 Fedora 32. I also propose putting this on the GDB 11 branch, with a suitable ChangeLog entry of course. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28131 (cherry picked from commit 4d0754c5f572b01cf2fe6c8ab292adba83331cbc) gdb/ChangeLog 2021-08-02 Tom Tromey <tromey@adacore.com> PR varobj/28131 * varobj.c (~varobj): Delete 'dynamic' before 'root'. gdb/testsuite/ChangeLog 2021-08-02 Tom Tromey <tromey@adacore.com> PR varobj/28131 * gdb.python/py-mi-var-info-path-expression.exp: Add regression test. Fixed. |