public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
@ 2020-12-05  7:35 ppluzhnikov at google dot com
  2020-12-05 16:40 ` [Bug python/27021] " ppluzhnikov at google dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2020-12-05  7:35 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

            Bug ID: 27021
           Summary: Python Exception <class 'AttributeError'> 'NoneType'
                    object has no attribute 'pointer': when using
                    pretty-printer
           Product: gdb
           Version: 9.1
            Status: NEW
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: ppluzhnikov at google dot com
  Target Milestone: ---

Not sure whether this reproduces at head, but suspect it does.

gdb ./a.out core.111836 
GNU gdb (GDB) Fedora 9.1-6.fc32
...

Reading symbols from ./a.out...
[New LWP 111836]
Core was generated by `./a.out'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007f8589eb89e5 in raise () from /lib64/libc.so.6

Missing separate debuginfos, use: dnf debuginfo-install
glibc-2.31-4.fc32.x86_64 libgcc-10.2.1-6.fc32.x86_64
libstdc++-10.2.1-6.fc32.x86_64

(gdb) p foo_map
$1 = std::map with 2 elements = {[1] = 10, [2] = 20}   <<<=== expected output
(gdb) q

Now install debuginfo and try again (same binary and core):

sudo dnf debuginfo-install glibc-2.31-4.fc32.x86_64 libgcc-10.2.1-6.fc32.x86_64
libstdc++-10.2.1-6.fc32.x86_64

gdb ./a.out core.111836 
GNU gdb (GDB) Fedora 9.1-6.fc32
...

Reading symbols from ./a.out...
[New LWP 111836]
Core was generated by `./a.out'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50        return ret;
(gdb) p foo_map
Python Exception <class 'AttributeError'> 'NoneType' object has no attribute
'pointer':    <<<=== bug
$1 = std::map with 2 elements
(gdb) up
#1  0x00007f8589ea1895 in __GI_abort () at abort.c:79
79            raise (SIGABRT);
(gdb) p foo_map
Python Exception <class 'AttributeError'> 'NoneType' object has no attribute
'pointer':    <<<=== bug
$2 = std::map with 2 elements
(gdb) up
#2  0x000000000040123b in foo () at foo.cc:10
10        abort();
(gdb) p foo_map
$3 = std::map with 2 elements = {[1] = 10, [2] = 20}   <<<=== now works!

(gdb) down
#1  0x00007f8589ea1895 in __GI_abort () at abort.c:79
79            raise (SIGABRT);
(gdb) p foo_map
Python Exception <class 'AttributeError'> 'NoneType' object has no attribute
'pointer':   <<<=== bug
$4 = std::map with 2 elements


It looks like GDB is trying to look up std::map::pointer in the DSO for current
frame despite the symbol being defined in a.out and having nothing to do with
current frame.

Source for a.out:

--- main.cc ---
int foo();
int main() { return foo(); }

--- foo.cc ---
#include <stdlib.h>
#include <map>

std::map<int, int> foo_map;

int foo()
{
  foo_map[1] = 10;
  foo_map[2] = 20;
  abort();
}


Build with 'g++ -g main.cc foo.cc'

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug python/27021] Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
  2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
@ 2020-12-05 16:40 ` ppluzhnikov at google dot com
  2020-12-06 15:08 ` z49x2vmq at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2020-12-05 16:40 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|9.1                         |HEAD

--- Comment #1 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
Simpler test case (no need for two files):

#include <stdlib.h>
#include <map>

std::map<int, int> foo_map;

int main()
{
  foo_map[1] = 10;
  foo_map[2] = 20;
  abort();
}

Also confirmed that current head:
  GNU gdb (GDB) 11.0.50.20201205-git
is affected.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug python/27021] Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
  2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
  2020-12-05 16:40 ` [Bug python/27021] " ppluzhnikov at google dot com
@ 2020-12-06 15:08 ` z49x2vmq at gmail dot com
  2020-12-06 16:58 ` ppluzhnikov at google dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: z49x2vmq at gmail dot com @ 2020-12-06 15:08 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

z49x2vmq at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |z49x2vmq at gmail dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug python/27021] Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
  2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
  2020-12-05 16:40 ` [Bug python/27021] " ppluzhnikov at google dot com
  2020-12-06 15:08 ` z49x2vmq at gmail dot com
@ 2020-12-06 16:58 ` ppluzhnikov at google dot com
  2020-12-08  1:05 ` z49x2vmq at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2020-12-06 16:58 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

--- Comment #2 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
There is a very similar failure when the current frame is in the correct ELF
image, but has the "wrong" language:

--- main.cc ---
#include <map>

extern "C" int foo();
static std::map<int, int> foo_map;

int main()
{
  foo_map[1] = 10;
  foo_map[2] = 20;
  return foo();
}

--- foo.c --- // Note: plain "C"
#include <stdlib.h>

int foo() { abort(); }


gcc -g -c foo.c && g++ -g main.cc foo.o && ./a.out
gdb ./a.out core

GNU gdb (GDB) 11.0.50.20201205-git
...
Reading symbols from a.out...
[New LWP 228379]
Core was generated by `./a.out'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) up
#1  0x00007fb556b98537 in __GI_abort () at abort.c:79
79      abort.c: No such file or directory.
(gdb)
#2  0x000055732abe9942 in foo () at foo.c:3
3       int foo() { abort(); }
(gdb) p foo_map
Python Exception <type 'exceptions.AttributeError'> 'NoneType' object has no
attribute 'pointer':
$1 = std::map with 2 elements

(gdb) info symbol foo
foo in section .text of /tmp/a.out

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug python/27021] Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
  2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
                   ` (2 preceding siblings ...)
  2020-12-06 16:58 ` ppluzhnikov at google dot com
@ 2020-12-08  1:05 ` z49x2vmq at gmail dot com
  2020-12-08  1:11 ` z49x2vmq at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: z49x2vmq at gmail dot com @ 2020-12-08  1:05 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

--- Comment #3 from z49x2vmq at gmail dot com ---
In /usr/share/gcc-10/python/libstdcxx/v6/printers.py, StdMapPrinter.__init__()
accepts val, which is type of gdb.Value. 

When "print foo_map" is executed from c++ frame, val.type is of: 
    "std::map<int, int, std::less<int>, std::allocator<std::pair<int const,
int> > >"

But when "print foo_map" is executed from c frame, val.type is of:
    "class std::map<int, int, std::less<int>, std::allocator<std::pair<int
const, int> > >"

Substring "class " is probablly causing the problem. And "class " comes from
c-typeprint.c:
> static void
> c_type_print_base_1 (struct type *type, struct ui_file *stream,
> 		     int show, int level,
> 		     enum language language,
> 		     const struct type_print_options *flags,
> 		     struct print_offset_data *podata)
> {
> .
> .
> .
>       if (language == language_c || language == language_minimal)
> 	{
> 	  if (type->code () == TYPE_CODE_UNION)
> 	    fprintf_filtered (stream, "union ");
> 	  else if (type->code () == TYPE_CODE_STRUCT)
> 	    {
> 	      if (TYPE_DECLARED_CLASS (type))
> 		fprintf_filtered (stream, "class ");
> ...

Looks like "class " is prepended if "language == language_c". 

I don't know if this should be considered as gdb bug.

Since /usr/share/gcc-10/python/libstdcxx/v6/printers.py belongs to "libstdc++"
package(Fedora), you might file a bug in libstdc++.


Quick workaround would be manually removing "class ", "struct ", "union ", and
"enum " in printers.py:
[1] 
# Starting with the type ORIG, search for the member type NAME.  This
# handles searching upward through superclasses.  This is needed to
# work around http://sourceware.org/bugzilla/show_bug.cgi?id=13615.
def find_type(orig, name):
    typ = orig.strip_typedefs()
    while True:
        # Strip cv-qualifiers.  PR 67440.
        search = '%s::%s' % (typ.unqualified(), name)
        search = re.sub(r'^(class|struct|enum|union) ', "", search)

[2]
# Starting with the type ORIG, search for the member type NAME.  This
# handles searching upward through superclasses.  This is needed to
# work around http://sourceware.org/bugzilla/show_bug.cgi?id=13615.
def find_type(orig, name):
    typ = orig.strip_typedefs()
    while True:
        # Strip cv-qualifiers.  PR 67440.
        search = '%s::%s' % (typ.unqualified(), name)
        search = re.sub(r'^(class|struct|enum|union) ', "", search)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug python/27021] Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
  2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
                   ` (3 preceding siblings ...)
  2020-12-08  1:05 ` z49x2vmq at gmail dot com
@ 2020-12-08  1:11 ` z49x2vmq at gmail dot com
  2020-12-08 18:31 ` simark at simark dot ca
  2020-12-16 12:33 ` rae.kim at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: z49x2vmq at gmail dot com @ 2020-12-08  1:11 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

--- Comment #4 from z49x2vmq at gmail dot com ---
[2]
def lookup_templ_spec(templ, *args):
    """
    Lookup template specialization templ<args...>
    """
    t = '{}<{}>'.format(templ, ', '.join([re.sub(r'^(class|struct|enum|union)
', "", str(a)) for a in args]))
    print(t)
    try:
        return gdb.lookup_type(t)
    except gdb.error as e:
        # Type not found, try again in versioned namespace.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug python/27021] Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
  2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
                   ` (4 preceding siblings ...)
  2020-12-08  1:11 ` z49x2vmq at gmail dot com
@ 2020-12-08 18:31 ` simark at simark dot ca
  2020-12-16 12:33 ` rae.kim at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: simark at simark dot ca @ 2020-12-08 18:31 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

Simon Marchi <simark at simark dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simark at simark dot ca

--- Comment #5 from Simon Marchi <simark at simark dot ca> ---
I don't have time to dig into this, but I think I've seen the same issue when
trying to print an std::list when debugging GDB itself.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug python/27021] Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer
  2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
                   ` (5 preceding siblings ...)
  2020-12-08 18:31 ` simark at simark dot ca
@ 2020-12-16 12:33 ` rae.kim at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: rae.kim at gmail dot com @ 2020-12-16 12:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27021

--- Comment #6 from Rae Kim <rae.kim at gmail dot com> ---

When "info variables foo_map" is executed returned type string doesn't have
"class "

> (gdb) info variables foo_map
> All variables matching regular expression "foo_map":
> 
> File main.c:
> 4:      std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > > foo_map;

Language is changed to the m_language of the symbol during "info variables
foo_map".
(scoped_switch_to_sym_language_if_auto l (sym))

symtab.c:
> 4883    static void
> 4884    print_symbol_info (enum search_domain kind,
> 4885                       struct symbol *sym,
> 4886                       int block, const char *last)
> 4887    {
> 4888      scoped_switch_to_sym_language_if_auto l (sym);
> 4889      struct symtab *s = symbol_symtab (sym);
> 4890
> 4891      if (last != NULL)
> 4892        {

Is it possible to apply something like "scoped_switch_to_sym_language_if_auto"
to pretty print?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-12-16 12:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-05  7:35 [Bug python/27021] New: Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': when using pretty-printer ppluzhnikov at google dot com
2020-12-05 16:40 ` [Bug python/27021] " ppluzhnikov at google dot com
2020-12-06 15:08 ` z49x2vmq at gmail dot com
2020-12-06 16:58 ` ppluzhnikov at google dot com
2020-12-08  1:05 ` z49x2vmq at gmail dot com
2020-12-08  1:11 ` z49x2vmq at gmail dot com
2020-12-08 18:31 ` simark at simark dot ca
2020-12-16 12:33 ` rae.kim at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).