From patchwork Wed May 13 08:51:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 471756 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E2972140758 for ; Wed, 13 May 2015 18:51:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=u1JnDdNC; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=Vw7Lo3Jsp2i97f4mnw33f/7Sl3wJxV81NVoX2Kgv2S4b/x OruKH5c8Nj/9u9Jqtk2GXoza87IlDEdq38O+pfi8627bEOQU0tEYomwHdVrM3Sd9 Rucgw6yw4HpHseufCYctrugLqcjgVNkUxD4fj7oCc9+bQ27nyhI+O2DAx6HW0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=o+NUqw1h/k9apOmUjet/zNeidJc=; b=u1JnDdNCcUiNaTt8Pm+p vj3u2UG8fLqP6luUFXk6iJJ1jygwTu+0WIMTEhTBVVALCOh/Ffa0gCn3KLPbNW7H 5vPAj5UzbCCNeamGktkUnzG6DMy+QWAHoK6MGJS+IRTMFZof1N3GgtZ7zHWgSpE5 i5nxAKRXy1Lzd4/4UsVUJEs= Received: (qmail 116830 invoked by alias); 13 May 2015 08:51:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 116815 invoked by uid 89); 13 May 2015 08:51:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_LOTSOFHASH, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f181.google.com Received: from mail-qk0-f181.google.com (HELO mail-qk0-f181.google.com) (209.85.220.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 13 May 2015 08:51:08 +0000 Received: by qku63 with SMTP id 63so23527937qku.3 for ; Wed, 13 May 2015 01:51:06 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.55.15.129 with SMTP id 1mr42084492qkp.29.1431507065946; Wed, 13 May 2015 01:51:05 -0700 (PDT) Received: by 10.229.215.4 with HTTP; Wed, 13 May 2015 01:51:05 -0700 (PDT) Date: Wed, 13 May 2015 10:51:05 +0200 Message-ID: Subject: [PATCH 1/7] [D] libiberty: Correctly decode white or non-printable characters From: Iain Buclaw To: gcc-patches , Ian Lance Taylor X-IsSubscribed: yes Hi, Started these as separate patches, but as more came out of what I was originally trying to achieve (see Patch 6/7), I thought it better to have it as a running series. These set out to update d-demangle.c for new ABI additions, general bug fixes, and improved template support. --- D templates can have string literals encoded inside them, which can also include tabs, newlines, and other whitespace characters. For example: return getHost!q{ auto he = gethostbyname(toStringz(param)); }(name); In this case, rather than decoding and writing out every character directly, whitespace or other non-printable characters should be represented as escape sequences. --- libiberty/ChangeLog: 2015-05-13 Iain Buclaw * d-demangle.c (dlang_parse_string): Represent embedded whitespace or non-printable characters as hex or escape sequences. * testsuite/d-demangle-expected: Add test for templates with tabs and newlines embedded into the signature. From f6d6383994f0537f3e9b527419232ae69e2ceb4a Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Mon, 11 May 2015 09:20:29 +0200 Subject: [PATCH 1/7] D demangle: Correctly decode white or non-printable characters --- libiberty/d-demangle.c | 33 ++++++++++++++++++++++++++++++++- libiberty/testsuite/d-demangle-expected | 4 ++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index bb481c0..fa01767 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -931,7 +931,38 @@ dlang_parse_string (string *decl, const char *mangled) char a = ascii2hex (mangled[0]); char b = ascii2hex (mangled[1]); char val = (a << 4) | b; - string_appendn (decl, &val, 1); + + /* Sanitize white and non-printable characters. */ + switch (val) + { + case ' ': + string_append (decl, " "); + break; + case '\t': + string_append (decl, "\\t"); + break; + case '\n': + string_append (decl, "\\n"); + break; + case '\r': + string_append (decl, "\\r"); + break; + case '\f': + string_append (decl, "\\f"); + break; + case '\v': + string_append (decl, "\\v"); + break; + + default: + if (ISPRINT (val)) + string_appendn (decl, &val, 1); + else + { + string_append (decl, "\\x"); + string_appendn (decl, mangled, 2); + } + } } else return NULL; diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected index 2aeacb8..b023f6d 100644 --- a/libiberty/testsuite/d-demangle-expected +++ b/libiberty/testsuite/d-demangle-expected @@ -934,3 +934,7 @@ serenity.persister.Sqlite.SqlitePersister!(serenity.persister.Sqlite.__unittest6 --format=dlang _D4test4mainFZv5localMFZi test.main().local() +# +--format=dlang +_D3std6socket12InternetHost221__T13getHostNoSyncVAyaa96_0a09202020206175746f2078203d2068746f6e6c28706172616d293b0a09202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e74294164647265737346616d696c792e494e4554293b0a09TkZ13getHostNoSyncMFkZb +std.socket.InternetHost.getHostNoSync!("\n\t auto x = htonl(param);\n\t auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);\n\t", uint).getHostNoSync(uint) -- 2.1.0