This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

STL pretty printing exceptions when running in google test


Hi,


I have an issue getting the STL pretty printing to work when debugging Google tests in GDB. The printing of vector of pointer triggers an exception which creates problems when I run GDB in VSCode (I've however done these tests in a direct GDB debugging session, so it's not a VSCode issue). The following code can be used to illustrate the issue.

Is this a bug in the pretty printer or I'm using it wrong?

Cheers.
========================================
#include <iostream>
#include <vector>

#define RUN_GTEST 0
#if RUN_GTEST
#include "gtest/gtest.h"
#else
#define TEST(a, b)  int RUN_ALL_TESTS()
int RUN_ALL_TESTS();
#endif

using namespace std;
int main(int argc, char **argv) {
#if RUN_GTEST
   ::testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
#else
   RUN_ALL_TESTS();
   return 0;
#endif

}

class A
{
    public:
        A(int a, int b) : aa(a), ab(b) {};
        int aa;
        int ab;
};

TEST(testsuite, my_test)
{
    vector<A*> as;
    as.push_back(new A(4, 5));

    cout << "Value " << as[0]->aa << endl;
}
=======================


With RUN_GTEST = 0 and breaking at line 38

(gdb) p as
$1 = {<No data fields>}
(gdb) p as[0]
$2 = (value_type &) @0x5555557c83e0: 0x5555557c83c0
(gdb) p *as[0]
$3 = {aa = 4, ab = 5}
=========
With RUN_GTEST = 1 and breaking at line 38
(gdb) p as
Python Exception <class 'RuntimeError'> Type is not a template.:
Python Exception <class 'RuntimeError'> Type is not a template.:
$1 = {<No data fields>}
(gdb) p as[0]
$2 = (__gnu_cxx::__alloc_traits::value_type &) @0x5555557c8f40: 0x5555557c8f20
(gdb) p *as[0]
$3 = {aa = 4, ab = 5}
======================

The full python stack trace of the execption is:
Traceback (most recent call last):
  File "/home/pg/gdb_printers/python/libstdcxx/v6/printers.py", line 1356, in __call__
    return self.lookup[basename].invoke(val)
  File "/home/pg/gdb_printers/python/libstdcxx/v6/printers.py", line 1293, in invoke
    return self.function(self.name, value)
  File "/home/pg/gdb_printers/python/libstdcxx/v6/printers.py", line 374, in __init__
    self.is_bool = val.type.template_argument(0).code  == gdb.TYPE_CODE_BOOL
RuntimeError: Type is not a template.
======================

Versions: g++ 7.3.0, gdb: 8.1.0.20180409-git
Compile flags: -g -std=gnu++14 -flto -O0





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]