This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB 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]

[Bug python/20622] New: Misleading error for pointer arithmetic with float operand from Python3


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

            Bug ID: 20622
           Summary: Misleading error for pointer arithmetic with float
                    operand from Python3
           Product: gdb
           Version: 7.10.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: jwakely.gcc at gmail dot com
  Target Milestone: ---

tmp$ cat ptr.c
int main()
{
  int i = 0;
  int* p = &i;
  return *p;
}

tmp$ gcc -g ptr.c
tmp$ gdb -q ./a.out
Reading symbols from ./a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x4004fa: file ptr.c, line 3.
Starting program: /tmp/a.out 

Temporary breakpoint 1, main () at ptr.c:3
3         int i = 0;
(gdb) n
4         int* p = &i;
(gdb) n
5         return *p;
(gdb) python p = gdb.parse_and_eval('p') ; offset = 1/4 ; p = p + offset
Traceback (most recent call last):
  File "<string>", line 1, in <module>
gdb.error: Argument to arithmetic operation not a number or boolean.
Error while executing Python code.

The error comes from
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/valarith.c;h=de6fcfd79abb2f3b6a1b341c36736ac949826cf3;hb=HEAD#l960

"Not a number" is highly confusing, because it certainly is a number. The
problem is that with Python 3 it's a float:

(gdb) python print(type(offset))
<class 'float'>
(gdb) python p + int(offset)
(gdb) # No error this time.

This breaks some libstdc++ printers. They used to work with Python2 where
type(1/4) is int, but using Python 3 the float type gives the "not a number"
error.

I don't know if GDB's scalar_binop function should accept Python floats, or the
conversion from Python values to GDB values should convert to TYPE_CODE_FLT, or
something else.

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

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