From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id b/T3F5wZ2WjgKBcAWB0awg (envelope-from ) for ; Sun, 28 Sep 2025 07:18:52 -0400 Received: by simark.ca (Postfix, from userid 112) id 4D8821E047; Sun, 28 Sep 2025 07:18:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4E15C1E047 for ; Sun, 28 Sep 2025 07:18:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6AFE13858C30 for ; Sun, 28 Sep 2025 11:18:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AFE13858C30 Received: from outboundhk.mxmail.xiaomi.com (outboundhk.mxmail.xiaomi.com [207.226.244.123]) by sourceware.org (Postfix) with ESMTP id 47A8B3858D1E for ; Sun, 28 Sep 2025 11:18:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47A8B3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=xiaomi.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xiaomi.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 47A8B3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.226.244.123 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759058293; cv=none; b=gMAv+tvvoHRDD386gOoyLuAfZBsSaPKlhy6RvvpPikq4+2UWx3EWf5ItewJWm/w+qmJDr2WuC4en/88JETCC+SQbxlhi2FAiT2FKtotmbGOPT6DeTptMlsqxPLQe6h7nU0OZ2n/6t5/HXl+d8bhq7kLttO5JpdAZFA9/FTtbFfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759058293; c=relaxed/simple; bh=QFx/N1AJnu0OnoiH5mR4HQ3mpY/Z3TCIR6C6mOyvlOE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=SYJMSX02jd4KJa3D8TBfH0uVpfZ81UWBDxUk3r6G29ZOz8wX1Te4MC2xHDmKZoOtx7mhrY7pxM3XMBzq4vlIz922Hy32W5jjDfMFWurMACLQc7Z/6Bx/qMuJJLYGSG68ceQQlX83Omk3+8ex6kwULzSuuKlyYQWVp//L635B7e0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47A8B3858D1E X-CSE-ConnectionGUID: vNLgh9i7SCOyvt8xDMyhmA== X-CSE-MsgGUID: s8OgYefoQD62TmxPe7XMsw== X-IronPort-AV: E=Sophos;i="6.18,299,1751212800"; d="scan'208";a="153827394" From: guoshengyuan1 To: CC: guoshengyuan1 Subject: [PATCH] [gdb/python]: add the orginal_value field in RegisterChangedEvent Date: Sun, 28 Sep 2025 19:18:08 +0800 Message-ID: <20250928111808.271065-1-guoshengyuan1@xiaomi.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Originating-IP: [10.149.34.18] X-ClientProxiedBy: yz-mbx01.mioffice.cn (10.237.88.121) To BJ-MBX13.mioffice.cn (10.237.8.133) 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~public-inbox=simark.ca@sourceware.org When the register_changed event is triggered, the user should be told what the previous value was so they can make a decision, rather than just being told what the modified value is. Signed-off-by: guoshengyuan1 --- gdb/doc/python.texi | 3 +++ gdb/observable.h | 4 +++- gdb/python/py-event.h | 2 +- gdb/python/py-inferior.c | 6 ++++-- gdb/python/py-infevents.c | 19 ++++++++++++++++--- gdb/testsuite/gdb.python/py-events.py | 1 + gdb/tui/tui-hooks.c | 4 +++- gdb/valops.c | 4 +++- 8 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 3763eee9d63..1d74910f400 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3979,6 +3979,9 @@ A gdb.Frame object representing the frame in which th= e register was modified. @defvar RegisterChangedEvent.regnum Denotes which register was modified. @end defvar +@defvar RegisterChangedEvent.original_value +Denotes the value of the register before it is modified. +@end defvar @item events.breakpoint_created This is emitted when a new breakpoint has been created. The argument diff --git a/gdb/observable.h b/gdb/observable.h index 4d913010c56..f65d42a2b00 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -20,6 +20,7 @@ #ifndef GDB_OBSERVABLE_H #define GDB_OBSERVABLE_H +#include "gdbsupport/common-types.h" #include "gdbsupport/observable.h" #include "target/waitstatus.h" @@ -222,7 +223,8 @@ extern observable inferior_call_post; /* A register in the inferior has been modified by the gdb user. */ -extern observable +extern observable register_changed; /* The user-selected inferior, thread and/or frame has changed. The diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index 3938368c9ca..2b696e23ff8 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -56,7 +56,7 @@ enum inferior_call_kind extern int emit_inferior_call_event (inferior_call_kind kind, ptid_t thread, CORE_ADDR addr); extern int emit_register_changed_event (const frame_info_ptr &frame, - int regnum); + int regnum, LONGEST original_value)= ; extern int emit_memory_changed_event (CORE_ADDR addr, ssize_t len); extern int evpy_emit_event (PyObject *event, eventregistry_object *registry); diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 2aa11d3160d..91f4bd862e5 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -19,6 +19,7 @@ #include "auto-load.h" #include "gdbcore.h" +#include "gdbsupport/common-types.h" #include "gdbthread.h" #include "inferior.h" #include "objfiles.h" @@ -158,11 +159,12 @@ python_on_memory_change (struct inferior *inferior, C= ORE_ADDR addr, ssize_t len, command). */ static void -python_on_register_change (const frame_info_ptr &frame, int regnum) +python_on_register_change (const frame_info_ptr &frame, int regnum, + LONGEST orginal_value) { gdbpy_enter enter_py (current_inferior ()->arch ()); - if (emit_register_changed_event (frame, regnum) < 0) + if (emit_register_changed_event (frame, regnum, orginal_value) < 0) gdbpy_print_stack (); } diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c index f74fb017edc..424abffcd1c 100644 --- a/gdb/python/py-infevents.c +++ b/gdb/python/py-infevents.c @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . = */ +#include "gdbsupport/common-types.h" #include "py-event.h" /* Construct either a gdb.InferiorCallPreEvent or a @@ -62,7 +63,8 @@ create_inferior_call_event_object (inferior_call_kind fla= g, ptid_t ptid, static gdbpy_ref<> create_register_changed_event_object (const frame_info_ptr &frame, - int regnum) + int regnum, + LONGEST original_value) { gdbpy_ref<> event =3D create_event_object (®ister_changed_event_objec= t_type); if (event =3D=3D NULL) @@ -82,6 +84,15 @@ create_register_changed_event_object (const frame_info_p= tr &frame, if (evpy_add_attribute (event.get (), "regnum", regnum_obj.get ()) < 0) return NULL; + gdbpy_ref<> original_value_obj =3D gdb_py_object_from_longest (original_= value); + if (original_value_obj =3D=3D NULL) + return NULL; + + auto original_value_status =3D evpy_add_attribute + (event.get (), "original_value", original_value_obj.get ()); + if (original_value_status < 0) + return NULL; + return event; } @@ -150,12 +161,14 @@ emit_memory_changed_event (CORE_ADDR addr, ssize_t le= n) will create a new Python register changed event object. */ int -emit_register_changed_event (const frame_info_ptr &frame, int regnum) +emit_register_changed_event (const frame_info_ptr &frame, int regnum, + LONGEST original_value) { if (evregpy_no_listeners_p (gdb_py_events.register_changed)) return 0; - gdbpy_ref<> event =3D create_register_changed_event_object (frame, regnu= m); + gdbpy_ref<> event =3D create_register_changed_event_object + (frame, regnum, original_value); if (event !=3D NULL) return evpy_emit_event (event.get (), gdb_py_events.register_changed); return -1; diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.pyth= on/py-events.py index 0573b16659b..663b9fb2119 100644 --- a/gdb/testsuite/gdb.python/py-events.py +++ b/gdb/testsuite/gdb.python/py-events.py @@ -90,6 +90,7 @@ def register_changed_handler(event): assert isinstance(event.frame, gdb.Frame) print("frame: %s" % (event.frame)) print("num: %s" % (event.regnum)) + print("num: %s" % (event.original_value)) def memory_changed_handler(event): diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c index 024fedd9955..e6bc56a26d4 100644 --- a/gdb/tui/tui-hooks.c +++ b/gdb/tui/tui-hooks.c @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . = */ +#include "gdbsupport/common-types.h" #include "symtab.h" #include "inferior.h" #include "symfile.h" @@ -47,7 +48,8 @@ tui_new_objfile_hook (struct objfile* objfile) /* Observer for the register_changed notification. */ static void -tui_register_changed (const frame_info_ptr &frame, int regno) +tui_register_changed (const frame_info_ptr &frame, int regno, + LONGEST original_value) { frame_info_ptr fi; diff --git a/gdb/valops.c b/gdb/valops.c index fa87546770a..df8582336d2 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1194,6 +1194,8 @@ value_assign (struct value *toval, struct value *from= val) { frame_info_ptr next_frame =3D frame_find_by_id (toval->next_frame_i= d ()); int value_reg =3D toval->regnum (); + const auto original_value_reg =3D value_as_long + (get_frame_register_value(frame_find_by_id(old_frame), value_reg)= ); if (next_frame =3D=3D nullptr) error (_("Value being assigned to is no longer active.")); @@ -1255,7 +1257,7 @@ value_assign (struct value *toval, struct value *from= val) } gdb::observers::register_changed.notify - (get_prev_frame_always (next_frame), value_reg); + (get_prev_frame_always (next_frame), value_reg, original_value_re= g); break; } -- 2.47.3 #/******=B1=BE=D3=CA=BC=FE=BC=B0=C6=E4=B8=BD=BC=FE=BA=AC=D3=D0=D0=A1=C3=D7= =B9=AB=CB=BE=B5=C4=B1=A3=C3=DC=D0=C5=CF=A2=A3=AC=BD=F6=CF=DE=D3=DA=B7=A2=CB= =CD=B8=F8=C9=CF=C3=E6=B5=D8=D6=B7=D6=D0=C1=D0=B3=F6=B5=C4=B8=F6=C8=CB=BB=F2= =C8=BA=D7=E9=A1=A3=BD=FB=D6=B9=C8=CE=BA=CE=C6=E4=CB=FB=C8=CB=D2=D4=C8=CE=BA= =CE=D0=CE=CA=BD=CA=B9=D3=C3=A3=A8=B0=FC=C0=A8=B5=AB=B2=BB=CF=DE=D3=DA=C8=AB= =B2=BF=BB=F2=B2=BF=B7=D6=B5=D8=D0=B9=C2=B6=A1=A2=B8=B4=D6=C6=A1=A2=BB=F2=C9= =A2=B7=A2=A3=A9=B1=BE=D3=CA=BC=FE=D6=D0=B5=C4=D0=C5=CF=A2=A1=A3=C8=E7=B9=FB= =C4=FA=B4=ED=CA=D5=C1=CB=B1=BE=D3=CA=BC=FE=A3=AC=C7=EB=C4=FA=C1=A2=BC=B4=B5= =E7=BB=B0=BB=F2=D3=CA=BC=FE=CD=A8=D6=AA=B7=A2=BC=FE=C8=CB=B2=A2=C9=BE=B3=FD= =B1=BE=D3=CA=BC=FE=A3=A1 This e-mail and its attachments contain confidenti= al information from XIAOMI, which is intended only for the person or entity= whose address is listed above. Any use of the information contained herein= in any way (including, but not limited to, total or partial disclosure, re= production, or dissemination) by persons other than the intended recipient(= s) is prohibited. If you receive this e-mail in error, please notify the se= nder by phone or email immediately and delete it!******/#