From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D6E24385BF92; Thu, 3 Feb 2022 11:45:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6E24385BF92 From: "jwakely.gcc at gmail dot com" To: gdb-prs@sourceware.org Subject: [Bug python/28856] New: Python pretty printer causes stack overflow when printing frame arguments Date: Thu, 03 Feb 2022 11:45:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: python X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jwakely.gcc at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Feb 2022 11:45:24 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D28856 Bug ID: 28856 Summary: Python pretty printer causes stack overflow when printing frame arguments Product: gdb Version: HEAD Status: UNCONFIRMED Severity: normal Priority: P2 Component: python Assignee: unassigned at sourceware dot org Reporter: jwakely.gcc at gmail dot com Target Milestone: --- Compile one C++ source file, as follows: struct category { virtual const char* name() const =3D 0; }; struct cat : category { const char* name() const { return "miaow"; } }; category* getcat() { static cat c; return &c; } struct error_code { error_code(int i =3D 0) : m_value(i), m_cat(getcat()) { } void assign(int i) { m_value =3D i; } int value() const { return m_value; } int m_value; category* m_cat; }; int f(error_code& ec) { ec.assign(1); return ec.value(); } int g(error_code& ec) { return f(ec); } int main() { error_code ec; return g(ec); } Add one Python file: class ErrorCodePrinter: "print an error_code" def __init__ (self, val): self.val =3D val @staticmethod def _category_name(cat): "Call the virtual function that overrides category::name()" gdb.set_convenience_variable('__cat', cat) return gdb.parse_and_eval('$__cat->name()').string() def to_string (self): value =3D self.val['m_value'] category =3D self._category_name(self.val['m_cat']) return 'error_code =3D {"%s": %d}' % (category, value) def ec_lookup_function(val): typ =3D val.type if typ.code =3D=3D gdb.TYPE_CODE_REF: typ =3D typ.target() if str(typ) =3D=3D 'error_code': return ErrorCodePrinter(val) return None gdb.pretty_printers.append(ec_lookup_function) Prepare an executable: g++ -g ec.cc -o ec And bake in the oven until it catches fire: gdb -q -iex "add-auto-load-safe-path $PWD/ec-gdb.py" -ex start -ex n -ex 'p &ec' -ex step -ex step -ex n -ex up -ex up ec Reading symbols from ec... Temporary breakpoint 1 at 0x40115e: file ec.C, line 37. Starting program: /tmp/ec=20 Temporary breakpoint 1, main () at ec.C:37 37 error_code ec; 38 return g(ec); $1 =3D (error_code *) 0x7fffffffd790 g (ec=3Derror_code =3D {"miaow": 0}) at ec.C:32 32 return f(ec); f (ec=3Derror_code =3D {"miaow": 0}) at ec.C:26 26 ec.assign(1); 27 return ec.value(); #1 0x0000000000401154 in g (ec=3D Fatal signal: Segmentation fault ----- Backtrace ----- 0x4bcd33 gdb_internal_backtrace_1 /home/jwakely/src/binutils-gdb/gdb/bt-utils.c:121 0x4bcd33 _Z22gdb_internal_backtracev /home/jwakely/src/binutils-gdb/gdb/bt-utils.c:164 0x5b32b1 handle_fatal_signal /home/jwakely/src/binutils-gdb/gdb/event-top.c:896 0x5b33f4 handle_sigsegv /home/jwakely/src/binutils-gdb/gdb/event-top.c:969 0x7f8d6d648a1f ??? ../sysdeps/unix/sysv/linux/sigaction.c:665 0x4b7ba5 _ZN22scoped_debug_start_endC2ERbPKcS2_S2_S2_S2_z /home/jwakely/src/binutils-gdb/gdb/../gdbsupport/common-debug.h:108 0x5cb846 _Z26frame_unwind_find_by_frameP10frame_infoPPv /home/jwakely/src/binutils-gdb/gdb/frame-unwind.c:181 0x5ce738 _Z17frame_unwind_archP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2896 0x5cb879 _Z26frame_unwind_find_by_frameP10frame_infoPPv /home/jwakely/src/binutils-gdb/gdb/frame-unwind.c:184 0x5ce738 _Z17frame_unwind_archP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2896 0x5cb879 _Z26frame_unwind_find_by_frameP10frame_infoPPv /home/jwakely/src/binutils-gdb/gdb/frame-unwind.c:184 0x5ce738 _Z17frame_unwind_archP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2896 0x5cb879 _Z26frame_unwind_find_by_frameP10frame_infoPPv /home/jwakely/src/binutils-gdb/gdb/frame-unwind.c:184 0x5ce738 _Z17frame_unwind_archP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2896 0x5cb879 _Z26frame_unwind_find_by_frameP10frame_infoPPv /home/jwakely/src/binutils-gdb/gdb/frame-unwind.c:184 [... several thousand more frames ...] 0x5ce738 _Z17frame_unwind_archP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2896 0x5cb879 _Z26frame_unwind_find_by_frameP10frame_infoPPv /home/jwakely/src/binutils-gdb/gdb/frame-unwind.c:184 0x5ce738 _Z17frame_unwind_archP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2896 0x5cb879 _Z26frame_unwind_find_by_frameP10frame_infoPPv /home/jwakely/src/binutils-gdb/gdb/frame-unwind.c:184 0x5ce738 _Z17frame_unwind_archP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2896 0x5ce784 frame_unwind_pc /home/jwakely/src/binutils-gdb/gdb/frame.c:944 0x5ce8cb _Z12get_frame_pcP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2571 0x5ce8cb _Z26get_frame_address_in_blockP10frame_info /home/jwakely/src/binutils-gdb/gdb/frame.c:2601 0x55727c dwarf2_frame_cache /home/jwakely/src/binutils-gdb/gdb/dwarf2/frame.c:903 0x558303 dwarf2_frame_prev_register /home/jwakely/src/binutils-gdb/gdb/dwarf2/frame.c:1136 0x5cee9b _Z27frame_unwind_register_valueP10frame_infoi /home/jwakely/src/binutils-gdb/gdb/frame.c:1233 0x5cf23a _Z21frame_register_unwindP10frame_infoiPiS1_P9lval_typePmS1_Ph /home/jwakely/src/binutils-gdb/gdb/frame.c:1143 0x5cf5c8 _Z21frame_unwind_registerP10frame_infoiPh /home/jwakely/src/binutils-gdb/gdb/frame.c:1199 0x5fe4e0 i386_unwind_pc /home/jwakely/src/binutils-gdb/gdb/i386-tdep.c:1970 0x5ce78f frame_unwind_pc /home/jwakely/src/binutils-gdb/gdb/frame.c:948 0x5ce869 _Z25get_frame_pc_if_availableP10frame_infoPm /home/jwakely/src/binutils-gdb/gdb/frame.c:2582 0x761b40 _Z16print_frame_infoRK19frame_print_optionsP10frame_infoi10print_whatii /home/jwakely/src/binutils-gdb/gdb/stack.c:1185 0x76246b _Z17print_stack_frameP10frame_infoi10print_whati /home/jwakely/src/binutils-gdb/gdb/stack.c:366 0x762502 _Z26print_stack_frame_to_uioutP6ui_outP10frame_infoi10print_whati /home/jwakely/src/binutils-gdb/gdb/stack.c:345 0x4eff7a cli_on_user_selected_context_changed /home/jwakely/src/binutils-gdb/gdb/cli/cli-interp.c:277 0x764463 _ZNKSt8functionIFv10enum_flagsI23user_selected_what_flagEEEclES2_ /usr/include/c++/11/bits/std_function.h:560 0x764463 _ZNK3gdb9observers10observableIJ10enum_flagsI23user_selected_what_flagEEE6n= otifyES4_ /home/jwakely/src/binutils-gdb/gdb/../gdbsupport/observable.h:150 0x764463 up_command /home/jwakely/src/binutils-gdb/gdb/stack.c:2690 0x4ee2a4 _Z8cmd_funcP16cmd_list_elementPKci /home/jwakely/src/binutils-gdb/gdb/cli/cli-decode.c:2459 0x7bdbe1 _Z15execute_commandPKci /home/jwakely/src/binutils-gdb/gdb/top.c:670 0x66dcd2 catch_command_errors /home/jwakely/src/binutils-gdb/gdb/main.c:523 0x66dd9f execute_cmdargs /home/jwakely/src/binutils-gdb/gdb/main.c:618 0x66f4b4 captured_main_1 /home/jwakely/src/binutils-gdb/gdb/main.c:1317 0x66ff5a captured_main /home/jwakely/src/binutils-gdb/gdb/main.c:1338 0x66ff5a _Z8gdb_mainP18captured_main_args /home/jwakely/src/binutils-gdb/gdb/main.c:1363 0x431624 main /home/jwakely/src/binutils-gdb/gdb/gdb.c:32 --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: . Segmentation fault (core dumped) --=20 You are receiving this mail because: You are on the CC list for the bug.=