From patchwork Sun Oct 29 14:50:30 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: 739062 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp743118wrt; Sun, 29 Oct 2023 07:53:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNQFAbGPdbbYa1P/6LdbSKgB7joY8QtVTPK6SECNEyRgfQnUSrq4y5FCIvUV5fSBp1PFbG X-Received: by 2002:a05:622a:1910:b0:41c:d1e7:27b5 with SMTP id w16-20020a05622a191000b0041cd1e727b5mr9663365qtc.25.1698591222534; Sun, 29 Oct 2023 07:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698591222; cv=none; d=google.com; s=arc-20160816; b=ppXeaWlEODXwWaDZvpAAAOA+mciNPHzFuVqRF0qATZXqDI9cS5k/WtMrSSegUZ5iWL IRsbtZCfFpjm6BzpoJzuVEyC/N/e+uWqZGZdgQH9ejDduo9ViNFvGvxa+1ORDvRXvSbJ Li7l0tqDtT1LuBW0l3CPco+X4aymPdgqEIMk1YAQ4QH7+lMbLcskOZjEH/osM1Oj3O8Q KzCFy1ndaZPuBBsLjPhHMXWpZLOeGntmIDAxzXnB3km68COyZhbwknaryLTvgL034pYW bzs0tMiGpCrrN6B/ACSByRHMrgjbPC5TW/8Bq8X2BJOiZMHz1IHFt7yEHqvA5r2M2qeC zbnw== 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=K3iMnzMdyIhqWBXr+FnuiLrqQWudWeq1Fvu4ovgLDXk=; fh=HXrGC0n1X/otZczwhO5oWLGGQ4smVCkZCYybZuA1FAQ=; b=r6Umiq2HJur/oYmifMRAq538UxoQ1osZwV69U3sBM/P3mBL2Ayp/Rnb2fVZKvOQfxo KNPUCHzDTdQs1cgWGwxLiVxxwEDq+r+sdO179hdE6O7sUub2YjlWtvq/y/lM3yGfMZKj wGnVrvvDOIaAWtdKlqK10yNYyPzyu56D2Xo+6zc3zcajRYQ8JQ+ZJ6TOegJKVPll6X1j q76gbbx6lcqIN2pRqS3BAZy3ONa2wy3Hko2e9mzd1UCg86+mQ5or7rCtg0qMPaqSgn0N 9iub9YsxPfYxI6vuXLIOi39qwuq3FD5GtIR2sjTy1TVA/NiZLVhpQqVnw/cRBWgLCCCd k6VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ygOiKp6v; 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 v6-20020a05622a130600b0041cbbbc2eeesi4061725qtk.379.2023.10.29.07.53.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Oct 2023 07:53:42 -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=ygOiKp6v; 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 1qx77s-0007cY-Tw; Sun, 29 Oct 2023 10:50:52 -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 1qx77q-0007ZS-Bm for qemu-devel@nongnu.org; Sun, 29 Oct 2023 10:50:50 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qx77l-00059F-2U for qemu-devel@nongnu.org; Sun, 29 Oct 2023 10:50:50 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40790b0a224so26962225e9.0 for ; Sun, 29 Oct 2023 07:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698591043; x=1699195843; 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=K3iMnzMdyIhqWBXr+FnuiLrqQWudWeq1Fvu4ovgLDXk=; b=ygOiKp6vKy8cUe8PPGSGI8H6GxB5nyAi3PAd9DbfZ2J8ReSqQ7Nelam+BWK1gkOm9Q HvvvCAM+9A48Llr9Z8g/TVAhr/MH79RJIIj5cKG9+K1sb14NXvXvMz6vwnw+xnAigpSE U/Qv5HV3WSxDesMk91g/cNuRvG/nsBnz0EBMwjy8X6ZLQ0nmesv6eAYRgijfrfQzPY4N DHt9lANI/LWe/rtDcHY/VaIXjpJEHX6MQGA5VXe5vj1lXhMfVlnAAo40bVDWKD1tnre1 d6EXeLzz+iWz/9Ha65L3mBAJ+Ss+eLUPhnoFp+5i9N31XiWjnb2sHOL79keWVonuerX4 9h6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698591043; x=1699195843; 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=K3iMnzMdyIhqWBXr+FnuiLrqQWudWeq1Fvu4ovgLDXk=; b=TH8ufBunZPw8QG13Y/rfXx/wbjwQZt6XTUpkHmvgqZlVThRjyKB7IuxtHzyGW1jyMs /wr9PXVueJFMI74eyBNyDnx2U+4mpFhNOTJ51LlGI2KXEr3seSG4BMjRWDEvR4W9jNnr K35c++hcrPtnUI9UVBhp136H2XCFN6V2I4bgNE0LjOPD3Yd9Ps4LKq6+0PHdXBRn15z6 /4AYSnHyekNk/jrbZyEuef7uikD9l4508+FBwui8rLxw5pfevzK2/oefBTAYIpMRs5Yk ZI81VtHVegh1YdhbEbXDDm3cd16hXMwHwiq6WvqW1wdAcv+EjVjdHgFMOy2I9n5XuxgS 6J0Q== X-Gm-Message-State: AOJu0YyG+CL8SByZln8QveAg0Q9hkxAHwNZ6a5J5DVvB7Z46ZT/6klRR Om97/NZEaYy0w9vbg+E0zg29KQ== X-Received: by 2002:a05:600c:4692:b0:409:2c35:7b3e with SMTP id p18-20020a05600c469200b004092c357b3emr5571808wmo.8.1698591043349; Sun, 29 Oct 2023 07:50:43 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id d12-20020a05600c3acc00b004068495910csm10002077wms.23.2023.10.29.07.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 07:50:40 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 9C1515F7A2; Sun, 29 Oct 2023 14:50:35 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Paolo Bonzini , Mahmoud Mandour , Wainer dos Santos Moschetta , Brad Smith , Aleksandar Rikalo , Kyle Evans , Aurelien Jarno , Jiaxun Yang , qemu-arm@nongnu.org, Peter Maydell , Thomas Huth , Warner Losh , "Edgar E. Iglesias" , Eduardo Habkost , =?utf-8?q?Alex_Benn=C3=A9e?= , Beraldo Leal , Brian Cain , Alexandre Iooss , Akihiko Odaki , Fabiano Rosas Subject: [PATCH v2 16/19] gdbstub: Check if gdb_regs is NULL Date: Sun, 29 Oct 2023 14:50:30 +0000 Message-Id: <20231029145033.592566-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231029145033.592566-1-alex.bennee@linaro.org> References: <20231029145033.592566-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.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> Tested-by: Fabiano Rosas Reviewed-by: Richard Henderson Tested-by: Richard Henderson Signed-off-by: Alex Bennée Message-Id: <20231028103311.347104-15-alex.bennee@linaro.org> --- 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;