From patchwork Tue Jul 11 14:48:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72497 Return-Path: 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 594B93858C3A for ; Tue, 11 Jul 2023 14:49:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 594B93858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689086987; bh=fWpuA0xqN9LuAJCtQxHvDG9bKNKDgyvoVkGlnfT9sIE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DmccyAIBkAeSd5Lx1lH8kQfu26gvFni7irlj7+uk6zUuZQ1rAi5fngkkOtFxHIx8h gu4p0v8DB+Abm3T2CEBBp0hlqgoUuXoxxjDelLiubCxXHblM4ifvbce4JlRClUOdQp XnDEdPXbCEQenxjrtxFUQPj+xQtGtqhkETC2Fd2g= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id A33463858C62 for ; Tue, 11 Jul 2023 14:48:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A33463858C62 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-77a62a84855so194332639f.1 for ; Tue, 11 Jul 2023 07:48:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689086935; x=1691678935; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fWpuA0xqN9LuAJCtQxHvDG9bKNKDgyvoVkGlnfT9sIE=; b=QZ2wGStU1+SfD34/cFZqTCoIVWoJWc64XVGK5k+qejexv41LcOt9uwP18te10jv1n4 XyNtRiurK9EE1QQ0udBawCqvmIwt+PqKe6imlHVzzdvi3oaecrHQpF+JRGLYHzoBCYlt Grdpp+pJcxH7ip3aq2fNQKCg6cGN1zJ15B5L5L7M5SiC6PGcDbMEGVT5qWMRqZoFpdXP 7mG1jqNszjL73pmZ/3f/OpsH93QLdmMhBnvYVTfHUmdghLeqedppUoriQB6yJCezfDkL HPqI8zA9sZV641KLJ05lITxHGfX8ZjmE8BfPIEBwhr6c7YfYTm1j2kil+vCqAj75gSOD e0eA== X-Gm-Message-State: ABy/qLZMCEwX9z68aLI3TLzFk/OhJr4o+GkTFWFZB5CauRLLnQNquAxA BVeNWp2VaFfln58+tizdvgrsbWx7yZex9JlUzgpL4Q== X-Google-Smtp-Source: APBJJlEiGQ487I1CFDDLguWyiquOiNQWROlr/Dp1wp5tNWj/KbhqKUZAytw4rfyqB8UzMJnsvmXdZw== X-Received: by 2002:a6b:dc08:0:b0:780:d76c:b640 with SMTP id s8-20020a6bdc08000000b00780d76cb640mr14755739ioc.9.1689086934863; Tue, 11 Jul 2023 07:48:54 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id r20-20020a056638101400b0041f4da30787sm567226jab.167.2023.07.11.07.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:48:54 -0700 (PDT) Date: Tue, 11 Jul 2023 08:48:52 -0600 Subject: [PATCH 1/3] Remove unused imports MIME-Version: 1.0 Message-Id: <20230711-dap-modules-v1-1-b4f6067c1b2e@adacore.com> References: <20230711-dap-modules-v1-0-b4f6067c1b2e@adacore.com> In-Reply-To: <20230711-dap-modules-v1-0-b4f6067c1b2e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed an unused import in dap/evaluate.py; and also I found out that my recent changes to use frame filters from DAP left some unused imports in dap/bt.py. --- gdb/python/lib/gdb/dap/bt.py | 3 --- gdb/python/lib/gdb/dap/evaluate.py | 1 - 2 files changed, 4 deletions(-) diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py index 0350a3bb6d5..d1f82817c5e 100644 --- a/gdb/python/lib/gdb/dap/bt.py +++ b/gdb/python/lib/gdb/dap/bt.py @@ -15,11 +15,8 @@ import gdb import os -import itertools from gdb.frames import frame_iterator -from gdb.FrameIterator import FrameIterator -from gdb.FrameDecorator import FrameDecorator from .frames import frame_id from .server import request, capability from .startup import send_gdb_with_response, in_gdb_thread diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 635a05fcdcd..63e80331b24 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -14,7 +14,6 @@ # along with this program. If not, see . import gdb -import gdb.printing # This is deprecated in 3.9, but required in older versions. from typing import Optional From patchwork Tue Jul 11 14:48:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72495 Return-Path: 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 A0F493858C62 for ; Tue, 11 Jul 2023 14:49:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0F493858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689086964; bh=163fFEsh1MRf2o1SsTv8TJC0zwAdqQk7DGcltRIjcaE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mEx5wFvMBQvOzsrnSSLVsgFFiF5vHhvXyFticAGmhcYmNMng2FsUD0JE8eL4xk3zA 00hf6s7xA3Zc11ZkKbWGyETTZqUbD3BD748j7K8FCqhvVh7yfLjP/BnQ/nqK6cjphu zjvAwcK9L7HFMF80DLQ+XKEfb+A45//2POLjrJQs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 5A1F23858C1F for ; Tue, 11 Jul 2023 14:48:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A1F23858C1F Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-7835ae70e46so186465839f.3 for ; Tue, 11 Jul 2023 07:48:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689086935; x=1691678935; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=163fFEsh1MRf2o1SsTv8TJC0zwAdqQk7DGcltRIjcaE=; b=ZQTqAoDz3NVxPQ49T6guyU/u5L2T9f27FZt4pr8uM/Byh1/gQWxqFZaeQBW0BmTVD1 ew+pQWQeiklLiKAzaAz2PLeo2WVAX+ZeYkUmUieelznNxjGtnZeoYtUfAXMjfSvrnMTj ursERqqQqqe2O6pQKnGdh6a94iRz9kZoE0wq/v+LK9J+RN+/PMWWwBnoiuzrcyP3oCAU ry0JMgHKPhaNq9ccD9Ks/f8Ood4JWwfVQ2lxtMCIZOy6y8h11fESQ0bPt/4Vg4EZnHKf 8r0Clvm0b6BqEGrtTJR9LPkk/STOAHmT33lEJ+FqEdQa5bi8ycbzJIyskDhRWhTu7VU6 W7KQ== X-Gm-Message-State: ABy/qLaaholSfpT4FJkCoRrCAvgfpWayeejXCf9jQr0pfwE4zabKt6ez EFEVTNwNcCEjL8+xjPGNaAiVopjzn5LwBGOnKoHNoA== X-Google-Smtp-Source: APBJJlEc2ImjkrftOBigH+iQ/DPdUD/ypl03FBzimApcv0RU/jIkBTmcRky8GS9ORy5nqhkDhdOGRw== X-Received: by 2002:a5d:9f0f:0:b0:786:25a3:ef30 with SMTP id q15-20020a5d9f0f000000b0078625a3ef30mr16063307iot.7.1689086935575; Tue, 11 Jul 2023 07:48:55 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id r20-20020a056638101400b0041f4da30787sm567226jab.167.2023.07.11.07.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:48:55 -0700 (PDT) Date: Tue, 11 Jul 2023 08:48:53 -0600 Subject: [PATCH 2/3] Add Progspace.objfile_for_address MIME-Version: 1.0 Message-Id: <20230711-dap-modules-v1-2-b4f6067c1b2e@adacore.com> References: <20230711-dap-modules-v1-0-b4f6067c1b2e@adacore.com> In-Reply-To: <20230711-dap-modules-v1-0-b4f6067c1b2e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.4 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds a new objfile_for_address method to gdb.Progspace. This makes it easy to find the objfile for a given address. There's a related PR; and while this change would have been sufficient for my original need, it's not clear to me whether I should close the bug. Nevertheless I think it makes sense to at least mention it here. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19288 Reviewed-By: Eli Zaretskii --- gdb/NEWS | 3 +++ gdb/doc/python.texi | 6 ++++++ gdb/progspace.c | 16 ++++++++++++++++ gdb/progspace.h | 4 ++++ gdb/python/py-progspace.c | 27 +++++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-progspace.exp | 7 +++++++ 6 files changed, 63 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index b924834d3d7..a97b5fb9364 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -230,6 +230,9 @@ info main ** gdb.Value now has the 'assign' method. + ** gdb.Progspace now has the new method "objfile_for_address". This + returns the gdb.Objfile, if any, that covers a given address. + *** Changes in GDB 13 * MI version 1 is deprecated, and will be removed in GDB 14. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 9a342f34bf0..9bb907d1982 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5068,6 +5068,12 @@ Return the name of the shared library holding the given @var{address} as a string, or @code{None}. @end defun +@findex Progspace.objfile_for_address +@defun Progspace.objfile_for_address (address) +Return the @code{gdb.Objfile} holding the given address, or +@code{None} if no objfile covers it. +@end defun + One may add arbitrary attributes to @code{gdb.Progspace} objects in the usual Python way. This is useful if, for example, one needs to do some extra record keeping diff --git a/gdb/progspace.c b/gdb/progspace.c index 32bdfebcf7c..5cf8334ee67 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -180,6 +180,22 @@ program_space::remove_objfile (struct objfile *objfile) /* See progspace.h. */ +struct objfile * +program_space::objfile_for_address (CORE_ADDR address) +{ + for (auto iter : objfiles ()) + { + /* Don't check separate debug objfiles. */ + if (iter->separate_debug_objfile_backlink != nullptr) + continue; + if (is_addr_in_objfile (address, iter)) + return iter; + } + return nullptr; +} + +/* See progspace.h. */ + void program_space::exec_close () { diff --git a/gdb/progspace.h b/gdb/progspace.h index 85215f0e2f1..ee12d89c173 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -249,6 +249,10 @@ struct program_space /* Free all the objfiles associated with this program space. */ void free_all_objfiles (); + /* Return the objfile containing ADDRESS, or nullptr if the address + is outside all objfiles in this progspace. */ + struct objfile *objfile_for_address (CORE_ADDR address); + /* Return a range adapter for iterating over all the solibs in this program space. Use it like: diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index a231d240342..b98ac8dde61 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -392,6 +392,30 @@ pspy_solib_name (PyObject *o, PyObject *args) return host_string_to_python_string (soname).release (); } +/* Implement objfile_for_address. */ + +static PyObject * +pspy_objfile_for_address (PyObject *o, PyObject *args) +{ + CORE_ADDR addr; + PyObject *addr_obj; + + pspace_object *self = (pspace_object *) o; + + PSPY_REQUIRE_VALID (self); + + if (!PyArg_ParseTuple (args, "O", &addr_obj)) + return nullptr; + if (get_addr_from_python (addr_obj, &addr) < 0) + return nullptr; + + struct objfile *objf = self->pspace->objfile_for_address (addr); + if (objf == nullptr) + Py_RETURN_NONE; + + return objfile_to_objfile_object (objf).release (); +} + /* Return the innermost lexical block containing the specified pc value, or 0 if there is none. */ static PyObject * @@ -569,6 +593,9 @@ static PyMethodDef progspace_object_methods[] = { "solib_name", pspy_solib_name, METH_VARARGS, "solib_name (Long) -> String.\n\ Return the name of the shared library holding a given address, or None." }, + { "objfile_for_address", pspy_objfile_for_address, METH_VARARGS, + "objfile_for_address (int) -> gdb.Objfile\n\ +Return the objfile containing the given address, or None." }, { "block_for_pc", pspy_block_for_pc, METH_VARARGS, "Return the block containing the given pc value, or None." }, { "find_pc_line", pspy_find_pc_line, METH_VARARGS, diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index 638b27927c6..f0dc208ae4b 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -68,6 +68,13 @@ if ![is_address_zero_readable] { gdb_test "python print (gdb.current_progspace ().block_for_pc (0))" "None" } +gdb_test "python print(gdb.current_progspace().objfile_for_address(${pc_val}).username)" \ + ".*py-progspace" \ + "objfile for pc" +gdb_test "python print(gdb.current_progspace().objfile_for_address(0))" \ + "None" \ + "no objfile for 0" + # With a single inferior, progspace.objfiles () and gdb.objfiles () should # be identical. gdb_test "python print (progspace.objfiles () == gdb.objfiles ())" "True" From patchwork Tue Jul 11 14:48:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72496 Return-Path: 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 C53DC385AFB6 for ; Tue, 11 Jul 2023 14:49:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C53DC385AFB6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689086968; bh=HzmONF6ABpqW12pC2qBV+xyvf+Kq+L3SQKmGMsbt8WM=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qNg+FD3kEG2MaB8KtR3zFL8RQLY3aW+R2veNpzolTHrn8mtJb76yVm9yYVokaQcnn JlX3plBxKv6QUOqD1myHIezvQKiecoizbQB2Fp7i5oThN7wYN3+ggm/ZJmO2HItCCj xckC2eu3Hb4HpVDV9BWF0vN37jUE9PNTPd3r4fos= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id 00F8F3858C31 for ; Tue, 11 Jul 2023 14:48:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00F8F3858C31 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-76c64da0e46so192062739f.0 for ; Tue, 11 Jul 2023 07:48:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689086936; x=1691678936; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HzmONF6ABpqW12pC2qBV+xyvf+Kq+L3SQKmGMsbt8WM=; b=T+0DgFJU+uDTzSBAFcTFO/L51Bi9+1Mosuj/CFqsnnAP36M8p5GpE/i+NH5RcGR6BA 7FQs67we9JA/iTZJx7ikuZ4vSiuDQlrYX8HyoRAe1ybHFeZG15AYK6O5Ss0Kjv1TuM3f t0bME7f2ycUlemIKxIxji1I6+rUs5ktzQSn0DSBLqweJnAaJfekcyrDcZKb7v6zEYONi kK4toS/uKFdtlRq04pcRua0O2LFmUAnma93IduDwCjvfG1xSqC6P/ZLAyHTb250FTNSf zSsQxKPt4p8tvC2eG6YHJyqV+gSv8v3itaIloGqiVD8s3qQplAZUPJqh3vAlv+cMflr5 Xpog== X-Gm-Message-State: ABy/qLanwWv5IrXXTk6gK92wmbD0hpwWCO6BGp1M9hs1vNKR7vA2WpIm jUby2R/u8l93R60rWxuGewqHW9SONxJZ3f/5mS2QqA== X-Google-Smtp-Source: APBJJlGGa5F/qirEeI7C0NNZCIokTYCZC6p344vDaGDWXvLRbD58/ThFa+tboKFVI0kW9I4EAu9GBg== X-Received: by 2002:a5e:8f47:0:b0:787:34d:f223 with SMTP id x7-20020a5e8f47000000b00787034df223mr7498237iop.11.1689086936133; Tue, 11 Jul 2023 07:48:56 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id r20-20020a056638101400b0041f4da30787sm567226jab.167.2023.07.11.07.48.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:48:55 -0700 (PDT) Date: Tue, 11 Jul 2023 08:48:54 -0600 Subject: [PATCH 3/3] Implement DAP modules request MIME-Version: 1.0 Message-Id: <20230711-dap-modules-v1-3-b4f6067c1b2e@adacore.com> References: <20230711-dap-modules-v1-0-b4f6067c1b2e@adacore.com> In-Reply-To: <20230711-dap-modules-v1-0-b4f6067c1b2e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This implements the DAP "modules" request, and also arranges to add the module ID to stack frames. --- gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/dap/__init__.py | 1 + gdb/python/lib/gdb/dap/bt.py | 7 ++- gdb/python/lib/gdb/dap/events.py | 14 ++++++ gdb/python/lib/gdb/dap/modules.py | 64 +++++++++++++++++++++++++++ gdb/testsuite/gdb.dap/modules-solib.c | 21 +++++++++ gdb/testsuite/gdb.dap/modules.c | 40 +++++++++++++++++ gdb/testsuite/gdb.dap/modules.exp | 81 +++++++++++++++++++++++++++++++++++ 8 files changed, 228 insertions(+), 1 deletion(-) diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index a3775a4a666..04a8c8eca69 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -98,6 +98,7 @@ PYTHON_FILE_LIST = \ gdb/dap/launch.py \ gdb/dap/locations.py \ gdb/dap/memory.py \ + gdb/dap/modules.py \ gdb/dap/next.py \ gdb/dap/pause.py \ gdb/dap/scopes.py \ diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py index f3dd3ff7ea8..689c2049eec 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -27,6 +27,7 @@ from . import evaluate from . import launch from . import locations from . import memory +from . import modules from . import next from . import pause from . import scopes diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py index d1f82817c5e..975c88f8208 100644 --- a/gdb/python/lib/gdb/dap/bt.py +++ b/gdb/python/lib/gdb/dap/bt.py @@ -18,6 +18,7 @@ import os from gdb.frames import frame_iterator from .frames import frame_id +from .modules import module_id from .server import request, capability from .startup import send_gdb_with_response, in_gdb_thread from .state import set_thread @@ -39,6 +40,7 @@ def _backtrace(thread_id, levels, startFrame): except gdb.error: frame_iter = () for current_frame in frame_iter: + pc = current_frame.address() newframe = { "id": frame_id(current_frame), "name": current_frame.function(), @@ -47,8 +49,11 @@ def _backtrace(thread_id, levels, startFrame): "line": 0, # GDB doesn't support columns. "column": 0, - "instructionPointerReference": hex(current_frame.address()), + "instructionPointerReference": hex(pc), } + objfile = gdb.current_progspace().objfile_for_address(pc) + if objfile is not None: + newframe["moduleId"] = module_id(objfile) line = current_frame.line() if line is not None: newframe["line"] = line diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index d9ae603dfa4..c1631442746 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -19,6 +19,7 @@ import gdb from .server import send_event from .startup import in_gdb_thread, Invoker, log from .breakpoint import breakpoint_descriptor +from .modules import is_module, make_module @in_gdb_thread @@ -78,6 +79,18 @@ def _new_thread(event): ) +@in_gdb_thread +def _new_objfile(event): + if is_module(event.new_objfile): + send_event( + "module", + { + "reason": "new", + "module": make_module(event.new_objfile), + }, + ) + + _suppress_cont = False @@ -161,3 +174,4 @@ gdb.events.breakpoint_modified.connect(_bp_modified) gdb.events.breakpoint_deleted.connect(_bp_deleted) gdb.events.new_thread.connect(_new_thread) gdb.events.cont.connect(_cont) +gdb.events.new_objfile.connect(_new_objfile) diff --git a/gdb/python/lib/gdb/dap/modules.py b/gdb/python/lib/gdb/dap/modules.py new file mode 100644 index 00000000000..6ba613bcd2b --- /dev/null +++ b/gdb/python/lib/gdb/dap/modules.py @@ -0,0 +1,64 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import gdb + +from .server import capability, request +from .startup import in_gdb_thread, send_gdb_with_response + + +@in_gdb_thread +def module_id(objfile): + """Return the module ID for the objfile.""" + return objfile.username + + +@in_gdb_thread +def is_module(objfile): + """Return True if OBJFILE represents a valid Module.""" + return objfile.is_valid() and objfile.owner is None + + +@in_gdb_thread +def make_module(objf): + """Return a Module representing the objfile OBJF. + + The objfile must pass the 'is_module' test.""" + return { + "id": module_id(objf), + "name": objf.username, + "path": objf.filename, + } + + +@in_gdb_thread +def _modules(start, count): + # Don't count invalid objfiles or separate debug objfiles. + objfiles = [x for x in gdb.objfiles() if is_module(x)] + if count == 0: + # Use all items. + last = len(objfiles) + else: + last = start + count + return { + "modules": [make_module(x) for x in objfiles[start:last]], + "totalModules": len(objfiles), + } + + +@capability("supportsModulesRequest") +@request("modules") +def modules(*, startModule: int = 0, moduleCount: int = 0, **args): + return send_gdb_with_response(lambda: _modules(startModule, moduleCount)) diff --git a/gdb/testsuite/gdb.dap/modules-solib.c b/gdb/testsuite/gdb.dap/modules-solib.c new file mode 100644 index 00000000000..a0bfcaa83d0 --- /dev/null +++ b/gdb/testsuite/gdb.dap/modules-solib.c @@ -0,0 +1,21 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +call_me (void (*callee) (void)) +{ + callee (); + return 0; +} diff --git a/gdb/testsuite/gdb.dap/modules.c b/gdb/testsuite/gdb.dap/modules.c new file mode 100644 index 00000000000..6ef8a600c5d --- /dev/null +++ b/gdb/testsuite/gdb.dap/modules.c @@ -0,0 +1,40 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include +#include + +void +stop (void) +{ +} + +int +main (void) +{ + void *handle; + int (*func)(void (*) (void)); + + stop (); + + handle = dlopen (SHLIB_NAME, RTLD_LAZY); + assert (handle != NULL); + + func = (int (*)(void (*) (void))) dlsym (handle, "call_me"); + func (stop); + + return 0; +} diff --git a/gdb/testsuite/gdb.dap/modules.exp b/gdb/testsuite/gdb.dap/modules.exp new file mode 100644 index 00000000000..e75ae578c78 --- /dev/null +++ b/gdb/testsuite/gdb.dap/modules.exp @@ -0,0 +1,81 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test DAP modules functionality. + +require allow_shlib_tests allow_dap_tests + +load_lib dap-support.exp + +standard_testfile + +set libname $testfile-solib +set srcfile_lib $srcdir/$subdir/$libname.c +set binfile_lib [standard_output_file $libname.so] + +if { [gdb_compile_shlib $srcfile_lib $binfile_lib {}] != "" } { + untested "failed to compile shared library" + return +} + +set binfile_lib_target [gdb_download_shlib $binfile_lib] +set define -DSHLIB_NAME=\"$binfile_lib_target\" + +if {[build_executable ${testfile}.exp $testfile $srcfile \ + [list additional_flags=$define debug shlib_load]] == -1} { + return +} + +if {[dap_launch $testfile] == ""} { + return +} + +set obj [dap_check_request_and_response "set breakpoint on two functions" \ + setFunctionBreakpoints \ + {o breakpoints [a [o name [s stop]]]}] +set fn_bpno [dap_get_breakpoint_number $obj] + +dap_check_request_and_response "start inferior" configurationDone + +dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ + "body reason" breakpoint \ + "body hitBreakpointIds" $fn_bpno + +dap_check_request_and_response "continue to next stop" continue \ + {o threadId [i 1]} + + +lassign [dap_wait_for_event_and_check "module event" module \ + "body reason" new] module_event ignore + +gdb_assert {[string match *$libname* [dict get $module_event body module id]]} \ + "module.id" +gdb_assert {[string match *$libname* [dict get $module_event body module name]]} \ + "module.name" +gdb_assert {[string match *$libname* [dict get $module_event body module path]]} \ + "module.path" + +dap_wait_for_event_and_check "second stop at function breakpoint" stopped \ + "body reason" breakpoint \ + "body hitBreakpointIds" $fn_bpno + +set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \ + {o threadId [i 1]}] \ + 0] +set frame_id [dict get [lindex [dict get $bt body stackFrames] 1] moduleId] + +gdb_assert {[string match *$libname* $frame_id]} "module.id in stack trace" + +dap_shutdown