From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +ZmcF5WNcmmnUBAAWB0awg (envelope-from ) for ; Thu, 22 Jan 2026 15:50:29 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=gIM3rTk7; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 5B9E21E0E7; Thu, 22 Jan 2026 15:50:29 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1C8961E089 for ; Thu, 22 Jan 2026 15:50:24 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 5F69A4BC895F for ; Thu, 22 Jan 2026 20:50:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F69A4BC895F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=gIM3rTk7 Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by sourceware.org (Postfix) with ESMTPS id 4070E4BA9001 for ; Thu, 22 Jan 2026 20:49:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4070E4BA9001 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4070E4BA9001 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::2f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769114955; cv=none; b=sMlcvIkYPNPNHTi0wq78ISBJCL6rNWMALapTqqtAiM028T1KePdy7yYOz4+cHhUt9LKdEyhW8jy28ZN+XRq1vv9HnTCCCC2Mgc2/LgNPGwaJzislHlLBcheb0hRV5W4ZmGeB65iaPAwMjg1AmBZ4QTBCHwH0ryHT2qz97F01dbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769114955; c=relaxed/simple; bh=mGDknSTvkoAjftTAURkCWAZA5BM5yk9x+PLCSdG8wxE=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=fkE4Nj+iM82tLoM2rtp90PKH8jOaN6lwyq8PmgritGeiTlmCQYpIO9WnOzdf/GGx13fXC1E2YJoiC6+G1YVyVikxt+YAtP+0kY0WDtwLnAxlB+15ZsBU5yegs9cauYD367dMq/EazR3oGYhWGT1Tymxq/LgmpDli0js7T1Lgik0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4070E4BA9001 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-4075798605aso481784fac.0 for ; Thu, 22 Jan 2026 12:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1769114954; x=1769719754; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Y1A9a4HOKxBDGYLi0QdoA/5fZqRnVtynWyIO0yD1abA=; b=gIM3rTk7uWOcsv2heodQVw2wSMRkftdjYn4KkeFS8t2GymJGhrlBD/43AkWP0gpY+C 3+TMD3EAR3Yml4I0b9L/p8UvaYLJCiN2lh2qvDaNa4lfxtfWKnVm3PCpx+jNomLzUpLE kzwMEV6EB9Y7HdIkKNzuHUOlsUOC3gAB6NPoyg2Rb/L4nXITHFlzsDA+rvJQ7q+ZuG6o wckepel3PGYvawsHjgBPjrlcLu0EnhSLd7BhKtOEXQi9s3Zp+Z05OPV0Jw9610lHST5M fzcs7kGLR/e6mc3gb565g89EG0tv+LBO4DTrbgwEIqheZT7Rbww5G52vr/U4hp2NegSD G/Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769114954; x=1769719754; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Y1A9a4HOKxBDGYLi0QdoA/5fZqRnVtynWyIO0yD1abA=; b=aOPam5uq+a4+kMB/8953wGJ8rzUaEEKxWmTSzp0+XJRj1crSX4LX1P8mXUJMEOdC9P AbNYgrtJepNtDA+zsXryq1DGL7fXBZxSRr5PE8AuPcg43ilH4/6cfcWYiqPvcTJC2zOB InHNQVDMZXafwXZ3CdFNHYg46dYLEeBAaAyRc+1ypID6cV15AwVEIjxvutOd2eqlFVEA 0VaPFI0ega524waW0KzZnShTwUjnGxTHh6TJM2cUY7Ul7J9g1bxzJnF0a43p1lM3T2jJ dFTsgE6M70rH0o8x0kZ/ix9nSpHjZyx00MVTAbhM2IaS1iAYZBg4AGsZinXzwON1sref jItA== X-Gm-Message-State: AOJu0YzLE0WK5uzlOJozJvFcJfaj3GusNs9CEABaKSTkK5laIjGg1Ygp RLF3tf0bcwErBwkOgnMTM2lbGJ3CamX62DdORDPUGGt3+4MKr2oBdrPtWiZ6WoGpVZlZWX31SAk YaT0= X-Gm-Gg: AZuq6aKgw2ABmYX5Rb6mZtSMcrfXs1jqcv/MUNXi8oso1dva74slSXrI9JP+v2l2Fl1 G7mluon/JwxiZocA6LtuPC7nyUJMnSpIDyp/BLkdql5yxtxM5ijfq6IPGcXxJN5h7WSEWNSv/rO mcH1/GcBsMlP8/G28RfUIRzAomHgs5Bh2sB6BqOyVxSDwBdwVlL/spzl3kAUZhU1QJRXr7iEsGe gUtZPqbb+6affSWQgsOYgP8yDeJHlB7vTizU2ohtX+25c8adr31BuoB/RDt4ERt4CxHWVnDObpQ eEDhgtgMw4AvFhevqnTfdLl1S2Razwc3aKvPdPyLd6ayHVqRgQ2rgh/2pSbK3pEZt/9o+YdMK0k Evxu88n8Q9jH/6Q88aCKqpWErsNxUjLr+zoziessNCNF4y96rIrMIoI3Jcem25vY1hfYDPOvB4c h/e5sghSfLIrAmX9QI4KqfkJXlDzXlq59Emur7+269kQ== X-Received: by 2002:a05:6871:6c0d:b0:404:35f0:5a9e with SMTP id 586e51a60fabf-408ab7fb53dmr508302fac.46.1769114954592; Thu, 22 Jan 2026 12:49:14 -0800 (PST) Received: from [192.168.0.26] (97-122-114-32.hlrn.qwest.net. [97.122.114.32]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-408afba74bfsm176755fac.13.2026.01.22.12.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 12:49:14 -0800 (PST) From: Tom Tromey Date: Thu, 22 Jan 2026 13:49:12 -0700 Subject: [PATCH 2/3] Don't make copies when calling find_cmd MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260122-command-no-alloca-v1-2-402aa429bbbf@adacore.com> References: <20260122-command-no-alloca-v1-0-402aa429bbbf@adacore.com> In-Reply-To: <20260122-command-no-alloca-v1-0-402aa429bbbf@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Currently both callers of find_cmd make a temporary string -- one with std::string and one with the dreaded alloca. However, as the previous change to find_cmd points out, these copies are not needed. Remove them and use a string_view instead. --- gdb/cli/cli-decode.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index c9bd610a3ac..f581f128a34 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -2258,7 +2258,6 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist, struct cmd_list_element **result_list, std::string *default_args, int ignore_help_classes, bool lookup_for_completion_p) { - char *command; int len, nfound; struct cmd_list_element *found, *c; bool found_alias = false; @@ -2273,18 +2272,11 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist, if (len == 0) return 0; - /* *text and p now bracket the first command word to lookup (and - it's length is len). We copy this into a local temporary. */ - - - command = (char *) alloca (len + 1); - memcpy (command, *text, len); - command[len] = '\0'; - - /* Look it up. */ + /* *TEXT is the first command word to lookup (and its length is + LEN). Look it up. */ found = 0; nfound = 0; - found = find_cmd (std::string_view (command, len), + found = find_cmd (std::string_view (*text, len), clist, ignore_help_classes, &nfound); /* If nothing matches, we have a simple failure. */ @@ -2666,8 +2658,8 @@ lookup_cmd_composition_1 (const char *text, return 0; /* TEXT is the start of the first command word to lookup (and - it's length is LEN). We copy this into a local temporary. */ - std::string command (text, len); + its length is LEN). */ + std::string_view command (text, len); /* Look it up. */ int nfound = 0; -- 2.52.0