Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 532660 - sys-devel/gdb-7.7.1 - strange printing of a number in a string
Summary: sys-devel/gdb-7.7.1 - strange printing of a number in a string
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-15 19:46 UTC by georg
Modified: 2015-02-20 15:49 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
test source code (main.c,174 bytes, text/plain)
2014-12-15 19:46 UTC, georg
Details
gdb emerge info (gdb.info.txt,5.46 KB, text/plain)
2014-12-15 19:48 UTC, georg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description georg 2014-12-15 19:46:28 UTC
The printing of variables inside gdb is sometimes very ugly.

Reproducible: Always

Steps to Reproduce:
1. compile attached program (gcc main.c -g -O0 -o test)
2. attach debugger (gdb test)
3. run until you pass the sprintf line
4. print v and buffer
Actual Results:  
 print v
$1 = 5.4000000000000004
print buffer
$2 = "5.40000000\000\377\377\177\000\000\230\221\244\367\377\177\000\000X\246\377\367\377\177\000\000H\341\377\367\377\177\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\375\006@\000\000\000\000\000\377\262\360", '\000' <repeats 13 times>, "\260\006@\000\000\000\000\000\020\005@\000\000\000\000\000`\340\377\377"


Expected Results:  
 print v
$1 = 5.4000000000000004
 print buffer
$2 = 5.40000000

It seems to be related to the pretty printing code.
Comment 1 georg 2014-12-15 19:46:54 UTC
Created attachment 391786 [details]
test source code
Comment 2 georg 2014-12-15 19:48:24 UTC
Created attachment 391788 [details]
gdb emerge info
Comment 3 georg 2014-12-15 19:50:39 UTC
I am uncertain if this is a bug which should be reported upstream or if it is related to some patch from gentoo ...
Comment 4 georg 2014-12-15 20:00:07 UTC
I got aware of such issue as i debugged some c++ application. See this snippet.

[INFO ] mgr::impl::check_create_config: int_config exists
[DEBUG] set sql: INSERT INTO myStructType (id, val1, val2, number, name) values ('100', '3.3999999999999999', '5.5999999999999996', '42', 'Georg')

Breakpoint 2, base::entity::mgr::impl::set (this=0x628d60, id=100, name="myStructType", desc=std::vector of length 4, capacity 4 = {...}, fnames=std::vector of length 4, capacity 4 = {...}, 
    values=std::vector of length 4, capacity 4 = {...}) at /home/georg/Dokumente/Entwicklung/misc/Comp/src/base/entity-mgr.cpp:201
201             char* err;
(gdb) print sql
$1 = "INSERT INTO myStructType (id, val1, val2, number, name) values ('100', '3.3", '9' <repeats 15 times>, "', '5.5", '9' <repeats 14 times>, "6', '42', 'Georg')"

I got
print sql
$1 = "INSERT INTO myStructType (id, val1, val2, number, name) values ('100', '3.3", '9' <repeats 15 times>, "', '5.5", '9' <repeats 14 times>, "6', '42', 'Georg')"

I expected
print sql
$1 = "INSERT INTO myStructType (id, val1, val2, number, name) values ('100', '3.3999999999999999', '5.5999999999999996', '42', 'Georg')"
Comment 5 SpanKY gentoo-dev 2015-02-20 15:49:21 UTC
it's a fixed size buffer, so gdb prints out the whole thing.  if you cast it to a pointer w/out a size, it displays as you expect:
(gdb) print (char *)buffer
$4 = 0x7fffffffcb10 "5.40000000"

there might be some option controlling this behavior, but i'd have to read the manual to find out