/* List lines of source files for GDB, the GNU debugger.
- Copyright (C) 1986-2019 Free Software Foundation, Inc.
+ Copyright (C) 1986-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "source-cache.h"
#include "cli/cli-style.h"
#include "observable.h"
+#include "build-id.h"
+#include "debuginfod-support.h"
#define OPEN_MODE (O_RDONLY | O_BINARY)
#define FDOPEN_MODE FOPEN_RB
result = gdb_open_cloexec (fullname->get (), OPEN_MODE, 0);
if (result >= 0)
{
- if (basenames_may_differ)
- *fullname = gdb_realpath (fullname->get ());
- else
- *fullname = gdb_abspath (fullname->get ());
+ *fullname = gdb_realpath (fullname->get ());
return scoped_fd (result);
}
if (rewritten_filename != NULL)
filename = rewritten_filename.get ();
- openp_flags flags = OPF_SEARCH_IN_PATH;
- if (basenames_may_differ)
- flags |= OPF_RETURN_REALPATH;
-
/* Try to locate file using filename. */
- result = openp (path, flags, filename, OPEN_MODE, fullname);
+ result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename,
+ OPEN_MODE, fullname);
if (result < 0 && dirname != NULL)
{
/* Remove characters from the start of PATH that we don't need when
cdir_filename.append (SLASH_STRING);
cdir_filename.append (filename_start);
- result = openp (path, flags, cdir_filename.c_str (), OPEN_MODE,
- fullname);
+ result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH,
+ cdir_filename.c_str (), OPEN_MODE, fullname);
}
if (result < 0)
{
/* Didn't work. Try using just the basename. */
p = lbasename (filename);
if (p != filename)
- result = openp (path, flags, p, OPEN_MODE, fullname);
+ result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, p,
+ OPEN_MODE, fullname);
}
return scoped_fd (result);
s->fullname = NULL;
scoped_fd fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s),
&fullname);
+
+ if (fd.get () < 0)
+ {
+ if (SYMTAB_COMPUNIT (s) != nullptr)
+ {
+ const objfile *ofp = COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (s));
+
+ std::string srcpath;
+ if (IS_ABSOLUTE_PATH (s->filename))
+ srcpath = s->filename;
+ else if (SYMTAB_DIRNAME (s) != nullptr)
+ {
+ srcpath = SYMTAB_DIRNAME (s);
+ srcpath += SLASH_STRING;
+ srcpath += s->filename;
+ }
+
+ const struct bfd_build_id *build_id = build_id_bfd_get (ofp->obfd);
+
+ /* Query debuginfod for the source file. */
+ if (build_id != nullptr && !srcpath.empty ())
+ fd = debuginfod_source_query (build_id->data,
+ build_id->size,
+ srcpath.c_str (),
+ &fullname);
+ }
+ }
+
s->fullname = fullname.release ();
return fd;
}
loc->set (s, line);
first_line_listed = line;
+ last_line_listed = line;
/* If printing of source lines is disabled, just print file and line
number. */
}
\f
+void _initialize_source ();
void
-_initialize_source (void)
+_initialize_source ()
{
struct cmd_list_element *c;