Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch] Support binary (0b...) numbers
Date: Mon, 11 Jan 2010 14:38:00 -0000	[thread overview]
Message-ID: <20100111143749.GA7420@host0.dyn.jankratochvil.net> (raw)

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 {} {


             reply	other threads:[~2010-01-11 14:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-11 14:38 Jan Kratochvil [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100111143749.GA7420@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox