Why gdb inside emacs cannot print out c++ object?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Why gdb inside emacs cannot print out c++ object?

Kevin Gao
Hello folks,

I hit an issue when debugging c++ code using gdb inside emacs.

Suppose: p is c++ iterator of an object of multimap<int, pair<string,
string>>;

inside emacs gdb (with many windows on), "p p" returns:
*$1 = {_M_node = 0x555555775fa0}*, which is meaningless to me.

As a comparison, in raw gdb (etc gdb ./a.out), "p p" returns:
*$1 = {first = 1, second = {first = "foo", second = "bar"}}*, which is what
I want to see.

Why gdb inside emacs cannot print out c++ object? Seems emacs does some
special setting which turns off c++ mode?

This is really a blocking issue for C++ debug. Please share you idea.

Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: Why gdb inside emacs cannot print out c++ object?

Eli Zaretskii
> From: Kevin Gao <[hidden email]>
> Date: Thu, 14 Mar 2019 00:04:29 -0700
>
> Suppose: p is c++ iterator of an object of multimap<int, pair<string,
> string>>;
>
> inside emacs gdb (with many windows on), "p p" returns:
> *$1 = {_M_node = 0x555555775fa0}*, which is meaningless to me.
>
> As a comparison, in raw gdb (etc gdb ./a.out), "p p" returns:
> *$1 = {first = 1, second = {first = "foo", second = "bar"}}*, which is what
> I want to see.
>
> Why gdb inside emacs cannot print out c++ object? Seems emacs does some
> special setting which turns off c++ mode?

Does it work if you invoke GDB with "M-x gud-gdb" instead of "M-x gdb"?

Reply | Threaded
Open this post in threaded view
|

Re: Why gdb inside emacs cannot print out c++ object?

Kevin Gao
Seems sth wrong with my machine. Sorry for the false report.

May I ask a related question? In the local windows, instead of showing the
value, it shows "<complex data type>". Is it possible to show the value of
c++ object? (eg a std::map's value)

Thanks,
Kevin


On Thu, Mar 14, 2019 at 8:00 AM Eli Zaretskii <[hidden email]> wrote:

> > From: Kevin Gao <[hidden email]>
> > Date: Thu, 14 Mar 2019 00:04:29 -0700
> >
> > Suppose: p is c++ iterator of an object of multimap<int, pair<string,
> > string>>;
> >
> > inside emacs gdb (with many windows on), "p p" returns:
> > *$1 = {_M_node = 0x555555775fa0}*, which is meaningless to me.
> >
> > As a comparison, in raw gdb (etc gdb ./a.out), "p p" returns:
> > *$1 = {first = 1, second = {first = "foo", second = "bar"}}*, which is
> what
> > I want to see.
> >
> > Why gdb inside emacs cannot print out c++ object? Seems emacs does some
> > special setting which turns off c++ mode?
>
> Does it work if you invoke GDB with "M-x gud-gdb" instead of "M-x gdb"?
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Why gdb inside emacs cannot print out c++ object?

Eli Zaretskii
> From: Kevin Gao <[hidden email]>
> Date: Fri, 15 Mar 2019 16:46:30 -0700
> Cc: [hidden email]
>
> Seems sth wrong with my machine. Sorry for the false report.

So the problem went away somehow?

> May I ask a related question? In the local windows, instead of showing the value, it shows "<complex data
> type>". Is it possible to show the value of c++ object? (eg a std::map's value)

I think in these cases you need to provide your own pretty-printer.
See the node "Pretty Printing" in the GDB manual.  Looks like the GCC
folks already wrote such pretty-printers, see this stackoverflow
discussion:

  https://stackoverflow.com/questions/11606048/how-to-pretty-print-stl-containers-in-gdb

Reply | Threaded
Open this post in threaded view
|

Re: Why gdb inside emacs cannot print out c++ object?

Kevin Gao
Thanks, the original problem has gone away.

About the link you shared:

etc this code.

*#include <map>*
*#include <string>*
*int main() {*
*    std::map<std::string, std::string> m = {{"aaa", "bbb"}};*
*    auto p = m.begin();*
*    return 0;*
*}*

gdb in emacs can print the value which "p" points. gdb prints out "*$1 =
{first = "aaa", second = "bbb"}*"

Emacs speedbar can show the value correctly. Speedbar shows "*p {first =
"aaa", second = "bbb"}*'

The issue is: gud -> locals window cannot show the value correctly. It shows
*std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > const,
std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >   p <complex data type>*

Do you know if it is possible for locals window to show correct value which
p points to? locals windows is more handy than gdb command and emacs
speedbar.

Thanks,
Kevin


On Sat, Mar 16, 2019 at 1:17 AM Eli Zaretskii <[hidden email]> wrote:

> > From: Kevin Gao <[hidden email]>
> > Date: Fri, 15 Mar 2019 16:46:30 -0700
> > Cc: [hidden email]
> >
> > Seems sth wrong with my machine. Sorry for the false report.
>
> So the problem went away somehow?
>
> > May I ask a related question? In the local windows, instead of showing
> the value, it shows "<complex data
> > type>". Is it possible to show the value of c++ object? (eg a std::map's
> value)
>
> I think in these cases you need to provide your own pretty-printer.
> See the node "Pretty Printing" in the GDB manual.  Looks like the GCC
> folks already wrote such pretty-printers, see this stackoverflow
> discussion:
>
>
> https://stackoverflow.com/questions/11606048/how-to-pretty-print-stl-containers-in-gdb
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Why gdb inside emacs cannot print out c++ object?

Kevin Gao
For now, I use gdb command "info locals" as workaround. which is able to
print out C++ objects. etc it prints out


*m = std::map with 1 element = {["aaa"] = "bbb"}*
*p = {first = "aaa", second = "bbb"}*

I wish emacs gud window, locals cannot show the same thing.

Thanks,
Kevin


On Sat, Mar 16, 2019 at 5:48 PM Kevin Gao <[hidden email]> wrote:

> Thanks, the original problem has gone away.
>
> About the link you shared:
>
> etc this code.
>
> *#include <map>*
> *#include <string>*
> *int main() {*
> *    std::map<std::string, std::string> m = {{"aaa", "bbb"}};*
> *    auto p = m.begin();*
> *    return 0;*
> *}*
>
> gdb in emacs can print the value which "p" points. gdb prints out "*$1 =
> {first = "aaa", second = "bbb"}*"
>
> Emacs speedbar can show the value correctly. Speedbar shows "*p {first =
> "aaa", second = "bbb"}*'
>
> The issue is: gud -> locals window cannot show the value correctly. It
> shows
> *std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char> > const,
> std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> > > >   p <complex data type>*
>
> Do you know if it is possible for locals window to show correct value
> which p points to? locals windows is more handy than gdb command and emacs
> speedbar.
>
> Thanks,
> Kevin
>
>
> On Sat, Mar 16, 2019 at 1:17 AM Eli Zaretskii <[hidden email]> wrote:
>
>> > From: Kevin Gao <[hidden email]>
>> > Date: Fri, 15 Mar 2019 16:46:30 -0700
>> > Cc: [hidden email]
>> >
>> > Seems sth wrong with my machine. Sorry for the false report.
>>
>> So the problem went away somehow?
>>
>> > May I ask a related question? In the local windows, instead of showing
>> the value, it shows "<complex data
>> > type>". Is it possible to show the value of c++ object? (eg a
>> std::map's value)
>>
>> I think in these cases you need to provide your own pretty-printer.
>> See the node "Pretty Printing" in the GDB manual.  Looks like the GCC
>> folks already wrote such pretty-printers, see this stackoverflow
>> discussion:
>>
>>
>> https://stackoverflow.com/questions/11606048/how-to-pretty-print-stl-containers-in-gdb
>>
>>