From patchwork Wed Jan 4 00:02:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 89749 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp8251252qgi; Tue, 3 Jan 2017 16:02:48 -0800 (PST) X-Received: by 10.99.110.10 with SMTP id j10mr117685771pgc.134.1483488168368; Tue, 03 Jan 2017 16:02:48 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x5si70440519pge.197.2017.01.03.16.02.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jan 2017 16:02:48 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-return-135981-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of gdb-patches-return-135981-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gdb-patches-return-135981-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=Qre2VNp4uB6yCNf6Rm+Kt/Kye3LEl efwG7+kcbSt5DA1yYo+4fIPMTyfQzZOpFY3Iqb+j8pBq6HOBGV+oT+cx+3mE5aL1 dcQAAjJYIVCzqQDELLlmXYiVAVEbyX9Ei+nxh6qZgl7YA0OO6+iu6CTSEcmySmhz HXPaAQoKhjliT4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=hK8EPhNlbSHG69LRcylsHlAD138=; b=LI9 YKp1TfCJdac7HPYt8OuAke6tLewcMV34sJeXbz2J1ZgKEEqFdJjlthD62roW/3N0 sAec6efksSuBUFoA5hXPUpAlk2rtW4VGpdCr7p3aHRt9+UqUslsLKJnNiZDS+liH 1mlPtrgrtetr3jzeMJ0pMyLDCfoRuFeygJGD70sY= Received: (qmail 110143 invoked by alias); 4 Jan 2017 00:02:41 -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 108768 invoked by uid 89); 4 Jan 2017 00:02:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=20170104, 2017-01-04, recognised, Hx-languages-length:3733 X-HELO: mail-vk0-f46.google.com Received: from mail-vk0-f46.google.com (HELO mail-vk0-f46.google.com) (209.85.213.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Jan 2017 00:02:30 +0000 Received: by mail-vk0-f46.google.com with SMTP id 137so281281308vkl.0 for ; Tue, 03 Jan 2017 16:02:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=Qz8Ifb0/zxGRNfiyOOPSbX6kz28fDlAwODYwBPqzu7M=; b=OoeAN2dUfCeXYcAaN1efkWK5XfxqKzlyuZU14XFWsKxJZAJ8+hhsrOll4VcVNKXgWx UW9HN4IOYiTWh1DSM+S67B7FXqt2pnmfkaJ/rkBiBLhN8CIjXMjdzTILpnqjlsuPyC1Y 5BEVAcDzW9tCP2e81kTUofMw+msHJ1Kvv2b5N+4OsBDTp57LekyiUkxj5p0JCv2ZAo4g fe0rlgLBfMYuvztS3UE+aRHs8bPms45v0mbOuW16ueitRIN0rEjZ6pfjOd+eh/CyFMQ9 wyGpm6H9eebM+F+WPfjY9LwkSww/l3Ul5LGWWwSxW4/Ae6uUWfJMW46N9RsR5o43oEuS EyfA== X-Gm-Message-State: AIkVDXL1mL46fhsXLghMtwpGTfpIbeivZAVyDKbuzVoumT2KISmJjGtKRGChzZ89noiQlZBDW0epwkzZy+XsNw== X-Received: by 10.31.7.200 with SMTP id 191mr23051747vkh.132.1483488148248; Tue, 03 Jan 2017 16:02:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.16.7 with HTTP; Tue, 3 Jan 2017 16:02:27 -0800 (PST) From: Iain Buclaw Date: Wed, 4 Jan 2017 01:02:27 +0100 Message-ID: Subject: [PATCH] D: Fix crash when expression debugging To: GDB Patches X-IsSubscribed: yes This patch fixes a crash found on "p *(type *)0x1234" when using "set debug expression 1". While casting works as expected with expression debugging turned off, this seems to be an indication that I'm infact doing something wrong in the building of the expression. (gdb) print *(int*)(0x0) Dump of expression @ 0x12db320, before conversion to prefix form: Language d, 11 elements, 16 bytes each. Index Opcode Hex Value String Value 0 OP_TYPE 87 W............... 1 20114800 p.2............. 2 OP_TYPE 87 W............... 3 OP_LONG 38 &............... 4 19696640 ..,............. 5 OP_NULL 0 ................ 6 OP_LONG 38 &............... 7 UNOP_CAST 51 3............... 8 20114800 p.2............. 9 UNOP_CAST 51 3............... 10 UNOP_IND 61 =............... Dump of expression @ 0x12db320, after conversion to prefix form: Expression: `*(int *) 0' Language d, 11 elements, 16 bytes each. 0 UNOP_IND 1 UNOP_CAST Type @0x132ed70 (int *) 4 OP_LONG Type @0x12c8c00 (int), value 0 (0x0) 8 Unknown format 9 UNOP_CAST Type @0x3d (Segmentation fault Looks like using UNOP_CAST_TYPE is the right thing to do here, as the TypeExp handler has wrapped the type around a pair of OP_TYPE opcodes. 2017-01-04 Iain Buclaw gdb/ChangeLog: * d-exp.y (CastExpression): Emit UNOP_CAST_TYPE. gdb/testsuite/ChangeLog: * gdb.dlang/debug-expr.exp: New file. --- diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 077e645..91d15f2 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -321,15 +321,12 @@ UnaryExpression: CastExpression: CAST_KEYWORD '(' TypeExp ')' UnaryExpression - { write_exp_elt_opcode (pstate, UNOP_CAST); - write_exp_elt_type (pstate, $3); - write_exp_elt_opcode (pstate, UNOP_CAST); } + { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } /* C style cast is illegal D, but is still recognised in the grammar, so we keep this around for convenience. */ | '(' TypeExp ')' UnaryExpression - { write_exp_elt_opcode (pstate, UNOP_CAST); - write_exp_elt_type (pstate, $2); - write_exp_elt_opcode (pstate, UNOP_CAST); } + { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); } + ; PowExpression: diff --git a/gdb/testsuite/gdb.dlang/debug-expr.exp b/gdb/testsuite/gdb.dlang/debug-expr.exp new file mode 100644 index 0000000..3bb2c09 --- /dev/null +++ b/gdb/testsuite/gdb.dlang/debug-expr.exp @@ -0,0 +1,40 @@ +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test "set debug expr 1" on d expressions. + +if { [skip_d_tests] } { continue } + +gdb_start +gdb_test_no_output "set language d" +gdb_test_no_output "set debug expression 1" + +# Test whether the expression debug machinery accepts the expression. + +proc test_debug_expr { cmd output } { + global gdb_prompt + + gdb_test_multiple $cmd "" { + -re ".*Invalid expression.*\r\n$gdb_prompt $" { + fail $cmd + } + -re ".*\[\r\n\]$output\r\n$gdb_prompt $" { + pass $cmd + } + } +} + +# This caused gdb to segfault. +test_debug_expr "print *(int*)(0)" "Cannot access memory at address 0x0"