Bug 24331 - set print elements not honoured in case of repeated elements
Summary: set print elements not honoured in case of repeated elements
Status: ASSIGNED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Paul Pluzhnikov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-14 09:56 UTC by Marco Barisione
Modified: 2019-06-24 00:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-06-24 00:00:00


Attachments
Reproducer (125 bytes, text/x-csrc)
2019-03-14 09:56 UTC, Marco Barisione
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Barisione 2019-03-14 09:56:46 UTC
Created attachment 11670 [details]
Reproducer

Sometimes, printing a char array prints more characters that what is set with "set print elements".

For example, if you have a "const char my_string[]" you get this:

(gdb) p my_string
$1 = "hello world"
(gdb) set print elements 5
(gdb) p my_string
$2 = "hello"...
(gdb) set print elements 4
(gdb) p my_string
$3 = "hell"...
(gdb) set print elements 3
(gdb) p my_string
$4 = "hell"...                  (Ops!)
(gdb) set print elements 2
(gdb) p my_string
$5 = "he"...

The bug seems related to the "l" being repeated. If I change the string to "helXo world" the problem doesn't happen.

This does not happen if I change my_string to be "const char *my_string".

I can reproduce both with Ubuntu's 8.1 and with git master.
Comment 1 Paul Pluzhnikov 2019-06-24 00:24:30 UTC
Confirmed using current trunk.

In generic_printstr(), this loop advances "i" past options->print_max if the last character has repeat count > 1:

2760	  while (i < options->print_max)
2761	    {
2762	      int r;
2763
2764	      QUIT;
2765
2766	      /* Grab the next character and repeat count.  */
2767	      r = count_next_character (&iter, &converted_chars);
2768
2769	      /* If less than zero, the end of the input string was reached.  */
2770	      if (r < 0)
2771		break;
2772
2773	      /* Otherwise, add the count to the total print count and get
2774		 the next character.  */
2775	      i += r;
2776	    }