From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v4 06/19] Add deferred_warnings parameter to read_addrmap_from_aranges
Date: Sun, 10 Dec 2023 14:41:14 -0700 [thread overview]
Message-ID: <20231210-t-bg-dwarf-reading-v4-6-b978c32fd12f@tromey.com> (raw)
In-Reply-To: <20231210-t-bg-dwarf-reading-v4-0-b978c32fd12f@tromey.com>
When DWARF reading is done in the background,
read_addrmap_from_aranges will be called from a worker thread.
Because warnings can't be emitted from these threads, this patch adds
a new deferred_warnings parameter to the function, letting the caller
control exactly how the warnings are emitted.
---
gdb/dwarf2/aranges.c | 77 ++++++++++++++++++++++---------------------
gdb/dwarf2/aranges.h | 3 +-
gdb/dwarf2/read-debug-names.c | 6 +++-
gdb/dwarf2/read.c | 8 +++--
gdb/utils.h | 16 ++++++---
5 files changed, 65 insertions(+), 45 deletions(-)
diff --git a/gdb/dwarf2/aranges.c b/gdb/dwarf2/aranges.c
index 06f49a494ba..b7d050b73f6 100644
--- a/gdb/dwarf2/aranges.c
+++ b/gdb/dwarf2/aranges.c
@@ -26,7 +26,8 @@
bool
read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
dwarf2_section_info *section,
- addrmap *mutable_map)
+ addrmap *mutable_map,
+ deferred_warnings *warn)
{
/* Caller must ensure that the section has already been read. */
gdb_assert (section->readin);
@@ -76,13 +77,13 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
const uint8_t offset_size = dwarf5_is_dwarf64 ? 8 : 4;
if (addr + entry_length > section->buffer + section->size)
{
- warning (_("Section .debug_aranges in %s entry at offset %s "
- "length %s exceeds section length %s, "
- "ignoring .debug_aranges."),
- objfile_name (objfile),
- plongest (entry_addr - section->buffer),
- plongest (bytes_read + entry_length),
- pulongest (section->size));
+ warn->warn (_("Section .debug_aranges in %s entry at offset %s "
+ "length %s exceeds section length %s, "
+ "ignoring .debug_aranges."),
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer),
+ plongest (bytes_read + entry_length),
+ pulongest (section->size));
return false;
}
@@ -91,10 +92,11 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
addr += 2;
if (version != 2)
{
- warning (_("Section .debug_aranges in %s entry at offset %s "
- "has unsupported version %d, ignoring .debug_aranges."),
- objfile_name (objfile),
- plongest (entry_addr - section->buffer), version);
+ warn->warn
+ (_("Section .debug_aranges in %s entry at offset %s "
+ "has unsupported version %d, ignoring .debug_aranges."),
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer), version);
return false;
}
@@ -105,22 +107,22 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
= debug_info_offset_to_per_cu.find (sect_offset (debug_info_offset));
if (per_cu_it == debug_info_offset_to_per_cu.cend ())
{
- warning (_("Section .debug_aranges in %s entry at offset %s "
- "debug_info_offset %s does not exists, "
- "ignoring .debug_aranges."),
- objfile_name (objfile),
- plongest (entry_addr - section->buffer),
- pulongest (debug_info_offset));
+ warn->warn (_("Section .debug_aranges in %s entry at offset %s "
+ "debug_info_offset %s does not exists, "
+ "ignoring .debug_aranges."),
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer),
+ pulongest (debug_info_offset));
return false;
}
const auto insertpair
= debug_info_offset_seen.insert (sect_offset (debug_info_offset));
if (!insertpair.second)
{
- warning (_("Section .debug_aranges in %s has duplicate "
- "debug_info_offset %s, ignoring .debug_aranges."),
- objfile_name (objfile),
- sect_offset_str (sect_offset (debug_info_offset)));
+ warn->warn (_("Section .debug_aranges in %s has duplicate "
+ "debug_info_offset %s, ignoring .debug_aranges."),
+ objfile_name (objfile),
+ sect_offset_str (sect_offset (debug_info_offset)));
return false;
}
dwarf2_per_cu_data *const per_cu = per_cu_it->second;
@@ -128,22 +130,23 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
const uint8_t address_size = *addr++;
if (address_size < 1 || address_size > 8)
{
- warning (_("Section .debug_aranges in %s entry at offset %s "
- "address_size %u is invalid, ignoring .debug_aranges."),
- objfile_name (objfile),
- plongest (entry_addr - section->buffer), address_size);
+ warn->warn
+ (_("Section .debug_aranges in %s entry at offset %s "
+ "address_size %u is invalid, ignoring .debug_aranges."),
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer), address_size);
return false;
}
const uint8_t segment_selector_size = *addr++;
if (segment_selector_size != 0)
{
- warning (_("Section .debug_aranges in %s entry at offset %s "
- "segment_selector_size %u is not supported, "
- "ignoring .debug_aranges."),
- objfile_name (objfile),
- plongest (entry_addr - section->buffer),
- segment_selector_size);
+ warn->warn (_("Section .debug_aranges in %s entry at offset %s "
+ "segment_selector_size %u is not supported, "
+ "ignoring .debug_aranges."),
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer),
+ segment_selector_size);
return false;
}
@@ -160,11 +163,11 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
{
if (addr + 2 * address_size > entry_end)
{
- warning (_("Section .debug_aranges in %s entry at offset %s "
- "address list is not properly terminated, "
- "ignoring .debug_aranges."),
- objfile_name (objfile),
- plongest (entry_addr - section->buffer));
+ warn->warn (_("Section .debug_aranges in %s entry at offset %s "
+ "address list is not properly terminated, "
+ "ignoring .debug_aranges."),
+ objfile_name (objfile),
+ plongest (entry_addr - section->buffer));
return false;
}
ULONGEST start = extract_unsigned_integer (addr, address_size,
diff --git a/gdb/dwarf2/aranges.h b/gdb/dwarf2/aranges.h
index 43e1cbd0930..e3e9cde8b5b 100644
--- a/gdb/dwarf2/aranges.h
+++ b/gdb/dwarf2/aranges.h
@@ -30,6 +30,7 @@ class addrmap;
extern bool read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
dwarf2_section_info *section,
- addrmap *mutable_map);
+ addrmap *mutable_map,
+ deferred_warnings *warn);
#endif /* GDB_DWARF2_ARANGES_H */
diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c
index e912c2a1114..0877bf3e778 100644
--- a/gdb/dwarf2/read-debug-names.c
+++ b/gdb/dwarf2/read-debug-names.c
@@ -153,12 +153,16 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
addrmap_mutable mutable_map;
+ deferred_warnings warnings;
section->read (per_objfile->objfile);
- if (read_addrmap_from_aranges (per_objfile, section, &mutable_map))
+ if (read_addrmap_from_aranges (per_objfile, section, &mutable_map,
+ &warnings))
per_bfd->index_addrmap
= new (&per_bfd->obstack) addrmap_fixed (&per_bfd->obstack,
&mutable_map);
+
+ warnings.emit ();
}
/* DWARF-5 debug_names reader. */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index bd45c2c9170..5189a7e0c45 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -4926,8 +4926,12 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
per_bfd->quick_file_names_table
= create_quick_file_names_table (per_bfd->all_units.size ());
if (!per_bfd->debug_aranges.empty ())
- read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges,
- index_storage.get_addrmap ());
+ {
+ deferred_warnings warn;
+ read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges,
+ index_storage.get_addrmap (), &warn);
+ warn.emit ();
+ }
{
using iter_type = decltype (per_bfd->all_units.begin ());
diff --git a/gdb/utils.h b/gdb/utils.h
index f646b300530..0acf11cf65f 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -395,13 +395,16 @@ assign_return_if_changed (T &lval, const T &val)
struct deferred_warnings
{
+ deferred_warnings ()
+ : m_can_style (gdb_stderr->can_emit_style_escape ())
+ {
+ }
+
/* Add a warning to the list of deferred warnings. */
void warn (const char *format, ...) ATTRIBUTE_PRINTF(2,3)
{
- /* Generate the warning text into a string_file. We allow the text to
- be styled only if gdb_stderr allows styling -- warnings are sent to
- gdb_stderr. */
- string_file msg (gdb_stderr->can_emit_style_escape ());
+ /* Generate the warning text into a string_file. */
+ string_file msg (m_can_style);
va_list args;
va_start (args, format);
@@ -421,6 +424,11 @@ struct deferred_warnings
private:
+ /* True if gdb_stderr supports styling at the moment this object is
+ constructed. This is done just once so that objects of this type
+ can be used off the main thread. */
+ bool m_can_style;
+
/* The list of all deferred warnings. */
std::vector<string_file> m_warnings;
};
--
2.43.0
next prev parent reply other threads:[~2023-12-10 21:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-10 21:41 [PATCH v4 00/19] Index DWARF in the background Tom Tromey
2023-12-10 21:41 ` [PATCH v4 01/19] Don't use objfile::intern in DWO code Tom Tromey
2024-01-09 18:44 ` Simon Marchi
2024-01-09 19:12 ` Tom Tromey
2024-01-09 19:51 ` Tom Tromey
2023-12-10 21:41 ` [PATCH v4 02/19] Pre-read DWZ section data Tom Tromey
2023-12-10 21:41 ` [PATCH v4 03/19] Add a couple of bfd_cache_close calls Tom Tromey
2023-12-10 21:41 ` [PATCH v4 04/19] Add thread-safety to gdb's BFD wrappers Tom Tromey
2023-12-10 21:41 ` [PATCH v4 05/19] Refactor complaint thread-safety approach Tom Tromey
2023-12-10 21:41 ` Tom Tromey [this message]
2023-12-10 21:41 ` [PATCH v4 07/19] Add quick_symbol_functions::compute_main_name Tom Tromey
2023-12-10 21:41 ` [PATCH v4 08/19] Add gdb::task_group Tom Tromey
2023-12-18 14:55 ` Tom Tromey
2023-12-10 21:41 ` [PATCH v4 09/19] Move cooked_index_storage to cooked-index.h Tom Tromey
2023-12-10 21:41 ` [PATCH v4 10/19] Add "maint set dwarf synchronous" Tom Tromey
2023-12-10 21:41 ` [PATCH v4 11/19] Change how cooked index waits for threads Tom Tromey
2023-12-10 21:41 ` [PATCH v4 12/19] Do more DWARF reading in the background Tom Tromey
2023-12-10 21:41 ` [PATCH v4 13/19] Simplify the public DWARF API Tom Tromey
2023-12-10 21:41 ` [PATCH v4 14/19] Remove two quick_symbol_functions methods Tom Tromey
2023-12-10 21:41 ` [PATCH v4 15/19] Change current_language to be a macro Tom Tromey
2023-12-10 21:41 ` [PATCH v4 16/19] Lazy language setting Tom Tromey
2023-12-10 21:41 ` [PATCH v4 17/19] Optimize lookup_minimal_symbol_text Tom Tromey
2023-12-10 21:41 ` [PATCH v4 18/19] Avoid language-based lookups in startup path Tom Tromey
2023-12-10 21:41 ` [PATCH v4 19/19] Back out some parallel_for_each features Tom Tromey
2024-01-09 1:08 ` [PATCH v4 00/19] Index DWARF in the background Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231210-t-bg-dwarf-reading-v4-6-b978c32fd12f@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).