mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-19 17:18:24 +08:00
Introduce find_source_or_rewrite
The final bug fix in this series would duplicate the logic in psymtab_to_fullname, so this patch extracts the body of this function into a new function.
This commit is contained in:
@ -953,26 +953,9 @@ psymtab_to_fullname (struct partial_symtab *ps)
|
|||||||
to handle cases like the file being moved. */
|
to handle cases like the file being moved. */
|
||||||
if (ps->fullname == NULL)
|
if (ps->fullname == NULL)
|
||||||
{
|
{
|
||||||
gdb::unique_xmalloc_ptr<char> fullname;
|
gdb::unique_xmalloc_ptr<char> fullname
|
||||||
scoped_fd fd = find_and_open_source (ps->filename, ps->dirname,
|
= find_source_or_rewrite (ps->filename, ps->dirname);
|
||||||
&fullname);
|
|
||||||
ps->fullname = fullname.release ();
|
ps->fullname = fullname.release ();
|
||||||
|
|
||||||
if (fd.get () < 0)
|
|
||||||
{
|
|
||||||
/* rewrite_source_path would be applied by find_and_open_source, we
|
|
||||||
should report the pathname where GDB tried to find the file. */
|
|
||||||
|
|
||||||
if (ps->dirname == NULL || IS_ABSOLUTE_PATH (ps->filename))
|
|
||||||
fullname.reset (xstrdup (ps->filename));
|
|
||||||
else
|
|
||||||
fullname.reset (concat (ps->dirname, SLASH_STRING,
|
|
||||||
ps->filename, (char *) NULL));
|
|
||||||
|
|
||||||
ps->fullname = rewrite_source_path (fullname.get ()).release ();
|
|
||||||
if (ps->fullname == NULL)
|
|
||||||
ps->fullname = fullname.release ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps->fullname;
|
return ps->fullname;
|
||||||
|
28
gdb/source.c
28
gdb/source.c
@ -1193,6 +1193,34 @@ open_source_file (struct symtab *s)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* See source.h. */
|
||||||
|
|
||||||
|
gdb::unique_xmalloc_ptr<char>
|
||||||
|
find_source_or_rewrite (const char *filename, const char *dirname)
|
||||||
|
{
|
||||||
|
gdb::unique_xmalloc_ptr<char> fullname;
|
||||||
|
|
||||||
|
scoped_fd fd = find_and_open_source (filename, dirname, &fullname);
|
||||||
|
if (fd.get () < 0)
|
||||||
|
{
|
||||||
|
/* rewrite_source_path would be applied by find_and_open_source, we
|
||||||
|
should report the pathname where GDB tried to find the file. */
|
||||||
|
|
||||||
|
if (dirname == nullptr || IS_ABSOLUTE_PATH (filename))
|
||||||
|
fullname.reset (xstrdup (filename));
|
||||||
|
else
|
||||||
|
fullname.reset (concat (dirname, SLASH_STRING,
|
||||||
|
filename, (char *) nullptr));
|
||||||
|
|
||||||
|
gdb::unique_xmalloc_ptr<char> rewritten
|
||||||
|
= rewrite_source_path (fullname.get ());
|
||||||
|
if (rewritten != nullptr)
|
||||||
|
fullname = std::move (rewritten);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullname;
|
||||||
|
}
|
||||||
|
|
||||||
/* Finds the fullname that a symtab represents.
|
/* Finds the fullname that a symtab represents.
|
||||||
|
|
||||||
This functions finds the fullname and saves it in s->fullname.
|
This functions finds the fullname and saves it in s->fullname.
|
||||||
|
@ -72,6 +72,13 @@ extern scoped_fd find_and_open_source (const char *filename,
|
|||||||
const char *dirname,
|
const char *dirname,
|
||||||
gdb::unique_xmalloc_ptr<char> *fullname);
|
gdb::unique_xmalloc_ptr<char> *fullname);
|
||||||
|
|
||||||
|
/* A wrapper for find_and_open_source that returns the full name. If
|
||||||
|
the full name cannot be found, a full name is constructed based on
|
||||||
|
the parameters, passing them through rewrite_source_path. */
|
||||||
|
|
||||||
|
extern gdb::unique_xmalloc_ptr<char> find_source_or_rewrite
|
||||||
|
(const char *filename, const char *dirname);
|
||||||
|
|
||||||
/* Open a source file given a symtab S. Returns a file descriptor or
|
/* Open a source file given a symtab S. Returns a file descriptor or
|
||||||
negative number for error. */
|
negative number for error. */
|
||||||
extern scoped_fd open_source_file (struct symtab *s);
|
extern scoped_fd open_source_file (struct symtab *s);
|
||||||
|
Reference in New Issue
Block a user