* [patch] Support binary (0b...) numbers
@ 2010-01-11 14:38 Jan Kratochvil
2010-01-11 15:03 ` Tristan Gingold
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Jan Kratochvil @ 2010-01-11 14:38 UTC (permalink / raw)
To: gdb-patches
Hi,
it is completely offtopic from my other work but I got now surprised GDB
cannot parse standard C syntax of binary (0b11 == 3) numbers.
No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu.
Thanks,
Jan
gdb/
2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
Implement binary numbers parsing.
* c-exp.y (parse_number): New case 'b' and 'B'.
gdb/testsuite/
2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
Implement binary numbers parsing.
* gdb.base/printcmds.exp (test_integer_literals_accepted)
(test_integer_literals_rejected): New binary tests.
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1411,6 +1411,16 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
}
break;
+ case 'b':
+ case 'B':
+ if (len >= 3)
+ {
+ p += 2;
+ base = 2;
+ len -= 2;
+ }
+ break;
+
case 't':
case 'T':
case 'd':
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -78,6 +78,13 @@ proc test_integer_literals_accepted {} {
gdb_test "p 0xabcdef" " = 11259375"
gdb_test "p 0xAbCdEf" " = 11259375"
gdb_test "p/x 0x123" " = 0x123"
+
+ # Test various binary values.
+
+ gdb_test "p 0b0" " = 0"
+ gdb_test "p 0b1111" " = 15"
+ gdb_test "p 0B1111" " = 15"
+ gdb_test "p -0b1111" " = -15"
}
proc test_character_literals_accepted {} {
@@ -99,7 +106,8 @@ proc test_character_literals_accepted {} {
proc test_integer_literals_rejected {} {
global gdb_prompt
- test_print_reject "p 0x"
+ test_print_reject "p 0x"
+ test_print_reject "p 0b"
gdb_test "p ''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
gdb_test "p '''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
test_print_reject "p '\\'"
@@ -131,6 +139,11 @@ proc test_integer_literals_rejected {} {
test_print_reject "p 0xG"
test_print_reject "p 0xAG"
+
+ # Test various binary values.
+
+ test_print_reject "p 0b2"
+ test_print_reject "p 0b12"
}
proc test_print_all_chars {} {
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 14:38 [patch] Support binary (0b...) numbers Jan Kratochvil
@ 2010-01-11 15:03 ` Tristan Gingold
2010-01-11 18:01 ` Jan Kratochvil
2010-01-11 17:51 ` Tom Tromey
` (4 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Tristan Gingold @ 2010-01-11 15:03 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
On Jan 11, 2010, at 3:37 PM, Jan Kratochvil wrote:
> Hi,
>
> it is completely offtopic from my other work but I got now surprised GDB
> cannot parse standard C syntax of binary (0b11 == 3) numbers.
'standard' ? I thought this was a GNU-C extension.
Anyways, that's a good idea.
Tristan.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 14:38 [patch] Support binary (0b...) numbers Jan Kratochvil
2010-01-11 15:03 ` Tristan Gingold
@ 2010-01-11 17:51 ` Tom Tromey
2010-01-11 17:59 ` Jan Kratochvil
2010-01-11 17:57 ` Joel Brobecker
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2010-01-11 17:51 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
Jan> 2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
Jan> Implement binary numbers parsing.
Jan> * c-exp.y (parse_number): New case 'b' and 'B'.
Jan> 2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
Jan> Implement binary numbers parsing.
Jan> * gdb.base/printcmds.exp (test_integer_literals_accepted)
Jan> (test_integer_literals_rejected): New binary tests.
Ok. Thanks.
Tom
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 14:38 [patch] Support binary (0b...) numbers Jan Kratochvil
2010-01-11 15:03 ` Tristan Gingold
2010-01-11 17:51 ` Tom Tromey
@ 2010-01-11 17:57 ` Joel Brobecker
2010-01-11 18:12 ` Jan Kratochvil
2010-01-11 19:06 ` Michael Snyder
` (2 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2010-01-11 17:57 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> 2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> Implement binary numbers parsing.
> * c-exp.y (parse_number): New case 'b' and 'B'.
Is this worth a NEWS entry?
--
Joel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 17:51 ` Tom Tromey
@ 2010-01-11 17:59 ` Jan Kratochvil
0 siblings, 0 replies; 12+ messages in thread
From: Jan Kratochvil @ 2010-01-11 17:59 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Mon, 11 Jan 2010 18:51:04 +0100, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
>
> Jan> 2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
> Jan> Implement binary numbers parsing.
> Jan> * c-exp.y (parse_number): New case 'b' and 'B'.
> Jan> 2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
> Jan> Implement binary numbers parsing.
> Jan> * gdb.base/printcmds.exp (test_integer_literals_accepted)
> Jan> (test_integer_literals_rejected): New binary tests.
>
> Ok. Thanks.
Checked-in:
http://sourceware.org/ml/gdb-cvs/2010-01/msg00094.html
Thanks,
Jan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 15:03 ` Tristan Gingold
@ 2010-01-11 18:01 ` Jan Kratochvil
0 siblings, 0 replies; 12+ messages in thread
From: Jan Kratochvil @ 2010-01-11 18:01 UTC (permalink / raw)
To: Tristan Gingold; +Cc: gdb-patches
On Mon, 11 Jan 2010 16:04:02 +0100, Tristan Gingold wrote:
> On Jan 11, 2010, at 3:37 PM, Jan Kratochvil wrote:
> > it is completely offtopic from my other work but I got now surprised GDB
> > cannot parse standard C syntax of binary (0b11 == 3) numbers.
>
> 'standard' ? I thought this was a GNU-C extension.
Ah, really:
info '(gcc)Binary constants'
is under node 'C Extensions'. I did not know.
Thanks,
Jan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 17:57 ` Joel Brobecker
@ 2010-01-11 18:12 ` Jan Kratochvil
2010-01-11 19:25 ` Eli Zaretskii
0 siblings, 1 reply; 12+ messages in thread
From: Jan Kratochvil @ 2010-01-11 18:12 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On Mon, 11 Jan 2010 18:57:22 +0100, Joel Brobecker wrote:
> > 2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
> >
> > Implement binary numbers parsing.
> > * c-exp.y (parse_number): New case 'b' and 'B'.
>
> Is this worth a NEWS entry?
That makes sense. OK to check-in?
Thanks,
Jan
2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
* NEWS: Document 0b binary number prefix parsing.
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -128,6 +128,11 @@ teval EXPR, ...
ftrace FN / FILE:LINE / *ADDR
Define a fast tracepoint at the given function, line, or address.
+* New expression syntax
+
+ GDB now parses the 0b prefix of binary numbers the same was as GCC does.
+ GDB now parses 0b101010 identically with 42.
+
* New options
set follow-exec-mode new|same
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 14:38 [patch] Support binary (0b...) numbers Jan Kratochvil
` (2 preceding siblings ...)
2010-01-11 17:57 ` Joel Brobecker
@ 2010-01-11 19:06 ` Michael Snyder
2010-01-11 23:03 ` Mark Kettenis
2010-01-12 1:09 ` Stan Shebs
5 siblings, 0 replies; 12+ messages in thread
From: Michael Snyder @ 2010-01-11 19:06 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
Jan Kratochvil wrote:
> Hi,
>
> it is completely offtopic from my other work but I got now surprised GDB
> cannot parse standard C syntax of binary (0b11 == 3) numbers.
Thanks for this! ;-)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 18:12 ` Jan Kratochvil
@ 2010-01-11 19:25 ` Eli Zaretskii
2010-01-11 19:31 ` Jan Kratochvil
0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2010-01-11 19:25 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: brobecker, gdb-patches
> Date: Mon, 11 Jan 2010 19:11:22 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: gdb-patches@sourceware.org
>
> That makes sense. OK to check-in?
>
>
> Thanks,
> Jan
>
>
> 2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> * NEWS: Document 0b binary number prefix parsing.
Yes, thanks.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 19:25 ` Eli Zaretskii
@ 2010-01-11 19:31 ` Jan Kratochvil
0 siblings, 0 replies; 12+ messages in thread
From: Jan Kratochvil @ 2010-01-11 19:31 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: brobecker, gdb-patches
On Mon, 11 Jan 2010 20:26:04 +0100, Eli Zaretskii wrote:
> > * NEWS: Document 0b binary number prefix parsing.
>
> Yes, thanks.
Fixed "was"->"way", checked-in.
Thanks,
Jan
http://sourceware.org/ml/gdb-cvs/2010-01/msg00096.html
--- src/gdb/ChangeLog 2010/01/11 18:15:05 1.11233
+++ src/gdb/ChangeLog 2010/01/11 19:29:12 1.11234
@@ -1,5 +1,9 @@
2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
+ * NEWS: Document the 0b binary number prefix parsing.
+
+2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
+
* objfiles.c (objfile_relocate1): Change the return type to int.
Describe the new return value. Return non-zero if data changed.
(objfile_relocate): New variable changed. Set it. Call
--- src/gdb/NEWS 2010/01/10 06:43:01 1.347
+++ src/gdb/NEWS 2010/01/11 19:29:12 1.348
@@ -128,6 +128,11 @@
ftrace FN / FILE:LINE / *ADDR
Define a fast tracepoint at the given function, line, or address.
+* New expression syntax
+
+ GDB now parses the 0b prefix of binary numbers the same way as GCC does.
+ GDB now parses 0b101010 identically with 42.
+
* New options
set follow-exec-mode new|same
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 14:38 [patch] Support binary (0b...) numbers Jan Kratochvil
` (3 preceding siblings ...)
2010-01-11 19:06 ` Michael Snyder
@ 2010-01-11 23:03 ` Mark Kettenis
2010-01-12 1:09 ` Stan Shebs
5 siblings, 0 replies; 12+ messages in thread
From: Mark Kettenis @ 2010-01-11 23:03 UTC (permalink / raw)
To: jan.kratochvil; +Cc: gdb-patches
> Date: Mon, 11 Jan 2010 15:37:49 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>
> Hi,
>
> it is completely offtopic from my other work but I got now surprised GDB
> cannot parse standard C syntax of binary (0b11 == 3) numbers.
Uh, standard C? My copy of C99 doesn't seem to mention these.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [patch] Support binary (0b...) numbers
2010-01-11 14:38 [patch] Support binary (0b...) numbers Jan Kratochvil
` (4 preceding siblings ...)
2010-01-11 23:03 ` Mark Kettenis
@ 2010-01-12 1:09 ` Stan Shebs
5 siblings, 0 replies; 12+ messages in thread
From: Stan Shebs @ 2010-01-12 1:09 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
Jan Kratochvil wrote:
> Hi,
>
> it is completely offtopic from my other work but I got now surprised GDB
> cannot parse standard C syntax of binary (0b11 == 3) numbers.
>
... and kudos for posting this on a totally appropriate day! :-)
Stan
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-01-12 1:09 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-11 14:38 [patch] Support binary (0b...) numbers Jan Kratochvil
2010-01-11 15:03 ` Tristan Gingold
2010-01-11 18:01 ` Jan Kratochvil
2010-01-11 17:51 ` Tom Tromey
2010-01-11 17:59 ` Jan Kratochvil
2010-01-11 17:57 ` Joel Brobecker
2010-01-11 18:12 ` Jan Kratochvil
2010-01-11 19:25 ` Eli Zaretskii
2010-01-11 19:31 ` Jan Kratochvil
2010-01-11 19:06 ` Michael Snyder
2010-01-11 23:03 ` Mark Kettenis
2010-01-12 1:09 ` Stan Shebs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox