From patchwork Fri Aug 3 04:22:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 28748 Received: (qmail 32980 invoked by alias); 3 Aug 2018 04:22:19 -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 32970 invoked by uid 89); 3 Aug 2018 04:22:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:dw_at_d, sk:dw_at_c, sk:DW_AT_c, sk:DW_AT_d X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Aug 2018 04:22:16 +0000 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A8CB3086246 for ; Fri, 3 Aug 2018 04:22:15 +0000 (UTC) Received: from pinnacle.lan (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D37FB309128B for ; Fri, 3 Aug 2018 04:22:14 +0000 (UTC) Date: Thu, 2 Aug 2018 21:22:13 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH 3/3] Test case for DW_OP_GNU_variable_value Message-ID: <20180802212213.16de7f4f@pinnacle.lan> In-Reply-To: <20180802210405.5c04ca7a@pinnacle.lan> References: <20180802210405.5c04ca7a@pinnacle.lan> MIME-Version: 1.0 X-IsSubscribed: yes gdb/testsuite/ChangeLog: * gdb.dwarf2/varval.c: New file. * gdb.dwarf2/varval.exp: New file. --- gdb/testsuite/gdb.dwarf2/varval.c | 30 ++++ gdb/testsuite/gdb.dwarf2/varval.exp | 279 ++++++++++++++++++++++++++++++++++++ 2 files changed, 309 insertions(+) diff --git a/gdb/testsuite/gdb.dwarf2/varval.c b/gdb/testsuite/gdb.dwarf2/varval.c new file mode 100644 index 0000000..ce5592e --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/varval.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 program for DW_OP_GNU_variable_value. */ + +int var_a = 8; +int var_b = 3; +int *var_p = &var_b; +struct { int a, b, c, d, e, f, g, h; } var_s = { 101, 102, 103, 104, 105, 106, 107, 108 }; + +int +main (void) +{ + asm ("main_label: .globl main_label"); + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/varval.exp b/gdb/testsuite/gdb.dwarf2/varval.exp new file mode 100644 index 0000000..f4319ae --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/varval.exp @@ -0,0 +1,279 @@ +# Copyright 2018 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 support for DW_OP_GNU_variable_value. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if ![dwarf2_support] { + return 0 +} + +# We'll place the output of Dwarf::assemble in varval.S. +standard_testfile .c .S + +# ${testfile} is now "varval". srcfile2 is "varval.S". +set executable ${testfile} +set asm_file [standard_output_file ${srcfile2}] + +# We need to know the size of integer and address types in order +# to write some of the debugging info we'd like to generate. +# +# For that, we ask GDB by debugging our varval program. +# Any program would do, but since we already have varval +# specifically for this testcase, might as well use that. +if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] { + return -1 +} + +# Create the DWARF. +Dwarf::assemble ${asm_file} { + global srcdir subdir srcfile + + cu {} { + DW_TAG_compile_unit { + {DW_AT_language @DW_LANG_C_plus_plus} + } { + declare_labels int_label ptr_label struct_label var_a_label \ + var_b_label var_c_label var_p_label var_bad_label \ + varval_label var_s_label var_untyped_label + + set int_size [get_sizeof "int" -1] + + # gdb always assumes references are implemented as pointers. + set addr_size [get_sizeof "void *" -1] + + int_label: DW_TAG_base_type { + {DW_AT_byte_size ${int_size} DW_FORM_udata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name "int"} + } + + ptr_label: DW_TAG_pointer_type { + {DW_AT_type :$int_label} + } + + var_a_label: DW_TAG_variable { + {DW_AT_name "var_a"} + {DW_AT_type :${int_label}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_a"]} SPECIAL_expr} + } + + var_b_label: DW_TAG_variable { + {DW_AT_name "var_b"} + {DW_AT_type :${int_label}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_b"]} SPECIAL_expr} + } + + var_c_label: DW_TAG_variable { + {DW_AT_name "var_c"} + {DW_AT_type :${int_label}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 53 DW_FORM_sdata} + } + + var_p_label: DW_TAG_variable { + {DW_AT_name "var_p"} + {DW_AT_type :${ptr_label}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_p"]} SPECIAL_expr} + } + + var_bad_label: DW_TAG_variable { + {DW_AT_name "var_bad"} + {DW_AT_type :${int_label}} + {DW_AT_external 1 DW_FORM_flag} + } + + struct_label: DW_TAG_structure_type { + {DW_AT_byte_size 8*$int_size DW_FORM_sdata} + } { + DW_TAG_member { + {DW_AT_name "a"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 0*$int_size DW_FORM_udata} + } + DW_TAG_member { + {DW_AT_name "b"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 1*$int_size DW_FORM_udata} + } + DW_TAG_member { + {DW_AT_name "c"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 2*$int_size DW_FORM_udata} + } + DW_TAG_member { + {DW_AT_name "d"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 3*$int_size DW_FORM_udata} + } + DW_TAG_member { + {DW_AT_name "e"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 4*$int_size DW_FORM_udata} + } + DW_TAG_member { + {DW_AT_name "f"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 5*$int_size DW_FORM_udata} + } + DW_TAG_member { + {DW_AT_name "g"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 6*$int_size DW_FORM_udata} + } + DW_TAG_member { + {DW_AT_name "h"} + {DW_AT_type :$int_label} + {DW_AT_data_member_location 7*$int_size DW_FORM_udata} + } + } + + var_s_label: DW_TAG_variable { + {DW_AT_name "var_s"} + {DW_AT_type :${struct_label}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_s"]} SPECIAL_expr} + } + + var_untyped_label: DW_TAG_variable { + {DW_AT_name "var_untyped"} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_b"]} SPECIAL_expr} + } + + DW_TAG_subprogram { + {MACRO_AT_func { "main" "${srcdir}/${subdir}/${srcfile}" }} + {DW_AT_type :${int_label}} + {DW_AT_external 1 DW_FORM_flag} + } { + varval_label: DW_TAG_variable { + {DW_AT_name "varval"} + {DW_AT_type :${int_label}} + {DW_AT_location { + DW_OP_GNU_variable_value ${var_a_label} + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "constval"} + {DW_AT_type :${int_label}} + {DW_AT_location { + DW_OP_GNU_variable_value ${var_c_label} + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "mixedval"} + {DW_AT_type :${int_label}} + {DW_AT_location { + DW_OP_GNU_variable_value ${var_c_label} + DW_OP_GNU_variable_value ${var_b_label} + DW_OP_div + DW_OP_GNU_variable_value ${varval_label} + DW_OP_plus + DW_OP_dup + DW_OP_plus + DW_OP_GNU_variable_value ${varval_label} + DW_OP_minus + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "pointerval"} + {DW_AT_type :${ptr_label}} + {DW_AT_location { + DW_OP_GNU_variable_value ${var_p_label} + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "badval"} + {DW_AT_type :${int_label}} + {DW_AT_location { + DW_OP_GNU_variable_value ${var_bad_label} + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "structval"} + {DW_AT_type :${struct_label}} + {DW_AT_location { + DW_OP_GNU_variable_value ${var_s_label} + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "untypedval"} + {DW_AT_location { + DW_OP_GNU_variable_value ${var_untyped_label} + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "bad_die_val1"} + {DW_AT_location { + DW_OP_GNU_variable_value 0xabcdef11 + DW_OP_stack_value + } SPECIAL_expr} + } + DW_TAG_variable { + {DW_AT_name "bad_die_val2"} + {DW_AT_location { + DW_OP_GNU_variable_value ${ptr_label}+1 + DW_OP_stack_value + } SPECIAL_expr} + } + } + } + } +} + +if [prepare_for_testing "failed to prepare" ${executable} [list ${asm_file} ${srcfile}] {}] { + return -1 +} + +# DW_OP_GNU_variable_value implementation requires a valid frame. +if ![runto_main] { + return -1 +} + +gdb_test "print varval" "= 8" +gdb_test "print constval" "= 53" +gdb_test "print mixedval" "= 42" +gdb_test "print pointerval" "= \\(int \\*\\) $hex " +gdb_test "print *pointerval" "= 3" +gdb_test "print badval" "value has been optimized out" + +# Jakub says: "The intended behavior is that the debug info consumer +# computes the value of that referenced variable at the current PC, +# and if it can compute it and pushes the value as a generic type +# integer into the DWARF stack (it is really only meaningful when +# referring to integral/pointer typed variables)." + +gdb_test "print structval" \ + "Type of DW_OP_GNU_variable_value DIE must be an integer or pointer\\." + +gdb_test "print untypedval" \ + "Type of DW_OP_GNU_variable_value DIE must be an integer or pointer\\." + +gdb_test "print bad_die_val1" \ + "invalid dwarf2 offset 0xabcdef11" +gdb_test "print bad_die_val2" \ + "Bad DW_OP_GNU_variable_value DIE\\."