abbrev_offsetp, NULL);
}
+Dwarf_CU *
+internal_function
+__libdw_dwp_findcu_id (Dwarf *dbg, uint64_t unit_id8)
+{
+ Dwarf_Package_Index *index = __libdw_package_index (dbg, false);
+ uint32_t unit_row;
+ Dwarf_Off offset;
+ Dwarf_CU *cu;
+ if (__libdw_dwp_unit_row (index, unit_id8, &unit_row) == 0
+ && __libdw_dwp_section_info (index, unit_row, DW_SECT_INFO, &offset,
+ NULL) == 0
+ && (cu = __libdw_findcu (dbg, offset, false)) != NULL
+ && cu->unit_type == DW_UT_split_compile
+ && cu->unit_id8 == unit_id8)
+ return cu;
+ else
+ return NULL;
+}
+
int
dwarf_cu_dwp_section_info (Dwarf_CU *cu, unsigned int section,
Dwarf_Off *offsetp, Dwarf_Off *sizep)
/* dwz alternate DWARF file. */
Dwarf *alt_dwarf;
+ /* DWARF package file. */
+ Dwarf *dwp_dwarf;
+
/* The section data. */
Elf_Data *sectiondata[IDX_last];
close this file descriptor. */
int alt_fd;
+ /* File descriptor of DWARF package file. */
+ int dwp_fd;
+
/* Information for traversing the .debug_pubnames section. This is
an array and separately allocated with malloc. */
struct pubnames_s
Dwarf_Off *abbrev_offsetp)
__nonnull_attribute__ (1, 7, 8) internal_function;
+/* Find the compilation unit in a DWARF package file with the given id. */
+extern Dwarf_CU *__libdw_dwp_findcu_id (Dwarf *dbg, uint64_t unit_id8)
+ __nonnull_attribute__ (1) internal_function;
+
/* Get abbreviation with given code. */
extern Dwarf_Abbrev *__libdw_findabbrev (struct Dwarf_CU *cu,
unsigned int code)
/* Get .debug_addr and addr_base greedy.
We also need it for the fake addr cu.
- There is only one per split debug. */
+ This needs to be done for each split unit (one per .dwo file, or multiple
+ per .dwp file). */
Dwarf *dbg = skel->dbg;
Dwarf *sdbg = split->dbg;
- if (sdbg->sectiondata[IDX_debug_addr] == NULL
- && dbg->sectiondata[IDX_debug_addr] != NULL)
+ if (dbg->sectiondata[IDX_debug_addr] != NULL
+ /* If this split file hasn't been linked yet... */
+ && (sdbg->sectiondata[IDX_debug_addr] == NULL
+ /* ... or it was linked to the same skeleton file for another
+ unit... */
+ || (sdbg->sectiondata[IDX_debug_addr]
+ == dbg->sectiondata[IDX_debug_addr])))
{
+ /* ... then link the address information for this file and unit. */
sdbg->sectiondata[IDX_debug_addr]
= dbg->sectiondata[IDX_debug_addr];
split->addr_base = __libdw_cu_addr_base (skel);
}
}
+static void
+try_dwp_file (Dwarf_CU *cu)
+{
+ if (cu->dbg->dwp_dwarf == NULL)
+ {
+ if (cu->dbg->elfpath != NULL)
+ {
+ /* The DWARF 5 standard says "the package file is typically placed in
+ the same directory as the application, and is given the same name
+ with a '.dwp' extension". */
+ size_t elfpath_len = strlen (cu->dbg->elfpath);
+ char *dwp_path = malloc (elfpath_len + 5);
+ if (dwp_path == NULL)
+ {
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return;
+ }
+ memcpy (dwp_path, cu->dbg->elfpath, elfpath_len);
+ strcpy (dwp_path + elfpath_len, ".dwp");
+ int dwp_fd = open (dwp_path, O_RDONLY);
+ free (dwp_path);
+ if (dwp_fd != -1)
+ {
+ Dwarf *dwp_dwarf = dwarf_begin (dwp_fd, DWARF_C_READ);
+ /* There's no way to know whether we got the correct file until
+ we look up the unit, but it should at least be a dwp file. */
+ if (dwp_dwarf != NULL
+ && (dwp_dwarf->sectiondata[IDX_debug_cu_index] != NULL
+ || dwp_dwarf->sectiondata[IDX_debug_tu_index] != NULL))
+ {
+ cu->dbg->dwp_dwarf = dwp_dwarf;
+ cu->dbg->dwp_fd = dwp_fd;
+ }
+ else
+ close (dwp_fd);
+ }
+ }
+ if (cu->dbg->dwp_dwarf == NULL)
+ cu->dbg->dwp_dwarf = (Dwarf *) -1;
+ }
+
+ if (cu->dbg->dwp_dwarf != (Dwarf *) -1)
+ {
+ Dwarf_CU *split = __libdw_dwp_findcu_id (cu->dbg->dwp_dwarf,
+ cu->unit_id8);
+ if (split != NULL)
+ {
+ if (tsearch (split->dbg, &cu->dbg->split_tree,
+ __libdw_finddbg_cb) == NULL)
+ {
+ /* Something went wrong. Don't link. */
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return;
+ }
+
+ /* Link skeleton and split compile units. */
+ __libdw_link_skel_split (cu, split);
+ }
+ }
+}
+
Dwarf_CU *
internal_function
__libdw_find_split_unit (Dwarf_CU *cu)
same id as the skeleton. */
if (cu->unit_type == DW_UT_skeleton)
{
+ /* First, try the dwp file. */
+ try_dwp_file (cu);
+
Dwarf_Die cudie = CUDIE (cu);
Dwarf_Attribute dwo_name;
- /* It is fine if dwo_dir doesn't exists, but then dwo_name needs
- to be an absolute path. */
- if (dwarf_attr (&cudie, DW_AT_dwo_name, &dwo_name) != NULL
- || dwarf_attr (&cudie, DW_AT_GNU_dwo_name, &dwo_name) != NULL)
+ /* Try a dwo file. It is fine if dwo_dir doesn't exist, but then
+ dwo_name needs to be an absolute path. */
+ if (cu->split == (Dwarf_CU *) -1
+ && (dwarf_attr (&cudie, DW_AT_dwo_name, &dwo_name) != NULL
+ || dwarf_attr (&cudie, DW_AT_GNU_dwo_name, &dwo_name) != NULL))
{
- /* First try the dwo file name in the same directory
+ /* Try the dwo file name in the same directory
as we found the skeleton file. */
const char *dwo_file = dwarf_formstring (&dwo_name);
const char *debugdir = cu->dbg->debugdir;