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 ADA063858C31 for ; Fri, 17 Feb 2023 12:35:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADA063858C31 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=1676637353; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EO+3MDXsmHU0uNr+oc4F99fCBxtDk+yRDN8M27RQBLI=; b=THymBUCFdiEmgkRhZsa097xtrOeDP9TnolG3k7JFKgrE2DAKHtQo/Os2r9bpjhxres5JLT rB4Tx1HbqvyO34q+cMy44ptudN/A7qNRhYEPlcgX5AIl8j2yQad+QBQt137u8cRrhkCtAH VCW2H4ZkVYtMzA+4yB66P0H5uK2bF/U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-LWnZFVkPONWEsYSKZwLmTA-1; Fri, 17 Feb 2023 07:35:51 -0500 X-MC-Unique: LWnZFVkPONWEsYSKZwLmTA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28678185A78B for ; Fri, 17 Feb 2023 12:35:51 +0000 (UTC) Received: from ovpn-208-17.brq.redhat.com (ovpn-208-17.brq.redhat.com [10.40.208.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 37B79492C14 for ; Fri, 17 Feb 2023 12:35:50 +0000 (UTC) From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Subject: [PATCH v2] Use styled_string when defering warnings when loading separate debug files Date: Fri, 17 Feb 2023 13:35:47 +0100 Message-Id: <20230217123547.2737612-1-ahajkova@redhat.com> In-Reply-To: <20230216195604.2685177-1-ahajkova@redhat.com> References: <20230216195604.2685177-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.2 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 List-Id: This improves commit 6647f05df023b63bbe056e9167e9e234172fa2ca, the filenames used in the warnings are styled properly now. --- This version: - adds comments to the new add_warning function - style filenames only, not the whole warning string - avoids creating duplicate type definitions gdb/build-id.c | 21 ++++++++++++++++++--- gdb/build-id.h | 3 ++- gdb/coffread.c | 6 +++--- gdb/elfread.c | 6 +++--- gdb/symfile.c | 30 +++++++++++++++++++++++++----- gdb/symfile.h | 5 ++++- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/gdb/build-id.c b/gdb/build-id.c index 00250c20ae9..6e48ec2e4ae 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" @@ -205,11 +206,23 @@ build_id_to_exec_bfd (size_t build_id_len, const bfd_byte *build_id) return build_id_to_bfd_suffix (build_id_len, build_id, ""); } +/* Use callbacks to produce the warnings. */ + +static void +add_warning (warnings_vec *vec, std::string filename) +{ + vec->emplace_back ([filename] () { + warning (_("\"%ps\": separate debug info file has no debug info"), + styled_string (file_name_style.style (), + filename.c_str())); + }); +} + /* See build-id.h. */ std::string find_separate_debug_file_by_buildid (struct objfile *objfile, - std::vector *warnings_vector) + warnings_vec *vec) { const struct bfd_build_id *build_id; @@ -232,8 +245,10 @@ find_separate_debug_file_by_buildid (struct objfile *objfile, = string_printf (_("\"%s\": separate debug info file has no " "debug info"), 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)); + warning (_("\"%ps\": separate debug info file has no debug info"), + styled_string (file_name_style.style (), + bfd_get_filename (abfd.get ()))); + add_warning(vec, bfd_get_filename (abfd.get ())); } else if (abfd != NULL) return std::string (bfd_get_filename (abfd.get ())); diff --git a/gdb/build-id.h b/gdb/build-id.h index 191720ddf28..addaec82526 100644 --- a/gdb/build-id.h +++ b/gdb/build-id.h @@ -21,6 +21,7 @@ #define BUILD_ID_H #include "gdb_bfd.h" +#include "gdb/symfile.h" #include "gdbsupport/rsp-low.h" /* Locate NT_GNU_BUILD_ID from ABFD and return its content. */ @@ -58,7 +59,7 @@ extern gdb_bfd_ref_ptr build_id_to_exec_bfd (size_t build_id_len, 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, warnings_vec *vec); /* Return an hex-string representation of BUILD_ID. */ diff --git a/gdb/coffread.c b/gdb/coffread.c index 65d7828e933..c534eb504cf 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -734,7 +734,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; + warnings_vec warnings_vector; std::string debugfile = find_separate_debug_file_by_buildid (objfile, &warnings_vector); @@ -752,8 +752,8 @@ 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) - warning ("%s", w.c_str ()); + for (const auto &cb : warnings_vector) + cb (); } } diff --git a/gdb/elfread.c b/gdb/elfread.c index ca684aab57e..d1c231c2f8c 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -1213,7 +1213,7 @@ elf_symfile_read_dwarf2 (struct objfile *objfile, && objfile->separate_debug_objfile == NULL && objfile->separate_debug_objfile_backlink == NULL) { - std::vector warnings_vector; + warnings_vec warnings_vector; std::string debugfile = find_separate_debug_file_by_buildid (objfile, &warnings_vector); @@ -1265,8 +1265,8 @@ 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) - warning ("%s", w.c_str ()); + for (const auto &cb : warnings_vector) + cb (); } return has_dwarf2; diff --git a/gdb/symfile.c b/gdb/symfile.c index 373f5592107..2571623dbc8 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1241,10 +1241,25 @@ symbol_file_clear (int from_tty) bool separate_debug_file_debug = false; +/* Use callbacks to produce the warnings. */ + +static void +add_warning (warnings_vec *vec, std::string filename, std:: string obj_filename) +{ + vec->emplace_back ([filename, obj_filename] () { + warning (_("the debug information found in \"%ps\"" + " does not match \"%ps\" (CRC mismatch).\n"), + styled_string (file_name_style.style (), + filename.c_str()), + styled_string (file_name_style.style (), + obj_filename.c_str())); + }); +} + static int separate_debug_file_exists (const std::string &name, unsigned long crc, struct objfile *parent_objfile, - std::vector *warnings_vector) + warnings_vec *warnings_vector) { unsigned long file_crc; int file_crc_p; @@ -1342,8 +1357,13 @@ separate_debug_file_exists (const std::string &name, unsigned long crc, " does not match \"%s\" (CRC mismatch).\n"), name.c_str (), objfile_name (parent_objfile)); if (separate_debug_file_debug) - gdb_printf (gdb_stdlog, "%s", msg.c_str ()); - warnings_vector->emplace_back (std::move (msg)); + warning (_("the debug information found in \"%ps\"" + " does not match \"%ps\" (CRC mismatch).\n"), + styled_string (file_name_style.style (), + name.c_str()), + styled_string (file_name_style.style (), + objfile_name (parent_objfile))); + add_warning(warnings_vector, name.c_str (), objfile_name (parent_objfile)); } return 0; @@ -1386,7 +1406,7 @@ find_separate_debug_file (const char *dir, const char *canon_dir, const char *debuglink, unsigned long crc32, struct objfile *objfile, - std::vector *warnings_vector) + warnings_vec *warnings_vector) { if (separate_debug_file_debug) gdb_printf (gdb_stdlog, @@ -1534,7 +1554,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, warnings_vec *warnings_vector) { unsigned long crc32; diff --git a/gdb/symfile.h b/gdb/symfile.h index b433e2be31a..0cb12176152 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -241,6 +241,9 @@ extern struct objfile *symbol_file_add_from_bfd (const gdb_bfd_ref_ptr &, extern void symbol_file_add_separate (const gdb_bfd_ref_ptr &, const char *, symfile_add_flags, struct objfile *); +using warning_cb = std::function; +using warnings_vec = std::vector; + /* Find separate debuginfo for OBJFILE (using .gnu_debuglink section). Returns pathname, or an empty string. @@ -248,7 +251,7 @@ extern void symbol_file_add_separate (const gdb_bfd_ref_ptr &, const char *, WARNINGS_VECTOR, one std::string per warning. */ extern std::string find_separate_debug_file_by_debuglink - (struct objfile *objfile, std::vector *warnings_vector); + (struct objfile *objfile, warnings_vec *warnings_vector); /* Build (allocate and populate) a section_addr_info struct from an existing section table. */ -- 2.39.1