From patchwork Wed Jan 7 14:35:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siva Chandra Reddy X-Patchwork-Id: 4546 Received: (qmail 9875 invoked by alias); 7 Jan 2015 14:35:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 9863 invoked by uid 89); 7 Jan 2015 14:35:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-oi0-f41.google.com Received: from mail-oi0-f41.google.com (HELO mail-oi0-f41.google.com) (209.85.218.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 07 Jan 2015 14:35:49 +0000 Received: by mail-oi0-f41.google.com with SMTP id i138so3085640oig.0 for ; Wed, 07 Jan 2015 06:35:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=6vz3t9IB90ExbBQ0zMZ9dmj9cVrYGSimPL/5Mt2GdkQ=; b=RU4aeGR9jEu/G7tk94toffCHiseQoMrq5yGbVsu1KSbiaqErqCTaWM7Kwy4glC+pQJ j+s1b1cHDkeKgY8K9y3aNOPFR7YujjsgcKeeiiVcGI0x+cd6IZ+PB66m1oG21WEpQ7LN ulbWwLfeIfJuXHzl3wP+QJ/ZskKtS1jr37iipxROd0+0bxnHkhvgLe8aDBI4yn9+eIy/ xuTGttXu6Rbs01OgxoxlGtdloT+m6CzzCYyxSYRN2vwq0joG5tumTCPvNenhEUF6gw7k LzV7OX4Te5iqT8X1NXJWbNcN6hgUxHlw7m9ZwRqaEjMyDtpJf4j6nfCrZE0eixFA3yP5 pXGw== X-Gm-Message-State: ALoCoQkXapnrThk45RDMBb5wlQdBAVMnedJHAyrtn7ssN7+5hbcrIIvdiVxwHH7Iwlsbydm9g6Wl MIME-Version: 1.0 X-Received: by 10.202.79.80 with SMTP id d77mr2068253oib.112.1420641347648; Wed, 07 Jan 2015 06:35:47 -0800 (PST) Received: by 10.202.197.133 with HTTP; Wed, 7 Jan 2015 06:35:47 -0800 (PST) Date: Wed, 7 Jan 2015 06:35:47 -0800 Message-ID: Subject: [PATCH v3] Remove unwanted spaces when looking up builtin types From: Siva Chandra To: Joel Brobecker Cc: gdb-patches X-IsSubscribed: yes On Tue, Jan 6, 2015 at 11:03 PM, Joel Brobecker wrote: >> +/* Return 1 if C is a whitespace character, 0 otherwise. */ >> + >> +static int >> +whitespace_p (const char c) >> +{ >> + if (c == ' ' || c == '\n' || c == '\t') >> + return 1; >> + else >> + return 0; > > Why not using isspace directly? Apologies if this was explained > before, but then, a comment would be helpful, and maybe a more > specific function name. My first reaction to this kind of routine > was that this should be in one of our "utils" files, so as to allow > other parts of the code to use it as well. To be honest, I did not know about the existence of "isspace". I have removed whitespace_p now from my patch. The v3 is attached. 2015-01-07 Siva Chandra Reddy gdb/ChangeLog: * language.c (language_lookup_primitive_type_1): Remove unwanted space in the type name before looking it up. gdb/testsuite/ChangeLog: * gdb.python/py-type.exp: Add new tests. diff --git a/gdb/language.c b/gdb/language.c index 1e6b983..0e6d241 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -994,13 +994,39 @@ language_lookup_primitive_type_1 (const struct language_arch_info *lai, const char *name) { struct type **p; + int len = strlen (name); + int i, j; + char *clean_name = (char *) xmalloc (sizeof (char) * len + 1); + + /* Remove unwanted whitespace in the typename. This could happen, for + example, if one does gdb.lookup_type(' unsigned long ') in Python. */ + for (i = 0, j = 0; i < len; i++) + { + if (isspace (name[i])) + { + if (j == 0 || clean_name[j - 1] == ' ') + continue; + } + + if (isspace (name[i])) + clean_name[j] = ' '; + else + clean_name[j] = name[i]; + + j++; + } + if (j > 0 && clean_name[j - 1] == ' ') + j--; + clean_name[j] = '\0'; for (p = lai->primitive_type_vector; (*p) != NULL; p++) { - if (strcmp (TYPE_NAME (*p), name) == 0) - return p; + if (strcmp (TYPE_NAME (*p), clean_name) == 0) + break; } - return NULL; + xfree (clean_name); + + return p; } /* See language.h. */ diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index c4c8d9f..0c45ec9 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -270,3 +270,15 @@ with_test_prefix "lang_cpp" { test_template test_enums } + +# Tests to lookup builtin types +gdb_test "python print gdb.lookup_type ('unsigned int')" "unsigned int" \ + "lookup unsigned int" +gdb_test "python print gdb.lookup_type (' unsigned long ')" "unsigned long" \ + "lookup unsigned long" +gdb_test "python print gdb.lookup_type (' unsigned char ')" "unsigned char" \ + "lookup unsigned char" +gdb_test "python print gdb.lookup_type (' unsigned\\n char ')" "unsigned char" \ + "lookup unsigned char" +gdb_test "python print gdb.lookup_type (' unsigned\\tlong ')" "unsigned long" \ + "lookup unsigned long"