diff options
author | Tom Tromey <tom@tromey.com> | 2021-07-04 13:26:15 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-07-17 10:41:42 -0600 |
commit | 4584f33d68b79c362ce9f3543052027b1676f30e (patch) | |
tree | 70a1be2b98dff96f47a37bb1df0bcfcbc97ba34b /gdb/source.c | |
parent | d030267c9cc0fb594d3dda264b78114afc6eb214 (diff) | |
download | gdb-4584f33d68b79c362ce9f3543052027b1676f30e.zip gdb-4584f33d68b79c362ce9f3543052027b1676f30e.tar.gz gdb-4584f33d68b79c362ce9f3543052027b1676f30e.tar.bz2 |
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.
Diffstat (limited to 'gdb/source.c')
-rw-r--r-- | gdb/source.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gdb/source.c b/gdb/source.c index c993e25..7d1934b 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1193,6 +1193,34 @@ open_source_file (struct symtab *s) 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. This functions finds the fullname and saves it in s->fullname. |