From patchwork Fri Nov 11 16:36:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 60436 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 8E6FF3858C36 for ; Fri, 11 Nov 2022 16:38:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E6FF3858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668184681; bh=Ls8USQt4xqhErKZEDHGKC4+jBFkpTTUScDeKtZgnRMM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=y0qS4fbTGlab0sNyuL6HFO/Br2qLBpTJ+nl9TDJKl283lGOEXcAaSb67o9ITXQVZL YT8PvVNhnMsw3o732q8EDcdec22RUfxLyyFLW3XFbq7Kv+nVXaOc2BK7pTmgHsI607 B4gJ3ugfrt+eBm9H/NQIxoBhk5/DLJm620vBIx2Y= 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 944603858408 for ; Fri, 11 Nov 2022 16:36:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 944603858408 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-558-O5qUWFYTPHi3posqw0XPrw-1; Fri, 11 Nov 2022 11:36:45 -0500 X-MC-Unique: O5qUWFYTPHi3posqw0XPrw-1 Received: by mail-qv1-f72.google.com with SMTP id on28-20020a056214449c00b004bbf12d7976so3960997qvb.18 for ; Fri, 11 Nov 2022 08:36:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ls8USQt4xqhErKZEDHGKC4+jBFkpTTUScDeKtZgnRMM=; b=58xdGLKUl/832fMisb8gdCPZ73tQ3ysII5Q1hLyHsrE37c3QmpgcXN8eiYfnIfPa5H KJerlkcTT0y/6+qnIotghK3NHrJ33lCCKmY8e/9vIjTA3Y/K+OcEgjMuEZkTgVrBUTM7 jnpSQe1gJmo50SbEPc+vRKHEbOlIn9SsjlYyA6bh1WRGprdohcDdJwfUJzjk55u3FC0o eQ+YeX7fzftnh9znsgyubHRsql7zrmA9MI9T/Xk8ejX3f3cGF+OLgQGxMb0mgUl1RLkb KP7j3J6wSp57szB/ZAbzKAPIbiLiOGsiSVhFH4LHOSxwTI8EPM0Gm6BFqgeSR+yL0VoV VKlQ== X-Gm-Message-State: ANoB5pkjxYEEDTRSBEhbjOAYZXKLhNeEREomWuzKEuLWKwTY1fc8rJEu m/sP1I/KjCwgLxPFrgjD8/HUYNOkaFHyINrOLelbSksrrUX/8l2+Rk5eX0i1eBa9f8PCeecnUpU w6Uj2rWjos8Hykn7M48mt1HuS/X8O6+/S/lCg00RpWS3ZMAKFX0bsB3NN1PKCra++azFlVtawEQ == X-Received: by 2002:ac8:148e:0:b0:397:c806:2162 with SMTP id l14-20020ac8148e000000b00397c8062162mr2104756qtj.171.1668184604622; Fri, 11 Nov 2022 08:36:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf6gaPxGi24UJQKWGyHOporYJSsyjJ3UfPRFEZt9siGAIJZlfdi2i6mi+S2d3etAXQPpJ77qog== X-Received: by 2002:ac8:148e:0:b0:397:c806:2162 with SMTP id l14-20020ac8148e000000b00397c8062162mr2104716qtj.171.1668184604204; Fri, 11 Nov 2022 08:36:44 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id bn4-20020a05620a2ac400b006f1187ca494sm1655621qkb.28.2022.11.11.08.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 08:36:44 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 6/6] gdb/testsuite: rewrite gdb.cp/call-method-register.exp with dwarf assembler Date: Fri, 11 Nov 2022 16:36:25 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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" Convert the gdb.cp/call-method-register.exp test to make use of the DWARF assembler. The existing gdb.cp/call-method-register.exp test relies on a GCC extension - forcing a local variable into a particular named register. This means that the test will only work with Clang, and, as we have to name the register into which the variable will be placed, will only work for those targets where we've selected a suitable register, currently this is x86-64, i386, and ppc64. By switching to the DWARF assembler, the test will work with gcc and clang, and should work on most, if not all, architectures. The test creates a small structure, something that can fit within a register, and then tries to call a method on the structure from within GDB. This should fail because GDB can't take the address of the in register structure (for the `this` pointer). As the test is for a failure case, then we don't really care _which_ register the structure is in, and I take advantage of this for the DWARF assembler test, I just declare that the variable is in DW_OP_reg0, whatever that might be. I've tested the new test on x86-64, ppc, aarch64, and risc-v, and the test runs, and passes on all these architectures, which is already more than we used to cover. Additionally, on x86-64, I've tested with Clang and gcc, and the test runs and passed with both compilers. Reviewed-By: Lancelot SIX --- gdb/testsuite/gdb.cp/call-method-register.cc | 49 +------- gdb/testsuite/gdb.cp/call-method-register.exp | 108 +++++++++++++----- 2 files changed, 81 insertions(+), 76 deletions(-) diff --git a/gdb/testsuite/gdb.cp/call-method-register.cc b/gdb/testsuite/gdb.cp/call-method-register.cc index d60fee03701..91cbf13ebca 100644 --- a/gdb/testsuite/gdb.cp/call-method-register.cc +++ b/gdb/testsuite/gdb.cp/call-method-register.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 1993-2022 Free Software Foundation, Inc. + Copyright 2022 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 @@ -15,54 +15,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#if defined __x86_64__ -# define ASM_REG "rax" -#elif defined __i386__ -# define ASM_REG "eax" -#elif defined __powerpc64__ -# define ASM_REG "r9" -#else -# error "port me" -#endif - -/* A class small enough that it fits in a register. */ -struct small -{ - int x; - int method (); -}; - -int -small::method () -{ - return x + 5; -} - -int -register_class () -{ - /* Given the use of the GNU register-asm local variables extension, - the compiler puts this variable in a register. This means that - GDB can't call any methods for this variable, which is what we - want to test. */ - register small v asm (ASM_REG); - - int i; - - /* Perform a computation sufficiently complicated that optimizing - compilers won't optimize out the variable. If some compiler - constant-folds this whole loop, maybe using a parameter to this - function here would help. */ - v.x = 0; - for (i = 0; i < 13; ++i) - v.x += i; - --v.x; /* v.x is now 77 */ - return v.x + 5; /* set breakpoint here */ -} - int main () { - register_class (); + asm ("main_label: .globl main_label"); return 0; } diff --git a/gdb/testsuite/gdb.cp/call-method-register.exp b/gdb/testsuite/gdb.cp/call-method-register.exp index a98b11e4c11..a86ea1e44f9 100644 --- a/gdb/testsuite/gdb.cp/call-method-register.exp +++ b/gdb/testsuite/gdb.cp/call-method-register.exp @@ -19,43 +19,93 @@ if { [skip_cplus_tests] } { continue } load_lib "cp-support.exp" +load_lib dwarf.exp -standard_testfile .cc +standard_testfile .cc -dw.S -if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ + {debug c++}]} { return -1 } -if {![test_compiler_info gcc-*-* c++]} { - untested "test relies on a gcc extension" - return -} +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + + set main_result \ + [function_range main ${::srcdir}/${::subdir}/${::srcfile}] + set main_start [lindex $main_result 0] + set main_length [lindex $main_result 1] + + cu {} { + compile_unit { + {DW_AT_language @DW_LANG_C_plus_plus} + {DW_AT_name $::srcfile} + {DW_AT_comp_dir /tmp} + } { + declare_labels int_type_label struct_type_label \ + struct_ptr_type_label + set ptr_size [get_sizeof "void *" 96] + + DW_TAG_subprogram { + {name main} + {low_pc $main_start addr} + {high_pc $main_length data8} + {DW_AT_type :$int_type_label} + } + + int_type_label: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name int} + } + + struct_type_label: DW_TAG_structure_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_name small} + } { + member { + {name xxx} + {type :$int_type_label} + {data_member_location 0 data1} + } + subprogram { + {name yyy} + {type :$int_type_label} + {data_member_location 0 data1} + } { + formal_parameter { + {type :$struct_ptr_type_label} + {artificial 1 flag_present} + } + } + } -proc test_call_register_class {} { - global gdb_prompt + struct_ptr_type_label: DW_TAG_pointer_type { + {DW_AT_byte_size $ptr_size DW_FORM_data1} + {type :$struct_type_label} + } - if ![runto_main] { - return + DW_TAG_variable { + {DW_AT_name global_var} + {DW_AT_type :$struct_type_label} + {DW_AT_location { + DW_OP_reg0 + } SPECIAL_expr} + {external 1 flag} + } + } } +} - set bp_location [gdb_get_line_number "set breakpoint here"] - gdb_breakpoint $bp_location - gdb_continue_to_breakpoint "break here" - - # This class is so small that an instance of it can fit in a register. - # When gdb tries to call a method, it gets embarrassed about taking - # the address of a register. - # - # That message is a PASS, not an XFAIL, because gdb prints an - # informative message and declines to do something impossible. - # - # The method call actually succeeds if the compiler allocates very - # small classes in memory instead of registers. If that happens, - # it's a FAIL, because the testcase is written in a form such that - # it should not happen. - gdb_test "print v.method ()" \ - "Address requested for identifier \"v\" which is in register .*" \ - "call method on register local" +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 } -test_call_register_class +gdb_test "print global_var.yyy ()" \ + "Address requested for identifier \"global_var\" which is in register .*" \ + "call method on register local"