I accidentally typed `b *804874e` when I meant to type `b *0x804874e`. The result was `Breakpoint 1 at 0xc480a` - with 0xc480a being the hex value of the decimal 804874. The trailing 'e' is being ignored. This is strange behavior seeing as `b *804874d` or `b *804874f` gives output `Invalid number "804874d".` or `Invalid number "804874f".` - i.e., it recognizes the number as an invalid 7-digit decimal number, not a valid 6-digit decimal number. Tested on versions 8.1 and 8.2.50.20190123-git on Debian 8.1-4+b1 and 7.1.1 on Ubuntu 7.11.1-0ubuntu1~16.5.
This is a funny one! "804874e" is being parsed as a floating-point number, which is why it works and "d" or "f" do not. Arguably "break *" should reject floating point numbers as being a weird way to write an address.
(In reply to Tom Tromey from comment #1) > This is a funny one! "804874e" is being parsed as a floating-point number, > which is why it works and "d" or "f" do not. > > Arguably "break *" should reject floating point numbers as being a > weird way to write an address. Hi Tom, I am trying to solve this problem. "804874e" is parsed as a floating point number because "en" stands for "10^n". If there is no decimal number after "e", "e" will be ignored. "d" and "f" are not as special as "e", that is why breakpoint address with a "d" or "f" are recognized as illegal. This is my understanding. In GDB, do users usually use decimal numbers to define the address of breakpoints? Or, if only hexadecimal numbers are used to set the breakpoint address, how about we restrict the value of the address to start with 0x?
(In reply to Enze Li from comment #2) > "804874e" is parsed as a floating point number because "en" stands for > "10^n". If there is no decimal number after "e", "e" will be ignored. "d" > and "f" are not as special as "e", that is why breakpoint address with a "d" > or "f" are recognized as illegal. This is my understanding. I think gdb's lexing here is weird, because it disagrees with C: prentzel. gcc --syntax-only q.c q.c:1:11: error: exponent has no digits 1 | float x = 80e; | ^~~ (gdb) print 80e $1 = 80 (gdb) ptype 80e type = double So not treating this as floating point (and rejecting the parse) might be fine. > In GDB, do users usually use decimal numbers to define the address of > breakpoints? No but nothing prohibits it. > Or, if only hexadecimal numbers are used to set the breakpoint > address, how about we restrict the value of the address to start with 0x? That's harder than it sounds because the text after the "*" is an arbitrary expression, not just an integer.
(In reply to Tom Tromey from comment #3) > (In reply to Enze Li from comment #2) > > > "804874e" is parsed as a floating point number because "en" stands for > > "10^n". If there is no decimal number after "e", "e" will be ignored. "d" > > and "f" are not as special as "e", that is why breakpoint address with a "d" > > or "f" are recognized as illegal. This is my understanding. > > I think gdb's lexing here is weird, because it disagrees with C: > > prentzel. gcc --syntax-only q.c > q.c:1:11: error: exponent has no digits > 1 | float x = 80e; > | ^~~ > > (gdb) print 80e > $1 = 80 > (gdb) ptype 80e > type = double > > So not treating this as floating point (and rejecting the parse) > might be fine. > > > In GDB, do users usually use decimal numbers to define the address of > > breakpoints? > > No but nothing prohibits it. > > > Or, if only hexadecimal numbers are used to set the breakpoint > > address, how about we restrict the value of the address to start with 0x? > > That's harder than it sounds because the text after the "*" is an > arbitrary expression, not just an integer. Hi Tom, Thanks for your reply. I have a proposed patch. FTR, I've posted here[1]. [1] https://sourceware.org/pipermail/gdb-patches/2022-September/191680.html