From nobody Wed Nov 27 16:50:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1697710264; cv=none; d=zohomail.com; s=zohoarc; b=Tz7PmJYim2Wm2J3C1Qr6ILkhuMctuHTRpRf5/bKvq0T+poYEakll9gaPLbB7T2OF2O93X81Trb3QVRl9CQ7i8h4sWJOWJm7I/XFSCG4X3CdVwnaGLuXyuB1h8YQkjBLp0rao34mKxybJTPlrjI/NpDhobal7kGAKNvvQ9083Ufg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697710264; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=Y9a4WcM7W3w4Ibv1QcOl1jK0U40rkzZ0nUtw12AhXXI=; b=NIxUc0DR7sfgpkdM9clWpJAQzW6XoSXP9DgWev0bKoHBzTupuWSt8iBtejKHzlfX6bPbHrlBqDSfhY1TK6SsgKr5Jl/SXTv4sv5yjkAy1+r6ZgSu/JjgMXOh4Ps0CNbqTZdjipe4AkA05KBYoBCwwV2yyl4apA6kQRt4G1G3+Mw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697710263981517.658319540675; Thu, 19 Oct 2023 03:11:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtPzJ-0005jC-1Y; Thu, 19 Oct 2023 06:10:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtPzH-0005iz-Ig for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:10:43 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtPzF-0007RN-SW for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:10:43 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c434c33ec0so54266335ad.3 for ; Thu, 19 Oct 2023 03:10:41 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id s15-20020a170902ea0f00b001a5fccab02dsm1534033plg.177.2023.10.19.03.10.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Oct 2023 03:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697710240; x=1698315040; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y9a4WcM7W3w4Ibv1QcOl1jK0U40rkzZ0nUtw12AhXXI=; b=xqL+u/CxqOyKqzPhLnljPHF6SBqU/kp4UZ3Sb0A1R1KetYj9FbDMEvQoM3MEYNijpE 7SroCwUjK+9eLSsDNpgY5aVPIYhCK+mg2ZeSlHa/U11wQS3RGzWXny4hzj5Xlr9fep7A hzh4lqiB5eCv/A0/f8fp/WOWXfik0HjoXf1aG4/T8U17L2HwK0H8FE5+8zZuTiEzcf/6 dItgh+ww9nL7Cef0Tt6MNVwimFWnwPYCLKBnaKCsCYqm/1iorSIdNg5R8qHEd4/XTJ1j vYaaPYnqzLOpXfOtVWaKAf9FqXYJaqYGXWKJLw5IFFwI2paLGOu5dcWvpYHava2fmG2T i5Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697710240; x=1698315040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y9a4WcM7W3w4Ibv1QcOl1jK0U40rkzZ0nUtw12AhXXI=; b=OvYStGiI34GGUHt/TvUu+/Aav8o4+RyYg49hTNNQZIdrHRRSuU/+moLA7xifwhDdM4 DCC0Vh8GvwSmZ/LXhyI2YplDY9rUh8Yf6oXx4wg3crkJBG+7vH/oueblqnvtJfIOJpmx tCJKIBASVdID0R9VAkXP8cPRzOCG7g9RYt7S+OutgbuSOPB45xfPUzCkPix+gcKb8keM Hg/x8RjlJ8e2SZbNAnvZq4NH3Fr55Rl7XoGqR9IlKJnYaWqqFtAwbO9kYSD9UNj7Rc4a 6bS4PLANCeL8GR/s/LHJkgnUQB8axVOc9ul0Ou9twIco5qpzC7MVpXMi1VyY1wXaFt4d OsAg== X-Gm-Message-State: AOJu0YxhH1is+5GdpOTpISY25pa1ey5kOZVDWYJpVuE4HgcYWvojZ569 aBwYEA7QvrpiXMETKR9W2dBI1A== X-Google-Smtp-Source: AGHT+IEtKxAniWbyH0tsxaR17xS08mN4wnZQ+2+Mi8jYnjDuxVCWXmzzDAdRY11Z0BZjylyotGlkrg== X-Received: by 2002:a17:902:ed01:b0:1ca:3d9c:a752 with SMTP id b1-20020a170902ed0100b001ca3d9ca752mr1989457pld.12.1697710240233; Thu, 19 Oct 2023 03:10:40 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Akihiko Odaki Subject: [PATCH v5 1/6] gdbstub: Check if gdb_regs is NULL Date: Thu, 19 Oct 2023 19:10:23 +0900 Message-ID: <20231019101030.128431-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019101030.128431-1-akihiko.odaki@daynix.com> References: <20231019101030.128431-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::634; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1697710266260100003 Content-Type: text/plain; charset="utf-8" cpu->gdb_regs may be NULL if no coprocessor is registered. Fixes: 73c392c26b ("gdbstub: Replace gdb_regs with an array") Signed-off-by: Akihiko Odaki Tested-by: Fabiano Rosas --- gdbstub/gdbstub.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 1e96a71c0c..29540a0284 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -385,12 +385,14 @@ static const char *get_feature_xml(const char *p, con= st char **newp, xml, g_markup_printf_escaped("", cc->gdb_core_xml_file)); - for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { - r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); - g_ptr_array_add( - xml, - g_markup_printf_escaped("", - r->xml)); + if (cpu->gdb_regs) { + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, = i); + g_ptr_array_add( + xml, + g_markup_printf_escaped("", + r->xml)); + } } g_ptr_array_add(xml, g_strdup("")); g_ptr_array_add(xml, NULL); @@ -430,10 +432,12 @@ static int gdb_read_register(CPUState *cpu, GByteArra= y *buf, int reg) return cc->gdb_read_register(cpu, buf, reg); } =20 - for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { - r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); - if (r->base_reg <=3D reg && reg < r->base_reg + r->num_regs) { - return r->get_reg(env, buf, reg - r->base_reg); + if (cpu->gdb_regs) { + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (r->base_reg <=3D reg && reg < r->base_reg + r->num_regs) { + return r->get_reg(env, buf, reg - r->base_reg); + } } } return 0; @@ -449,10 +453,12 @@ static int gdb_write_register(CPUState *cpu, uint8_t = *mem_buf, int reg) return cc->gdb_write_register(cpu, mem_buf, reg); } =20 - for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { - r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); - if (r->base_reg <=3D reg && reg < r->base_reg + r->num_regs) { - return r->set_reg(env, mem_buf, reg - r->base_reg); + if (cpu->gdb_regs) { + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (r->base_reg <=3D reg && reg < r->base_reg + r->num_regs) { + return r->set_reg(env, mem_buf, reg - r->base_reg); + } } } return 0; --=20 2.42.0