From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 60C183858CDA for ; Thu, 30 Mar 2023 08:12:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60C183858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680163926; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9I9K7XiIhoiu6z/U+KGZGPjg9ph24z6LOTD2r8ucDPU=; b=hxoODsCLwhpYg/+lHjlZdU0elh3PAe3wW6nSlrVlfT/Y+KEQGEwi/bYVpwNd/Zs0TDi8JB c9+47DmZza2XF1bDEHUIwPBQYCfgBE5GdOgcybT1d065PTfMZopIwX2UBo0Tef6qKEwWMn NpYXJw7+zMUKnUQPXv3NEgoHywLPHa0= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-AMsK7fpBPi6khSvREbknEg-1; Thu, 30 Mar 2023 04:12:04 -0400 X-MC-Unique: AMsK7fpBPi6khSvREbknEg-1 Received: by mail-pg1-f197.google.com with SMTP id q30-20020a631f5e000000b0050760997f4dso5129852pgm.6 for ; Thu, 30 Mar 2023 01:12:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680163923; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9I9K7XiIhoiu6z/U+KGZGPjg9ph24z6LOTD2r8ucDPU=; b=cG1kLNVGIkwR78Y9EJIWIyNHeMzu5h5VsXqK1lYDTNAzdHxZRQg4NiFEzqv9qOaT+X b5a6cUnYE4r9nEyk0mqNcaRVj7JtsD4BSjjgcsTfl4QHODpGW8yyiv0Za2a6WcSCl0yd XByA7Oc4J8HDCuRIiKGcnKinbkBPzYS9RLiapMMVKR5cVeKN6Knnz8pPWSoWZTHn0qKI x6MS5vH+oCbdy7wAPR8+Ng1nGI/m9PhkESRAwxK6Hzlzg4tRsOda+5aTED/ZVNaHTC3t tb/G/61CJHJElHhIykiatT3fZUXDfPQDU20N0Q5BiPA44MPlukRT+t6fnv3iOHNV/Ug3 pvog== X-Gm-Message-State: AAQBX9frWml0Zb79byFL3y3X3Woo3Fxosx/woV7rcd2T97mgxWWwGGs8 pw5zdZ0LtUYuhLZZ953BNbKktW4hdTj7eErTpkbe8ZOi1emetchQ45lFvOWRIdsE5GVBhI0sJUd OLO+DMmXiYLNN5gRJQBbOJuj9b1A/XU1uyBd+rA== X-Received: by 2002:a63:4850:0:b0:503:7bbb:9a77 with SMTP id x16-20020a634850000000b005037bbb9a77mr6096845pgk.8.1680163923142; Thu, 30 Mar 2023 01:12:03 -0700 (PDT) X-Google-Smtp-Source: AKy350bfFzktoblG/KxI/2Sjjf4m+8nxY476plbazaUurxWa2OdXgIHKJW5Ov61x24Nslag2z262uPk2hqraMnBKuMo= X-Received: by 2002:a63:4850:0:b0:503:7bbb:9a77 with SMTP id x16-20020a634850000000b005037bbb9a77mr6096842pgk.8.1680163922687; Thu, 30 Mar 2023 01:12:02 -0700 (PDT) MIME-Version: 1.0 References: <20230320145638.1202335-1-ahajkova@redhat.com> In-Reply-To: <20230320145638.1202335-1-ahajkova@redhat.com> From: Alexandra Petlanova Hajkova Date: Thu, 30 Mar 2023 10:11:51 +0200 Message-ID: Subject: Re: [PATCH v2] Use styled_string when defering warnings when loading separate debug files To: =?UTF-8?Q?Alexandra_H=C3=A1jkov=C3=A1?= Cc: gdb-patches@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000c6cc6c05f819a5dc" X-Spam-Status: No, score=-15.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,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 List-Id: --000000000000c6cc6c05f819a5dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ping On Mon, Mar 20, 2023 at 3:56=E2=80=AFPM Alexandra H=C3=A1jkov=C3=A1 via Gdb= -patches < gdb-patches@sourceware.org> wrote: > This improves commit 6647f05df023b63bbe056e9167e9e234172fa2ca, the > filenames used in the warnings are styled properly now. > --- > This version uses ui_file rather instead of vector of callback functions > that emit warnings. > Addresses various cosmetic issues. > > gdb/build-id.c | 16 ++++++++++------ > gdb/build-id.h | 4 ++-- > gdb/coffread.c | 4 ++-- > gdb/elfread.c | 4 ++-- > gdb/symfile.c | 26 ++++++++++++++++---------- > gdb/symfile.h | 4 ++-- > gdb/ui-file.h | 7 +++++++ > 7 files changed, 41 insertions(+), 24 deletions(-) > > diff --git a/gdb/build-id.c b/gdb/build-id.c > index 00250c20ae9..5d5114e2ace 100644 > --- a/gdb/build-id.c > +++ b/gdb/build-id.c > @@ -18,6 +18,7 @@ > along with this program. If not, see . > */ > > #include "defs.h" > +#include "cli/cli-style.h" > #include "bfd.h" > #include "gdb_bfd.h" > #include "build-id.h" > @@ -209,7 +210,7 @@ build_id_to_exec_bfd (size_t build_id_len, const > bfd_byte *build_id) > > std::string > find_separate_debug_file_by_buildid (struct objfile *objfile, > - std::vector > *warnings_vector) > + std::vector > *warnings_vector) > { > const struct bfd_build_id *build_id; > > @@ -228,12 +229,15 @@ find_separate_debug_file_by_buildid (struct objfile > *objfile, > && filename_cmp (bfd_get_filename (abfd.get ()), > objfile_name (objfile)) =3D=3D 0) > { > - std::string msg > - =3D string_printf (_("\"%s\": separate debug info file has no= " > - "debug info"), bfd_get_filename (abfd.get > ())); > + string_file warnings (true); > + warnings.printf ("\"%ps\":separate debug info file has no debug > info", > + styled_string (file_name_style.style (), > + bfd_get_filename (abfd.get ()))= ); > if (separate_debug_file_debug) > - gdb_printf (gdb_stdlog, "%s", msg.c_str ()); > - warnings_vector->emplace_back (std::move (msg)); > + /* Avoid styling for the debug output. */ > + gdb_printf (gdb_stdlog, _("%s: separate debug info file has no > debug info"), > + bfd_get_filename (abfd.get ())); > + warnings_vector->emplace_back (std::move (warnings)); > } > else if (abfd !=3D NULL) > return std::string (bfd_get_filename (abfd.get ())); > diff --git a/gdb/build-id.h b/gdb/build-id.h > index 191720ddf28..0c2c4181b4e 100644 > --- a/gdb/build-id.h > +++ b/gdb/build-id.h > @@ -52,13 +52,13 @@ extern gdb_bfd_ref_ptr build_id_to_exec_bfd (size_t > build_id_len, > separate debug file, otherwise, return an empty string. > > Any warnings that are generated by the lookup process should be added > to > - WARNINGS_VECTOR, one std::string per warning. If some other mechanism > can > + WARNINGS_VECTOR, one string_file per warning. If some other mechanism > can > be used to lookup the debug information then the warning will not be > shown, > however, if GDB fails to find suitable debug information using any > approach, then any warnings will be printed. */ > > extern std::string find_separate_debug_file_by_buildid > - (struct objfile *objfile, std::vector *warnings_vector); > + (struct objfile *objfile, std::vector *warnings_vector); > > /* Return an hex-string representation of BUILD_ID. */ > > diff --git a/gdb/coffread.c b/gdb/coffread.c > index e993b17db09..32705c215fd 100644 > --- a/gdb/coffread.c > +++ b/gdb/coffread.c > @@ -729,7 +729,7 @@ coff_symfile_read (struct objfile *objfile, > symfile_add_flags symfile_flags) > /* Try to add separate debug file if no symbols table found. */ > if (!objfile->has_partial_symbols ()) > { > - std::vector warnings_vector; > + std::vector warnings_vector; > std::string debugfile > =3D find_separate_debug_file_by_buildid (objfile, &warnings_vecto= r); > > @@ -747,7 +747,7 @@ coff_symfile_read (struct objfile *objfile, > symfile_add_flags symfile_flags) > /* If all the methods to collect the debuginfo failed, print any > warnings that were collected. */ > if (debugfile.empty () && !warnings_vector.empty ()) > - for (const std::string &w : warnings_vector) > + for (const string_file &w : warnings_vector) > warning ("%s", w.c_str ()); > } > } > diff --git a/gdb/elfread.c b/gdb/elfread.c > index b414da9ed21..4bc89d09d65 100644 > --- a/gdb/elfread.c > +++ b/gdb/elfread.c > @@ -1217,7 +1217,7 @@ elf_symfile_read_dwarf2 (struct objfile *objfile, > && objfile->separate_debug_objfile =3D=3D NULL > && objfile->separate_debug_objfile_backlink =3D=3D NULL) > { > - std::vector warnings_vector; > + std::vector warnings_vector; > > std::string debugfile > =3D find_separate_debug_file_by_buildid (objfile, &warnings_vecto= r); > @@ -1269,7 +1269,7 @@ elf_symfile_read_dwarf2 (struct objfile *objfile, > /* If all the methods to collect the debuginfo failed, print > the warnings, if there're any. */ > if (debugfile.empty () && !has_dwarf2 && !warnings_vector.empty ()) > - for (const std::string &w : warnings_vector) > + for (const string_file &w : warnings_vector) > warning ("%s", w.c_str ()); > } > > diff --git a/gdb/symfile.c b/gdb/symfile.c > index bb9981a4634..64d29ea71f9 100644 > --- a/gdb/symfile.c > +++ b/gdb/symfile.c > @@ -1244,7 +1244,7 @@ bool separate_debug_file_debug =3D false; > static int > separate_debug_file_exists (const std::string &name, unsigned long crc, > struct objfile *parent_objfile, > - std::vector *warnings_vector) > + std::vector *warnings_vector) > { > unsigned long file_crc; > int file_crc_p; > @@ -1337,13 +1337,19 @@ separate_debug_file_exists (const std::string > &name, unsigned long crc, > > if (verified_as_different || parent_crc !=3D file_crc) > { > - std::string msg > - =3D string_printf (_("the debug information found in \"%s\"" > - " does not match \"%s\" (CRC mismatch).\n"= ), > - name.c_str (), objfile_name (parent_objfile)= ); > + string_file warnings (true); > + warnings.printf (_("the debug information found in \"%ps\"" > + " does not match \"%ps\" (CRC mismatch)."), > + styled_string (file_name_style.style (), > + name.c_str ()), > + styled_string (file_name_style.style (), > + objfile_name (parent_objfile))); > + /* Avoid styling for the debug output. */ > if (separate_debug_file_debug) > - gdb_printf (gdb_stdlog, "%s", msg.c_str ()); > - warnings_vector->emplace_back (std::move (msg)); > + gdb_printf (gdb_stdlog, _("the debug information found in %s" > + " does not match %s (CRC > mismatch).\n"), > + name.c_str(), objfile_name (parent_objfile)); > + warnings_vector->emplace_back (std::move (warnings)); > } > > return 0; > @@ -1379,14 +1385,14 @@ show_debug_file_directory (struct ui_file *file, > int from_tty, > string. > > Any warnings generated as part of the lookup process are added to > - WARNINGS_VECTOR, one std::string per warning. */ > + WARNINGS_VECTOR, one string_file per warning. */ > > static std::string > find_separate_debug_file (const char *dir, > const char *canon_dir, > const char *debuglink, > unsigned long crc32, struct objfile *objfile, > - std::vector *warnings_vector) > + std::vector *warnings_vector) > { > if (separate_debug_file_debug) > gdb_printf (gdb_stdlog, > @@ -1534,7 +1540,7 @@ terminate_after_last_dir_separator (char *path) > > std::string > find_separate_debug_file_by_debuglink > - (struct objfile *objfile, std::vector *warnings_vector) > + (struct objfile *objfile, std::vector *warnings_vector) > { > unsigned long crc32; > > diff --git a/gdb/symfile.h b/gdb/symfile.h > index b433e2be31a..041f6f74f9c 100644 > --- a/gdb/symfile.h > +++ b/gdb/symfile.h > @@ -245,10 +245,10 @@ extern void symbol_file_add_separate (const > gdb_bfd_ref_ptr &, const char *, > Returns pathname, or an empty string. > > Any warnings generated as part of this lookup are added to > - WARNINGS_VECTOR, one std::string per warning. */ > + WARNINGS_VECTOR, one string_file per warning. */ > > extern std::string find_separate_debug_file_by_debuglink > - (struct objfile *objfile, std::vector *warnings_vector); > + (struct objfile *objfile, std::vector *warnings_vector); > > /* Build (allocate and populate) a section_addr_info struct from an > existing section table. */ > diff --git a/gdb/ui-file.h b/gdb/ui-file.h > index de24620e247..4444c8adcdb 100644 > --- a/gdb/ui-file.h > +++ b/gdb/ui-file.h > @@ -212,6 +212,13 @@ class string_file : public ui_file > return *this; > } > > + string_file(string_file &&other) > + : m_string (std::move (other.c_str ())), > + m_term_out (other.m_term_out) > + { > + > + } > + > /* Provide a few convenience methods with the same API as the > underlying std::string. */ > const char *data () const { return m_string.data (); } > -- > 2.39.1 > > --000000000000c6cc6c05f819a5dc--