1 /* debuginfod utilities for GDB.
2 Copyright (C) 2020 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "cli/cli-style.h"
22 #include "gdbsupport/scoped_fd.h"
23 #include "debuginfod-support.h"
25 #ifndef HAVE_LIBDEBUGINFOD
27 debuginfod_source_query (const unsigned char *build_id
,
30 gdb::unique_xmalloc_ptr
<char> *destname
)
32 return scoped_fd (-ENOSYS
);
36 debuginfod_debuginfo_query (const unsigned char *build_id
,
39 gdb::unique_xmalloc_ptr
<char> *destname
)
41 return scoped_fd (-ENOSYS
);
44 #include <elfutils/debuginfod.h>
46 /* TODO: Use debuginfod API extensions instead of these globals. */
47 static std::string desc
;
48 static std::string fname
;
49 static bool has_printed
;
52 progressfn (debuginfod_client
*c
, long cur
, long total
)
54 if (check_quit_flag ())
56 printf_filtered ("Cancelling download of %s %ps...\n",
58 styled_string (file_name_style
.style (), fname
.c_str ()));
62 if (!has_printed
&& total
!= 0)
64 /* Print this message only once. */
66 printf_filtered ("Downloading %s %ps...\n",
68 styled_string (file_name_style
.style (), fname
.c_str ()));
74 static debuginfod_client
*
77 debuginfod_client
*c
= debuginfod_begin ();
80 debuginfod_set_progressfn (c
, progressfn
);
85 /* See debuginfod-support.h */
88 debuginfod_source_query (const unsigned char *build_id
,
91 gdb::unique_xmalloc_ptr
<char> *destname
)
93 if (getenv (DEBUGINFOD_URLS_ENV_VAR
) == NULL
)
94 return scoped_fd (-ENOSYS
);
96 debuginfod_client
*c
= debuginfod_init ();
99 return scoped_fd (-ENOMEM
);
101 desc
= std::string ("source file");
102 fname
= std::string (srcpath
);
105 scoped_fd
fd (debuginfod_find_source (c
,
111 /* TODO: Add 'set debug debuginfod' command to control when error messages are shown. */
112 if (fd
.get () < 0 && fd
.get () != -ENOENT
)
113 printf_filtered (_("Download failed: %s. Continuing without source file %ps.\n"),
114 safe_strerror (-fd
.get ()),
115 styled_string (file_name_style
.style (), srcpath
));
117 destname
->reset (xstrdup (srcpath
));
123 /* See debuginfod-support.h */
126 debuginfod_debuginfo_query (const unsigned char *build_id
,
128 const char *filename
,
129 gdb::unique_xmalloc_ptr
<char> *destname
)
131 if (getenv (DEBUGINFOD_URLS_ENV_VAR
) == NULL
)
132 return scoped_fd (-ENOSYS
);
134 debuginfod_client
*c
= debuginfod_init ();
137 return scoped_fd (-ENOMEM
);
139 desc
= std::string ("separate debug info for");
140 fname
= std::string (filename
);
142 char *dname
= nullptr;
144 scoped_fd
fd (debuginfod_find_debuginfo (c
, build_id
, build_id_len
, &dname
));
146 if (fd
.get () < 0 && fd
.get () != -ENOENT
)
147 printf_filtered (_("Download failed: %s. Continuing without debug info for %ps.\n"),
148 safe_strerror (-fd
.get ()),
149 styled_string (file_name_style
.style (), filename
));
151 destname
->reset (dname
);
This page took 0.034851 seconds and 4 git commands to generate.