From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id NVyHBk6OTWL9MwAAWB0awg (envelope-from ) for ; Wed, 06 Apr 2022 08:57:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 0AD341F344; Wed, 6 Apr 2022 08:57:50 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_DYNAMIC, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0BBF61ED17 for ; Wed, 6 Apr 2022 08:57:49 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71045385DC2D for ; Wed, 6 Apr 2022 12:57:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71045385DC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649249868; bh=uyhqlOjs9lV9cMX9pO7U4TLHydj0bK7FaTqESswOi2k=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PbNejwBbtIqvq+4DLJsT05IrPCsKxi2XCKxR+basU3S+nsDcSaVx1M/cGupmX621D 2XQyG4CGAQk8o+cCzXr2dwuGp28ikVQg6mu3kBJgYhYYHTnl1jd2NuFZBXcA04/wWq FGftnow8q32PIEblEfAECEqyED37N8TVWUvo8FfE= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id C2F67385840C for ; Wed, 6 Apr 2022 12:57:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2F67385840C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 236CvMr2020680 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Apr 2022 08:57:26 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 236CvMr2020680 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D02F21ED17; Wed, 6 Apr 2022 08:57:21 -0400 (EDT) Message-ID: Date: Wed, 6 Apr 2022 08:57:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCHv2 01/16] gdb: don't try to use readline before it's initialized Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: <9c64efb79e96864df070a3c715b207a24b601219.1649246538.git.aburgess@redhat.com> In-Reply-To: <9c64efb79e96864df070a3c715b207a24b601219.1649246538.git.aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 6 Apr 2022 12:57:22 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2022-04-06 08:04, Andrew Burgess via Gdb-patches wrote: > While working on a different patch, I triggered an assertion from the > initialize_current_architecture code, specifically from one of > the *_gdbarch_init functions in a *-tdep.c file. This exposes a > couple of issues with GDB. > > This is easy enough to reproduce by adding 'gdb_assert (false)' into a > suitable function. For example, I added a line into i386_gdbarch_init > and can see the following issue. > > I start GDB and immediately hit the assert, the output is as you'd > expect, except for the very last line: > > $ ./gdb/gdb --data-directory ./gdb/data-directory/ > ../../src.dev-1/gdb/i386-tdep.c:8455: internal-error: i386_gdbarch_init: Assertion `false' failed. > A problem internal to GDB has been detected, > further debugging may prove unreliable. > ----- Backtrace ----- > ... snip ... > --------------------- > ../../src.dev-1/gdb/i386-tdep.c:8455: internal-error: i386_gdbarch_init: Assertion `false' failed. > A problem internal to GDB has been detected, > further debugging may prove unreliable. > Quit this debugging session? (y or n) ../../src.dev-1/gdb/ser-event.c:212:16: runtime error: member access within null pointer of type 'struct serial' > > Something goes wrong when we try to query the user. Note, I > configured GDB with --enable-ubsan, I suspect that without this the > above "error" would actually just be a crash. > > The backtrace from ser-event.c:212 looks like this: > > (gdb) bt 10 > #0 serial_event_clear (event=0x675c020) at ../../src/gdb/ser-event.c:212 > #1 0x0000000000769456 in invoke_async_signal_handlers () at ../../src/gdb/async-event.c:211 > #2 0x000000000295049b in gdb_do_one_event () at ../../src/gdbsupport/event-loop.cc:194 > #3 0x0000000001f015f8 in gdb_readline_wrapper ( > prompt=0x67135c0 "../../src/gdb/i386-tdep.c:8455: internal-error: i386_gdbarch_init: Assertion `false' failed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable.\nQuit this debugg"...) > at ../../src/gdb/top.c:1141 > #4 0x0000000002118b64 in defaulted_query(const char *, char, typedef __va_list_tag __va_list_tag *) ( > ctlstr=0x2e4eb68 "%s\nQuit this debugging session? ", defchar=0 '\000', args=0x7fffffffa6e0) > at ../../src/gdb/utils.c:934 > #5 0x0000000002118f72 in query (ctlstr=0x2e4eb68 "%s\nQuit this debugging session? ") > at ../../src/gdb/utils.c:1026 > #6 0x00000000021170f6 in internal_vproblem(internal_problem *, const char *, int, const char *, typedef __va_list_tag __va_list_tag *) (problem=0x6107bc0 , file=0x2b976c8 "../../src/gdb/i386-tdep.c", > line=8455, fmt=0x2b96d7f "%s: Assertion `%s' failed.", ap=0x7fffffffa8e8) at ../../src/gdb/utils.c:417 > #7 0x00000000021175a0 in internal_verror (file=0x2b976c8 "../../src/gdb/i386-tdep.c", line=8455, > fmt=0x2b96d7f "%s: Assertion `%s' failed.", ap=0x7fffffffa8e8) at ../../src/gdb/utils.c:485 > #8 0x00000000029503b3 in internal_error (file=0x2b976c8 "../../src/gdb/i386-tdep.c", line=8455, > fmt=0x2b96d7f "%s: Assertion `%s' failed.") at ../../src/gdbsupport/errors.cc:55 > #9 0x000000000122d5b6 in i386_gdbarch_init (info=..., arches=0x0) at ../../src/gdb/i386-tdep.c:8455 > (More stack frames follow...) > > It turns out that the problem is that the async event handler > mechanism has been invoked, but this has not yet been initialized. > > If we look at gdb_init (in gdb/top.c) we can indeed see the call to > gdb_init_signals is after the call to initialize_current_architecture. > > If I reorder the calls, moving gdb_init_signals earlier, then the > initial error is resolved, however, things are still broken. I now > see the same "Quit this debugging session? (y or n)" prompt, but when > I provide an answer and press return GDB immediately crashes. > > So what's going on now? The next problem is that the call_readline > field within the current_ui structure is not initialized, and this > callback is invoked to process the reply I entered. > > The problem is that call_readline is setup as a result of calling > set_top_level_interpreter, which is called from captured_main_1. > Unfortunately, set_top_level_interpreter is called after gdb_init is > called. > > I wondered how to solve this problem for a while, however, I don't > know if there's an easy "just reorder some lines" solution here. > Looking through captured_main_1 there seems to be a bunch of > dependencies between printing various things, parsing config files, > and setting up the interpreter. I'm sure there is a solution hiding > in there somewhere.... I'm just not sure I want to spend any longer > looking for it. > > So. > > I propose a simpler solution, more of a hack/work-around. In utils.c > we already have a function filtered_printing_initialized, this is > checked in a few places within internal_vproblem. In some of these > cases the call gates whether or not GDB will query the user. > > My proposal is to add a new readline_initialized function, which > checks if the current_ui has had readline initialized yet. If this is > not the case then we should not attempt to query the user. > > After this change GDB prints the error message, the backtrace, and > then aborts (including dumping core). This actually seems pretty sane > as, if GDB has not yet made it through the initialization then it > doesn't make much sense to allow the user to say "no, I don't want to > quit the debug session" (I think). I think this is reasonable. In theory, the internal error could be for something you don't care about, and you could still want to continue. But there's also a limit to the far-fetched theoritical scenarios we must support. So I think it is ok to say that any internal error during initialization is fatal. The patch LGTM. Simon