From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v4 13/19] Simplify the public DWARF API
Date: Sun, 10 Dec 2023 14:41:21 -0700 [thread overview]
Message-ID: <20231210-t-bg-dwarf-reading-v4-13-b978c32fd12f@tromey.com> (raw)
In-Reply-To: <20231210-t-bg-dwarf-reading-v4-0-b978c32fd12f@tromey.com>
dwarf2_has_info and dwarf2_initialize_objfile are only separate
because the DWARF reader implemented lazy psymtab reading. However,
now that this is gone, we can simplify the public DWARF API again.
---
gdb/coffread.c | 6 +++---
gdb/dwarf2/public.h | 18 +++++++++++-------
gdb/dwarf2/read.c | 49 ++++++++++++++++++++++---------------------------
gdb/elfread.c | 6 ++++--
gdb/machoread.c | 11 ++---------
gdb/xcoffread.c | 3 +--
6 files changed, 43 insertions(+), 50 deletions(-)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 37363631915..3a64325a822 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -716,10 +716,10 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
*info->stabsects,
info->stabstrsect->filepos, stabstrsize);
}
- if (dwarf2_has_info (objfile, NULL))
+
+ if (dwarf2_initialize_objfile (objfile))
{
- /* DWARF2 sections. */
- dwarf2_initialize_objfile (objfile);
+ /* Nothing. */
}
/* Try to add separate debug file if no symbols table found. */
diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h
index 0e74857eb1a..efb754b5fe8 100644
--- a/gdb/dwarf2/public.h
+++ b/gdb/dwarf2/public.h
@@ -20,10 +20,6 @@
#ifndef DWARF2_PUBLIC_H
#define DWARF2_PUBLIC_H
-extern bool dwarf2_has_info (struct objfile *,
- const struct dwarf2_debug_sections *,
- bool = false);
-
/* A DWARF names index variant. */
enum class dw_index_kind
{
@@ -34,9 +30,17 @@ enum class dw_index_kind
DEBUG_NAMES,
};
-/* Initialize for reading DWARF for OBJFILE, and push the appropriate
- entry on the objfile's "qf" list. */
-extern void dwarf2_initialize_objfile (struct objfile *objfile);
+/* Try to locate the sections we need for DWARF 2 debugging
+ information. If these are found, begin reading the DWARF and
+ return true. Otherwise, return false. NAMES points to the dwarf2
+ section names, or is NULL if the standard ELF names are used.
+ CAN_COPY is true for formats where symbol interposition is possible
+ and so symbol values must follow copy relocation rules. */
+
+extern bool dwarf2_initialize_objfile
+ (struct objfile *,
+ const struct dwarf2_debug_sections * = nullptr,
+ bool = false);
extern void dwarf2_build_frame_info (struct objfile *);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8a60cf91612..8778bffc485 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1354,14 +1354,10 @@ dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data *per_cu,
this->m_symtabs[per_cu->index] = symtab;
}
-/* Try to locate the sections we need for DWARF 2 debugging
- information and return true if we have enough to do something.
- NAMES points to the dwarf2 section names, or is NULL if the standard
- ELF names are used. CAN_COPY is true for formats where symbol
- interposition is possible and so symbol values must follow copy
- relocation rules. */
+/* Helper function for dwarf2_initialize_objfile that creates the
+ per-BFD object. */
-bool
+static bool
dwarf2_has_info (struct objfile *objfile,
const struct dwarf2_debug_sections *names,
bool can_copy)
@@ -3199,9 +3195,14 @@ static quick_symbol_functions_up make_cooked_index_funcs
/* See dwarf2/public.h. */
-void
-dwarf2_initialize_objfile (struct objfile *objfile)
+bool
+dwarf2_initialize_objfile (struct objfile *objfile,
+ const struct dwarf2_debug_sections *names,
+ bool can_copy)
{
+ if (!dwarf2_has_info (objfile, names, can_copy))
+ return false;
+
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
@@ -3231,48 +3232,42 @@ dwarf2_initialize_objfile (struct objfile *objfile)
= create_quick_file_names_table (per_bfd->all_units.size ());
objfile->qf.emplace_front (new readnow_functions);
- return;
}
-
/* Was a GDB index already read when we processed an objfile sharing
PER_BFD? */
- if (per_bfd->index_table != nullptr)
+ else if (per_bfd->index_table != nullptr)
{
dwarf_read_debug_printf ("re-using symbols");
objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
- return;
}
-
- if (dwarf2_read_debug_names (per_objfile))
+ else if (dwarf2_read_debug_names (per_objfile))
{
dwarf_read_debug_printf ("found debug names");
objfile->qf.push_front
(per_bfd->index_table->make_quick_functions ());
- return;
}
-
- if (dwarf2_read_gdb_index (per_objfile,
- get_gdb_index_contents_from_section<struct dwarf2_per_bfd>,
- get_gdb_index_contents_from_section<dwz_file>))
+ else if (dwarf2_read_gdb_index (per_objfile,
+ get_gdb_index_contents_from_section<struct dwarf2_per_bfd>,
+ get_gdb_index_contents_from_section<dwz_file>))
{
dwarf_read_debug_printf ("found gdb index from file");
objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
- return;
}
-
/* ... otherwise, try to find the index in the index cache. */
- if (dwarf2_read_gdb_index (per_objfile,
+ else if (dwarf2_read_gdb_index (per_objfile,
get_gdb_index_contents_from_cache,
get_gdb_index_contents_from_cache_dwz))
{
dwarf_read_debug_printf ("found gdb index from cache");
global_index_cache.hit ();
objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
- return;
}
-
- global_index_cache.miss ();
- objfile->qf.push_front (make_cooked_index_funcs (per_objfile));
+ else
+ {
+ global_index_cache.miss ();
+ objfile->qf.push_front (make_cooked_index_funcs (per_objfile));
+ }
+ return true;
}
\f
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 5dc8f21d7c7..c5ba8837217 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1198,8 +1198,10 @@ elf_symfile_read_dwarf2 (struct objfile *objfile,
{
bool has_dwarf2 = true;
- if (dwarf2_has_info (objfile, NULL, true))
- dwarf2_initialize_objfile (objfile);
+ if (dwarf2_initialize_objfile (objfile, nullptr, true))
+ {
+ /* Nothing. */
+ }
/* If the file has its own symbol tables it has no separate debug
info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to
SYMTABS/PSYMTABS. `.gnu_debuglink' may no longer be present with
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 87d30ec8587..f27ce63c24c 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -785,6 +785,8 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
macho_symfile_read_all_oso at the end of this function. */
gdb::def_vector<asymbol *> symbol_table;
+ dwarf2_initialize_objfile (objfile);
+
/* Get symbols from the symbol table only if the file is an executable.
The symbol table of object files is not relocated and is expected to
be in the executable. */
@@ -822,9 +824,6 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
}
/* Try to read .eh_frame / .debug_frame. */
- /* First, locate these sections. We ignore the result status
- as it only checks for debug info. */
- dwarf2_has_info (objfile, NULL);
dwarf2_build_frame_info (objfile);
/* Check for DSYM file. */
@@ -854,12 +853,6 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
}
}
- if (dwarf2_has_info (objfile, NULL))
- {
- /* DWARF 2 sections */
- dwarf2_initialize_objfile (objfile);
- }
-
/* Then the oso. */
if (!oso_vector.empty ())
macho_symfile_read_all_oso (&oso_vector, objfile, symfile_flags);
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 856fa134ed7..13ee3105baf 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2871,8 +2871,7 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags)
/* DWARF2 sections. */
- if (dwarf2_has_info (objfile, &dwarf2_xcoff_names))
- dwarf2_initialize_objfile (objfile);
+ dwarf2_initialize_objfile (objfile, &dwarf2_xcoff_names);
}
\f
static void
--
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 ` [PATCH v4 06/19] Add deferred_warnings parameter to read_addrmap_from_aranges Tom Tromey
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 ` Tom Tromey [this message]
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-13-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).