From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KGQUMPGF2GZ5EiAAWB0awg (envelope-from ) for ; Wed, 04 Sep 2024 12:08:17 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Jf3RA1Ej; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A1E1D1E353; Wed, 4 Sep 2024 12:08:17 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.1 required=5.0 tests=ARC_SIGNED,ARC_VALID, BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 A1C671E08F for ; Wed, 4 Sep 2024 12:08:16 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37F9A386103C for ; Wed, 4 Sep 2024 16:08:16 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 6D95B3858424 for ; Wed, 4 Sep 2024 16:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D95B3858424 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6D95B3858424 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725466071; cv=none; b=mDDBLsIA4u12px2XWxyq339EhQcnK4VHOLhlhhxQ2iiZ+SWi0GaJhj8HkgiNTiSHoxyTfR6coYeZ0hqq3ap+hrFAmd8vBsnt7vEbTcIPz0jUxvgAT3WmxoITp0C18Hbe+wNkEmZH8K3jx5XzPtrNcb+1YhCfz5T81qP+y0VWTCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725466071; c=relaxed/simple; bh=nmLLg5Zvo63kDFn/4ihJrV5NApOXKbdfYuoi3/6eynQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kiPqjUxAcU1n0iwjkTrQnV7hn7eNcaVIQ/04ZUwlVXffJlIMIQSUPCAurao0HyRvObvR8DGYhTbRw2gg8ZwtmusgAMGXbtGGFMzeBvIK5lV2o3PAeXloHWaqDKWQyUFfi5suocDUrMqTne6J6L2kiauw5naPflLEbgMB4UBdZcM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725466068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nhwEGB6pgqAZM1cpng8W7mSQrXBGBq42rqlaf4KYzgQ=; b=Jf3RA1EjKDVLxkb3ohwTtF4hQGdQ7AcJDiNhHyv0R45+8k+FZFpBqswybDkSp8uwN85HO0 dmaX3VxIDsrvcHhiXxP9R74Tr2Ki+ubNt65CH8UTNRqowkPskPCyzbbpqHFyTpr08WAiAY b1eFknew7d2f8cpMhyVB5X64MOK/LY4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-48-5FzX3pFUOcmLhE74gkK2Wg-1; Wed, 04 Sep 2024 12:07:47 -0400 X-MC-Unique: 5FzX3pFUOcmLhE74gkK2Wg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37496a7daf2so4490036f8f.2 for ; Wed, 04 Sep 2024 09:07:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725466066; x=1726070866; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nhwEGB6pgqAZM1cpng8W7mSQrXBGBq42rqlaf4KYzgQ=; b=I8IEraet4WDE87tUtnYk3ewxyogtCQorC7JrES7A43KQUzQH9TdSEaeJ0Fef4s5xX7 exnVdTfThctiquPt73Jr1by8mqqPGLLhAMf6d2gPhgjbhElRld08Iqi454b4sN49LZN0 VZTBsjSgW6a+lOASz7vOW9p3YmyfNEwTJvKqORDcpMyQ4LD5x2EgkzHmtVuEt6fHw2BV K/qAUr1rHDyqjTEEvTMGp40cK+ekZCJHKQ8Au9ps8VvZEkK9tertZkZA6UfNSdcSHAJv zmZzX64jFS8jJDCFDK8S/U+ZO0xVd2Anhl5a0dFb1yHyO2wtcX38CEUAxuZ7tzmReme5 Xkzw== X-Forwarded-Encrypted: i=1; AJvYcCUX15qr4ODwXuH9HCsf5TZcvs4Cevnap/K105d21qoxLtqN8SL2EhhI6ZgSqW1Gst/uqkoDeETv3DxrZg==@sourceware.org X-Gm-Message-State: AOJu0YxGvzgFDJKG4Hxro2DLPwQXtOq0S+cAkG/sxFFPsUxRQuMlu+gJ rjsm63ac3VuIH3obWODl/2fmQPgnp/TIDJwLug8hWlCxRFjHUrTaXH4p+K1WeiwurNHiJYGCPHJ f/a6f5n8G8rqyuQdS7zZPVYMEYSUR12drca/2qMYUfHqn00EBfhLP/jhLPnU= X-Received: by 2002:adf:e2c6:0:b0:374:c671:2324 with SMTP id ffacd0b85a97d-376dea47305mr3445197f8f.44.1725466065641; Wed, 04 Sep 2024 09:07:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFy4sHcN3PFPSfoZe6V3TwJPgKyq72cFh1wyANpp3y3xn3FsYiCyUYO5SxfY/ihPI466QIAKQ== X-Received: by 2002:adf:e2c6:0:b0:374:c671:2324 with SMTP id ffacd0b85a97d-376dea47305mr3445163f8f.44.1725466064865; Wed, 04 Sep 2024 09:07:44 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bbd46b60bsm134711065e9.1.2024.09.04.09.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 09:07:44 -0700 (PDT) From: Andrew Burgess To: binutils@sourceware.org, gdb-patches@sourceware.org Subject: Re: [PATCH] libiberty: sync with gcc In-Reply-To: References: Date: Wed, 04 Sep 2024 17:07:43 +0100 Message-ID: <87wmjrs8q8.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Andrew Burgess writes: > This syncs binutils-gdb/libiberty with gcc/libiberty up to GCC commit > 64028d626a50410dbf29. This picks up the follow 3 GCC commits: > > ea238096883 (gcc-delete-unused-func) libiberty/argv.c: remove only_whitespace > 5e1d530da87 (gcc-buildargv) libiberty/buildargv: handle input consisting of only white space > a87954610f5 libiberty/buildargv: POSIX behaviour for backslash handling I've gone ahead and checked this in. If there are any issues then let me know. Thanks, Andrew > --- > libiberty/ChangeLog | 21 ++++ > libiberty/argv.c | 113 ++++++++--------- > libiberty/testsuite/test-expandargv.c | 170 ++++++++++++++++++++++---- > 3 files changed, 221 insertions(+), 83 deletions(-) > > diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog > index cdcd4b3ced8..949fec62fe4 100644 > --- a/libiberty/ChangeLog > +++ b/libiberty/ChangeLog > @@ -1,3 +1,24 @@ > +2024-08-05 Andrew Burgess > + > + * argv.c (only_whitespace): Delete. > + > +2024-07-16 Andrew Burgess > + > + * argv.c (buildargv): Treat input of only whitespace as an empty > + argument list. > + (expandargv): Remove work around for intput that is only > + whitespace. > + * testsuite/test-expandargv.c: Add new tests 10, 11, and 12. > + Extend testing to call buildargv in more cases. > + > +2024-07-16 Andrew Burgess > + > + * argv.c (buildargv): Backslashes within single quotes are > + literal, backslashes only escape POSIX defined special characters > + within double quotes, and backslashed newlines should act as line > + continuations. > + * testsuite/test-expandargv.c: Add new tests 7, 8, and 9. > + > 2024-04-02 Tom Tromey > > * cplus-dem.c (cplus_demangle): Try the D demangler with > diff --git a/libiberty/argv.c b/libiberty/argv.c > index 45f16854603..f889432a868 100644 > --- a/libiberty/argv.c > +++ b/libiberty/argv.c > @@ -124,15 +124,6 @@ consume_whitespace (const char **input) > } > } > > -static int > -only_whitespace (const char* input) > -{ > - while (*input != EOS && ISSPACE (*input)) > - input++; > - > - return (*input == EOS); > -} > - > /* > > @deftypefn Extension char** buildargv (char *@var{sp}) > @@ -212,67 +203,74 @@ char **buildargv (const char *input) > argv[argc] = NULL; > } > /* Begin scanning arg */ > - arg = copybuf; > - while (*input != EOS) > + if (*input != EOS) > { > - if (ISSPACE (*input) && !squote && !dquote && !bsquote) > - { > - break; > - } > - else > + arg = copybuf; > + while (*input != EOS) > { > - if (bsquote) > - { > - bsquote = 0; > - *arg++ = *input; > - } > - else if (*input == '\\') > + if (ISSPACE (*input) && !squote && !dquote && !bsquote) > { > - bsquote = 1; > - } > - else if (squote) > - { > - if (*input == '\'') > - { > - squote = 0; > - } > - else > - { > - *arg++ = *input; > - } > + break; > } > - else if (dquote) > + else > { > - if (*input == '"') > + if (bsquote) > { > - dquote = 0; > + bsquote = 0; > + if (*input != '\n') > + *arg++ = *input; > } > - else > + else if (*input == '\\' > + && !squote > + && (!dquote > + || strchr ("$`\"\\\n", *(input + 1)) != NULL)) > { > - *arg++ = *input; > + bsquote = 1; > } > - } > - else > - { > - if (*input == '\'') > + else if (squote) > { > - squote = 1; > + if (*input == '\'') > + { > + squote = 0; > + } > + else > + { > + *arg++ = *input; > + } > } > - else if (*input == '"') > + else if (dquote) > { > - dquote = 1; > + if (*input == '"') > + { > + dquote = 0; > + } > + else > + { > + *arg++ = *input; > + } > } > else > { > - *arg++ = *input; > + if (*input == '\'') > + { > + squote = 1; > + } > + else if (*input == '"') > + { > + dquote = 1; > + } > + else > + { > + *arg++ = *input; > + } > } > + input++; > } > - input++; > } > + *arg = EOS; > + argv[argc] = xstrdup (copybuf); > + argc++; > } > - *arg = EOS; > - argv[argc] = xstrdup (copybuf); > - argc++; > argv[argc] = NULL; > > consume_whitespace (&input); > @@ -435,17 +433,8 @@ expandargv (int *argcp, char ***argvp) > } > /* Add a NUL terminator. */ > buffer[len] = '\0'; > - /* If the file is empty or contains only whitespace, buildargv would > - return a single empty argument. In this context we want no arguments, > - instead. */ > - if (only_whitespace (buffer)) > - { > - file_argv = (char **) xmalloc (sizeof (char *)); > - file_argv[0] = NULL; > - } > - else > - /* Parse the string. */ > - file_argv = buildargv (buffer); > + /* Parse the string. */ > + file_argv = buildargv (buffer); > /* If *ARGVP is not already dynamically allocated, copy it. */ > if (*argvp == original_argv) > *argvp = dupargv (*argvp); > diff --git a/libiberty/testsuite/test-expandargv.c b/libiberty/testsuite/test-expandargv.c > index 1e9cb0a0d5a..ca7031eaf68 100644 > --- a/libiberty/testsuite/test-expandargv.c > +++ b/libiberty/testsuite/test-expandargv.c > @@ -142,6 +142,64 @@ const char *test_data[] = { > "b", > 0, > > + /* Test 7 - No backslash removal within single quotes. */ > + "'a\\$VAR' '\\\"'", /* Test 7 data */ > + ARGV0, > + "@test-expandargv-7.lst", > + 0, > + ARGV0, > + "a\\$VAR", > + "\\\"", > + 0, > + > + /* Test 8 - Remove backslash / newline pairs. */ > + "\"ab\\\ncd\" ef\\\ngh", /* Test 8 data */ > + ARGV0, > + "@test-expandargv-8.lst", > + 0, > + ARGV0, > + "abcd", > + "efgh", > + 0, > + > + /* Test 9 - Backslash within double quotes. */ > + "\"\\$VAR\" \"\\`\" \"\\\"\" \"\\\\\" \"\\n\" \"\\t\"", /* Test 9 data */ > + ARGV0, > + "@test-expandargv-9.lst", > + 0, > + ARGV0, > + "$VAR", > + "`", > + "\"", > + "\\", > + "\\n", > + "\\t", > + 0, > + > + /* Test 10 - Mixed white space characters. */ > + "\t \n \t ", /* Test 10 data */ > + ARGV0, > + "@test-expandargv-10.lst", > + 0, > + ARGV0, > + 0, > + > + /* Test 11 - Single ' ' character. */ > + " ", /* Test 11 data */ > + ARGV0, > + "@test-expandargv-11.lst", > + 0, > + ARGV0, > + 0, > + > + /* Test 12 - Multiple ' ' characters. */ > + " ", /* Test 12 data */ > + ARGV0, > + "@test-expandargv-12.lst", > + 0, > + ARGV0, > + 0, > + > 0 /* Test done marker, don't remove. */ > }; > > @@ -231,6 +289,78 @@ erase_test (int test) > fatal_error (__LINE__, "Failed to erase test file.", errno); > } > > +/* compare_argv: > + TEST is the current test number, and NAME is a short string to identify > + which libibery function is being tested. ARGC_A and ARGV_A describe an > + argument array, and this is compared to ARGC_B and ARGV_B, return 0 if > + the two arrays match, otherwise return 1. */ > + > +static int > +compare_argv (int test, const char *name, int argc_a, char *argv_a[], > + int argc_b, char *argv_b[]) > +{ > + int failed = 0, k; > + > + if (argc_a != argc_b) > + { > + printf ("FAIL: test-%s-%d. Argument count didn't match\n", name, test); > + failed = 1; > + } > + /* Compare each of the argv's ... */ > + else > + for (k = 0; k < argc_a; k++) > + if (strcmp (argv_a[k], argv_b[k]) != 0) > + { > + printf ("FAIL: test-%s-%d. Arguments don't match.\n", name, test); > + failed = 1; > + break; > + } > + > + if (!failed) > + printf ("PASS: test-%s-%d.\n", name, test); > + > + return failed; > +} > + > +/* test_buildargv > + Test the buildargv function from libiberty. TEST is the current test > + number and TEST_INPUT is the string to pass to buildargv (after calling > + run_replaces on it). ARGC_AFTER and ARGV_AFTER are the expected > + results. Return 0 if the test passes, otherwise return 1. */ > + > +static int > +test_buildargv (int test, const char * test_input, int argc_after, > + char *argv_after[]) > +{ > + char * input, ** argv; > + size_t len; > + int argc, failed; > + > + /* Generate RW copy of data for replaces */ > + len = strlen (test_input); > + input = malloc (sizeof (char) * (len + 1)); > + if (input == NULL) > + fatal_error (__LINE__, "Failed to malloc buildargv input buffer.", errno); > + > + memcpy (input, test_input, sizeof (char) * (len + 1)); > + /* Run all possible replaces */ > + run_replaces (input); > + > + /* Split INPUT into separate arguments. */ > + argv = buildargv (input); > + > + /* Count the arguments we got back. */ > + argc = 0; > + while (argv[argc]) > + ++argc; > + > + failed = compare_argv (test, "buildargv", argc_after, argv_after, argc, argv); > + > + free (input); > + freeargv (argv); > + > + return failed; > +} > > /* run_tests: > Run expandargv > @@ -242,12 +372,16 @@ run_tests (const char **test_data) > { > int argc_after, argc_before; > char ** argv_before, ** argv_after; > - int i, j, k, fails, failed; > + int i, j, k, fails; > + const char * input_str; > > i = j = fails = 0; > /* Loop over all the tests */ > while (test_data[j]) > { > + /* Save original input in case we run a buildargv test. */ > + input_str = test_data[j]; > + > /* Write test data */ > writeout_test (i, test_data[j++]); > /* Copy argv before */ > @@ -271,29 +405,23 @@ run_tests (const char **test_data) > for (k = 0; k < argc_after; k++) > run_replaces (argv_after[k]); > > + /* If the test input is just a file to expand then we can also test > + calling buildargv directly as the expected output is equivalent to > + calling buildargv on the contents of the file. > + > + The results of calling buildargv will not include the ARGV0 constant, > + which is why we pass 'argc_after - 1' and 'argv_after + 1', this skips > + over the ARGV0 in the expected results. */ > + if (argc_before == 2) > + fails += test_buildargv (i, input_str, argc_after - 1, argv_after + 1); > + else > + printf ("SKIP: test-buildargv-%d. This test isn't for buildargv\n", i); > + > /* Run test: Expand arguments */ > expandargv (&argc_before, &argv_before); > > - failed = 0; > - /* Compare size first */ > - if (argc_before != argc_after) > - { > - printf ("FAIL: test-expandargv-%d. Number of arguments don't match.\n", i); > - failed++; > - } > - /* Compare each of the argv's ... */ > - else > - for (k = 0; k < argc_after; k++) > - if (strcmp (argv_before[k], argv_after[k]) != 0) > - { > - printf ("FAIL: test-expandargv-%d. Arguments don't match.\n", i); > - failed++; > - } > - > - if (!failed) > - printf ("PASS: test-expandargv-%d.\n", i); > - else > - fails++; > + fails += compare_argv (i, "expandargv", argc_before, argv_before, > + argc_after, argv_after); > > freeargv (argv_before); > freeargv (argv_after); > > base-commit: 40a1603112d2b1d330e11792b5506457d5584648 > -- > 2.25.4