* why so
@ 2009-03-08 13:12 Uladzislau Rezki
2009-03-08 17:21 ` Paul Pluzhnikov
0 siblings, 1 reply; 3+ messages in thread
From: Uladzislau Rezki @ 2009-03-08 13:12 UTC (permalink / raw)
To: gdb
Hello gdb list,
I am stuck with debugging C++ application that uses STL.
So, i have a simple code:
#include <iostream>
static int
test(std::string s)
{
std::cout << s << std::endl;
return 0;
}
int main(int argc, char **argv)
{
std::string a = "hello";
test(a);
return 0;
}
while debugging *test* function, i try to print s variable and
i see following stauff, thought i expect to see "hello":
(gdb) print s.c_str()
$2 = 0xbf9486d8 "\024pR\b"
gdb version is:
demon >>> gdb -v
GNU gdb 6.8-debian
Copyright (C) 2008 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".
demon >>>
thanks in advance.
--
Uladzislau Rezki
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: why so
2009-03-08 13:12 why so Uladzislau Rezki
@ 2009-03-08 17:21 ` Paul Pluzhnikov
2009-03-09 9:24 ` Uladzislau Rezki
0 siblings, 1 reply; 3+ messages in thread
From: Paul Pluzhnikov @ 2009-03-08 17:21 UTC (permalink / raw)
To: Uladzislau Rezki; +Cc: gdb
On Sun, Mar 8, 2009 at 6:12 AM, Uladzislau Rezki <urezki@gmail.com> wrote:
> I am stuck with debugging C++ application that uses STL.
> So, i have a simple code:
>
> #include <iostream>
>
> static int
> test(std::string s)
Note that passing strings by value is very inefficient.
You should probably pass 'const string &' instead, and this will
also cure the glitch you are observing.
> while debugging *test* function, i try to print s variable and
> i see following stauff, thought i expect to see "hello":
>
> (gdb) print s.c_str()
> $2 = 0xbf9486d8 "\024pR\b"
I can reproduce this using gcc-4.3.1, but not 4.2.2 or 4.4.4.
It's a GCC bug: it emits incorrect information for functions that
pass structs by value. I can't find it in GCC bugzilla though.
Cheers,
--
Paul Pluzhnikov
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: why so
2009-03-08 17:21 ` Paul Pluzhnikov
@ 2009-03-09 9:24 ` Uladzislau Rezki
0 siblings, 0 replies; 3+ messages in thread
From: Uladzislau Rezki @ 2009-03-09 9:24 UTC (permalink / raw)
To: Paul Pluzhnikov; +Cc: gdb
On Sun, Mar 8, 2009 at 7:21 PM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:
> On Sun, Mar 8, 2009 at 6:12 AM, Uladzislau Rezki <urezki@gmail.com> wrote:
>
>> I am stuck with debugging C++ application that uses STL.
>> So, i have a simple code:
>>
>> #include <iostream>
>>
>> static int
>> test(std::string s)
>
> Note that passing strings by value is very inefficient.
> You should probably pass 'const string &' instead, and this will
> also cure the glitch you are observing.
>
If i pass "std::string &s', everything will work in my case and i see normal
string, this issue happens just in case 'std::string s'.
Thanks for your answer.
--
Uladzislau Rezki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-03-09 9:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-08 13:12 why so Uladzislau Rezki
2009-03-08 17:21 ` Paul Pluzhnikov
2009-03-09 9:24 ` Uladzislau Rezki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox