From patchwork Tue Jun 8 13:06:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas De Schampheleire X-Patchwork-Id: 1489430 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=czBep592; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fzr9q47Wvz9sPf for ; Tue, 8 Jun 2021 23:07:11 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id AD36D402CF; Tue, 8 Jun 2021 13:07:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GSVdBjDHd0CO; Tue, 8 Jun 2021 13:07:05 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp2.osuosl.org (Postfix) with ESMTP id 1BA04400E7; Tue, 8 Jun 2021 13:07:04 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 235321BF3FC for ; Tue, 8 Jun 2021 13:06:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 1205F83BE2 for ; Tue, 8 Jun 2021 13:06:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id quEtMHBGtC49 for ; Tue, 8 Jun 2021 13:06:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by smtp1.osuosl.org (Postfix) with ESMTPS id DFA1483BA9 for ; Tue, 8 Jun 2021 13:06:50 +0000 (UTC) Received: by mail-ed1-x52b.google.com with SMTP id f5so19420234eds.0 for ; Tue, 08 Jun 2021 06:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zdYuBWXyKuCY2iwGn1IvjfksCXoDiMHzsJFoIJOqDN4=; b=czBep592gSzMwRHqYly1QrCtCh/k1+Z3trJDFWnxXQVYH8qbH0WN6I98fQXJb4GpYe z4wxElqeiND1uHz5tuvPq6492Pmxk6P1aU9djjOmR3jMht1t3TcZRy/CxzqJpMQ87Wbe 1guqYgDR4RQ34WEHrHVFuRzMAoRYBKTXFj5vyrFk1gXDhzialjVPLAqSd6KVgW+2+ygh rKbzpQG3ZcjE+x49ugnCB36uS4tT2RmNZYAgkYGhSUG7aZiLoC0RZ2twCL5TI35dWRtT NSoyW57sN+bnZEfRy0DfVI3zEF61qHNEp7yBYaNYv946ghLWzzmPfKlG0+CWMgey4fZ1 y6hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zdYuBWXyKuCY2iwGn1IvjfksCXoDiMHzsJFoIJOqDN4=; b=ncDVh+1IqOcNpOb9+Am6SpE5qK+aDStihr6eQk+cuiSWkYDV+h8aF7sP1EUwaNx2Pg QqwLQeXl1XW1BpVSLjlHYjF/fnt7AfGPcRSM4e9J7sx8Jh3ZDTNhaEhGf1g/8GEjOa48 6/rvMpqLdj/0i1MLIWX9J9DAb0OmLxseuCMervZdhsgC+3AfOF4ZuP2KQKV9LQEui3Xt pYxf7G83arm0QlBa1hvLPdagPVaXwVfWwZBsVfAldZyKWEyT4JfH1yGgLD0X+fQudcxD 3Bm3YsyVuKrdsjYigG2lQN4AtCeg4gAtUYa/wz51oaaHlMIUuqCJld7MxHnNk1DHMBts w8yw== X-Gm-Message-State: AOAM531mqGIbcRJRknHFp8D8Q9lSey2Y8f91BBLtyOdoOjTNhO6W0iRL rdsG25/FnfvAeOkNvrtFHgO6rF6BcCEyB4b2 X-Google-Smtp-Source: ABdhPJymtk3nPMBP+0fuuDObEvDnfUAm1zYS3QEHwk/WdMYJmuNUTHd2QqiJ//ZNQ+C2uSWxEKQm3g== X-Received: by 2002:aa7:cc87:: with SMTP id p7mr24901376edt.82.1623157608972; Tue, 08 Jun 2021 06:06:48 -0700 (PDT) Received: from localhost (ptr-5gw9tzn82s1glqex1i.18120a2.ip6.access.telenet.be. [2a02:1810:510:3800:ad4b:62a2:fdc7:acc6]) by smtp.gmail.com with ESMTPSA id du7sm587714edb.1.2021.06.08.06.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:06:48 -0700 (PDT) From: Thomas De Schampheleire To: buildroot@buildroot.org Date: Tue, 8 Jun 2021 15:06:41 +0200 Message-Id: <20210608130644.10909-2-patrickdepinguin@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210608130644.10909-1-patrickdepinguin@gmail.com> References: <20210608130644.10909-1-patrickdepinguin@gmail.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH 1/3] package/gdb: fix gdb 9.2 segfault with Python 3.9 support X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas De Schampheleire Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Thomas De Schampheleire When enabling Python 3 support in gdb 9.2, gdb segfaults at startup. The issue is tracked back to following upstream gdb commit, present since gdb 10.1. commit c47bae859a5af0d95224d90000df0e529f7c5aa0 Author: Kevin Buettner Date: Wed May 27 20:05:40 2020 -0700 Fix Python3.9 related runtime problems [...] Backport this commit to 9.2 in Buildroot. Signed-off-by: Thomas De Schampheleire --- ...x-Python3.9-related-runtime-problems.patch | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 package/gdb/9.2/0007-Fix-Python3.9-related-runtime-problems.patch diff --git a/package/gdb/9.2/0007-Fix-Python3.9-related-runtime-problems.patch b/package/gdb/9.2/0007-Fix-Python3.9-related-runtime-problems.patch new file mode 100644 index 0000000000..89b0cdc4a0 --- /dev/null +++ b/package/gdb/9.2/0007-Fix-Python3.9-related-runtime-problems.patch @@ -0,0 +1,227 @@ +From c47bae859a5af0d95224d90000df0e529f7c5aa0 Mon Sep 17 00:00:00 2001 +From: Kevin Buettner +Date: Wed, 27 May 2020 20:05:40 -0700 +Subject: [PATCH] Fix Python3.9 related runtime problems + +Python3.9b1 is now available on Rawhide. GDB w/ Python 3.9 support +can be built using the configure switch -with-python=/usr/bin/python3.9. + +Attempting to run gdb/Python3.9 segfaults on startup: + + #0 0x00007ffff7b0582c in PyEval_ReleaseLock () from /lib64/libpython3.9.so.1.0 + #1 0x000000000069ccbf in do_start_initialization () + at worktree-test1/gdb/python/python.c:1789 + #2 _initialize_python () + at worktree-test1/gdb/python/python.c:1877 + #3 0x00000000007afb0a in initialize_all_files () at init.c:237 + ... + +Consulting the the documentation... + +https://docs.python.org/3/c-api/init.html + +...we find that PyEval_ReleaseLock() has been deprecated since version +3.2. It recommends using PyEval_SaveThread or PyEval_ReleaseThread() +instead. In do_start_initialization, in gdb/python/python.c, we +can replace the calls to PyThreadState_Swap() and PyEval_ReleaseLock() +with a single call to PyEval_SaveThread. (Thanks to Keith Seitz +for working this out.) + +With that in place, GDB gets a little bit further. It still dies +on startup, but the backtrace is different: + + #0 0x00007ffff7b04306 in PyOS_InterruptOccurred () + from /lib64/libpython3.9.so.1.0 + #1 0x0000000000576e86 in check_quit_flag () + at worktree-test1/gdb/extension.c:776 + #2 0x0000000000576f8a in set_active_ext_lang (now_active=now_active@entry=0x983c00 ) + at worktree-test1/gdb/extension.c:705 + #3 0x000000000069d399 in gdbpy_enter::gdbpy_enter (this=0x7fffffffd2d0, + gdbarch=0x0, language=0x0) + at worktree-test1/gdb/python/python.c:211 + #4 0x0000000000686e00 in python_new_inferior (inf=0xddeb10) + at worktree-test1/gdb/python/py-inferior.c:251 + #5 0x00000000005d9fb9 in std::function::operator()(inferior*) const (__args#0=, this=0xccad20) + at /usr/include/c++/10/bits/std_function.h:617 + #6 gdb::observers::observable::notify (args#0=0xddeb10, + this=) + at worktree-test1/gdb/../gdbsupport/observable.h:106 + #7 add_inferior_silent (pid=0) + at worktree-test1/gdb/inferior.c:113 + #8 0x00000000005dbcb8 in initialize_inferiors () + at worktree-test1/gdb/inferior.c:947 + ... + +We checked with some Python Developers and were told that we should +acquire the GIL prior to calling any Python C API function. We +definitely don't have the GIL for calls of PyOS_InterruptOccurred(). + +I moved class_gdbpy_gil earlier in the file and use it in +gdbpy_check_quit_flag() to acquire (and automatically release) the +GIL. + +With those changes in place, I was able to run to a GDB prompt. But, +when trying to quit, it segfaulted again due to due to some other +problems with gdbpy_check_quit_flag(): + + Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. + 0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0 + (top-gdb) bt 8 + #0 0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0 + #1 0x00007ffff7afa5ea in PyGILState_Ensure.cold () + from /lib64/libpython3.9.so.1.0 + #2 0x000000000069b58c in gdbpy_gil::gdbpy_gil (this=) + at worktree-test1/gdb/python/python.c:278 + #3 gdbpy_check_quit_flag (extlang=) + at worktree-test1/gdb/python/python.c:278 + #4 0x0000000000576e96 in check_quit_flag () + at worktree-test1/gdb/extension.c:776 + #5 0x000000000057700c in restore_active_ext_lang (previous=0xe9c050) + at worktree-test1/gdb/extension.c:729 + #6 0x000000000088913a in do_my_cleanups ( + pmy_chain=0xc31870 , + old_chain=0xae5720 ) + at worktree-test1/gdbsupport/cleanups.cc:131 + #7 do_final_cleanups () + at worktree-test1/gdbsupport/cleanups.cc:143 + +In this case, we're trying to call a Python C API function after +Py_Finalize() has been called from finalize_python(). I made +finalize_python set gdb_python_initialized to false and then cause +check_quit_flag() to return early when it's false. + +With these changes in place, GDB seems to be working again with +Python3.9b1. I think it likely that there are other problems lurking. +I wouldn't be surprised to find that there are other calls into Python +where we don't first make sure that we have the GIL. Further changes +may well be needed. + +I see no regressions testing on Rawhide using a GDB built with the +default Python version (3.8.3) versus one built using Python 3.9b1. + +I've also tested on Fedora 28, 29, 30, 31, and 32 (all x86_64) using +the default (though updated) system installed versions of Python on +those OSes. This means that I've tested against Python versions +2.7.15, 2.7.17, 2.7.18, 3.7.7, 3.8.2, and 3.8.3. In each case GDB +still builds without problem and shows no regressions after applying +this patch. + +gdb/ChangeLog: + +2020-MM-DD Kevin Buettner + Keith Seitz + + * python/python.c (do_start_initialization): For Python 3.9 and + later, call PyEval_SaveThread instead of PyEval_ReleaseLock. + (class gdbpy_gil): Move to earlier in file. + (finalize_python): Set gdb_python_initialized. + (gdbpy_check_quit_flag): Acquire GIL via gdbpy_gil. Return early + when not initialized. + + +[import into Buildroot, removing ChangeLog change to avoid conflict] +Signed-off-by: Thomas De Schampheleire + +--- + gdb/ChangeLog | 10 ++++++++ + gdb/python/python.c | 56 ++++++++++++++++++++++++--------------------- + 2 files changed, 40 insertions(+), 26 deletions(-) + +diff --git a/gdb/python/python.c b/gdb/python/python.c +index 67f362b852d..4bdd2201abc 100644 +--- a/gdb/python/python.c ++++ b/gdb/python/python.c +@@ -238,6 +238,30 @@ gdbpy_enter::~gdbpy_enter () + PyGILState_Release (m_state); + } + ++/* A helper class to save and restore the GIL, but without touching ++ the other globals that are handled by gdbpy_enter. */ ++ ++class gdbpy_gil ++{ ++public: ++ ++ gdbpy_gil () ++ : m_state (PyGILState_Ensure ()) ++ { ++ } ++ ++ ~gdbpy_gil () ++ { ++ PyGILState_Release (m_state); ++ } ++ ++ DISABLE_COPY_AND_ASSIGN (gdbpy_gil); ++ ++private: ++ ++ PyGILState_STATE m_state; ++}; ++ + /* Set the quit flag. */ + + static void +@@ -251,6 +275,10 @@ gdbpy_set_quit_flag (const struct extension_language_defn *extlang) + static int + gdbpy_check_quit_flag (const struct extension_language_defn *extlang) + { ++ if (!gdb_python_initialized) ++ return 0; ++ ++ gdbpy_gil gil; + return PyOS_InterruptOccurred (); + } + +@@ -943,30 +971,6 @@ gdbpy_source_script (const struct extension_language_defn *extlang, + + /* Posting and handling events. */ + +-/* A helper class to save and restore the GIL, but without touching +- the other globals that are handled by gdbpy_enter. */ +- +-class gdbpy_gil +-{ +-public: +- +- gdbpy_gil () +- : m_state (PyGILState_Ensure ()) +- { +- } +- +- ~gdbpy_gil () +- { +- PyGILState_Release (m_state); +- } +- +- DISABLE_COPY_AND_ASSIGN (gdbpy_gil); +- +-private: +- +- PyGILState_STATE m_state; +-}; +- + /* A single event. */ + struct gdbpy_event + { +@@ -1616,6 +1620,7 @@ finalize_python (void *ignore) + + Py_Finalize (); + ++ gdb_python_initialized = false; + restore_active_ext_lang (previous_active); + } + +@@ -1785,8 +1790,7 @@ do_start_initialization () + return false; + + /* Release the GIL while gdb runs. */ +- PyThreadState_Swap (NULL); +- PyEval_ReleaseLock (); ++ PyEval_SaveThread (); + + make_final_cleanup (finalize_python, NULL); + +-- +2.26.3 + From patchwork Tue Jun 8 13:06:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas De Schampheleire X-Patchwork-Id: 1489431 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=D3pyg8E3; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzrB212gqz9sPf for ; Tue, 8 Jun 2021 23:07:22 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8747D83BE3; Tue, 8 Jun 2021 13:07:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dSNGzJI5uR4Q; Tue, 8 Jun 2021 13:07:18 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id C1D1083BE2; Tue, 8 Jun 2021 13:07:17 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 4AFC11BF3FC for ; Tue, 8 Jun 2021 13:06:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 3AA356070D for ; Tue, 8 Jun 2021 13:06:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qtAPClfoGIsJ for ; Tue, 8 Jun 2021 13:06:53 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by smtp3.osuosl.org (Postfix) with ESMTPS id 0B60A606A8 for ; Tue, 8 Jun 2021 13:06:52 +0000 (UTC) Received: by mail-ej1-x62e.google.com with SMTP id he7so13085218ejc.13 for ; Tue, 08 Jun 2021 06:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mwf9yqzQI4kAwpuVlBliJkXUSzbGeDKjMm0sa4QXdQI=; b=D3pyg8E39rsbCX6rxnqZXYriEm7XSbmItVqKzeGXeESW3nsMzA1FG7dUdFxMm648Ap +DqJS7PvvTQKYdNpXZ+/ccwBzIskE0wTszCrHPOWWxWrfEuDMmbAP98ZWIlkDR/PiNbw C7G2pcpuUopcNNb6OdedYYrIRTFXBmF56njFC+BbB7KrLfLtTnfYBzhar5J6R06v475N H9C0uj8P84UiVaDUTYyOA+8mUr2CF0N/JkcuTpCtKYGP4RN1A7UGv1mdm+u7LDTQqv7S giwv1p2LvC4Cqk5H8Y6tfn33AugfDVaiaEeqXXAO/+UJvJ2GDvStFIS4u5WyjPw4jnZW hUWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mwf9yqzQI4kAwpuVlBliJkXUSzbGeDKjMm0sa4QXdQI=; b=Wf3tVJZPcK+QPctEMeBH/Stfp6xhFzTwxBOs/a7SxhGO+1yc30dZv0SZyrvlC+4ILv ntvfEYL6C9rAG7pRB8zX36y1aCG+4CpkdX8Srzy5oNpMd1G0YH9V7YZDBqnhChzlVDZH IzNDEAcLoj5RWwFfejSHW6Nlkw7Fgh0Zj+0N5yh416mwEg/f+vpELGrEehAcU8AlHXEy FqhdhmjuFTx6TL761BgV8Tp39PgyWZK/QtusLP2Op0Offutsu4kjrXRegPJAiOtu8/uo HZwJ3GC4n/fbquC/RcEoCswYEfHOAi20mXYtpgltJyfm/dYtggT5V2jvqbBKHi56kwMz 59eg== X-Gm-Message-State: AOAM533h2WhYpmy4kIeduNY8rai34qNnzVNo9K+QMXXNwSbSeCA8b09s iS09b/WNZyuEzF6urRa3HT5bMwUEZ4uaCbjR X-Google-Smtp-Source: ABdhPJyRRhFJB5QmBkLKyKzcvCpjr4JY+5zv9K1ojLj2RxV+shFysCU05Xp2HSnJeNiBlhpffUXzFg== X-Received: by 2002:a17:907:4cd:: with SMTP id vz13mr23426425ejb.109.1623157610892; Tue, 08 Jun 2021 06:06:50 -0700 (PDT) Received: from localhost (ptr-5gw9tzn82s1glqex1i.18120a2.ip6.access.telenet.be. [2a02:1810:510:3800:ad4b:62a2:fdc7:acc6]) by smtp.gmail.com with ESMTPSA id h6sm5453589edj.91.2021.06.08.06.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:06:50 -0700 (PDT) From: Thomas De Schampheleire To: buildroot@buildroot.org Date: Tue, 8 Jun 2021 15:06:42 +0200 Message-Id: <20210608130644.10909-3-patrickdepinguin@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210608130644.10909-1-patrickdepinguin@gmail.com> References: <20210608130644.10909-1-patrickdepinguin@gmail.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH 2/3] toolchain/toolchain-external: fixup gdb pretty-printer loader for libstdcxx X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Naour , Thomas Petazzoni , Thomas De Schampheleire Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Thomas De Schampheleire gcc installs a libstdcxx-...so-gdb.py file that gdb will load automatically when it loads libstdcxx.so, via the mechanism described at [1]. However, the auto-load file installed by gcc contains hardcoded paths referring to the location where the (external) toolchain was built, which are normally not available. Fix up the paths in the load file so that the pretty printers can be loaded automatically. Note that gdb will only auto-load the file if its location is marked as 'safe'. A subsequent commit will take care of that. [1] https://sourceware.org/gdb/onlinedocs/gdb/objfile_002dgdbdotext-file.html Signed-off-by: Thomas De Schampheleire --- .../pkg-toolchain-external.mk | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk index 6d91cb5d1e..1b519d1832 100644 --- a/toolchain/toolchain-external/pkg-toolchain-external.mk +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk @@ -485,6 +485,26 @@ define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT fi endef +# GCC installs a libstdcxx-...so-gdb.py file that gdb will load automatically, +# but it contains hardcoded paths referring to the location where the (external) +# toolchain was built. Fix up these paths so that the pretty printers can be +# loaded automatically. +# By default, the pretty printers are installed in +# $(datadir)/gcc-$(gcc_version)/python but this could have been overwritten with +# the gcc configure option: --with-python-dir. We thus have to search the +# correct path first. +define TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER + loadfile=$$(find $(STAGING_DIR) -name 'libstdc++.so*-gdb.py' 2>/dev/null); \ + pythondir=$$(find $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR) -path '*/libstdcxx/__init__.py' 2>/dev/null | xargs dirname | xargs dirname); \ + if [ -n "$$loadfile" ] && [ -n "$$pythondir" ]; then \ + echo "Fixing up hardcoded paths in GDB pretty-printer auto-load file for libstdcxx: $$loadfile"; \ + sed -ri \ + -e 's%^libdir\s*=.*%libdir = "$(STAGING_DIR)/lib"%' \ + -e "s%^pythondir\s*=.*%pythondir = '$$pythondir'%" \ + $$loadfile; \ + fi +endef + # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not # patched specifically for uClibc-ng, so it continues to generate # binaries that expect the dynamic loader to be named ld-uClibc.so.0, @@ -589,6 +609,7 @@ define $(2)_INSTALL_STAGING_CMDS $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS) $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER) $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT) + $$(TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER) endef # Even though we're installing things in both the staging, the host From patchwork Tue Jun 8 13:06:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas De Schampheleire X-Patchwork-Id: 1489432 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=m/rZwwjO; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzrBH4V5nz9sPf for ; Tue, 8 Jun 2021 23:07:34 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D524B608B3; Tue, 8 Jun 2021 13:07:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4BsoOiL7Qd3a; Tue, 8 Jun 2021 13:07:31 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id 33C296070D; Tue, 8 Jun 2021 13:07:30 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 2FE141BF3FC for ; Tue, 8 Jun 2021 13:06:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 1E015402E5 for ; Tue, 8 Jun 2021 13:06:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ld8uxlAcvaUd for ; Tue, 8 Jun 2021 13:06:55 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by smtp4.osuosl.org (Postfix) with ESMTPS id CB3D2402E0 for ; Tue, 8 Jun 2021 13:06:54 +0000 (UTC) Received: by mail-ed1-x52f.google.com with SMTP id u24so24406735edy.11 for ; Tue, 08 Jun 2021 06:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cAyIKqWdnEguNL6UQrSMESV+1rLJlIj0DhRxfCAa0q0=; b=m/rZwwjOK3QymUl+qc/VKvnvmAy//TBA/c946RwUkfPSIdhpJLnO37B0gvAcXPK1s+ gF4TBChy/8rv6Lfx3lCnjQibs0dXXQZyR/1qGyB4WIl/hmSWm3T4jb7yF95e+hxnLefn ZiTabsupgX7s9ZgeG2NdJWCoPOemfPhCmGZ6oLW9/Cm4h418IgVT35dG8rDV2X3omLXm eeRXdKUg4uWrORrAycbeuhHy4FNaqtDrMPdbt5cwe98epNVVtXg9p2cySVXQakLn8UIS rTnUu8cK+aslRYYI4DS+h8/oqa5qQD2OcIuRlk3JlxTzyNrHAUx3LNrMnZ+eyioxNr/7 l+Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cAyIKqWdnEguNL6UQrSMESV+1rLJlIj0DhRxfCAa0q0=; b=j3oXGFNESpB7iNz950P6HmIhVX5sYzE70oaqyJKALpOR85W7jjDl4w7lJA8R7I82zg aunJ6Ch93TjKKM2+Wx7Q6ycE4kjYZUwCkvjvwaAVbb+5wC1mqvDW4TPZbjb6GG8/UgNb XTrDYkhNrN3pyZKsPIR1nUcdsGMGpCalBtnhY8tpIvE3k0KGMTrvQtbEWr/FMTV0SmWJ ekCOxo/jzufXeCYNC+TxrFHRmRLTel2IT+jkCnMwX3XKE6YAVUaBq0ooSljHwsWOClKf wGeapazFHY2FpazPBFgDsAyMQaptUzi064CYalMstdto29hY+sxiO0cDyucl6S/LdeKV ieUw== X-Gm-Message-State: AOAM532ag3Ok2CHCLGIFXQ9c4c4nTkLO+2CfiPNHpLhAGqu64TRMF50N itUhdfCSWNoNdWoPG6+rUmByWtHWBfIm+i8d X-Google-Smtp-Source: ABdhPJzDbwbkAv1yHEGURyy5OgLeNzhLkXBKhZNJPgHQkm2p765WlrY+w4Jp7GxQkO+XDAS9eQQuFw== X-Received: by 2002:aa7:db90:: with SMTP id u16mr25006716edt.106.1623157613011; Tue, 08 Jun 2021 06:06:53 -0700 (PDT) Received: from localhost (ptr-5gw9tzn82s1glqex1i.18120a2.ip6.access.telenet.be. [2a02:1810:510:3800:ad4b:62a2:fdc7:acc6]) by smtp.gmail.com with ESMTPSA id o20sm8728672eds.20.2021.06.08.06.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:06:52 -0700 (PDT) From: Thomas De Schampheleire To: buildroot@buildroot.org Date: Tue, 8 Jun 2021 15:06:43 +0200 Message-Id: <20210608130644.10909-4-patrickdepinguin@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210608130644.10909-1-patrickdepinguin@gmail.com> References: <20210608130644.10909-1-patrickdepinguin@gmail.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH 3/3] toolchain: mark sysroot as 'safe' path for gdb auto-load X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Naour , Thomas Petazzoni , Thomas De Schampheleire Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Thomas De Schampheleire gdb can automatically load certain files as described in [1]. Such files could install pretty-printers for complex data structures. libstdcxx (C++ standard library) provided by gcc, is one example of a library for which such auto-load file is available. But there are other examples too, like libglib2. However, gdb will only auto-load files if the file is located in one of the locations treated as 'safe'. The Buildroot sysroot is not by default in that list. Provide a better debugging experience by adding the sysroot to the 'safe' list, via the gdbinit file prepared by Buildroot. [1] https://sourceware.org/gdb/onlinedocs/gdb/objfile_002dgdbdotext-file.html Signed-off-by: Thomas De Schampheleire --- toolchain/helpers.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk index 17bc159f3e..dfb2581ed5 100644 --- a/toolchain/helpers.mk +++ b/toolchain/helpers.mk @@ -483,7 +483,8 @@ check_toolchain_ssp = \ # gen_gdbinit_file = \ mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \ - echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit + echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit ; \ + echo "add-auto-load-safe-path $(STAGING_DIR)" >> $(STAGING_DIR)/usr/share/buildroot/gdbinit # Given a path, determine the relative prefix (../) needed to return to the # root level. Note that the last component is treated as a file component; use a