From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7836 invoked by alias); 24 Apr 2013 14:03:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 7825 invoked by uid 89); 24 Apr 2013 14:03:22 -0000 X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 24 Apr 2013 14:03:21 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 24 Apr 2013 07:02:57 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 24 Apr 2013 07:02:55 -0700 Received: from ulslx001.iul.intel.com (ulslx001.iul.intel.com [172.28.207.63]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id r3OE2sRt025323; Wed, 24 Apr 2013 15:02:55 +0100 Received: from ulslx001.iul.intel.com (localhost [127.0.0.1]) by ulslx001.iul.intel.com with ESMTP id r3OE2svu027898; Wed, 24 Apr 2013 16:02:54 +0200 Received: (from wtedesch@localhost) by ulslx001.iul.intel.com with id r3OE2od9027894; Wed, 24 Apr 2013 16:02:50 +0200 From: Walfred Tedeschi To: gdb-patches@sourceware.org, walfred.tedeschi@intel.com, drow@false.org, tromey@redhat.com Subject: [PATCH] Fix display of structures/bitfields in register description. Date: Wed, 24 Apr 2013 17:30:00 -0000 Message-Id: <1366812163-27865-1-git-send-email-walfred.tedeschi@intel.com> X-SW-Source: 2013-04/txt/msg00736.txt.bz2 Add support for displaying structures and bitfields for registers when executing the "maint print c-tdesc". Command is also used when converting the xml target description file into c file. Example of the behaviour is given below reporting a snipet of the xml file and a snippet of the c code generated. XML file contains: ... ... Setting this xml file as target description file and issuing the maintenance print c-tdesc the following output is obtained: feature = tdesc_create_feature (result, "extra"); field_type = tdesc_named_type (feature, "int8"); tdesc_create_vector (feature, "v4int8", field_type, 4); field_type = tdesc_named_type (feature, "int16"); tdesc_create_vector (feature, "v2int16", field_type, 2); type = tdesc_create_union (feature, "vecint"); field_type = tdesc_named_type (feature, "v4int8"); tdesc_add_field (type, "v4", field_type); field_type = tdesc_named_type (feature, "v2int16"); tdesc_add_field (type, "v2", field_type); C output is not supported type "struct1". This is finally the issue. 2013-03-27 Walfred Tedeschi * target-descriptions.c (maint_print_c_tdesc_cmd): Add case to parse structures as register types and bitfields. testsuite/gdb.xml/ * maint_print_struct.exp: New file. * maint_print_struct.xml: New file. Signed-off-by: Walfred Tedeschi --- gdb/target-descriptions.c | 30 +++++++++++++++++++++ gdb/testsuite/gdb.xml/maint_print_struct.exp | 37 ++++++++++++++++++++++++++ gdb/testsuite/gdb.xml/maint_print_struct.xml | 26 ++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 gdb/testsuite/gdb.xml/maint_print_struct.exp create mode 100644 gdb/testsuite/gdb.xml/maint_print_struct.xml diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 95980c5..88a08ad 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -1746,6 +1746,36 @@ feature = tdesc_create_feature (result, \"%s\");\n", (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n", type->name, type->u.v.count); break; + case TDESC_TYPE_STRUCT: + printf_unfiltered + (" type = tdesc_create_struct (feature, \"%s\");\n", + type->name); + if (type->u.u.size != 0) + printf_unfiltered + (" tdesc_set_struct_size (type, %s);\n", + plongest (type->u.u.size)); + for (ix3 = 0; + VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f); + ix3++) + { + /* Going first for implicitly sized types, else part handles + bitfields. As reported on xml-tdesc.c implicitly sized types + cannot contain a bitfield. */ + if (f->start == 0 && f->end == 0) + { + printf_unfiltered + (" field_type = tdesc_named_type (feature, \"%s\");\n", + f->type->name); + printf_unfiltered + (" tdesc_add_field (type, \"%s\", field_type);\n", + f->name); + } + else + printf_unfiltered + (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n", + f->name, f->start, f->end); + } + break; case TDESC_TYPE_UNION: printf_unfiltered (" type = tdesc_create_union (feature, \"%s\");\n", diff --git a/gdb/testsuite/gdb.xml/maint_print_struct.exp b/gdb/testsuite/gdb.xml/maint_print_struct.exp new file mode 100644 index 0000000..f444451 --- /dev/null +++ b/gdb/testsuite/gdb.xml/maint_print_struct.exp @@ -0,0 +1,37 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2013 Free Software Foundation, Inc. +# +# Contributed by Intel Corp. +# +# 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 . + +if {[gdb_skip_xml_test]} { + unsupported "maint_print_struct.exp" + return -1 +} + +gdb_start +global srcdir +global subdir + +# Required registers are not present so it is expected a warning. +# +gdb_test "set tdesc filename $srcdir/$subdir/maint_print_struct.xml" " +warning:.*" "setting a new tdesc having only a structure" + +gdb_test "maint print c-tdesc" " +.*tdesc_create_reg \\(feature, \"bad_reg1\", \[0-9\]+, 1, NULL, 128, \"two_fielded\"\\);\r +.*tdesc_create_reg \\(feature, \"bad_reg2\", \[0-9\]+, 1, NULL, 64, \"bitfield\"\\);\r +.*" "printing tdesc with a structure and a bitfield" diff --git a/gdb/testsuite/gdb.xml/maint_print_struct.xml b/gdb/testsuite/gdb.xml/maint_print_struct.xml new file mode 100644 index 0000000..dab71fa --- /dev/null +++ b/gdb/testsuite/gdb.xml/maint_print_struct.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + -- 1.7.10.4