From patchwork Sat Oct 28 10:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 738940 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp302011wrt; Sat, 28 Oct 2023 03:37:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+cRjDlzOqmPBCIOouYdI2ARPHh4FpQk0kVu0tiKb2ET81c/OOc63LsUUBOWjMGdmUMcS/ X-Received: by 2002:ac8:5fc3:0:b0:418:a364:c4ea with SMTP id k3-20020ac85fc3000000b00418a364c4eamr6179451qta.30.1698489428869; Sat, 28 Oct 2023 03:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698489428; cv=none; d=google.com; s=arc-20160816; b=T8g+JTf8eRMLJwGhlwDxxrydcVJBV7fRHMRiPsMRV+nnHTG7edPAhZmmoeknGxVaYj 0asHHyQ47mGX/n9ktZeYppuRvXQck5rDAicKxF3C/mR4t5ldF6qy9JclTjOlYpJ0BrvT GZD3LuWCRL0/Ek46sgndLto+8TazQkPkLhU71NOhPX0UtnTm53/P9UlJKu3yS6TPDooN 2lh+Kk8getWr54XAwsVEE5cvBYOQinyPrB97GNiRZic91QcbpTw87uRne37OXmrwB4Ut 0UWTMo0N5JEaw8+iWdI6TK/NFBhWOuP+Q1AiDPtV6AZn4qFDZnkg3xPref4ivhmu6jnI VydA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M9D0IAeyBl7tCHLFuwBJ3K5ngt4JViKy0HwHpFD6M2Y=; fh=tcRf3N+HoqRYgA1NvQewzEUemSKYLbZXXLWmvSL4NFY=; b=oMLWTAARsDM6H2p+GmdpuROKyTXCZO4UKvuNDijPu3LxnGrv4ErZIq0Jx2FrAzfy15 U7QOsYYqXVN8+xAvoFynyfI/aP1kgoHTySdQwKRJkHqan23J8rXWO44vUXjX0f03MUJ3 8bFFgcCsI6TRACWSidRBdJ9HcmscAxTwRGY8UK39vnKxIM/udmHrYYwYK+VTd0Mm7qsT PDdXtO3z5LjTB5URq1+zvJWRL1JEft5pkl7/pmjQmNTUi7zK43pFrj0AWGja4zZZk+1Y QVFDY3UtxAdhzm7/LwEppm8vi5bEdrac5T49mEXSh9iVwOuBnF7whwZu2DpEC6efP1Qi WTkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ors6grAt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m13-20020a05622a054d00b004122ededdfesi2060630qtx.253.2023.10.28.03.37.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 28 Oct 2023 03:37:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ors6grAt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qwgdM-0006LE-Bw; Sat, 28 Oct 2023 06:33:36 -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 1qwgdG-0006Ii-SC for qemu-devel@nongnu.org; Sat, 28 Oct 2023 06:33:32 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qwgd7-0003AO-2O for qemu-devel@nongnu.org; Sat, 28 Oct 2023 06:33:30 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-507b96095abso4117513e87.3 for ; Sat, 28 Oct 2023 03:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698489199; x=1699093999; 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=M9D0IAeyBl7tCHLFuwBJ3K5ngt4JViKy0HwHpFD6M2Y=; b=ors6grAt5/KN4yOvC5orcw9Tjz4hrOcQQq05skR39BpOho8XecGCeKScN3FM22TI0O kfyiEJdtdkkjE1i/ultBBbPIJehA73sYqNOEAV6AwjpZrpCsoZtnipwb9kh8T8gZzomv WSIA8Fw5n89RoECzgukBcmhT4vukofUbJGJfvRjZ0RUqhGy8DBPEexcqN9F1OviN48MZ F479ZtpytKNQHVs/eg/FqHWv8JRFRuyjI+gbMhfCVVYZ9J/a166BBMhiMrfHwKtDr7Rm t7d6SX0uvbxpZ4IF3JOw/2JkJtDeCTb2ZErP531gDTrJn3+sodMZVFxowJrQMF3yzS3I imZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698489199; x=1699093999; 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=M9D0IAeyBl7tCHLFuwBJ3K5ngt4JViKy0HwHpFD6M2Y=; b=DL79Ze65JD8BOE5p0mZexZt088KD8a6ywVm94NGgk5Ix8cjhlKSiGGsYBXnhPfWKhg MIF+T/Tbs7/Oyb+ba1ylUMkl1FIAQG2NZStQx8YFET0LWJR+nJOURtf/Bpfq1aiiVGk9 tJoogrDKtdZu4SKHcbiDQyNJh4GFNUuyjqznj4mAj1SFWvg1tqP53kczzM1/SUIvoJWZ i0d7BQawwg/W1wXkOV3DrinTLgZuJF7sZBf0u+/KBA7NOvD5afSfqVkeSaXbHIHMREe+ tem9PkZpRLytOaahV1bFH+8VhewVXi+KmUTThWZpengbOHVFB2PoUDu680Tt4b2LxD0o mzSQ== X-Gm-Message-State: AOJu0YyXaxzHW5yN/y5oGl83toLcR0kDiTQMKaJOWE6EOWBIUwr8nrDu mPqcfjB1sDwkNKbu0JT1TYnztA== X-Received: by 2002:ac2:495d:0:b0:507:9787:6779 with SMTP id o29-20020ac2495d000000b0050797876779mr3445417lfi.3.1698489199359; Sat, 28 Oct 2023 03:33:19 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id y15-20020a05600c2b0f00b004083996dad8sm7108076wme.18.2023.10.28.03.33.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 03:33:18 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 638545F798; Sat, 28 Oct 2023 11:33:13 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Beraldo Leal , Mahmoud Mandour , Brian Cain , Paolo Bonzini , Warner Losh , Eduardo Habkost , Alexandre Iooss , "Edgar E. Iglesias" , Kyle Evans , qemu-arm@nongnu.org, Aleksandar Rikalo , Aurelien Jarno , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Richard Henderson , Wainer dos Santos Moschetta , Peter Maydell , Brad Smith , Jiaxun Yang , Thomas Huth , Akihiko Odaki , Fabiano Rosas Subject: [PATCH 14/17] gdbstub: Check if gdb_regs is NULL Date: Sat, 28 Oct 2023 11:33:08 +0100 Message-Id: <20231028103311.347104-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231028103311.347104-1-alex.bennee@linaro.org> References: <20231028103311.347104-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x133.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki 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 Message-Id: <20231019101030.128431-2-akihiko.odaki@daynix.com> Signed-off-by: Alex Bennée Tested-by: Fabiano Rosas Reviewed-by: Richard Henderson Tested-by: Richard Henderson --- 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, const char **newp, xml, g_markup_printf_escaped("", cc->gdb_core_xml_file)); - for (guint i = 0; i < cpu->gdb_regs->len; i++) { - r = &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 = 0; i < cpu->gdb_regs->len; i++) { + r = &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, GByteArray *buf, int reg) return cc->gdb_read_register(cpu, buf, reg); } - for (guint i = 0; i < cpu->gdb_regs->len; i++) { - r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); - if (r->base_reg <= 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 = 0; i < cpu->gdb_regs->len; i++) { + r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (r->base_reg <= 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); } - for (guint i = 0; i < cpu->gdb_regs->len; i++) { - r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); - if (r->base_reg <= 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 = 0; i < cpu->gdb_regs->len; i++) { + r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { + return r->set_reg(env, mem_buf, reg - r->base_reg); + } } } return 0;