@@ -30,9 +30,9 @@ Context::Context()
3030}
3131
3232std::shared_ptr<Dwarf::Info>
33- Context::getDwarf (const std::filesystem::path &filename)
33+ Context::findDwarf (const std::filesystem::path &filename)
3434{
35- return getDwarf ( getImage (filename));
35+ return findDwarf ( findImage (filename));
3636}
3737
3838debuginfod_client *
@@ -66,13 +66,13 @@ Context::debuginfod()
6666
6767
6868std::shared_ptr<Dwarf::Info>
69- Context::getDwarf (const Elf::BuildID &bid)
69+ Context::findDwarf (const Elf::BuildID &bid)
7070{
71- return getDwarf ( getImage (bid));
71+ return findDwarf ( findImage (bid));
7272}
7373
7474Dwarf::Info::sptr
75- Context::getDwarf (Elf::Object::sptr object)
75+ Context::findDwarf (Elf::Object::sptr object)
7676{
7777 auto it = dwarfCache.find (object);
7878 counters.dwarfLookups ++;
@@ -154,6 +154,11 @@ Context::getImageIfLoaded(const Container &ctr, const typename Container::key_ty
154154 return {};
155155}
156156
157+ std::shared_ptr<Elf::Object>
158+ Context::openImage (const std::filesystem::path &path, int fd, bool isDebug) {
159+ return std::make_shared<Elf::Object>(*this , std::make_shared<MmapReader>(*this , path, fd) , isDebug);
160+ }
161+
157162/*
158163 * Find an image from a name, caching in container, and using "paths" as potential prefixes for name
159164 */
@@ -178,7 +183,7 @@ Context::getImageInPath(const std::vector<std::filesystem::path> &paths, NameMap
178183 }
179184 }
180185 try {
181- res = std::make_shared<Elf::Object>(* this , std::make_shared<MmapReader>(* this , path) , isDebug);
186+ res = openImage ( path, - 1 , isDebug );
182187 break ;
183188 }
184189 catch (const std::exception &ex) {
@@ -199,7 +204,7 @@ Context::getImageInPath(const std::vector<std::filesystem::path> &paths, NameMap
199204 * get an image from a filename
200205 */
201206std::shared_ptr<Elf::Object>
202- Context::getImage (const std::filesystem::path &name) {
207+ Context::findImage (const std::filesystem::path &name) {
203208 if (options.noLocalFiles )
204209 return nullptr ;
205210 return getImageInPath (exePrefixes, imageByName, name, false , false );
@@ -208,7 +213,7 @@ Context::getImage(const std::filesystem::path &name) {
208213/*
209214 * get an image, given its build ID. It may be a debug image, or an
210215 * "executable". We first defer to the filesystem, using the string versions of
211- * "getImage ", and a broken-down form of the build id, with the first octet of
216+ * "findImage ", and a broken-down form of the build id, with the first octet of
212217 * the build-id being a directlry name, and the remainder being the filename,
213218 * with a possible suffix. This allows us to find things of the form
214219 * /usr/lib/debug/build-id/NN/NNNNNNNNNNNNNNNNNNNN.debug for example. The
@@ -218,42 +223,42 @@ Context::getImage(const std::filesystem::path &name) {
218223
219224std::shared_ptr<Elf::Object> Context::getImageImpl ( const Elf::BuildID &bid, bool isDebug) {
220225
221- IdMap &container = isDebug ? debugImageByID : imageByID;
222- NameMap &nameContainer = isDebug ? debugImageByName : imageByName;
223- std::vector<std::filesystem::path> &paths = isDebug ? debugBuildIdPrefixes : exeBuildIdPrefixes;
224-
226+ Elf::Object::sptr res;
225227 if (!bid || options.noBuildIds )
226228 return nullptr ;
229+ IdMap &container = isDebug ? debugImageByID : imageByID;
230+
227231 std::optional<Elf::Object::sptr> cached = getImageIfLoaded ( container, bid, isDebug );
228232 if (cached)
229233 return *cached;
230234
231- std::stringstream bucket;
232- bucket << AsHex ( bid[ 0 ] );
233- std::stringstream rest;
234- rest << AsHex (std::views::all (bid) | std::views::drop (1 ));
235- if ( isDebug )
236- rest << " .debug" ;
235+ if (!options.noLocalFiles ) {
236+ NameMap &nameContainer = isDebug ? debugImageByName : imageByName;
237+ std::vector<std::filesystem::path> &paths = isDebug ? debugBuildIdPrefixes : exeBuildIdPrefixes;
237238
238- std::filesystem::path bidpath = std::filesystem::path ( bucket.str () ) / std::filesystem::path ( rest.str () );
239+ std::stringstream bucket;
240+ bucket << AsHex ( bid[ 0 ] );
241+ std::stringstream rest;
242+ rest << AsHex (std::views::all (bid) | std::views::drop (1 ));
243+ if ( isDebug )
244+ rest << " .debug" ;
239245
240- Elf::Object::sptr res = getImageInPath (paths, nameContainer, bidpath, isDebug, true );
246+ std::filesystem::path bidpath = std::filesystem::path ( bucket.str () ) / std::filesystem::path ( rest.str () );
247+ res = getImageInPath (paths, nameContainer, bidpath, isDebug, true );
248+ }
241249#ifdef DEBUGINFOD
242250 if (!res && debuginfod ()) {
243- char *path;
251+ char *path = nullptr ;
244252 int progress = 0 ;
245253 debuginfod_set_user_data (debuginfod (), &progress);
246254 int fd = (isDebug ? debuginfod_find_debuginfo : debuginfod_find_executable)
247255 (debuginfod (), bid.data (), int ( bid.size () ), &path);
248256 if (progress > 0 ) {
257+ // If we reported progress at least once, move to the next line
249258 std::cerr << " \n " ;
250259 }
251260 if (fd >= 0 ) {
252- // Wrap the fd in a reader, and then a cache reader...
253- std::shared_ptr<Reader> reader = std::make_shared<FileReader>(*this , path, fd );
254- reader = std::make_shared<CacheReader>(reader);
255- // and then wrap the lot in an ELF object.
256- res = std::make_shared<Elf::Object>( *this , reader, true );
261+ res = openImage ( path, fd, true );
257262 free (path);
258263 if (verbose)
259264 *debug << " fetched " << *res->io << " for " << bid << " with debuginfod\n " ;
@@ -267,7 +272,7 @@ std::shared_ptr<Elf::Object> Context::getImageImpl( const Elf::BuildID &bid, boo
267272}
268273
269274std::shared_ptr<Elf::Object>
270- Context::getDebugImage (const std::filesystem::path &name) {
275+ Context::findDebugImage (const std::filesystem::path &name) {
271276 return getImageInPath (debugPrefixes, debugImageByName, name, true , false );
272277}
273278
@@ -279,8 +284,8 @@ int debuginfod_find_executable (debuginfod_client *, const unsigned char *, int,
279284}
280285#endif
281286
282- std::shared_ptr<Elf::Object> Context::getDebugImage (const Elf::BuildID &bid) { return getImageImpl (bid, true ); }
283- std::shared_ptr<Elf::Object> Context::getImage (const Elf::BuildID &bid) { return getImageImpl (bid, false ); }
287+ std::shared_ptr<Elf::Object> Context::findDebugImage (const Elf::BuildID &bid) { return getImageImpl (bid, true ); }
288+ std::shared_ptr<Elf::Object> Context::findImage (const Elf::BuildID &bid) { return getImageImpl (bid, false ); }
284289
285290std::shared_ptr<const Reader>
286291Context::loadFile (const std::filesystem::path &path) {
0 commit comments