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.
Created attachment 391786 [details] test source code
Created attachment 391788 [details] gdb emerge info
I am uncertain if this is a bug which should be reported upstream or if it is related to some patch from gentoo ...
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')"
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