From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 479543853815 for ; Mon, 15 May 2023 09:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 479543853815 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684143826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wLR3QgD+BrS7sSSUJtbUoe9jss2w7LUthGx1Vc99+q8=; b=IffPp6hBpVBg2usQ5nKQ9Fjspv1CJXFI2zO2h4Y0II4XTV62FYvAlXc+WQc3TIikDU+DgT 6DN4CzykUR/5kkPnpvNZiayrcc/QBd7lbV5gq+ofUq6xViOpdkiwfoFb3O/2I1usW7z9+K y/ovFUI1QZL8oSyGhj4g3MoSWbvmYnE= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-VYt0rlFYNRyIHYAatXEK5g-1; Mon, 15 May 2023 05:43:45 -0400 X-MC-Unique: VYt0rlFYNRyIHYAatXEK5g-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-307cea53cf4so2710857f8f.3 for ; Mon, 15 May 2023 02:43:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684143824; x=1686735824; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wLR3QgD+BrS7sSSUJtbUoe9jss2w7LUthGx1Vc99+q8=; b=KJ01Xtf797ezlSCwtn9jTzSYFvt7ZU4ZE7ujNdW87OE9ysW8yd0TgVcmCtrq4IiZBp Jcf4W4j137YUbeIXJ4tbo9QFho80Ac9W8YKfXnXZsDdRCXO21dJAbfaxHs2+HXUyzqMe qCTp6axodrm+HXJ2zD3oNuHu44BxhTL+H0aZgQl9tIQva4lVXQJf3waMwSPDFAqwpMRi BEGx6mKloOTnW+ggXqbaZtQqq9f3j2B4+60Z33d8QCVTACI9vNLS3HIcfDR9npKuoqYt hejgwff+54v7PBvVYULtt3kVAdtGjFsHE3siN16FZTCzBuucTJpM/suKjOGEoIqFIJsH 4Aww== X-Gm-Message-State: AC+VfDx2Bu9pmA8YCPmFTopBFpvmDyneCzuYzsrdnArADJtnJxLfGo87 qTF3VtVG3ZAyqRL+NemP4TGkNr18/E5n86PCSz8Uu4KfI3udZ92hxamHLzcLD0aqaEdx68KB5m/ u9Zix9byk3Qb7nXsTNAgHnCIztEkXeUe96QSn9iOt/yBLUQ6DuKgCUg6tDmNkmGilcJ7UGcWYU/ qtqNsPAQ== X-Received: by 2002:adf:eec8:0:b0:306:2b0f:5d48 with SMTP id a8-20020adfeec8000000b003062b0f5d48mr22165709wrp.26.1684143824261; Mon, 15 May 2023 02:43:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jH7IWYXa4kea4gGNcWGIcQO+96Un+GOq+qVk88vXlmyjpltkzZWt37uAH3GMT7I4AVjQXkA== X-Received: by 2002:adf:eec8:0:b0:306:2b0f:5d48 with SMTP id a8-20020adfeec8000000b003062b0f5d48mr22165690wrp.26.1684143823790; Mon, 15 May 2023 02:43:43 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id p8-20020a056000018800b002f28de9f73bsm32410603wrx.55.2023.05.15.02.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:43:43 -0700 (PDT) From: Andrew Burgess To: Paul Pluzhnikov via Gdb-patches , gdb-patches@sourceware.org Cc: Paul Pluzhnikov Subject: Re: [PATCH] Fix bad interaction between element limit and repeated values (BZ#24331). In-Reply-To: <20230508012211.3770553-1-ppluzhnikov@google.com> References: <20230508012211.3770553-1-ppluzhnikov@google.com> Date: Mon, 15 May 2023 10:43:41 +0100 Message-ID: <87a5y653qq.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Paul Pluzhnikov via Gdb-patches writes: > Currently > > print -elements=3 -- "AAAAAA" > > prints complete string, which is not what the user asked for. > > Fix two buggy tests exposed by the fix, and add a new test. > --- > gdb/testsuite/gdb.base/printcmds.exp | 15 +++++++++++++ > gdb/testsuite/gdb.python/py-format-string.exp | 2 +- > gdb/valprint.c | 22 ++++++++++++++----- > 3 files changed, 33 insertions(+), 6 deletions(-) > > diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp > index db57769c303..f2be549f2a5 100644 > --- a/gdb/testsuite/gdb.base/printcmds.exp > +++ b/gdb/testsuite/gdb.base/printcmds.exp > @@ -1027,6 +1027,9 @@ proc test_repeat_bytes {} { > set fmt(SR) "\"%s\", %s" > set fmt(SS) "\"%s%s\"" > > + # We have up to 60 elements to print. > + gdb_test_no_output "set print elements 100" > + > # Set the target-charset to ASCII, because the output varies from > # different charset. > with_target_charset "ASCII" { > @@ -1074,6 +1077,17 @@ proc test_repeat_bytes {} { > } > } > > +# Test for BZ#24331 It's fine to reference the bug, but could you expand this comment to say what's actually being tested, e.g. # Test that 'set elements' correctly limits the number of characters # printed from a string. This is PR gdb/24331. > +proc test_repeat_bytes_limit {} { > + gdb_test "print -elem 3 -- \"AAAAA\"" "= \"AAA\"..." > + gdb_test "print -char 3 -elem 10 -- \"AAAAA\"" "= \"AAA\"..." > + gdb_test "print -elem 3 -- \"ABBBB\"" "= \"ABB\"..." > + gdb_test "print -char 3 -elem 10 -- \"ABBBB\"" "= \"ABB\"..." > + > + gdb_test "print -elem 3 -repeats 2 -- \"AAABBB\"" "= 'A' ..." > + gdb_test "print -elem 4 -repeats 2 -- \"AAABBB\"" "= 'A' , 'B' " > +} > + > # Test printf of convenience variables. > # These tests can be done with or without a running inferior. > # PREFIX ensures uniqueness of test names. > @@ -1199,3 +1213,4 @@ test_printf_with_strings > test_print_symbol > test_repeat_bytes > test_radices > +test_repeat_bytes_limit > diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp > index 1d50f59dee3..2a011ebd45a 100644 > --- a/gdb/testsuite/gdb.python/py-format-string.exp > +++ b/gdb/testsuite/gdb.python/py-format-string.exp > @@ -748,7 +748,7 @@ proc test_max_string_one { setting unlimited } { > # This will print four characters instead of three, see > # . This comment seems to be out of date now and likely needs updating. Thanks, Andrew > check_format_string "a_binary_string_array" $opts \ > - "\"hell\"..." > + "\"hel\"..." > check_format_string "a_big_string" $opts \ > [get_cut_big_string 3] > if { $setting == "elements"} { > diff --git a/gdb/valprint.c b/gdb/valprint.c > index b05d90dd26b..b770c93d805 100644 > --- a/gdb/valprint.c > +++ b/gdb/valprint.c > @@ -2363,16 +2363,19 @@ print_converted_chars_to_obstack (struct obstack *obstack, > const std::vector &chars, > int quote_char, int width, > enum bfd_endian byte_order, > - const struct value_print_options *options) > + const struct value_print_options *options, > + int *finished) > { > - unsigned int idx; > + unsigned int idx, num_elements; > const converted_character *elem; > enum {START, SINGLE, REPEAT, INCOMPLETE, FINISH} state, last; > gdb_wchar_t wide_quote_char = gdb_btowc (quote_char); > bool need_escape = false; > + const int print_max = options->print_max_chars > 0 > + ? options->print_max_chars : options->print_max; > > /* Set the start state. */ > - idx = 0; > + idx = num_elements = 0; > last = state = START; > elem = NULL; > > @@ -2400,7 +2403,13 @@ print_converted_chars_to_obstack (struct obstack *obstack, > obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t)); > } > /* Output the character. */ > - for (j = 0; j < elem->repeat_count; ++j) > + int repeat_count = elem->repeat_count; > + if (print_max < repeat_count + num_elements) > + { > + repeat_count = print_max - num_elements; > + *finished = 0; > + } > + for (j = 0; j < repeat_count; ++j) > { > if (elem->result == wchar_iterate_ok) > print_wchar (elem->chars[0], elem->buf, elem->buflen, width, > @@ -2408,6 +2417,7 @@ print_converted_chars_to_obstack (struct obstack *obstack, > else > print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, > byte_order, obstack, quote_char, &need_escape); > + num_elements += 1; > } > } > break; > @@ -2439,6 +2449,7 @@ print_converted_chars_to_obstack (struct obstack *obstack, > obstack_grow_wstr (obstack, LCST ("'")); > std::string s = string_printf (_(" "), > elem->repeat_count); > + num_elements += elem->repeat_count; > for (j = 0; s[j]; ++j) > { > gdb_wchar_t w = gdb_btowc (s[j]); > @@ -2463,6 +2474,7 @@ print_converted_chars_to_obstack (struct obstack *obstack, > print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, byte_order, > obstack, 0, &need_escape); > obstack_grow_wstr (obstack, LCST (">")); > + num_elements += 1; > > /* We do not attempt to output anything after this. */ > state = FINISH; > @@ -2597,7 +2609,7 @@ generic_printstr (struct ui_file *stream, struct type *type, > > /* Print the output string to the obstack. */ > print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char, > - width, byte_order, options); > + width, byte_order, options, &finished); > > if (force_ellipses || !finished) > obstack_grow_wstr (&wchar_buf, LCST ("...")); > -- > 2.40.1.521.gf1e218fcd8-goog