From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B50953857413 for ; Fri, 11 Mar 2022 16:31:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B50953857413 Received: by mail-io1-xd33.google.com with SMTP id x4so10666157iop.7 for ; Fri, 11 Mar 2022 08:31:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ui7Vz4hmhn91zMUULJIMa/mn60mW+wTmMv72HWkPTlk=; b=a3EyOGLNYYyHJGkScMfIrKw2z+7gZMyzh2tLF0MExIVqZdMgyAV2t1svTTmLRrcG98 9Ksj5ULZm+1ao+3kKaCeuWfzQmW2jWxyxXc6Aa/iOEDj9KQ1vrR0sQI7qI7vsIsUHJhd 3oeMc8P3F7DTSfJTwy40NsGyj4dJrW6mJ1nlmF34H8mMpA5F0ZRv2iceemZQqrGHSaEf JzCN2bg88NSQmgxy5H73k1zml8ATCL1YcAv5VJ5arKaiIeFJQAEErZ3RERNbw05f8VN5 gC/8OpJlgIIMrIvFUJmGIouLnYcgAnKylDki6rFUcsTa42fGofOoIwpdzfs9PCzZv9fi bhNg== X-Gm-Message-State: AOAM531456/382tQ+P42Rlpmek7zmH0YGYA+HNzpU1LMpHsQZrwNAFu+ 0L5G+OVAgxaH6pENjMLbYwl1zoeRvi2pkA== X-Google-Smtp-Source: ABdhPJzjF/bUEMR7OrfRHm1jC89HJ96jNfSnEvMMGHHp8kuat/jMFlmhB/vEqMub2kxCuylQALqlxw== X-Received: by 2002:a02:19c6:0:b0:30e:e6a5:67ad with SMTP id b189-20020a0219c6000000b0030ee6a567admr9202631jab.45.1647016295991; Fri, 11 Mar 2022 08:31:35 -0800 (PST) Received: from murgatroyd.Home (75-166-141-253.hlrn.qwest.net. [75.166.141.253]) by smtp.gmail.com with ESMTPSA id k15-20020a92c24f000000b002c76d6bc354sm2337190ilo.86.2022.03.11.08.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 08:31:35 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Implement gdbarch_stack_frame_destroyed_p for aarch64 Date: Fri, 11 Mar 2022 09:31:33 -0700 Message-Id: <20220311163133.668809-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 11 Mar 2022 16:31:38 -0000 The internal AdaCore testsuite has a test that checks that an out-of-scope watchpoint is deleted. This fails on some aarch64 configurations, reporting an extra stop: (gdb) continue Continuing. Thread 3 hit Watchpoint 2: result Old value = 64 New value = 0 0x0000000040021648 in pck.get_val (seed=0, off_by_one=false) at [...]/pck.adb:13 13 end Get_Val; I believe what is happening here is that the variable is stored at: DW_AT_location : 2 byte block: 91 7c (DW_OP_fbreg: -4) and the extra stop is reported just before a return, when the ldp instruction is executed: 0x0000000040021644 <+204>: ldp x29, x30, [sp], #48 0x0000000040021648 <+208>: ret This instruction modifies the frame base calculation, and so the test picks up whatever memory is pointed to in the callee frame. Implementing the gdbarch hook gdbarch_stack_frame_destroyed_p fixes this problem. As usual with this sort of patch, it has passed internal testing, but I don't have a good way to try it with dejagnu. So, I don't know whether some existing test covers this. I suspect there must be one, but it's also worth noting that this test passes for aarch64 in some configurations -- I don't know what causes one to fail and another to succeed. --- gdb/aarch64-tdep.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index b3efb3ebaff..5effa95d71b 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3379,6 +3379,25 @@ aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum) || regnum == AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base)); } +/* Implement the stack_frame_destroyed_p gdbarch method. */ + +static int +aarch64_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + CORE_ADDR func_start, func_end; + if (!find_pc_partial_function (pc, NULL, &func_start, &func_end)) + return 0; + + enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch); + uint32_t insn = read_memory_unsigned_integer (pc, 4, byte_order_for_code); + + aarch64_inst inst; + if (aarch64_decode_insn (insn, &inst, 1, nullptr) != 0) + return 0; + + return streq (inst.opcode->name, "ret"); +} + /* Initialize the current architecture based on INFO. If possible, re-use an architecture from ARCHES, which is a list of architectures already created during this debugging session. @@ -3585,6 +3604,9 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); set_gdbarch_type_align (gdbarch, aarch64_type_align); + /* Detect whether PC is at a point where the stack has been destroyed. */ + set_gdbarch_stack_frame_destroyed_p (gdbarch, aarch64_stack_frame_destroyed_p); + /* Internal <-> external register number maps. */ set_gdbarch_dwarf2_reg_to_regnum (gdbarch, aarch64_dwarf_reg_to_regnum); -- 2.34.1