Message ID | 20231115135204.3747216-1-tromey@adacore.com |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB1ED3858C29 for <patchwork@sourceware.org>; Wed, 15 Nov 2023 13:52:31 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id B45073858C98 for <gdb-patches@sourceware.org>; Wed, 15 Nov 2023 13:52:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B45073858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B45073858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700056339; cv=none; b=VszpdaIMWuwQsCUG2CC/OOX9VAUrXDVnF3/tdS+Fk1910si9WPy4sRJxxlk7viEhXjy0ag19xGFtkme9ZiPP0XWIONEixUn/9WXHG7XLe6st8EkqNNPrPYvIIeb23D6hfRBpfdINl89wBFd/GhxFJtPPeIWZQ7BlMMU2yrLL7tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700056339; c=relaxed/simple; bh=l5qymJzm0RxuFmmnwZc/FSr4noAQ2JB73rU+Eg4OrKQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VgZ1iWKceNI8G2lLa7HgA4i7wJaevrcCaykrkgTwuHCX9017P2LkOlga0oRfP5gfzmeHWC7hQWK/uZ6yzMZoVKQZjtM6UdYo7DEl+Yi+0saWzpowiuI9DnveViZ9rWzXDPVIvbG6uUCaRnmL/hV+x1lEcfiWDURAITsIIWXPJis= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-7a69a1b51baso20520739f.1 for <gdb-patches@sourceware.org>; Wed, 15 Nov 2023 05:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1700056336; x=1700661136; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iUViqLg9xTq1wkpJoEJX6zytfKSjk1B0SqA/ItpvoXI=; b=OReec0fAMLWGH1ly+i+qu4Xv0vhlPhiNLGUJckC8TnoT0PUDxQ/YbGD38tvINfqVEx 4LMzIBVM107+bjYZrt3NgqTRJyKAwzsCl/krD6hqF/Yvc9bfnb9iDbagDZcPG627ItAP 5u69NxXhxUbd+HHa1gouPmxhhmfPrNVvGWnEQDfF4Hga1df/v92HBe34jNQEXKUqcsfw nGRFKE3WtfnBYF6ZyrFqbDX0JftXoxvZuyHScZ0V7vP24yj/CyUmyAvXYyAJgiNomu5X wgGUabgPlRWrubuEM3Sd8qYhhU8/FAzrvyAeSQMkzcXCW9iVpDrL+qTNqPEMSgTT/may T0MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700056336; x=1700661136; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iUViqLg9xTq1wkpJoEJX6zytfKSjk1B0SqA/ItpvoXI=; b=wFlPDYRHKBR83Ye3pyuweQz1DlxFgmZGYKhw/1TBNmpAUUxATofeFtHw+4kTpFGCTW RaTiurJs3jOY37S6cLH8b2HmqHSlWdQRunWEHTCbDzuIuPLLg9QN0pOBkoX1qoMnP8Q2 i1M8lzw1QRRDSt1n15TjdoyAh7w8FQO/xbJ0upfQ0Pxc09U6nMfSFdinuMsGcUh8L/6/ Nl98v3DM6HfdXFjh+dK6qg+ANnuNJIh6NJ0T8kgLQb9gAMj5LBYQW3iV9LAk2WSsIXV7 1pgD7TACwHDu6tXjKqonqZnokIHx+pqF2aPU5pubIjFZG5sLJ5rcZPVPekxAJUCWvOzv cRcQ== X-Gm-Message-State: AOJu0Yw6kgmsKPlieIP5aQdt5tCh2NjxkvjJLCNZwJqi6GXy6J2IWW2J rd9bPXd7buowOJwn2jwjYTpbXrZDhf9BS5hDcSzRMw== X-Google-Smtp-Source: AGHT+IE1jZNMU4y54uWKUsREu5VmbwzyG/4F9mO9rtXVr/2miD5X18LILfvMNoYxK1EPWK+herRPCw== X-Received: by 2002:a6b:c846:0:b0:7a6:7b18:dbf3 with SMTP id y67-20020a6bc846000000b007a67b18dbf3mr5590190iof.7.1700056336149; Wed, 15 Nov 2023 05:52:16 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id br7-20020a05663846c700b0042ad887f705sm1013400jab.143.2023.11.15.05.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:52:15 -0800 (PST) From: Tom Tromey <tromey@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey <tromey@adacore.com> Subject: [PATCH] Check gdb_python_module in gdbpy_handle_missing_debuginfo Date: Wed, 15 Nov 2023 06:52:04 -0700 Message-ID: <20231115135204.3747216-1-tromey@adacore.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org |
Series |
Check gdb_python_module in gdbpy_handle_missing_debuginfo
|
|
Checks
Context | Check | Description |
---|---|---|
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 | warning | Patch is already merged |
linaro-tcwg-bot/tcwg_gdb_build--master-arm | warning | Patch is already merged |
Commit Message
Tom Tromey
Nov. 15, 2023, 1:52 p.m. UTC
If you run gdb in the build tree without --data-directory, on a program that does not have debug info, it will crash, because gdbpy_handle_missing_debuginfo unconditionally uses gdb_python_module. Other code in gdb using gdb_python_module checks it first. I'm not really sure why gdb_python_initialized does not cover this case (maybe so that python can be partially initialized and still somewhat work?), but it seemes harmless to do the same thing here. --- gdb/python/python.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 11/15/23 5:52 AM, Tom Tromey wrote: > If you run gdb in the build tree without --data-directory, on a > program that does not have debug info, it will crash, because > gdbpy_handle_missing_debuginfo unconditionally uses gdb_python_module. > > Other code in gdb using gdb_python_module checks it first. I'm not > really sure why gdb_python_initialized does not cover this case (maybe > so that python can be partially initialized and still somewhat work?), > but it seemes harmless to do the same thing here. > --- > gdb/python/python.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gdb/python/python.c b/gdb/python/python.c > index 4523e30ed24..7e48165db21 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -1703,7 +1703,7 @@ gdbpy_handle_missing_debuginfo (const struct extension_language_defn *extlang, > struct objfile *objfile) > { > /* Early exit if Python is not initialised. */ > - if (!gdb_python_initialized) > + if (!gdb_python_initialized || gdb_python_module == nullptr) > return {}; > > struct gdbarch *gdbarch = objfile->arch (); Looks good to me. I suspect you can only check gdb_python_module == nullptr here and assume that if it is non-null, gdb_python_initialized is also non-zero as we set gdb_python_module in do_initialize() IFF do_start_initialize() (which sets gdb_python_initialized) succeeds. The error in do_initialize when the gdb module fails to load does seem to explain why this condition exists and lines up with what you guess in the commit log: gdb_python_module = PyImport_ImportModule ("gdb"); if (gdb_python_module == NULL) { gdbpy_print_stack (); /* This is passed in one call to warning so that blank lines aren't inserted between each line of text. */ warning (_("\n" "Could not load the Python gdb module from `%s'.\n" "Limited Python support is available from the _gdb module.\n" "Suggest passing --data-directory=/path/to/gdb/data-directory."), gdb_pythondir.c_str ()); /* We return "success" here as we've already emitted the warning. */ return true; }
>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:
John> Looks good to me. I suspect you can only check gdb_python_module == nullptr
John> here and assume that if it is non-null, gdb_python_initialized is also non-zero
John> as we set gdb_python_module in do_initialize() IFF do_start_initialize()
John> (which sets gdb_python_initialized) succeeds.
Yeah. I think you're right, but other spots also check
gdb_python_initialized, so I think we might as well leave it as-is.
John> The error in do_initialize when the gdb module fails to load does seem to
John> explain why this condition exists and lines up with what you guess in the
John> commit log:
I'll update the commit message to reflect this.
Tom
Tom Tromey <tromey@adacore.com> writes: > If you run gdb in the build tree without --data-directory, on a > program that does not have debug info, it will crash, because > gdbpy_handle_missing_debuginfo unconditionally uses gdb_python_module. > > Other code in gdb using gdb_python_module checks it first. I'm not > really sure why gdb_python_initialized does not cover this case (maybe > so that python can be partially initialized and still somewhat work?), > but it seemes harmless to do the same thing here. Gah. I was dropping the ball all over the place with those patches. Thanks for fixing this (with whatever updated commit message you use). Approved-By: Andrew Burgess <aburgess@redhat.com> Thanks, Andrew > --- > gdb/python/python.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gdb/python/python.c b/gdb/python/python.c > index 4523e30ed24..7e48165db21 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -1703,7 +1703,7 @@ gdbpy_handle_missing_debuginfo (const struct extension_language_defn *extlang, > struct objfile *objfile) > { > /* Early exit if Python is not initialised. */ > - if (!gdb_python_initialized) > + if (!gdb_python_initialized || gdb_python_module == nullptr) > return {}; > > struct gdbarch *gdbarch = objfile->arch (); > -- > 2.41.0
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
Andrew> Gah. I was dropping the ball all over the place with those patches.
Don't worry about it, and especially don't feel bad about this case,
which is a weird corner case that only affects gdb developers and people
who messed up their gdb install.
Tom
diff --git a/gdb/python/python.c b/gdb/python/python.c index 4523e30ed24..7e48165db21 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1703,7 +1703,7 @@ gdbpy_handle_missing_debuginfo (const struct extension_language_defn *extlang, struct objfile *objfile) { /* Early exit if Python is not initialised. */ - if (!gdb_python_initialized) + if (!gdb_python_initialized || gdb_python_module == nullptr) return {}; struct gdbarch *gdbarch = objfile->arch ();