aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2025-09-06 12:16:26 -0600
committerTom Tromey <tom@tromey.com>2025-09-08 18:52:47 -0600
commit247712bb942184ec7c744ee05a78fbda055b5c19 (patch)
tree5539fb717d6234b50cf475c2133684e439605167 /gdb
parent5b17433341939d3f8c18f2fcb5fe270cf9a9f73e (diff)
downloadbinutils-247712bb942184ec7c744ee05a78fbda055b5c19.zip
binutils-247712bb942184ec7c744ee05a78fbda055b5c19.tar.gz
binutils-247712bb942184ec7c744ee05a78fbda055b5c19.tar.bz2
Move compute_include_file_name earlier
I noticed that the compute_include_file_name intro comment was slightly wrong, and while looking at this, I also noticed that it has a single caller. This patch hoists it slightly so that a forward declaration isn't needed. Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/dwarf2/read.c144
1 files changed, 69 insertions, 75 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index efff522..30a0141 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1037,12 +1037,6 @@ dwarf2_per_cu_deleter::operator() (dwarf2_per_cu *data)
delete data;
}
-static const char *compute_include_file_name
- (const struct line_header *lh,
- const file_entry &fe,
- const file_and_directory &cu_info,
- std::string &name_holder);
-
static struct dwo_unit *lookup_dwo_unit_in_dwp
(dwarf2_per_bfd *per_bfd, struct dwp_file *dwp_file,
const char *comp_dir, ULONGEST signature, int is_debug_types);
@@ -1692,6 +1686,75 @@ dwarf2_per_bfd::allocate_signatured_type (dwarf2_section_info *section,
return result;
}
+/* Subroutine of dw2_get_file_names_reader to simplify it.
+ Return the file name for the given file_entry.
+ CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
+ If space for the result is malloc'd, *NAME_HOLDER will be set.
+ Returns NULL if FILE_INDEX should be ignored, i.e., it is
+ equivalent to CU_INFO. */
+
+static const char *
+compute_include_file_name (const struct line_header *lh, const file_entry &fe,
+ const file_and_directory &cu_info,
+ std::string &name_holder)
+{
+ const char *include_name = fe.name;
+ const char *include_name_to_compare = include_name;
+
+ const char *dir_name = fe.include_dir (lh);
+
+ std::string hold_compare;
+ if (!IS_ABSOLUTE_PATH (include_name)
+ && (dir_name != nullptr || cu_info.get_comp_dir () != nullptr))
+ {
+ /* Avoid creating a duplicate name for CU_INFO.
+ We do this by comparing INCLUDE_NAME and CU_INFO.
+ Before we do the comparison, however, we need to account
+ for DIR_NAME and COMP_DIR.
+ First prepend dir_name (if non-NULL). If we still don't
+ have an absolute path prepend comp_dir (if non-NULL).
+ However, the directory we record in the include-file's
+ psymtab does not contain COMP_DIR (to match the
+ corresponding symtab(s)).
+
+ Example:
+
+ bash$ cd /tmp
+ bash$ gcc -g ./hello.c
+ include_name = "hello.c"
+ dir_name = "."
+ DW_AT_comp_dir = comp_dir = "/tmp"
+ DW_AT_name = "./hello.c"
+
+ */
+
+ if (dir_name != NULL)
+ {
+ name_holder = path_join (dir_name, include_name);
+ include_name = name_holder.c_str ();
+ include_name_to_compare = include_name;
+ }
+ if (!IS_ABSOLUTE_PATH (include_name)
+ && cu_info.get_comp_dir () != nullptr)
+ {
+ hold_compare = path_join (cu_info.get_comp_dir (), include_name);
+ include_name_to_compare = hold_compare.c_str ();
+ }
+ }
+
+ std::string copied_name;
+ const char *cu_filename = cu_info.get_name ();
+ if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.get_comp_dir () != nullptr)
+ {
+ copied_name = path_join (cu_info.get_comp_dir (), cu_filename);
+ cu_filename = copied_name.c_str ();
+ }
+
+ if (FILENAME_CMP (include_name_to_compare, cu_filename) == 0)
+ return nullptr;
+ return include_name;
+}
+
/* die_reader_func for dw2_get_file_names. */
static void
@@ -15793,75 +15856,6 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu,
comp_dir);
}
-/* Subroutine of dwarf_decode_lines to simplify it.
- Return the file name for the given file_entry.
- CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
- If space for the result is malloc'd, *NAME_HOLDER will be set.
- Returns NULL if FILE_INDEX should be ignored, i.e., it is
- equivalent to CU_INFO. */
-
-static const char *
-compute_include_file_name (const struct line_header *lh, const file_entry &fe,
- const file_and_directory &cu_info,
- std::string &name_holder)
-{
- const char *include_name = fe.name;
- const char *include_name_to_compare = include_name;
-
- const char *dir_name = fe.include_dir (lh);
-
- std::string hold_compare;
- if (!IS_ABSOLUTE_PATH (include_name)
- && (dir_name != nullptr || cu_info.get_comp_dir () != nullptr))
- {
- /* Avoid creating a duplicate name for CU_INFO.
- We do this by comparing INCLUDE_NAME and CU_INFO.
- Before we do the comparison, however, we need to account
- for DIR_NAME and COMP_DIR.
- First prepend dir_name (if non-NULL). If we still don't
- have an absolute path prepend comp_dir (if non-NULL).
- However, the directory we record in the include-file's
- psymtab does not contain COMP_DIR (to match the
- corresponding symtab(s)).
-
- Example:
-
- bash$ cd /tmp
- bash$ gcc -g ./hello.c
- include_name = "hello.c"
- dir_name = "."
- DW_AT_comp_dir = comp_dir = "/tmp"
- DW_AT_name = "./hello.c"
-
- */
-
- if (dir_name != NULL)
- {
- name_holder = path_join (dir_name, include_name);
- include_name = name_holder.c_str ();
- include_name_to_compare = include_name;
- }
- if (!IS_ABSOLUTE_PATH (include_name)
- && cu_info.get_comp_dir () != nullptr)
- {
- hold_compare = path_join (cu_info.get_comp_dir (), include_name);
- include_name_to_compare = hold_compare.c_str ();
- }
- }
-
- std::string copied_name;
- const char *cu_filename = cu_info.get_name ();
- if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.get_comp_dir () != nullptr)
- {
- copied_name = path_join (cu_info.get_comp_dir (), cu_filename);
- cu_filename = copied_name.c_str ();
- }
-
- if (FILENAME_CMP (include_name_to_compare, cu_filename) == 0)
- return nullptr;
- return include_name;
-}
-
/* See dwarf2/read.h. */
void