From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A88943858C5F; Thu, 8 Feb 2024 16:06:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A88943858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1707408393; bh=X4xMTaSK089f0QeTCd+smEfDW3pPapB0gX6idKV/Tq8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LbbAGM/A8mjeA5/OsXq0QobDxDthRwOxAQObfrVI3vjLJM0o4Pl8ZUO+/kUChSIpO 7KoY6pJnRRHrMYUQXdG+0PmrmFIjzkBnwoCe/Evdly/W4mwQ49eCexKq+8DHNDwqOX 4RsoKr1gAKxPHa1BBzzVHTljFewgF9DQb3OLmj5s= From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug dap/31275] [gdb/dap, gdb.dap/pause.exp] ERROR: timeout reading json header Date: Thu, 08 Feb 2024 16:06:31 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: dap X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: tromey at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31275 --- Comment #4 from Tom de Vries --- I investigated this by aborting at exception, and investigation the coredum= p, using: ... diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index 7cd1ef2fba1..54bc3d00950 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -21,6 +21,7 @@ import queue import threading import traceback import sys +import os from enum import IntEnum, auto @@ -179,6 +180,10 @@ def log_stack(level=3DLogLevel.DEFAULT): if dap_log.log_file is not None and level <=3D _log_level.value: traceback.print_exc(file=3Ddap_log.log_file) +def dap_excepthook(exc_type, exc_value, exc_traceback): + os.abort() + +sys.excepthook =3D dap_excepthook @in_gdb_thread def exec_and_log(cmd): ... The coredump is not too usable due to PR31352, but by using fprintf in sig_write we get a usable one: (gdb) bt #0 0x00007f7ca054e76b in raise () from /lib64/libpthread.so.0 #1 0x00000000007a3695 in handle_fatal_signal (sig=3D6) at /data/vries/gdb/src/gdb/event-top.c:926 #2 #3 0x00007f7c9d853d2b in raise () from /lib64/libc.so.6 #4 0x00007f7c9d8553e5 in abort () from /lib64/libc.so.6 #5 0x00007f7c9f7717e9 in os_abort_impl (module=3D) at ./Modules/posixmodule.c:10430 #6 os_abort (module=3D, _unused_ignored=3D) = at ./Modules/clinic/posixmodule.c.h:5000 #7 0x00007f7c9f6b90ef in _PyCFunction_FastCallDict ( func_obj=3D, args=3D0x7f7c9d5afc30, nargs=3D0,=20 kwargs=3D) at Objects/methodobject.c:192 #8 0x00007f7c9f72aa72 in call_function (pp_stack=3Dpp_stack@entry=3D0x7ffe3802e4f8, oparg=3D,=20 kwnames=3Dkwnames@entry=3D0x0) at Python/ceval.c:4851 #9 0x00007f7c9f72eed5 in _PyEval_EvalFrameDefault (f=3D, throwflag=3D) at Python/ceval.c:3335 #10 0x00007f7c9f72a67f in _PyFunction_FastCall (co=3Dco@entry=3D0x7f7c9e8e0= 9c0, args=3D,=20 args@entry=3D0x7ffe3802e6c0, nargs=3Dnargs@entry=3D3,=20 globals=3Dglobals@entry=3D{'__name__': 'gdb.dap.startup', '__doc__': No= ne, '__package__': 'gdb.dap', '__loader__': , '__spec__': , origin=3D'/data/vries/gdb/leap-15-4/build/gdb/data-directory/python/gdb/dap= /startup.py', loader_state=3DNone, submodule_search_locations=3DNone, _set_fileattr=3DTru= e, _cached=3D'/data/vries/gdb/leap-15-4/build/gdb/data-directory/python/gdb/da= p/__pycache__/startup.cpython-36.pyc', _initializing=3DFalse) at remote 0x7f7c9e8e6748>, '__file__': '/data/vries/gdb/leap-15-4/build/gdb/data-directory/python/gdb/dap/startup.= py', '__cached__': '/data/vries/gdb/leap-15-4/build/gdb/data-directory/python/gdb/dap/__pycach= e__/startup.cpython-36.pyc', '__builtins__': {'__name__': 'builtins', '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__pac...(truncated)) at Python/ceval.c:4933 #11 0x00007f7c9f732870 in _PyFunction_FastCallDict (func=3Dfunc@entry=3D,=20 args=3Dargs@entry=3D0x7ffe3802e6c0, nargs=3D3, kwargs=3Dkwargs@entry=3D= 0x0) at Python/ceval.c:5035 #12 0x00007f7c9f670b7e in _PyObject_FastCallDict (func=3D,=20 args=3Dargs@entry=3D0x7ffe3802e6c0, nargs=3Dnargs@entry=3D3, kwargs=3Dkwargs@entry=3D0x0) at Objects/abstract.c:2310 #13 0x00007f7c9f75537c in PyErr_PrintEx (set_sys_last_vars=3D1) at Python/pythonrun.c:669 #14 0x0000000000aaabd3 in gdbpy_print_stack () at /data/vries/gdb/src/gdb/python/python.c:1541 #15 0x0000000000aada09 in gdbpy_event::operator() (this=3D0x7f7c68004a60) at /data/vries/gdb/src/gdb/python/python.c:1063 #16 0x0000000000aadfda in std::_Function_handler::_M_invoke(std::_Any_data const&) ( __functor=3D...) at /usr/include/c++/7/bits/std_function.h:316 #17 0x0000000000622a48 in std::function::operator()() const (this=3D0x7f7c68004940) at /usr/include/c++/7/bits/std_function.h:706 #18 0x0000000000b6159a in run_events (error=3D0, client_data=3D0x0) at /data/vries/gdb/src/gdb/run-on-main-thread.c:76 #19 0x00000000014f9eec in handle_file_event (file_ptr=3D0x2c936e0, ready_ma= sk=3D1) at /data/vries/gdb/src/gdbsupport/event-loop.cc:573 #20 0x00000000014fa482 in gdb_wait_for_event (block=3D1) at /data/vries/gdb/src/gdbsupport/event-loop.cc:694 #21 0x00000000014f9365 in gdb_do_one_event (mstimeout=3D-1) at /data/vries/gdb/src/gdbsupport/event-loop.cc:264 #22 0x00000000009364a2 in start_event_loop () at /data/vries/gdb/src/gdb/main.c:401 #23 0x0000000000936603 in captured_command_loop () at /data/vries/gdb/src/gdb/main.c:465 #24 0x0000000000937eb4 in captured_main (data=3D0x7ffe3802eae0) at /data/vries/gdb/src/gdb/main.c:1335 #25 0x0000000000937f4e in gdb_main (args=3D0x7ffe3802eae0) at /data/vries/gdb/src/gdb/main.c:1354 #26 0x000000000041a1c3 in main (argc=3D14, argv=3D0x7ffe3802ebf8) at /data/vries/gdb/src/gdb/gdb.c:39 ... I can reliably make the test-case fail by adding a time.sleep(1) either bef= ore or after the try-catch in here: ... @@ -226,6 +232,7 @@ def send_gdb_with_response(fn): result_q =3D DAPQueue() def message(): + time.sleep(1) try: val =3D fn() result_q.put(val) ... and observe the same backtrace in the corefile. So, my theory is that there's a race between one thread calling PyErr_SetInterrupt, and another one calling message. If the interrupt is handled while "val =3D fn()" is executing, cancellation= is successful and a KeyboardInterrupt is thrown which is caught by the try-cat= ch. But if the interrupt is handled before or after the try-catch, it escapes a= nd is printed by the gdbpy_event::operator. I suppose a partial fix could be that you'd block interrupts before calling into python, and unblock them only once you're in the try-catch. That would take care of delaying too-early interrupts. I suppose interrupts may be dealt with by ignoring them, if we can identify that the request that it was supposed to cancel already has finished. --=20 You are receiving this mail because: You are on the CC list for the bug.=