Bug 24124 - Command `b *804874e` sets breakpoint at 0xc480a - hex value of 804874
Summary: Command `b *804874e` sets breakpoint at 0xc480a - hex value of 804874
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: cli (show other bugs)
Version: 8.1
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-23 03:09 UTC by avanscy
Modified: 2022-09-04 08:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description avanscy 2019-01-23 03:09:42 UTC
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.
Comment 1 Tom Tromey 2019-01-23 22:22:04 UTC
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.
Comment 2 Enze Li 2022-09-03 13:43:03 UTC
(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?
Comment 3 Tom Tromey 2022-09-03 21:15:14 UTC
(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.
Comment 4 Enze Li 2022-09-04 08:45:13 UTC
(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