[Bug tui/21467] New: Display function shows one less byte when the last one is \000

dedeco.balaco at yahoo dot com sourceware-bugzilla@sourceware.org
Sun May 7 11:06:00 GMT 2017


            Bug ID: 21467
           Summary: Display function shows one less byte when the last one
                    is \000
           Product: gdb
           Version: 7.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: tui
          Assignee: unassigned at sourceware dot org
          Reporter: dedeco.balaco at yahoo dot com
  Target Milestone: ---

Display function, in GDBTUI, with an @ element, shows one less byte when the
last one is \000.

Showing this is probably easier for all to see it clearly. I will try to make a
few steps to anyone reproduce this problem.

1. Given the file p.c:

#include <stdio.h>
int main(int c, char **v)
    char p[10] = {'a','b','c','d','e',0,0,0,0,0};
    printf("p = \"%s\"\n", p);
    return 0;

compile it with:

gcc -Wall -ggdb p.c

2. Call gdbtui with:

gdbtui a.out

3. Inside gdbtui, do these commands:

disp p[0]@5
disp p[0]@6
disp p[0]@7
disp p[0]@8
disp p[0]@9
disp p[0]@10

Compare the output for each command. The last null byte is not shown. With a
counter given (the "@n"), I expect to *see* all the values I asked. For a small
number of values, it is easy. But with a few more being shown, we must count
all of them to know which is the case: are we seeing the last value or is it

After doing the above steps, the output of the last disp is:

(gdb) disp
6: p[0]@10 = "abcde\000\000\000\000"
5: p[0]@9 = "abcde\000\000\000"
4: p[0]@8 = "abcde\000\000"
3: p[0]@7 = "abcde\000"
2: p[0]@6 = "abcde"
1: p[0]@5 = "abcde"

P.S.: A small observation to something that I did not find a proper place,
"Environment", as pointed at http://www.gnu.org/software/gdb/bugs/ is that the
output of "gdbtui --version" command is:

$ gdbtui --version
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:

You are receiving this mail because:
You are on the CC list for the bug.

More information about the Gdb-prs mailing list