Bug 21467 - Display function shows one less byte when the last one is \000
Summary: Display function shows one less byte when the last one is \000
Status: RESOLVED DUPLICATE of bug 16933
Alias: None
Product: gdb
Classification: Unclassified
Component: cli (show other bugs)
Version: 7.1
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 21468 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-05-07 11:06 UTC by Balaco
Modified: 2024-01-10 16:26 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Balaco 2017-05-07 11:06:47 UTC
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:

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

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 zero?

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"
(gdb) 
==


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:
<http://www.gnu.org/software/gdb/bugs/>.
==
Comment 1 Tom Tromey 2018-04-12 19:44:00 UTC
*** Bug 21468 has been marked as a duplicate of this bug. ***
Comment 2 Tom Tromey 2018-04-12 19:45:21 UTC
Does this work the same way for you without the TUI?
And, what does "show print null-stop" say for you?
Comment 3 Tom Tromey 2019-11-14 22:52:01 UTC
Moving - not a TUI bug
Comment 4 Hannes Domani 2024-01-10 16:26:48 UTC
Dup.

*** This bug has been marked as a duplicate of bug 16933 ***