From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 6C9AF3948800 for ; Thu, 11 Jun 2020 13:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6C9AF3948800 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-483-M0hGWOd3MjKuuVWe0kNbNg-1; Thu, 11 Jun 2020 09:10:46 -0400 X-MC-Unique: M0hGWOd3MjKuuVWe0kNbNg-1 Received: by mail-wm1-f72.google.com with SMTP id u15so1089717wmm.5 for ; Thu, 11 Jun 2020 06:10:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Oi/dTv87l+dTb3ERuuN4lehPQA4Choa1qrZ6c7delUo=; b=YnEBEBmVOyWPAKSjlp4ZUo3nCfMboDlcyevFFIoViabSDD/ChVdiRDxAA5/uv0lzDF 6RplWof0pwidMi0qbWJEhjBPrOrAToxmvd48/4L3df1UV0SgDs9x+zscOZ1b5bsF9Jyj Ls/6x9KvwBhSOuctCUVnLa9ROTe30h0CiS9oGL6FBWjlNM0LOGSIkXeNrvW330Hrz7rY 7eaXngxOYi9rP8Eb+IVhvepT1W4KPxTwqGqH/orL/Ncf0i2UCoMudb2gPzf+Ad6nd2cg 2LZDUR4TQdNa5NDn7EdTdyF5+cRQqtW4fDYuvboRMr1XHvnO7UJ5v427E+0El6NU8bKT 1RfA== X-Gm-Message-State: AOAM530rqr+Ry4rxxLdl94Hj02oSL4CjnMJbNz5E4rbydK6NdGWeBguO aoSy3DEVD+o7+s1ZA6yOwTrS1gbf3V72HaLDw59V5GpbrHtYj8s7HDieyIqpCINNABQmEcRUxYn ymBWm3Vy+mFHCgA/ntWvKzw== X-Received: by 2002:a1c:a1c5:: with SMTP id k188mr8495498wme.41.1591881044623; Thu, 11 Jun 2020 06:10:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0jHOCtpg/J5kzhoZQhx9ZFG9rugRnRt6eE6iapMB43O4jR9l6Vlrv0icTi4BxNvRmlqlp8A== X-Received: by 2002:a1c:a1c5:: with SMTP id k188mr8495481wme.41.1591881044283; Thu, 11 Jun 2020 06:10:44 -0700 (PDT) Received: from ?IPv6:2001:8a0:f922:c400:56ee:75ff:fe8d:232b? ([2001:8a0:f922:c400:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id y66sm4338457wmy.24.2020.06.11.06.10.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jun 2020 06:10:43 -0700 (PDT) Subject: Re: [PATCH 2/2] gdb: New maintenance command to print XML target description To: Andrew Burgess , gdb-patches@sourceware.org References: <1247d74ec150f017e7ac1fea946af1d3da7ea79e.1591871818.git.andrew.burgess@embecosm.com> From: Pedro Alves Message-ID: Date: Thu, 11 Jun 2020 14:10:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1247d74ec150f017e7ac1fea946af1d3da7ea79e.1591871818.git.andrew.burgess@embecosm.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Thu, 11 Jun 2020 13:10:53 -0000 On 6/11/20 11:41 AM, Andrew Burgess wrote: > However, that class produced XML which seems designed for a machine to > read, with only minimal indentation. With a bit of tweaking I was > able to restructure things so I could inherit from the existing XML > producer and add indentation. > Cool. An interesting testcase this could add would be, run a program to main, and then: (gdb) pipe maint print xml-tdesc | cat > target.xml (*) (gdb) set tdesc filename target.xml and then step to fetch registers with the new tesc. Also another test that this could do is make make sure a roundtrip through GDB of a GDB-generated XML produces the exact same XML. Like: (gdb) pipe maint print xml-tdesc input.xml | cat > out-1.xml (gdb) pipe maint print xml-tdesc out-1.xml | cat > out-2.xml After this, input.xml and out-*.xml may be different, but out-1.xml and out-2.xml should be exactly the same, right? (*) - or something like maint print xml-tdesc -o target.xml > +/* Class to format the target description XML with nesting. */ > + > +class gdb_print_xml_feature : public print_xml_feature > +{ > +public: > + /* Constructor. */ > + > + gdb_print_xml_feature (std::string *arg) explicit. > + :print_xml_feature (arg) Space after ":". > + { /* Nothing. */ } > + > + /* Override this from the parent so we can add the compatibility > + information. */ Curious. Do you know why this isn't done in the parent? > + > + void visit_pre (const target_desc *e) override > + { > + print_xml_feature::visit_pre (e); > + for (const bfd_arch_info_type *compatible : e->compatible) > + add_line ("%s", compatible->printable_name); > + }; > + > +protected: > + > + /* Pull in all copies of add_line. */ > + > + using print_xml_feature::add_line; > + > + /* Override this version of add_line to add white space for indentation > + at the start of the line. */ > + > + void add_line (const std::string &str) override > + { > + std::string tmp = string_printf ("%*s", m_depth, ""); > + tmp += str; > + print_xml_feature::add_line (tmp); > + } > + > + /* Increase our nesting by ADJUST. We use two spaces for every level of > + indentation. */ > + > + void indent (int adjust) override > + { > + m_depth += (adjust * 2); > + } > + > +private: > + > + /* The current level of indentation. */ > + int m_depth = 0; > +}; > + > +/* Implement the maintenance print xml-tdesc command. */ > + > +static void > +maint_print_xml_tdesc_cmd (const char *args, int from_tty) > +{ > + const struct target_desc *tdesc; > + > + if (args == NULL) > + { > + /* Use the global target-supplied description, not the current > + architecture's. This lets a GDB for one architecture generate C > + for another architecture's description, even though the gdbarch The "generate C" bit (copied from "maint print c-tdesc") should be tweaked to say XML instead. > + initialization code will reject the new description. */ > + tdesc = current_target_desc; > + } > + else > + { > + /* Use the target description from the XML file. */ > + tdesc = file_read_description_xml (args); > + } > + > + if (tdesc == NULL) > + error (_("There is no target description to print.")); > + > + std::string buf; > + gdb_print_xml_feature v (&buf); > + tdesc->accept (v); > + puts_unfiltered (buf.c_str ()); > +} > + > +# > +# 4. Indentation of lines will be preserved so your input file needs > +# to follow the expected indentation. > +if {[gdb_skip_xml_test]} { > + unsupported "maint-xml-dump.exp" This just results in: UNSUPPORTED: gdb.xml/maint-xml-dump.exp: maint-xml-dump.exp See: https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#A.22untested.22_calls > + return -1 > +} > + > +gdb_start > + close $ifd > + > + # Due handling the tags we can end up with a stray This reads a bit strange: is there a word missing in "Due handling"? > + # '\r\n' at the start of the output pattern. Remove it here. > + if {[string range $pattern 0 1] == "\r\n"} { > + set pattern [string range $pattern 2 end] > + } > + > + return $pattern > +} > --- a/gdbsupport/tdesc.h > +++ b/gdbsupport/tdesc.h > @@ -401,6 +401,21 @@ class print_xml_feature : public tdesc_element_visitor > void visit (const tdesc_type_with_fields *type) override; > void visit (const tdesc_reg *reg) override; > > +protected: > + > + /* Called with a positive value of ADJUST we move inside an element, for Spurious double space. Maybe missing "when" as in "ADJUST when we" ? > + example inside , and with a negative value when we leave the > + element. In this class this function does nothing, but a sub-class > + can override this to track the current level of nesting. */ > + virtual void indent (int adjust) > + { /* Nothing. */ } > + > + /* Functions to add lines to the output buffer M_BUFFER. Each of these > + functions appends a newline, so don't include one the strings being > + sent. */ Did you mean "don't include one IN the" ? > + virtual void add_line (const std::string &str); > + virtual void add_line (const char *fmt, ...); > + > private: > std::string *m_buffer; > }; > Thanks, Pedro Alves