From patchwork Tue Nov 14 18:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 79863 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 2E1E03858410 for ; Tue, 14 Nov 2023 18:44:21 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 681E83858D39 for ; Tue, 14 Nov 2023 18:44:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 681E83858D39 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 681E83858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987448; cv=none; b=V0X/J3SLnxr2B89cu7KR9m3aCX/HG23lQZeBpahkOoCOEO/mFKVkzwyDbxpjJsQIoM6pIUVMoh7gRa1hw8Ivxp4v592hAOFlHtLJEshLz8rKojUkxSe1Z9P5563rQeO2Z2PjRXHxUonmPP+MJXPOdYX9v9Fa/00Y18VpoWbi3fI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987448; c=relaxed/simple; bh=CZYkjWKdCf5VL6kStlhMtlDWQqWyuLnlA5evzAZTtdk=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=BJj5XnvoXZjiPRNkg9IY6vrXs5wgg3YizvRS72HVLrR7+jHXniPLsx/PBxKmQ+RlFT+MmwV31HnA8DSzwPThBeW+A7QnDwdNVaGGzSEf3fynPpFuiz4wW5nRVpxm1Mb/DpAOdTv2gxGF+U9nCElAwjdSDNOe/+6u+h05a2dS3/E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-3594560fa09so23205685ab.0 for ; Tue, 14 Nov 2023 10:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699987445; x=1700592245; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1Y1Y6rpGw2+A8qXVhsBBSyuN+IGOerBBto9AuosjnKc=; b=FanwQbsflZcIWdbdzZ7XSjc+K4Uq6MEQAzOqf0e1ixInz9RO3IsxHN3bfyOLYxBX+M IE/+gNnjnV8vPEo2VuYnm1CUUQ5VKXVt5RhVO8l3tczyDhOPIrCQiXKZsAk9JpTsdKAN BSmc9IeRlDW5yxt61BXGyg/MUMJxI0pnMQQd/KkkIJdHitpV7otH9eaeer0sqnPRQ8gN UOjwXxXj2J8AZmmK8hQO9LeEBvp2psZBQq0Z+NKCV4lZJkk7ulRn7Wf664YKqdcUd89/ RsTsFsFJ1YDgOqe81jlxPTKyuamjNRQ2aN80k9G6DmcGmaN5VxOrCZpbU2ZIiH2ozxfL YPsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699987445; x=1700592245; 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=1Y1Y6rpGw2+A8qXVhsBBSyuN+IGOerBBto9AuosjnKc=; b=Wm7wFTkovPni6tdJFxuw8yuGn9Tudx6xDaKISW0rtSBefbRPQDN/raEVOLHTWDMGb6 RTNiZarqYSYWvp4zKgjuGA9tPre+/pE+F0UlfiY6PLQ4cJeiKYYN4Z+VqoK9wR1V0S1R 9aXxZl5RcjEVBz7U87eJyuXLhb8wulIjrUE9TfhTd4LqurdLKK50vVyFW1HWS1FRspMS hkueEDCMWuC2LcjFgkViL2q9aXIzNdeunS0VqGLJCdXUvuBhBjtGcIxTVeELlYreQ9Iy 4kpp9Drf2deGLo262StUtatlx+VgKDYWuMI4R2+2qT0laGWa1XiZ5jGFSMW0+gEvJqIu fgog== X-Gm-Message-State: AOJu0YxJJdwQENCcez/OJLb3/rmaa/MCQFrAWciT92q1eMEau1dWlFQc 4mFdZ9jT+s6Cc1vQA4OhhixJ8S1Vmkdx+MofjaHY9Q== X-Google-Smtp-Source: AGHT+IFvjbg2PPxmVyhpgMLdGbb4cICgDALD8LLAJ2HlzZNwJAjkP3D5jHyNpvY+s07sMiGu/PGSow== X-Received: by 2002:a05:6e02:2162:b0:359:3fd2:1dda with SMTP id s2-20020a056e02216200b003593fd21ddamr14300182ilv.0.1699987445534; Tue, 14 Nov 2023 10:44:05 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id e97-20020a02866a000000b0043194542229sm528513jai.52.2023.11.14.10.44.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 10:44:05 -0800 (PST) From: Tom Tromey Date: Tue, 14 Nov 2023 11:44:03 -0700 Subject: [PATCH 1/3] Move py_ui_out to a new header MIME-Version: 1.0 Message-Id: <20231114-py-stop-reason-v1-1-4ff440c956a9@adacore.com> References: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> In-Reply-To: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This moves the declaration of py_ui_out to a new header, so that it can more readily be used by other code. --- gdb/python/py-mi.c | 129 +----------------------------------------- gdb/python/py-uiout.h | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 128 deletions(-) diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c index a7b4f4fa3cf..2b265ad80d6 100644 --- a/gdb/python/py-mi.c +++ b/gdb/python/py-mi.c @@ -19,142 +19,15 @@ #include "defs.h" #include "python-internal.h" +#include "py-uiout.h" #include "utils.h" #include "ui.h" -#include "ui-out.h" #include "interps.h" #include "target.h" #include "mi/mi-parse.h" #include "mi/mi-console.h" #include "mi/mi-interp.h" -/* A ui_out subclass that creates a Python object based on the data - that is passed in. */ - -class py_ui_out : public ui_out -{ -public: - - py_ui_out () - : ui_out (fix_multi_location_breakpoint_output - | fix_breakpoint_script_output) - { - do_begin (ui_out_type_tuple, nullptr); - } - - bool can_emit_style_escape () const override - { return false; } - - bool do_is_mi_like_p () const override - { return true; } - - /* Return the Python object that was created. If a Python error - occurred during the processing, set the Python error and return - nullptr. */ - PyObject *result () - { - if (m_error.has_value ()) - { - m_error->restore (); - return nullptr; - } - return current ().obj.release (); - } - -protected: - - void do_progress_end () override { } - void do_progress_start () override { } - void do_progress_notify (const std::string &, const char *, double, double) - override - { } - - void do_table_begin (int nbrofcols, int nr_rows, const char *tblid) override - { - do_begin (ui_out_type_list, tblid); - } - void do_table_body () override - { } - void do_table_end () override - { - do_end (ui_out_type_list); - } - void do_table_header (int width, ui_align align, - const std::string &col_name, - const std::string &col_hdr) override - { } - - void do_begin (ui_out_type type, const char *id) override; - void do_end (ui_out_type type) override; - - void do_field_signed (int fldno, int width, ui_align align, - const char *fldname, LONGEST value) override; - void do_field_unsigned (int fldno, int width, ui_align align, - const char *fldname, ULONGEST value) override; - - void do_field_skip (int fldno, int width, ui_align align, - const char *fldname) override - { } - - void do_field_string (int fldno, int width, ui_align align, - const char *fldname, const char *string, - const ui_file_style &style) override; - void do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) override - ATTRIBUTE_PRINTF (7, 0); - - void do_spaces (int numspaces) override - { } - - void do_text (const char *string) override - { } - - void do_message (const ui_file_style &style, - const char *format, va_list args) - override ATTRIBUTE_PRINTF (3,0) - { } - - void do_wrap_hint (int indent) override - { } - - void do_flush () override - { } - - void do_redirect (struct ui_file *outstream) override - { } - -private: - - /* When constructing Python objects, this class keeps a stack of - objects being constructed. Each such object has this type. */ - struct object_desc - { - /* Name of the field (or empty for lists) that this object will - eventually become. */ - std::string field_name; - /* The object under construction. */ - gdbpy_ref<> obj; - /* The type of structure being created. Note that tables are - treated as lists here. */ - ui_out_type type; - }; - - /* The stack of objects being created. */ - std::vector m_objects; - - /* If an error occurred, this holds the exception information for - use by the 'release' method. */ - gdb::optional m_error; - - /* Return a reference to the object under construction. */ - object_desc ¤t () - { return m_objects.back (); } - - /* Add a new field to the current object under construction. */ - void add_field (const char *name, const gdbpy_ref<> &obj); -}; - void py_ui_out::add_field (const char *name, const gdbpy_ref<> &obj) { diff --git a/gdb/python/py-uiout.h b/gdb/python/py-uiout.h new file mode 100644 index 00000000000..e9abf8ee5be --- /dev/null +++ b/gdb/python/py-uiout.h @@ -0,0 +1,153 @@ +/* Python implementation of ui_out + + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +#ifndef GDB_PYTHON_PY_UIOUT_H +#define GDB_PYTHON_PY_UIOUT_H + +#include "python-internal.h" +#include "ui-out.h" + +/* A ui_out subclass that creates a Python object based on the data + that is passed in. */ + +class py_ui_out : public ui_out +{ +public: + + py_ui_out () + : ui_out (fix_multi_location_breakpoint_output + | fix_breakpoint_script_output) + { + do_begin (ui_out_type_tuple, nullptr); + } + + bool can_emit_style_escape () const override + { return false; } + + bool do_is_mi_like_p () const override + { return true; } + + /* Return the Python object that was created. If a Python error + occurred during the processing, set the Python error and return + nullptr. */ + PyObject *result () + { + if (m_error.has_value ()) + { + m_error->restore (); + return nullptr; + } + return current ().obj.release (); + } + +protected: + + void do_progress_end () override { } + void do_progress_start () override { } + void do_progress_notify (const std::string &, const char *, double, double) + override + { } + + void do_table_begin (int nbrofcols, int nr_rows, const char *tblid) override + { + do_begin (ui_out_type_list, tblid); + } + void do_table_body () override + { } + void do_table_end () override + { + do_end (ui_out_type_list); + } + void do_table_header (int width, ui_align align, + const std::string &col_name, + const std::string &col_hdr) override + { } + + void do_begin (ui_out_type type, const char *id) override; + void do_end (ui_out_type type) override; + + void do_field_signed (int fldno, int width, ui_align align, + const char *fldname, LONGEST value) override; + void do_field_unsigned (int fldno, int width, ui_align align, + const char *fldname, ULONGEST value) override; + + void do_field_skip (int fldno, int width, ui_align align, + const char *fldname) override + { } + + void do_field_string (int fldno, int width, ui_align align, + const char *fldname, const char *string, + const ui_file_style &style) override; + void do_field_fmt (int fldno, int width, ui_align align, + const char *fldname, const ui_file_style &style, + const char *format, va_list args) override + ATTRIBUTE_PRINTF (7, 0); + + void do_spaces (int numspaces) override + { } + + void do_text (const char *string) override + { } + + void do_message (const ui_file_style &style, + const char *format, va_list args) + override ATTRIBUTE_PRINTF (3,0) + { } + + void do_wrap_hint (int indent) override + { } + + void do_flush () override + { } + + void do_redirect (struct ui_file *outstream) override + { } + +private: + + /* When constructing Python objects, this class keeps a stack of + objects being constructed. Each such object has this type. */ + struct object_desc + { + /* Name of the field (or empty for lists) that this object will + eventually become. */ + std::string field_name; + /* The object under construction. */ + gdbpy_ref<> obj; + /* The type of structure being created. Note that tables are + treated as lists here. */ + ui_out_type type; + }; + + /* The stack of objects being created. */ + std::vector m_objects; + + /* If an error occurred, this holds the exception information for + use by the 'release' method. */ + gdb::optional m_error; + + /* Return a reference to the object under construction. */ + object_desc ¤t () + { return m_objects.back (); } + + /* Add a new field to the current object under construction. */ + void add_field (const char *name, const gdbpy_ref<> &obj); +}; + +#endif /* GDB_PYTHON_PY_UIOUT_H */ From patchwork Tue Nov 14 18:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 79864 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 144BB3858CDB for ; Tue, 14 Nov 2023 18:44:35 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id 128893858D32 for ; Tue, 14 Nov 2023 18:44:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 128893858D32 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 128893858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987449; cv=none; b=b36lTfuwq6dixGMXdrncYL8eTYUGOHLa5iSkdGUJrVS3bbhqIpoDudV1i1/vBv8IBcZszWG8x9B7E5UL1w8A7RsjvVx0cd7i2XHwmtAwIr8MLS29n95BydFB+PxleQ36DIDdTllnyGJ7K64ngX2/DYQqIXwL+82bGzw+AmZZfUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987449; c=relaxed/simple; bh=m0gQyHRgHsn4kc3Fz2TT28rYoAckEwW6bG39gSxPt2I=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=ivK3WCKGnnjKGc4NwEn6/+mJhbegxUrsJikW5T3YbvVt2jRbcAAkVSVcemswOa0UHSOOQqjWeOyvG6IHHajOt7AL5eBIeMwI8cTtAhXli7X/CnTbYuBTnSCxlJb9VI5E11FO+RvLRkYpNx+ZGiMOblOodjz9TyGl7K789cKYZgg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-7a98fdeaac7so253483639f.1 for ; Tue, 14 Nov 2023 10:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699987446; x=1700592246; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CpXqfyNxIcNrNief+VePvnpBCufu4X6DbrcQYCx/FwA=; b=ByVUBeACwG6xR1C0bwJl0eMxhY7EiR9YAVu3mXtOpXWaTSKlUgQ1oR9nDUTdQH1y90 bNvyOKbyICUXWiwjtExVtFvrf3AEuZAO8oruvXwLnykRVrUkxW9KaTAcwE+fSII60v8r Ks1+ophJoeZKZMCjJZ9jWaaE8v0QQEfBaDD0RlXUva25/2I6KFZ0E3QLqs3BvfDxRX/e dtvbK+GXrVeAwJLG1cV76g/ObWSwzXYZjNT9aocpq30N/vCpmNRIuG4ljJGJd0EIgkJ7 JSvt0bU+SDX4yUmhyF4QqJvECKLx9iBgILsVoND3OrJQWnQ/QE3iT8J+8TB21F6KfMUO y1CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699987446; x=1700592246; 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=CpXqfyNxIcNrNief+VePvnpBCufu4X6DbrcQYCx/FwA=; b=AGtB/JJtWLq0wen+JP5XxA2ctE5WYxt5KRFFUoXkh6kn0Pf+SdmRyP+A0LEFwRElD3 5ZdjwE8+9lHirHv41FSJLnVKFm8omLxHseTLi+RZbQ+zSf9XDbl+mROiHEZpmdc1IPAM SlylO/zP9Z65LursNoOz0ZZK9gJ9KkDEaXeWBPUoVn5iyrGO2uPshmnOujWRXs8kmO4B Jju8FrIt4Pw79Dx8r1SpvgQrvNmktTeqoLW7gd6QptW+XRYEJtvP5B20W6jOFTSjFdSG cTpvBq8A0ZJXMJuLSJk5+hSx+jiTSeV5Fru0qoeJ5ch/4s8M7ti+lwyx7riWxl2XcZVO O/hw== X-Gm-Message-State: AOJu0YyqnEgrjZrQhuxHPDBW/ci8LBxSJn+1Eq3nrGnBytza/6aqAxhQ 8hW5acZwFUv9seWq0kuik2eDjtdtD/uXCUmBKikRIw== X-Google-Smtp-Source: AGHT+IFvFJzz602VBYNiL79xTAvtJpiuk+qgDAUl9BLs0OdYcGAibSGi4iWEo+trwz3bnJPrQ0tgvw== X-Received: by 2002:a92:c24f:0:b0:358:ffc:e7ab with SMTP id k15-20020a92c24f000000b003580ffce7abmr15422698ilo.19.1699987446228; Tue, 14 Nov 2023 10:44:06 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id e97-20020a02866a000000b0043194542229sm528513jai.52.2023.11.14.10.44.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 10:44:05 -0800 (PST) From: Tom Tromey Date: Tue, 14 Nov 2023 11:44:04 -0700 Subject: [PATCH 2/3] Emit stop reason details in Python stop events MIME-Version: 1.0 Message-Id: <20231114-py-stop-reason-v1-2-4ff440c956a9@adacore.com> References: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> In-Reply-To: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This changes Python stop events to carry a "details" dictionary, that holds any relevant information about the stop. The details are constructed using more or less the same procedure as is done for MI. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13587 Reviewed-By: Eli Zaretskii --- gdb/NEWS | 4 +++ gdb/doc/python.texi | 11 ++++++++ gdb/python/py-bpevent.c | 5 ++-- gdb/python/py-mi.c | 2 +- gdb/python/py-signalevent.c | 5 ++-- gdb/python/py-stopevent.c | 65 +++++++++++++++++++++++++++++++++++++++++---- gdb/python/py-stopevent.h | 9 ++++--- gdb/python/py-uiout.h | 4 +-- 8 files changed, 90 insertions(+), 15 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 93fbcf1c13e..12387ad9f4a 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -50,6 +50,10 @@ disable missing-debug-handler LOCUS HANDLER sub-classed to create handlers for objfiles with missing debug information. + ** Stop events now have a "details" attribute that holds a + dictionary that carries the same information as an MI "*stopped" + event. + * New commands maintenance info linux-lwps diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index b65991bbad0..ab2abcfc5b1 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3750,6 +3750,17 @@ registry extend @code{gdb.StopEvent}. As a child of thread when @value{GDBN} is running in non-stop mode. Refer to @code{gdb.ThreadEvent} above for more details. +@code{gdb.StopEvent} has the following additional attributes: + +@defvar StopEvent.details +A dictionary holding any details relevant to the stop. The exact keys +and values depend on the type of stop, but are identical to the +corresponding MI output (@pxref{GDB/MI Async Records}). + +A dictionary was used for this (rather than adding attributes directly +to the event object) so that the MI keys could be used unchanged. +@end defvar + Emits @code{gdb.SignalEvent}, which extends @code{gdb.StopEvent}. This event indicates that the inferior or one of its threads has diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c index 00fb625794b..b640ec9ddd9 100644 --- a/gdb/python/py-bpevent.c +++ b/gdb/python/py-bpevent.c @@ -24,10 +24,11 @@ references to BREAKPOINT_LIST and FIRST_BP. */ gdbpy_ref<> -create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp) +create_breakpoint_event_object (const gdbpy_ref<> &dict, + PyObject *breakpoint_list, PyObject *first_bp) { gdbpy_ref<> breakpoint_event_obj - = create_stop_event_object (&breakpoint_event_object_type); + = create_stop_event_object (&breakpoint_event_object_type, dict); if (breakpoint_event_obj == NULL) return NULL; diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c index 2b265ad80d6..04873e86dd3 100644 --- a/gdb/python/py-mi.c +++ b/gdb/python/py-mi.c @@ -173,7 +173,7 @@ gdbpy_execute_mi_command (PyObject *self, PyObject *args, PyObject *kw) return nullptr; } - return uiout.result (); + return uiout.result ().release (); } /* Convert KEY_OBJ into a string that can be used as a field name in MI diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c index 93d06706542..edbd9b0a7ec 100644 --- a/gdb/python/py-signalevent.c +++ b/gdb/python/py-signalevent.c @@ -21,10 +21,11 @@ #include "py-stopevent.h" gdbpy_ref<> -create_signal_event_object (enum gdb_signal stop_signal) +create_signal_event_object (const gdbpy_ref<> &dict, + enum gdb_signal stop_signal) { gdbpy_ref<> signal_event_obj - = create_stop_event_object (&signal_event_object_type); + = create_stop_event_object (&signal_event_object_type, dict); if (signal_event_obj == NULL) return NULL; diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c index 0aa9d5381f8..f395e8c042e 100644 --- a/gdb/python/py-stopevent.c +++ b/gdb/python/py-stopevent.c @@ -19,12 +19,61 @@ #include "defs.h" #include "py-stopevent.h" +#include "py-uiout.h" gdbpy_ref<> -create_stop_event_object (PyTypeObject *py_type) +create_stop_event_object (PyTypeObject *py_type, const gdbpy_ref<> &dict) { gdbpy_ref<> thread = py_get_event_thread (inferior_ptid); - return create_thread_event_object (py_type, thread.get ()); + if (thread == nullptr) + return nullptr; + + gdbpy_ref<> result = create_thread_event_object (py_type, thread.get ()); + if (result == nullptr) + return nullptr; + + if (evpy_add_attribute (result.get (), "details", dict.get ()) < 0) + return nullptr; + + return result; +} + +/* Print BPSTAT to a new Python dictionary. Returns the dictionary, + or null if a Python exception occurred. */ + +static gdbpy_ref<> +py_print_bpstat (bpstat *bs, enum gdb_signal stop_signal) +{ + py_ui_out uiout; + + try + { + scoped_restore save_uiout = make_scoped_restore (¤t_uiout, &uiout); + + thread_info *tp = inferior_thread (); + if (tp->thread_fsm () != nullptr && tp->thread_fsm ()->finished_p ()) + { + async_reply_reason reason = tp->thread_fsm ()->async_reply_reason (); + uiout.field_string ("reason", async_reason_lookup (reason)); + } + + if (stop_signal != GDB_SIGNAL_0 && stop_signal != GDB_SIGNAL_TRAP) + print_signal_received_reason (&uiout, stop_signal); + else + { + struct target_waitstatus last; + get_last_target_status (nullptr, nullptr, &last); + + bpstat_print (bs, last.kind ()); + } + } + catch (const gdb_exception &except) + { + gdbpy_convert_exception (except); + return nullptr; + } + + return uiout.result (); } /* Callback observers when a stop event occurs. This function will create a @@ -45,6 +94,10 @@ emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal) if (evregpy_no_listeners_p (gdb_py_events.stop)) return 0; + gdbpy_ref<> dict = py_print_bpstat (bs, stop_signal); + if (dict == nullptr) + return -1; + /* Add any breakpoint set at this location to the list. */ for (current_bs = bs; current_bs != NULL; current_bs = current_bs->next) { @@ -71,7 +124,8 @@ emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal) if (list != NULL) { - stop_event_obj = create_breakpoint_event_object (list.get (), + stop_event_obj = create_breakpoint_event_object (dict, + list.get (), first_bp); if (stop_event_obj == NULL) return -1; @@ -81,7 +135,7 @@ emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal) if (stop_signal != GDB_SIGNAL_0 && stop_signal != GDB_SIGNAL_TRAP) { - stop_event_obj = create_signal_event_object (stop_signal); + stop_event_obj = create_signal_event_object (dict, stop_signal); if (stop_event_obj == NULL) return -1; } @@ -90,7 +144,8 @@ emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal) be known and this should eventually be unused. */ if (stop_event_obj == NULL) { - stop_event_obj = create_stop_event_object (&stop_event_object_type); + stop_event_obj = create_stop_event_object (&stop_event_object_type, + dict); if (stop_event_obj == NULL) return -1; } diff --git a/gdb/python/py-stopevent.h b/gdb/python/py-stopevent.h index 649112f0488..92282c9c413 100644 --- a/gdb/python/py-stopevent.h +++ b/gdb/python/py-stopevent.h @@ -22,14 +22,17 @@ #include "py-event.h" -extern gdbpy_ref<> create_stop_event_object (PyTypeObject *py_type); +extern gdbpy_ref<> create_stop_event_object (PyTypeObject *py_type, + const gdbpy_ref<> &dict); extern int emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal); -extern gdbpy_ref<> create_breakpoint_event_object (PyObject *breakpoint_list, +extern gdbpy_ref<> create_breakpoint_event_object (const gdbpy_ref<> &dict, + PyObject *breakpoint_list, PyObject *first_bp); -extern gdbpy_ref<> create_signal_event_object (enum gdb_signal stop_signal); +extern gdbpy_ref<> create_signal_event_object (const gdbpy_ref<> &dict, + enum gdb_signal stop_signal); #endif /* PYTHON_PY_STOPEVENT_H */ diff --git a/gdb/python/py-uiout.h b/gdb/python/py-uiout.h index e9abf8ee5be..6e43b425968 100644 --- a/gdb/python/py-uiout.h +++ b/gdb/python/py-uiout.h @@ -46,14 +46,14 @@ class py_ui_out : public ui_out /* Return the Python object that was created. If a Python error occurred during the processing, set the Python error and return nullptr. */ - PyObject *result () + gdbpy_ref<> result () { if (m_error.has_value ()) { m_error->restore (); return nullptr; } - return current ().obj.release (); + return std::move (current ().obj); } protected: From patchwork Tue Nov 14 18:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 79865 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 DCDCD3858C30 for ; Tue, 14 Nov 2023 18:44:49 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id C1C0C3858CD1 for ; Tue, 14 Nov 2023 18:44:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1C0C3858CD1 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 C1C0C3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987449; cv=none; b=BpPQH4m6GJYB8nT78mGOSdVmZqY1ko/lAopVj1Erf07T+6T5/wihmYU8fgpMkNx92k8P7o9lCVvYUDG1MnoNZMT2jx7LUtfaGnTI1YsMKGmdoJFtmGWc5dxpu2XMeMnH2Y/uzjbAHryYo7cWdPrUs3XWvU6bHLRVOOZ7/rtq5TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699987449; c=relaxed/simple; bh=TxrLMdttqSFaaYomlwSWR7SwKBo7wwHRyJjnBp8dEaw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=P2P6jiwPiV0151/4MsfuDnMEmogPAVRG6sVpzSaPdH1913hKMlGGI1LzJu8lyeeliJfRlmNiZA4cTk5Ha3GvxRgKu9GqFdk4Hs1T2bD9kkQfXSH4F3rAVdueP21HaMCpB1osuz0hQzrm9BQdoj3+J8IbGxXAyjRu8Y0PgVJ7t3M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7afff3ea94dso184729839f.3 for ; Tue, 14 Nov 2023 10:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699987447; x=1700592247; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=akdQa/FlNRu6qUaNtTGdAovd9pls1oOWrc9QwkbOcys=; b=R/HY5Q8ji9SRFuOmoB1s7If/kxkgwOVju1x0LqKgC2dJs2mWz86sYeG1GsDOw8Qb9r ROl2GtImEJ+SvPKMCD3CkCjuPqj36Ydt6DaWie46F5VMu6t5++SVD0tAOpSBvEOVhgEQ o+U7HoWvKEuCee23H5ygEpm1mmutk8KE6Ed2YFdFHoEOJZhJeUmQiPo5NmDj7i/8pEY5 HxFWRjVvJmuRpLvfnYoMtm3KNMIHKUDu/9H5Ge0mKFr0lu5IVE359otJaS8CL9HKQmjv Mr15HnkYT1rT2hKtqxktuTVhjNJCsl7Mpd9coefPeS7wCAZRmwiAiZ3+J20SHr2dqOAA mvZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699987447; x=1700592247; 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=akdQa/FlNRu6qUaNtTGdAovd9pls1oOWrc9QwkbOcys=; b=HKnGCSCK9atCb34SRJmAi1Cr9ox9kylJQtgUjl7tQGFNgKctC6nHB5R7fO3H1qrkkg 1iP760UdgDno5i/G0bEiscspF0Bs7Tkpao9l69JIZWNUCyz6J4nEfWXQD0OtVqkLSP4x pxOIFZZFPrEOUkzaS832Ydv2aEsxL2R/IMnlCLjpcHXxOGfh0sf/GMLOZvNLSWszf6Sg qA0WJmGXkL+tc6rnUKZ5jw3uGMFoFMZfZw7efAoVAYJFEHXGi0FMYBkPTdC1m6tjWCzc 4XvYBkRsUrCnj8ydj4JEFVQL3upoKUHHcwD4IphtLOgagb2V7rPljC0FWi3x8v8vssp/ a18A== X-Gm-Message-State: AOJu0Yw+YPSZH84ufww00quSiWvnE2B2QosCdzUIKrIwoxzlfo6RMTmx 3ic/2rLnPwykX7tB2w65HJv6HHmi43f4d38ri9/IPw== X-Google-Smtp-Source: AGHT+IFeunLcv0yidKwsHM+XnirUPTN4cNqcds3oM0a822vIRq2qQwceVaix4s1QCXWdnjfauXl3Yw== X-Received: by 2002:a05:6e02:1d96:b0:359:4199:1fe2 with SMTP id h22-20020a056e021d9600b0035941991fe2mr15563314ila.8.1699987446961; Tue, 14 Nov 2023 10:44:06 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id e97-20020a02866a000000b0043194542229sm528513jai.52.2023.11.14.10.44.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 10:44:06 -0800 (PST) From: Tom Tromey Date: Tue, 14 Nov 2023 11:44:05 -0700 Subject: [PATCH 3/3] Simplify DAP stop-reason code MIME-Version: 1.0 Message-Id: <20231114-py-stop-reason-v1-3-4ff440c956a9@adacore.com> References: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> In-Reply-To: <20231114-py-stop-reason-v1-0-4ff440c956a9@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Now that gdb adds stop-reason details to stop events, we can simplify the DAP code to emit correct stop reasons in its own events. For the most part a simple renaming of gdb reasons is sufficient; however, "pause" must still be handled specially. --- gdb/python/lib/gdb/dap/events.py | 79 +++++++++++++++++++++++++--------------- gdb/python/lib/gdb/dap/launch.py | 4 +- gdb/python/lib/gdb/dap/next.py | 10 ++--- gdb/python/lib/gdb/dap/pause.py | 4 +- 4 files changed, 57 insertions(+), 40 deletions(-) diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index e9ddcab135f..bdd2a6ebadc 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -99,60 +99,79 @@ def _cont(event): ) -class StopKinds(enum.Enum): - # The values here are chosen to follow the DAP spec. - STEP = "step" - BREAKPOINT = "breakpoint" - PAUSE = "pause" - EXCEPTION = "exception" - - -_expected_stop = None - - -@in_gdb_thread -def expect_stop(reason): - """Indicate that a stop is expected, for the reason given.""" - global _expected_stop - _expected_stop = reason +_expected_pause = False # A wrapper for Invoker that also sets the expected stop. class ExecutionInvoker(Invoker): - """A subclass of Invoker that sets the expected stop. - Note that this assumes that the command will restart the inferior, - so it will also cause ContinuedEvents to be suppressed.""" + """A subclass of Invoker that sets the continue-suppression flag. - def __init__(self, cmd, expected): + When EXPECTED_PAUSE is True, a stop that looks like a pause (e.g., + a SIGINT) will be reported as "pause" instead. + """ + + def __init__(self, cmd, expected_pause=False): super().__init__(cmd) - self.expected = expected + self.expected_pause = expected_pause @in_gdb_thread def __call__(self): - expect_stop(self.expected) + global _expected_pause + _expected_pause = self.expected_pause global _suppress_cont _suppress_cont = True # FIXME if the call fails should we clear _suppress_cont? super().__call__() +# Map from gdb stop reasons to DAP stop reasons. Some of these can't +# be seen ordinarily in DAP -- only if the client lets the user toggle +# some settings (e.g. stop-on-solib-events) or enter commands (e.g., +# 'until'). +stop_reason_map = { + "breakpoint-hit": "breakpoint", + "watchpoint-trigger": "data breakpoint", + "read-watchpoint-trigger": "data breakpoint", + "access-watchpoint-trigger": "data breakpoint", + "function-finished": "step", + "location-reached": "step", + "watchpoint-scope": "data breakpoint", + "end-stepping-range": "step", + "exited-signalled": "exited", + "exited": "exited", + "exited-normally": "exited", + "signal-received": "signal", + "solib-event": "solib", + "fork": "fork", + "vfork": "vfork", + "syscall-entry": "syscall-entry", + "syscall-return": "syscall-return", + "exec": "exec", + "no-history": "no-history", +} + + @in_gdb_thread def _on_stop(event): log("entering _on_stop: " + repr(event)) - global _expected_stop + log(" details: " + repr(event.details)) obj = { "threadId": gdb.selected_thread().global_num, "allThreadsStopped": True, } if isinstance(event, gdb.BreakpointEvent): - # Ignore the expected stop, we hit a breakpoint instead. - _expected_stop = StopKinds.BREAKPOINT obj["hitBreakpointIds"] = [x.number for x in event.breakpoints] - elif _expected_stop is None: - # FIXME what is even correct here - _expected_stop = StopKinds.EXCEPTION - obj["reason"] = _expected_stop.value - _expected_stop = None + global stop_reason_map + reason = event.details["reason"] + global _expected_pause + if ( + _expected_pause + and reason == "signal-received" + and event.details["signal-name"] in ("SIGINT", "SIGSTOP") + ): + obj["reason"] = "pause" + else: + obj["reason"] = stop_reason_map[reason] send_event("stopped", obj) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index d13037fa476..7dead0c7c35 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -88,6 +88,4 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): def config_done(**args): global _program if _program is not None: - # Suppress the continue event, but don't set any particular - # expected stop. - send_gdb(ExecutionInvoker("run", None)) + send_gdb(ExecutionInvoker("run")) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index e5bb8d64da0..76c9360383a 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -15,7 +15,7 @@ import gdb -from .events import StopKinds, ExecutionInvoker +from .events import ExecutionInvoker from .server import capability, request from .startup import in_gdb_thread, send_gdb, send_gdb_with_response from .state import set_thread @@ -57,7 +57,7 @@ def next( cmd = "next" if granularity == "instruction": cmd += "i" - send_gdb(ExecutionInvoker(cmd, StopKinds.STEP)) + send_gdb(ExecutionInvoker(cmd)) @capability("supportsSteppingGranularity") @@ -70,17 +70,17 @@ def step_in( cmd = "step" if granularity == "instruction": cmd += "i" - send_gdb(ExecutionInvoker(cmd, StopKinds.STEP)) + send_gdb(ExecutionInvoker(cmd)) @request("stepOut") def step_out(*, threadId: int, singleThread: bool = False, **args): send_gdb(lambda: _handle_thread_step(threadId, singleThread, True)) - send_gdb(ExecutionInvoker("finish", StopKinds.STEP)) + send_gdb(ExecutionInvoker("finish")) @request("continue") def continue_request(*, threadId: int, singleThread: bool = False, **args): locked = send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread)) - send_gdb(ExecutionInvoker("continue", None)) + send_gdb(ExecutionInvoker("continue")) return {"allThreadsContinued": not locked} diff --git a/gdb/python/lib/gdb/dap/pause.py b/gdb/python/lib/gdb/dap/pause.py index 1e59d630523..a89741cbf69 100644 --- a/gdb/python/lib/gdb/dap/pause.py +++ b/gdb/python/lib/gdb/dap/pause.py @@ -13,11 +13,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from .events import StopKinds, ExecutionInvoker +from .events import ExecutionInvoker from .server import request from .startup import send_gdb @request("pause") def pause(**args): - send_gdb(ExecutionInvoker("interrupt -a", StopKinds.PAUSE)) + send_gdb(ExecutionInvoker("interrupt -a", True))