From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 624F83858D20; Fri, 20 Jan 2023 19:52:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 624F83858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674244367; bh=dS8TfQK5T/STMUFCo9tbybgkn3L1SWEVBJIJ6LVS8BU=; h=From:To:Subject:Date:From; b=RGb5hoC0vUj3xObYYFkCJBwKUifS+qxVnh+VhPeCWL8RP627xUG2TyCxDlJeCfGwq JTjFUqkCe+0CxC5XPYz4UcH9K5e0m375OpJy0QLRq/KybWXLPhJD1rC2EG5CSE4V7u aS0vQkXogytSlcoJBDqOHt8Pvr9e7AkxTAbBIGCA= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: add user-created frames to stash X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 848ab2ae8afe44843b8d06676604a48e45fa8969 X-Git-Newrev: f649a718522b018bbb09eb96beb103a4f5892a45 Message-Id: <20230120195247.624F83858D20@sourceware.org> Date: Fri, 20 Jan 2023 19:52:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df649a718522b= 018bbb09eb96beb103a4f5892a45 commit f649a718522b018bbb09eb96beb103a4f5892a45 Author: Simon Marchi Date: Tue Dec 13 22:34:36 2022 -0500 gdb: add user-created frames to stash =20 A subsequent patch makes it possible for frame_info_ptr to reinflate user-created frames. If two frame_info_ptr objects wrapping the same user-created frame_info need to do reinflation, we want them to end up pointing to the same frame_info instance, and not create two separate frame_infos. Otherwise, GDB gets confused down the line, as the state kept in one frame_info object starts differing from the other frame_info. =20 Achieve this by making create_new_frame place the user-created frames in the frame stash. This way, when the second frame_info_ptr does reinflation, it will find the existing frame_info object, created by the other frame_info_ptr, in the frame stash. =20 To make the frame stash differentiate between regular and user-created frame infos which would otherwise be equal, change frame_addr_hash and frame_id::operator=3D=3D to account for frame_id::user_created_p. =20 I made create_new_frame look up existing frames in the stash, and only create one if it doesn't find one. The goal is to avoid the "select-frame view"/"info frame view"/"frame view" commands from overriding existing entries into the stash, should the user specify the same frame more than once. This will also help in the subsequent patch that makes frame_info_ptr capable of reinflating user-created frames. It will be able to just call create_new_frame and it will do the right thing. =20 Change-Id: I14ba5799012056c007b4992ecb5c7adafd0c2404 Reviewed-By: Bruno Larsen Diff: --- gdb/frame.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gdb/frame.c b/gdb/frame.c index 4dcfad37cd7..2e6a477ef16 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -240,6 +240,9 @@ frame_addr_hash (const void *ap) hash =3D iterative_hash (&f_id.special_addr, sizeof (f_id.special_addr), hash); =20 + char user_created_p =3D f_id.user_created_p; + hash =3D iterative_hash (&user_created_p, sizeof (user_created_p), hash); + return hash; } =20 @@ -775,6 +778,8 @@ frame_id::operator=3D=3D (const frame_id &r) const else if (artificial_depth !=3D r.artificial_depth) /* If artificial depths are different, the frames must be different. = */ eq =3D false; + else if (user_created_p !=3D r.user_created_p) + eq =3D false; else /* Frames are equal. */ eq =3D true; @@ -1931,6 +1936,14 @@ create_new_frame (CORE_ADDR addr, CORE_ADDR pc) =20 frame_debug_printf ("addr=3D%s, pc=3D%s", hex_string (addr), hex_string = (pc)); =20 + /* Avoid creating duplicate frames, search for an existing frame with th= at id + in the stash. */ + frame_id id =3D frame_id_build (addr, pc); + id.user_created_p =3D 1; + frame_info_ptr frame =3D frame_stash_find (id); + if (frame !=3D nullptr) + return frame; + fi =3D FRAME_OBSTACK_ZALLOC (struct frame_info); =20 fi->next =3D create_sentinel_frame (current_program_space, @@ -1952,8 +1965,10 @@ create_new_frame (CORE_ADDR addr, CORE_ADDR pc) frame_unwind_find_by_frame (frame_info_ptr (fi), &fi->prologue_cache); =20 fi->this_id.p =3D frame_id_status::COMPUTED; - fi->this_id.value =3D frame_id_build (addr, pc); - fi->this_id.value.user_created_p =3D 1; + fi->this_id.value =3D id; + + bool added =3D frame_stash_add (fi); + gdb_assert (added); =20 frame_debug_printf (" -> %s", fi->to_string ().c_str ());