debug lists in gdb

Hi there!

I am working with a list l from the STL. In gdb, if I call 'l.front()' I get this message:

1
2
3

Cannot evaluate function -- may be inlined


Why? I have been surfing the net for ages but found nothing.


This is the output of gdb -v and gcc -v, respectively.

1
2
3
4

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)


And this is the compile instruction:

1
2
3

g++ -Wall -g -fno-inline-functions -O0 -std=c++0x  main.cpp -o main


Please help!!

Thank you very much!
g++ -std=c++0x -Wall -Wextra -pedantic-errors -ggdb main.cpp -o main
Hi JLBorges,

Thank you very much for your help! But the problem persists.

This is the actual code:

1
2
3
4
5
6
7
8
#include <list>

int main(){

    std::list<int> l;
    l.push_back(2);
    return 0;
}


If debugging in gdb in the return statement I execute 'print l.front()' I get the same result: 'Cannot evaluate function -- may be inlined'

Anyone could help me??
You can define a helper function:
1
2
3
4
5
6
7
8
9
10
11
12
#include <list>

// template < typename CNTR > const auto& front( const CNTR& cntr ) { return cntr.front() ; }

const int& front( const std::list<int>& cntr ) { return cntr.front() ; }

int main()
{
    std::list<int> l ;
    l.push_back(2);
    return 0;
}

and then call it from within the debugger: print front(l)

If STL support tools are not installed, you may want to install it: https://sourceware.org/gdb/wiki/STLSupport
Hi JLBorges,

Thank you very much again for your help!

I got the same message again. I downloaded this one: http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt and renamed it to dbinit.

Is this script the good one? I applied it with this gdb invocation

1
2
3

 gdb --command=dbinit main


Am I doing something wrong maybe?
> I downloaded this one
> I applied it with this gdb invocation
> Am I doing something wrong maybe?
¿what results did you get?
stl-views only define functions to print containers.

Also
1
2
#   This file should be "included" in .gdbinit as following:
#   source stl-views.gdb or just paste it into your .gdbinit file 
Hi ne555,

The message I get is

 
Cannot evaluate function -- may be inlined


This messaged is shown when I execute 'print l.front()' in gdb.

I expected gdb would print 2 (the list's front) but instead it shows the error message. I have this problem with other STL containers. I just give this simple code as an example.

I tried your solution but still get the same message.

I have been surfing the net for a long time to solve this problem but found nothing
I'm telling you that stl-views would not allow you that.
You may use (gdb) plist l int 0 to emulate that, however.
With http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt
this command should work: p l (print the contents of l in a readable form).

It doesn't provide any support for evaluating l.front() in the debugger.

It is a crude and primitive debugging environment as far as C++ (particularly templates) is concerned; if the code is portable, consider using a Microsoft debugger.
Hi JLBorges

I already tried printing the list in a readable form. But I was looking for something to yield l.front() and other STL Container methods.

Yes, my code is portable. So I can test it with Microsoft compiler.

Thank you all very much!!

Topic archived. No new replies allowed.