From patchwork Thu Nov 2 09:02:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?5qKB6ZWH?= X-Patchwork-Id: 78916 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 08C943858418 for ; Thu, 2 Nov 2023 09:02:34 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from t03.bc.larksuite.com (t03.bc.larksuite.com [209.127.231.35]) by sourceware.org (Postfix) with UTF8SMTPS id DB8C43858D28 for ; Thu, 2 Nov 2023 09:02:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB8C43858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=spacemit.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=spacemit.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB8C43858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.127.231.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698915741; cv=none; b=IH7QL9qMx5V2tzaMaqtGId6IThpo2yevZmgktxuauSVCznHJAiwdSQck4bqez1PFzB88ddP3aa7mRYfuqKr5n2dXnFYAqEyoo7n228WJ35sEeedVT4iXQcvIDuJVwIIeTBtuYCiZd12vuWgOT5P9bazdlRbY/ufxD8zKcL9YUNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698915741; c=relaxed/simple; bh=K4eph7T/BhUsmJCsLC8+Kyw55XFs0G3wc4+DXgG4GFA=; h=DKIM-Signature:Mime-Version:Message-Id:To:From:Date:Subject; b=xtnqIdyyhx/bVrkF8E0Gff11mNG3g2qaLfuGOCA5xlzmRhZia8aVyV0/KHeKHcjEpSokByx/0EO5ZLifA7X2YtZShOne0k+EvMpp/2l0mSj1O2ry4wvQ4MnbwhzAXArb9jC6zmtjh7l2sk+joobSoaql92s7d5yk6Q3wSuMBGNA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2303021642; d=spacemit.com; t=1698915727; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=K4eph7T/BhUsmJCsLC8+Kyw55XFs0G3wc4+DXgG4GFA=; b=MESpm/w/SWtu5Y3UenMdauhm81v5b6Y1MjmXBtzP0izaJzharNHXcPxJYmIS4fmwUV0WyD PBLkt2qGHD+GwECcGa1fwJ5hRk6TzBc3mFQjou/qGnq87e8NlDPF1GMvGLM2pp5RhaH09M 9Th0VkwvnhFUjpz2q5Mp0UxRghGZNzExeGfttZXZC+VtpuF0vgtryZpPwCjU8i2bOdk9ng nsPYCI6ziMq+Cti+zAPb5eF1AamvocS8gw4iOF/VqeiiRhDLUJYAj2KTcjxkXkkRUstZrv Z8iHodBCX0006E2XTo3SmVgsTw2+kgedJrgxPcToBudg4b2WB7338LlMIBCulg== Cc: =?utf-8?b?5bqE56eL5b2s?= Mime-Version: 1.0 Message-Id: To: "gdb-patches@sourceware.org" From: =?utf-8?b?5qKB6ZWH?= X-Lms-Return-Path: Date: Thu, 02 Nov 2023 17:02:05 +0800 Subject: [PATCH] [gdb/riscv-tdep] Avoid scan invalid prologue X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_50, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, 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 When running gdb connect to openocd, I run into: (gdb) set debug remote 1 (gdb) set *0x40000000=0 [remote] Sending packet: $m0,2#fb [remote] Packet received: 7310 [remote] Sending packet: $m2,2#fd [remote] Packet received: 4030 [remote] Sending packet: $X40000000,0:#72 [remote] Packet received: OK [remote] check_binary_download: binary downloading supported by target [remote] Sending packet: $X40000000,4:\000\000\000\000#76 [remote] Packet received: OK [remote] Sending packet: $g#67 [remote] Packet received: 0000000000000000820a000000000000201e002000000000000000000000000000000000000000002500000000000000601f002000000000b11e0020000000000000000000000000781e0020000000008d01000000000000781e0020000000000100000000000000f40100000000000000040000000000000100000000000000070000000000000000000000000000000100000000000000ff2f000000000000f4010000000000001400011000000000000001100000000000000000000000000d000000000000004000000000000000000000000000000000000000000000006e89000000000000981f00200000000043000000000000000000000000000000 [16 bytes omitted] [remote] Sending packet: $m0,2#fb [remote] Packet received: 7310 [remote] Sending packet: $m2,2#fd [remote] Packet received: 4030 It means that this operation has performed some invalid operations, and in some cases it will cause the system to slow down. When I file and load xxx.elf into, run again: (gdb) set *0x40000000=0 [remote] Sending packet: $X40000000,4:\000\000\000\000#76 [remote] Packet received: OK [remote] Sending packet: $g#67 [remote] Packet received: 0000000000000000820a000000000000201e002000000000000000000000000000000000000000002500000000000000601f002000000000b11e0020000000000000000000000000781e0020000000008d01000000000000781e0020000000000100000000000000f40100000000000000040000000000000100000000000000070000000000000000000000000000000100000000000000ff2f000000000000f4010000000000001400011000000000000001100000000000000000000000000d000000000000004000000000000000000000000000000000000000000000006e89000000000000981f00200000000043000000000000000000000000000000 [16 bytes omitted] When I debug gdb hit in riscv_frame_cache: { ... /* Scan the prologue, filling in the cache.  */ start_addr = get_frame_func (this_frame); pc = get_frame_pc (this_frame); riscv_scan_prologue (gdbarch, start_addr, pc, cache); start_addr -> get_frame_func -> get_frame_func_if_available -> get_pc_function_start (pc = 0x40000000) -> return 0 So that scan invalid prologue, filling in the cache. ---  gdb/riscv-tdep.c | 5 ++++-  1 file changed, 4 insertions(+), 1 deletion(-) --• 2.25.1 This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking. 本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。 diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 3a2891c2c92..ebd1fc950e0 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -3723,6 +3723,8 @@ riscv_frame_cache (frame_info_ptr this_frame, void **this_cache) •    /* Scan the prologue, filling in the cache.  */    start_addr = get_frame_func (this_frame); +  if (start_addr == 0) +    return NULL;    pc = get_frame_pc (this_frame);    riscv_scan_prologue (gdbarch, start_addr, pc, cache); • @@ -3776,7 +3778,8 @@ riscv_frame_this_id (frame_info_ptr this_frame,    try      {        cache = riscv_frame_cache (this_frame, prologue_cache); -      *this_id = cache->this_id; +      if (cache) +-->    *this_id = cache->this_id;      }    catch (const gdb_exception_error &ex)      {