From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 944C8385828D for ; Fri, 10 Feb 2023 03:10:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 944C8385828D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id BC3741E110; Thu, 9 Feb 2023 22:10:34 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1675998634; bh=sOoUK3HN6aPfYdJnYuICu6ArXCFHWvB1t0fbMI47eXs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=QP4GTPIckVwmk8TG/1G4iCd2hmQ2wLXTDh6pz4SiqlOTjYN9Kf5QnmVg0FcvbMFGU 4r1+O5Jb3IkMTGBilhBxKvfumsmt2YVVxVoT1+Syjz0YoGOwY5rVRP6i+EcVB0K1Mo R84r2dswiwGO0E9xjUuBauExwALadLYPNY7DDOGg= Message-ID: <30ee85a3-d6aa-c69e-2fe6-3c6d53a11a90@simark.ca> Date: Thu, 9 Feb 2023 22:10:34 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH] gdb: fix dealloc function not being called for frame 0 Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org Cc: Tom de Vries References: <20230209195037.100368-1-simon.marchi@efficios.com> From: Simon Marchi In-Reply-To: <20230209195037.100368-1-simon.marchi@efficios.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > @@ -2105,7 +2106,23 @@ reinit_frame_cache (void) > invalidate_selected_frame (); > > /* Invalidate cache. */ > - sentinel_frame = NULL; > + if (sentinel_frame != nullptr) > + { > + /* If frame 0's id is not computed, it is not in the frame stash, so its > + dealloc functions will not be called when emptying the frash stash. > + Call frame_info_del manually in that case. */ > + frame_info *current_frame = sentinel_frame->prev; > + if (current_frame != nullptr) > + { > + gdb_assert (current_frame->this_id.p != frame_id_status::COMPUTING); Well, this gdb_assert happens to cause a failure in gdb.server/server-kill.exp: (gdb) PASS: gdb.server/server-kill.exp: kill_pid_of=inferior: test_unwind_syms: p server_pid Executing on target: kill -9 1567851 (timeout = 300) builtin_spawn -ignore SIGHUP kill -9 1567851 bt /home/simark/src/binutils-gdb/gdb/frame.c:2117: internal-error: reinit_frame_cache: Assertion `current_frame->this_id.p != frame_id_status::COMPUTING' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. FAIL: gdb.server/server-kill.exp: kill_pid_of=inferior: test_unwind_syms: bt (GDB internal error) This happens because the remote connection breaks while computing a frame id. The stack looks roughly like this (many frames removed for readability): 0x55cd4623396c internal_error_loc(char const*, int, char const*, ...) /home/simark/src/binutils-gdb/gdbsupport/errors.cc:58 0x55cd4434f5a1 reinit_frame_cache() /home/simark/src/binutils-gdb/gdb/frame.c:2117 0x55cd457e1bce switch_to_no_thread() /home/simark/src/binutils-gdb/gdb/thread.c:1330 0x55cd44618270 switch_to_inferior_no_thread(inferior*) /home/simark/src/binutils-gdb/gdb/inferior.c:671 0x55cd451467c9 remote_unpush_target /home/simark/src/binutils-gdb/gdb/remote.c:5903 0x55cd45183b88 unpush_and_perror /home/simark/src/binutils-gdb/gdb/remote.c:9612 0x55cd451840ce remote_target::readchar(int) /home/simark/src/binutils-gdb/gdb/remote.c:9652 0x55cd45188e91 remote_target::getpkt_or_notif_sane_1(std::__debug::vector > >*, int, int, int*) /home/simark/src/binutils-gdb/gdb/remote.c:10118 0x55cd4518a2fe remote_target::getpkt_sane(std::__debug::vector > >*, int) /home/simark/src/binutils-gdb/gdb/remote.c:10220 0x55cd451889d6 remote_target::getpkt(std::__debug::vector > >*, int) /home/simark/src/binutils-gdb/gdb/remote.c:10062 0x55cd45181137 remote_target::remote_read_bytes_1(unsigned long, unsigned char*, unsigned long, int, unsigned long*) /home/simark/src/binutils-gdb/gdb/remote.c:9379 0x55cd45182772 remote_target::remote_read_bytes(unsigned long, unsigned char*, unsigned long, int, unsigned long*) /home/simark/src/binutils-gdb/gdb/remote.c:9503 0x55cd4519cd2d remote_target::xfer_partial(target_object, char const*, unsigned char*, unsigned char const*, unsigned long, unsigned long, unsigned long*) /home/simark/src/binutils-gdb/gdb/remote.c:11421 ... 0x55cd4433d812 compute_frame_id /home/simark/src/binutils-gdb/gdb/frame.c:606 So, I will remove that gdb_assert and simplify the code to: /* If frame 0's id is not computed, it is not in the frame stash, so its dealloc functions will not be called when emptying the frash stash. Call frame_info_del manually in that case. */ frame_info *current_frame = sentinel_frame->prev; if (current_frame != nullptr && current_frame->this_id.p == frame_id_status::NOT_COMPUTED) frame_info_del (current_frame); With that change, the test passes again. If the state of the id of the current frame is "COMPUTING", I think it's better not to call frame_info_del and the dealloc functions, because the state of the per-unwinder cache object is maybe not in a state expected that the dealloc functions expect. If something goes wrong during the computation of the frame id, I think it's best to let the unwinder make sure to clean up anything it has started. Simon