From patchwork Tue May 9 11:23:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 68954 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A4A003858C3A for ; Tue, 9 May 2023 11:23:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4A003858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683631417; bh=pi45AtZwccijRtxWljdWS9RhiN81ODTMAGWQ8RAWBxA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZhEnucX4Y3aneAQVJN1xB3Q4uizBwnqVuGpH6jgU+8qaY+Jad8nOlzNJ6Haju0t5M QWs4/2v9TzqtwrqlCOmH6GdgZ9AZkRdpBVqn5WuVxA2DFpLjZokNhclT74whj5E1k0 eyib0npF5BnVK76jLqxGLmkrwHnTybjPok8RtBE4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5DF563858D37 for ; Tue, 9 May 2023 11:23:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DF563858D37 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-v4PlzJevMJKzN05deILphg-1; Tue, 09 May 2023 07:23:13 -0400 X-MC-Unique: v4PlzJevMJKzN05deILphg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f4245ffbb4so12421865e9.3 for ; Tue, 09 May 2023 04:23:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683631391; x=1686223391; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pi45AtZwccijRtxWljdWS9RhiN81ODTMAGWQ8RAWBxA=; b=N6bnxat7FHpA+5Y/qTbihJ93doz0398cJ3xN2bEewbd7DP/DngnUWOoa8okvAeLTqe hDHArhEnPjB8Ji6ao3BTIiit2AUM3z3q3R//3lDHFdxm7e+bBBUzh+1PmkGO03Qgmtvn 5TqmPOnYR5Gok/j8NpL6kx7CLOjDWe/COXFxPm13LHeYBxafKo77SeKlI1rby438RoeO CgU5r/iRUT/bvWgfsal8XS/qm4qynz35jJw3v9ljrQFf0Tg3pqfz7+1Q1aXbnb1+DyJh PV46c3F7RBVUyRZlNx6DRP0FiM08vZGUZe4kON4fXlcRggl3qhCynPnDQpfiOsEzupv2 ME+A== X-Gm-Message-State: AC+VfDznEUt3eyt5R1EMVbbeOaQ+UbFRZcgR3wJSjHFVHBnQ+hBIv/Th H8gQRWxyZL1utS3jaRb6c/os3U9Ub6vTyzkwdfav9Xj720jBzCNR92XJop/SdBysNJxD7/xqvSV G1QAn69PqrmODSv/bi11Ak9K2rEB8xehsFqvrVy1AecjJcxYMnCM3Xrukd7gjF6p4dGMqMWc0cn 0/7hp+pg== X-Received: by 2002:a05:6000:124d:b0:307:8800:bbdd with SMTP id j13-20020a056000124d00b003078800bbddmr7704445wrx.64.1683631391640; Tue, 09 May 2023 04:23:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Grxo6UoSBrMTB4n6Qd2OwSDUZLA2JSmi1oTnhQf2wAbspdisBmpechPU+2xRg+n7z7e3LLA== X-Received: by 2002:a05:6000:124d:b0:307:8800:bbdd with SMTP id j13-20020a056000124d00b003078800bbddmr7704422wrx.64.1683631391253; Tue, 09 May 2023 04:23:11 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id z18-20020a1c4c12000000b003f188f608b9sm19499651wmf.8.2023.05.09.04.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 04:23:10 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb/rust: fix crash for expression debug with strings Date: Tue, 9 May 2023 12:23:08 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on another patch I did this: (gdb) set debug expression 1 (gdb) set language rust (gdb) p "foo" Operation: OP_AGGREGATE Type: &str Fatal signal: Segmentation fault ... etc ... The problem is that the second field of the rust_aggregate_operation is created as a nullptr, this can be seen in rust-parse.c. in the function rust_parser::parse_string(). However, in expop.h, in the function dump_for_expression, we make the assumption that the expressions will never be nullptr. I did consider moving the nullptr handling into a new function rust_aggregate_operation::dump, however, as the expression debug dumping code is not exercised as much as it might be, I would rather that this code be hardened and able to handle a nullptr without crashing, so I propose that we add nullptr handling into the general dump_for_expression function. The behaviour is now: (gdb) set debug expression 1 (gdb) set language rust (gdb) p "foo" Operation: OP_AGGREGATE Type: &str nullptr Vector: String: data_ptr Operation: UNOP_ADDR Operation: OP_STRING String: foo String: length Operation: OP_LONG Type: usize Constant: 3 evaluation of this expression requires the target program to be active (gdb) There's a new test to check for this case. Reviewed-By: Tom Tromey --- gdb/expop.h | 5 ++++- gdb/testsuite/gdb.rust/expr.exp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) base-commit: 55a75aae9d971d3d0f49884e3954ac4794559542 diff --git a/gdb/expop.h b/gdb/expop.h index 854945c8688..a9da11cc70d 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -314,7 +314,10 @@ static inline void dump_for_expression (struct ui_file *stream, int depth, const operation_up &op) { - op->dump (stream, depth); + if (op == nullptr) + gdb_printf (stream, _("%*snullptr\n"), depth, ""); + else + op->dump (stream, depth); } extern void dump_for_expression (struct ui_file *stream, int depth, diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp index 908d1a3680b..ce2cce2677c 100644 --- a/gdb/testsuite/gdb.rust/expr.exp +++ b/gdb/testsuite/gdb.rust/expr.exp @@ -148,3 +148,24 @@ gdb_test "print r#" "No symbol 'r' in current context" gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22" gdb_test "print 5," "Syntax error near ','" + +# Check expression debug works for strings. +gdb_test "with debug expression 1 -- print \"foo\"" \ + [multi_line \ + "Operation: OP_AGGREGATE" \ + " Type: &str" \ + " nullptr" \ + " Vector:" \ + " String: data_ptr" \ + " Operation: UNOP_ADDR" \ + " Operation: OP_STRING" \ + " String: foo" \ + " String: length" \ + " Operation: OP_LONG" \ + " Type: usize" \ + " Constant: 3" \ + "Operation: OP_LONG" \ + " Type: i32" \ + " Constant: 0" \ + "evaluation of this expression requires the target program to be active"] \ + "print a string with expression debug turned on"