From patchwork Tue Oct 31 14:43:58 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: 739576 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1688159wrt; Tue, 31 Oct 2023 07:47:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgnJTOX+CrDHoKx+VRTGPQ+CfsTun183PfZHxJgIbd+4yoDXrZWfitPJImuwJv5d4UVRzS X-Received: by 2002:a05:622a:44f:b0:412:1e51:8fef with SMTP id o15-20020a05622a044f00b004121e518fefmr14578362qtx.30.1698763629798; Tue, 31 Oct 2023 07:47:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698763629; cv=none; d=google.com; s=arc-20160816; b=t/oDuZbQ8TyB+PAUMXotT0YI7w0dIQu73OhpUI8gLefh1TH3f33qLXyuCRufLcLtG3 a/tdb42/sunfeXBuAqtuEPoQiyx48oZOx1nI0UN0xy3SHvYYWqDxtHsagla3BH+jH9gf temgn8XqIEQtDS0QSv4dKFsKqUwILShxeOaBrXGmxeVYgIez9pHhoTPT3gW1wJ4og++O gb52tzcMvmxovm/EgRoo8X1+w6F3bvKNaj5gZb+EfcVHGV+OSJyMdj5cgxZs1J5SiN4s bHVn9znogWpuhNaUCIGEHon62my1Wty6+UmJB0afICxwCM3MmnEYS/XREopPyp7ZX7zW iNTQ== 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=LVt32BVhuMD6mZN5AcPveEcpa9SvvyPpVXag3OAT//A=; fh=SzlSU5amjcbxiAlyeAEUroviu/QzYjQp8F+rgY0sMA8=; b=d6/O/qporc8VThsUhsITlM62bSFoY80KkatwWMocC6WLY4Fp7SL5uEKawN5I/gZxs/ oncNRKwXbAYwmEwIq2Seb02OBFOK7mAdiI80N4v31BXGuCyQ3JxiBSNCASvaI78hqHa7 hyI6VrAVBoDZ8u232JgAcj5RZNGRx6mMRjdD+534auGDgxihH5ICvyxqZpQLajhBgy/j jTAPGEdxGlq5vpwrhgFJ2zBWVKyWX/vPy6jBnL3y55VGR6oVL2sPCJWWfyL4F9x7+ewR TTuilYEfv2UxVj46exIjta8XRTzezP7J+nsTU4Gs7psaibFyKvmg2z8WtpTjwJYQmcbp LJOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cITNaC7p; 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 l6-20020a05622a174600b0041cbbcb8088si1232441qtk.242.2023.10.31.07.47.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Oct 2023 07:47:09 -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=cITNaC7p; 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 1qxpyf-0004tT-SP; Tue, 31 Oct 2023 10:44:21 -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 1qxpyd-0004sn-M8 for qemu-devel@nongnu.org; Tue, 31 Oct 2023 10:44:19 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxpyb-0002D1-TK for qemu-devel@nongnu.org; Tue, 31 Oct 2023 10:44:19 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4084e49a5e5so47188915e9.3 for ; Tue, 31 Oct 2023 07:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698763456; x=1699368256; 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=LVt32BVhuMD6mZN5AcPveEcpa9SvvyPpVXag3OAT//A=; b=cITNaC7pCBNqLeY0DcyGQyEPB2xSoGUt4KH94Yk4qvZH+tL13oIX6K7PlGGVMC/EBs xVh0aHO73yfCcDjE663gVuBoz40QYEt2So/O6BYDLlgHXwjdZFJCX/fLG42b6auB4w4k 8ei6czSde7FXcEXjBYXObKJcvVcqDJnCgUj71FMAIN+f4Bz/7UFqn+zyZtNEGEN452MZ dkGFdozX/xEt5Gs96QMOojsZZ4npFBVu7RVjZRW6qoLBepYu2wpfn+Eb94KGcFsAsfMw Ht2XFDC522oW5Alc8IHNJrVIoDDqbwyS10GoRPt4svmGz2ZNYWs949y84mT0Au3qwAFR Xk6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698763456; x=1699368256; 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=LVt32BVhuMD6mZN5AcPveEcpa9SvvyPpVXag3OAT//A=; b=n2UrqPi8ml4+YUd4Yb/O66hMVabfbL92/xvkkI2fSOZUMyhdO0/xAQTkdRy6MKrf2s V/OgJo9s+kyOPNzu8w6JdRVBXosQ431wEm48HmYKyl8ovxK5JtCYBkRwvKILiCZRqHud Z0Qe6wDc6qzq0buyfWtGDe6W8c8b/iqzuC4+mBMnf8Yvw9QQCVsjqsOIdksegOQXJ3I5 b1w4sAPGLK39y61Ee/XQlZUsGcq93AI99GKQvTZaJZstt2hvTZT9qqRnCAD3GdtrERHA uCgDwfW0vaJJyBzKU2VupQjSzdjmfXt7TFYgKoZXHiNXx4tDMGIGSjPiDAgnPr0b0O3H lEVw== X-Gm-Message-State: AOJu0YxlXwEkKZyeqXozqGUonRfX2DXfiRbQgRpf81e6/Rtjxhns1mO0 1g8kbJp2Wr4V3DN8mwrN7Iuyzg== X-Received: by 2002:adf:f7c3:0:b0:329:6dbc:e9a8 with SMTP id a3-20020adff7c3000000b003296dbce9a8mr10352317wrq.8.1698763456591; Tue, 31 Oct 2023 07:44:16 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id o8-20020adfe808000000b0031980294e9fsm1647761wrm.116.2023.10.31.07.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 07:44:12 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 532346572F; Tue, 31 Oct 2023 14:44:03 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Fabiano Rosas , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 16/19] gdbstub: Check if gdb_regs is NULL Date: Tue, 31 Oct 2023 14:43:58 +0000 Message-Id: <20231031144401.1238210-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231031144401.1238210-1-alex.bennee@linaro.org> References: <20231031144401.1238210-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.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, T_SCC_BODY_TEXT_LINE=-0.01 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: <20231029145033.592566-17-alex.bennee@linaro.org> Message-Id: <20231019101030.128431-2-akihiko.odaki@daynix.com> Tested-by: Fabiano Rosas Reviewed-by: Richard Henderson Tested-by: Richard Henderson Signed-off-by: Alex Bennée 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;