aboutsummaryrefslogtreecommitdiff
path: root/gas/dwarf2dbg.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-09-09 09:14:42 -0700
committerH.J. Lu <hjl.tools@gmail.com>2021-09-09 18:56:44 -0700
commit58f3b6a3495074da39ba6e19935e4401dcbacf88 (patch)
tree0502264d6cdc1b9524a452871a6bfe36636b61a9 /gas/dwarf2dbg.c
parent653cc1a141ca3ce901f31479f0f27abc99866cd5 (diff)
downloadgdb-58f3b6a3495074da39ba6e19935e4401dcbacf88.zip
gdb-58f3b6a3495074da39ba6e19935e4401dcbacf88.tar.gz
gdb-58f3b6a3495074da39ba6e19935e4401dcbacf88.tar.bz2
gas: Use the directory name in .file 0
DWARF5 allows .file 0 to take an optional directory name. Set the entry 0 of the directory table to the directory name in .file 0. PR gas/28266 * dwarf2dbg.c (get_directory_table_entry): Add an argument for the directory name in .file 0 and use it, instead of PWD. (allocate_filenum): Pass NULL to get_directory_table_entry. (allocate_filename_to_slot): Pass the incoming dirname to get_directory_table_entry. * testsuite/gas/elf/dwarf-5-file0-2.d: New file. * testsuite/gas/elf/dwarf-5-file0-2.s: Likewise. * testsuite/gas/elf/elf.exp: Run dwarf-5-file0-2.
Diffstat (limited to 'gas/dwarf2dbg.c')
-rw-r--r--gas/dwarf2dbg.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 8f52485..9e3437b 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -592,6 +592,7 @@ get_basename (const char * pathname)
static unsigned int
get_directory_table_entry (const char *dirname,
+ const char *file0_dirname,
size_t dirlen,
bool can_use_zero)
{
@@ -621,7 +622,7 @@ get_directory_table_entry (const char *dirname,
{
if (dirs == NULL || dirs[0] == NULL)
{
- const char * pwd = getpwd ();
+ const char * pwd = file0_dirname ? file0_dirname : getpwd ();
if (dwarf_level >= 5 && strcmp (dirname, pwd) != 0)
{
@@ -630,7 +631,8 @@ get_directory_table_entry (const char *dirname,
directory). Since we are about to create a directory entry that
is not the same, allocate the current directory first.
FIXME: Alternatively we could generate an error message here. */
- (void) get_directory_table_entry (pwd, strlen (pwd), true);
+ (void) get_directory_table_entry (pwd, NULL, strlen (pwd),
+ true);
d = 1;
}
else
@@ -726,7 +728,7 @@ allocate_filenum (const char * pathname)
file = get_basename (pathname);
dir_len = file - pathname;
- dir = get_directory_table_entry (pathname, dir_len, false);
+ dir = get_directory_table_entry (pathname, NULL, dir_len, false);
/* Do not use slot-0. That is specifically reserved for use by
the '.file 0 "name"' directive. */
@@ -766,6 +768,7 @@ allocate_filename_to_slot (const char *dirname,
const char *file;
size_t dirlen;
unsigned int i, d;
+ const char *file0_dirname = dirname;
/* Short circuit the common case of adding the same pathname
as last time. */
@@ -856,7 +859,8 @@ allocate_filename_to_slot (const char *dirname,
file = filename;
}
- d = get_directory_table_entry (dirname, dirlen, num == 0);
+ d = get_directory_table_entry (dirname, file0_dirname, dirlen,
+ num == 0);
i = num;
if (! assign_file_to_slot (i, file, d))