From patchwork Fri Nov 15 17:29:50 2019 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: 179510 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp12753727ilf; Fri, 15 Nov 2019 09:31:06 -0800 (PST) X-Google-Smtp-Source: APXvYqwxSvtmNkcSxlvEXeOzIRi5bPdqtOJm5oSAladli+HXnlsOtPqd4O+bhXWxWk9Hrx0bOs3R X-Received: by 2002:a1c:1f03:: with SMTP id f3mr15875949wmf.131.1573839066699; Fri, 15 Nov 2019 09:31:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573839066; cv=none; d=google.com; s=arc-20160816; b=Z7xzBy6fklVtk7beyj1UnofkzhVwZk6xKx/Y6ZJPy/eqh1zW1FSzCXVHcyX4PU4qTd lo1HZXFcmbxVjmdnw1lfB7wJIodHrm6QfuD9NGmggqb1TOakffcWT9TN6AjR7u2zmbRf ohTadjodoH6VaqL3Nd8c0JAJtJKonT2TJAnaCy2H1Xrt2GodtI3KH3KQY8niMBvIfAF3 Y2pB0i/dUxk5Z/S5368cxldFJwRaBwoqyZlkGCMM1UNTQecHUYL3i7189kcxIoXuxe2r ideUm1hSy8AsKNspRNbficu/Un72Nc9ZHf9g/15g/Y+ZA1HcY3370j7YaWUfJY0y1edM MwZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=b3lRu2lU9dlRQQ6ScHgKfSG/1eYQg9vd77Swnr8j6IA=; b=Kv7hWamb631XSZb+tNA3MppPFLHf/r6keLDV3CvnfCsf8odX7MqBkThhywxXZovy1l Vp3NILB4ls1k3QmeLKbymdoZNot8haInSefOn5Tw/q5DxFjUWzQTUjGyu2QqEgV0DELZ u1gab7va7EEALXxHZIJcI1iPGOQvnykaKRAh6RTVcY3Kt9nq08I2dZqBdBgaFn4zZM6e 2f5oBLtESdFJ9CxfyJdbRIVzP8muVgS2s6E2o7ZuYAtlbuldE3GSyHxXzuwOyaivWpql 4wk9lFUbU/V/gcBnD39a8j5VTtwP0mU4tow0k6FVii8g5C5Eo2NgKreMSHUMi6kZBUIr /h9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VX4rYQkb; 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=fail (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 g15si7398956edl.95.2019.11.15.09.31.06 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Nov 2019 09:31:06 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b=VX4rYQkb; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVfR2-0007FY-91 for patch@linaro.org; Fri, 15 Nov 2019 12:31:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34425) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVfQ6-0007BH-Ja for qemu-devel@nongnu.org; Fri, 15 Nov 2019 12:30:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iVfQ4-0002i5-Dy for qemu-devel@nongnu.org; Fri, 15 Nov 2019 12:30:06 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:36694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iVfQ4-0002dp-3f for qemu-devel@nongnu.org; Fri, 15 Nov 2019 12:30:04 -0500 Received: by mail-wr1-x444.google.com with SMTP id r10so11851227wrx.3 for ; Fri, 15 Nov 2019 09:30:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b3lRu2lU9dlRQQ6ScHgKfSG/1eYQg9vd77Swnr8j6IA=; b=VX4rYQkbDLJQAzgEhNQU4zCu21NMgPbg7GNdfh8AFd2iMQ7uL2Dm4WX8I2pe1QjjJh tPAmG92LF77wtSOpKpoGYSsGDoxLMjgzuYYRldGRcqkFEXgaS4Ib14FegxGT7Kqs2GvZ W9pzhAUQIhdeNggKOJwB89oZWa2EhxvNnXvzcth41eUdyzGRCM55dnf9arTuvIjRV5dr 8HM7WXNFPNt3EG8mvQAgx+xx4BsEwN3MpiBDFRcNO9Xw1RmZpNWxHznZysUUGHP/lH5u +tWVKyCCXN8UYL2hTXp49ZI3ns6D/7wfNXb9EQgOg3LYglI9CfD+BCoeo1VSBSdiQgGp 9Eiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b3lRu2lU9dlRQQ6ScHgKfSG/1eYQg9vd77Swnr8j6IA=; b=gezzMJAUvAeV2aUQfynr7GeDo59wU3eRpQkaJESZ2o+NJkRObMhwV+fheNQ/pAkq5v zH/b3tm7PR8QtIweX81PWDHaIrvsYTKRNgfFLgM6WgzUXlOTx5bieifJnDmwR5OBrCbD 2UKBoCqRVjcfH8VmbRqVDQsRxUZQlN4Nc3OkRmdGeu6Prco7k9LZUEO2G47hDmkGN9ra 6GpO9qKtKASRwaHuQnHAtbMzBlv3iGUy5gfhfbvqyLmjmtNVVNAdvoY7scFWUvB9sjI1 2bfgw8I66e8Re+gh8SfwKtkN4/gY0Oe3NLszTP1PBT1etnOeXPuydcBQI6NpfM86VeAz ovBw== X-Gm-Message-State: APjAAAVrSWhan58BnsL83IlDz/wjK8PHkRSQropfy4NOnv5hx9BIRNyU HmY1MXBDMON307a6EqY2Eo7uNA== X-Received: by 2002:a5d:4684:: with SMTP id u4mr15846457wrq.352.1573839002363; Fri, 15 Nov 2019 09:30:02 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x11sm12248423wro.84.2019.11.15.09.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 09:30:01 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DC5201FF8C; Fri, 15 Nov 2019 17:30:00 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 01/11] gdbstub: move allocation of GDBState to one place Date: Fri, 15 Nov 2019 17:29:50 +0000 Message-Id: <20191115173000.21891-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191115173000.21891-1-alex.bennee@linaro.org> References: <20191115173000.21891-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , richard.henderson@linaro.org, alan.hayward@arm.com, =?utf-8?q?Alex_Be?= =?utf-8?b?bm7DqWU=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We use g_new0() as it is the preferred form for such allocations. We can also ensure that gdbserver_state is reset in one place. Signed-off-by: Alex Bennée --- gdbstub.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) -- 2.20.1 Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde diff --git a/gdbstub.c b/gdbstub.c index 4cf8af365e2..c5b6701825f 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -374,6 +374,13 @@ static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; static GDBState *gdbserver_state; +static GDBState *gdb_allocate_state(void) +{ + g_assert(!gdbserver_state); + gdbserver_state = g_new0(GDBState, 1); + return gdbserver_state; +} + bool gdb_has_xml; #ifdef CONFIG_USER_ONLY @@ -3083,15 +3090,13 @@ static bool gdb_accept(void) return false; } - s = g_malloc0(sizeof(GDBState)); + s = gdb_allocate_state(); create_default_process(s); s->processes[0].attached = true; s->c_cpu = gdb_first_attached_cpu(s); s->g_cpu = s->c_cpu; s->fd = fd; gdb_has_xml = false; - - gdbserver_state = s; return true; } @@ -3359,8 +3364,7 @@ int gdbserver_start(const char *device) s = gdbserver_state; if (!s) { - s = g_malloc0(sizeof(GDBState)); - gdbserver_state = s; + s = gdb_allocate_state(); qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);