From patchwork Fri Jun 30 18:04:13 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: 697973 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp596898wrs; Fri, 30 Jun 2023 11:14:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Aqk0sM9dqQEX3Yz6Qu6qwtIRCN9ZJ++swucOOeewno3GZ5h6MatimwtI6az1BP38QTqbo X-Received: by 2002:a05:620a:460a:b0:765:5c3a:26d6 with SMTP id br10-20020a05620a460a00b007655c3a26d6mr11823659qkb.12.1688148875480; Fri, 30 Jun 2023 11:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688148875; cv=none; d=google.com; s=arc-20160816; b=ounmsLAnqL6Ubgn9GqT3wgKZqImpiAbQJYUcC4bPqL7n/L5cpVm18PSoamU62gnKva 0wJsk2nrKkUps8Rs1jql5ELSJqnf7MTBO67grNF7PJ5b4KZCBQirMrnO0CKSE8sZEq2a TGrBJ+t2GLLPM6FIjZmdAYqDOe+T4tWEne3CIPP3NxFX10g2M62m8VjUBkzWj/9OwmXt cLwD9yTznwZtUrj+dju1ExvFcLCgKCRFgCHhPf6PbQLfqdbhgiVq60CjRm/ELS82aHJl XSLo6Upsz/zJA4pGpvGVDFDj2yndFiSJTLyAymis4QrqFmTiEzn8lNkHkfnXtKd/BFlM f0hg== 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=FGpbXodwi7eOtwTW0EyiBhg0MRqzyOGDQJmw/dX1YZQ=; fh=OltHerz+Vf7zZkebZbScoRT4WgVwJDskRS7DoEjx2Hw=; b=1DqfJHyKgo1eEWSj7gUXG7ho0JHbHLajahhbU0viSC8544RAhNdTUXCpYdhzVmISV1 dY8SDNdHVWYqIC0fw1MYIAF0wpwudzxup5riSlvLiUVtbmA7ZTb15/Z2PidTlq126djo AfYK6WHdAd9RdDTatFOLsBY0wiePskajY5c8m1OfDAPBc5QFGWvNAs/nWgQH32Gm9CSM dQGD/i00rv24/cLytOLByOB3WqWD7HI7TdzjVwSa51+BDh05fLkC8xCG4hEd7xdGZcBe NvHHuoTqg4b5fkEcQo1NpE0/s8zwdFXoE7oRZqTLMp8Wf8Bx/ENW9uJl/s192Ns16L6Q swIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qbpC3mhD; 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 jl7-20020ad45e87000000b00625c59cf054si7654140qvb.329.2023.06.30.11.14.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 11:14:35 -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=qbpC3mhD; 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 1qFIcx-0005UD-Mh; Fri, 30 Jun 2023 14:13:53 -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 1qFIcg-0005Nu-WA for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:35 -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 1qFIcd-0003Vy-P5 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:34 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbc244d3a8so16979615e9.2 for ; Fri, 30 Jun 2023 11:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688148810; x=1690740810; 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=FGpbXodwi7eOtwTW0EyiBhg0MRqzyOGDQJmw/dX1YZQ=; b=qbpC3mhDVEt4vOC/cNCfXQ7ApVvxwz2j4QDN9+L08kRZB1MAVF36ZMa2vz+RgFQOmc jQr1F9ew6n8s1hpS/1IvW14Lq6A50crqjZ8J9fZ/HQbk7zAI6zDHHewvo0KGqrOcbf7M U+rMtmSBT9pvCedeXNXwwZBhC9G9tQFg5de/PuaniMCXNDV4qyX1auqVbZVN4J0pyS80 FZZGPcp/5tRZVpR6u8bajJ+w+MzRaXU96n2onSkusGFACAt+aOsFysxlvP7sMj+MB6Xs rkqVhhhjiQfuRn55ZdVmNs61mg6+0mqVoQwSikptmJLvPjAjAPlfQbn3YIeRYkvmokD6 BB+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688148810; x=1690740810; 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=FGpbXodwi7eOtwTW0EyiBhg0MRqzyOGDQJmw/dX1YZQ=; b=BeiIdNd6pycDSET/fLWf6t/QLXlFUrd4Vs/PdRnDIY0P79f3RH4DbE9g7mcYJRS5Wg NbHCpKdYwph856kMoGyh0sIXCJQ8wD9PkkpRamKyO4ptvCJHo0Ti2GsUoqBBfz2q5ylK JeLiUZaBad6BmWtyCUxJ4nSzizhOryFtyt661temtRiY4413WgS52q042bCcn+ncoNfq jdtTwn4C27btrNSBnKSEW/neTKVwKSkzXwvzX4yNmdjzToxSQdVGo+T2v+v1P6P0fmxa BVwEddMxpCAtLMNTSc8jSAJJcgm1+C0+IHHdVTUtTeLvM8wLRzaLw8FlJR2cjDln9uF9 s25w== X-Gm-Message-State: AC+VfDy/QhiT1uLo5arpqsWH1yP3BS4KOHc1ofIhFwKC9aEQ+OwNDYR8 eCtCty+PqhAPLcN1rgB11lArAQ== X-Received: by 2002:a05:600c:286:b0:3fb:b6f3:e528 with SMTP id 6-20020a05600c028600b003fbb6f3e528mr2747867wmk.25.1688148810147; Fri, 30 Jun 2023 11:13:30 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id s25-20020a7bc399000000b003fa96fe2bebsm14598535wmj.41.2023.06.30.11.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 11:13:28 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3742A1FFD1; Fri, 30 Jun 2023 19:04:27 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Paolo Bonzini , Stefan Hajnoczi , Leonardo Bras , Laurent Vivier , Peter Xu , Juan Quintela , Beraldo Leal , Radoslaw Biernacki , Qiuhao Li , Peter Maydell , Yanan Wang , Riku Voipio , Wainer dos Santos Moschetta , Mahmoud Mandour , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Eduardo Habkost , Thomas Huth , Laurent Vivier , Bin Meng , Marcel Apfelbaum , Bandan Das , Cleber Rosa , Richard Henderson , Leif Lindholm , Marcin Juszkiewicz , qemu-arm@nongnu.org, Darren Kenny , Alexander Bulekov Subject: [PATCH v4 28/38] gdbstub: lightly refactor connection to avoid snprintf Date: Fri, 30 Jun 2023 19:04:13 +0100 Message-Id: <20230630180423.558337-29-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230630180423.558337-1-alex.bennee@linaro.org> References: <20230630180423.558337-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, 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 This may be a bit too much to avoid an snprintf and the slightly dodgy assign to a const variable. But hopefully not. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v2 - fix checkpatch warning --- gdbstub/softmmu.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index 99d994e6bf..f509b7285d 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -332,11 +332,9 @@ static void create_processes(GDBState *s) int gdbserver_start(const char *device) { - trace_gdbstub_op_start(device); - - char gdbstub_device_name[128]; Chardev *chr = NULL; Chardev *mon_chr; + g_autoptr(GString) cs = g_string_new(device); if (!first_cpu) { error_report("gdbstub: meaningless to attach gdb to a " @@ -350,15 +348,16 @@ int gdbserver_start(const char *device) return -1; } - if (!device) { + if (cs->len == 0) { return -1; } - if (strcmp(device, "none") != 0) { - if (strstart(device, "tcp:", NULL)) { + + trace_gdbstub_op_start(cs->str); + + if (g_strcmp0(cs->str, "none") != 0) { + if (g_str_has_prefix(cs->str, "tcp:")) { /* enforce required TCP attributes */ - snprintf(gdbstub_device_name, sizeof(gdbstub_device_name), - "%s,wait=off,nodelay=on,server=on", device); - device = gdbstub_device_name; + g_string_append_printf(cs, ",wait=off,nodelay=on,server=on"); } #ifndef _WIN32 else if (strcmp(device, "stdio") == 0) { @@ -373,7 +372,7 @@ int gdbserver_start(const char *device) * FIXME: it's a bit weird to allow using a mux chardev here * and implicitly setup a monitor. We may want to break this. */ - chr = qemu_chr_new_noreplay("gdb", device, true, NULL); + chr = qemu_chr_new_noreplay("gdb", cs->str, true, NULL); if (!chr) { return -1; }