Skip to content

Commit 214f513

Browse files
committed
TCling: Register and print list of autoloaded libraries.
Use `gInterpreter->Print(autoloaded);` to print a list of the libraries that have been automaticaly loaded during TClass::GetClass and due to a symbol requested during code interpretation.
1 parent 885f558 commit 214f513

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

Diff for: core/base/src/TROOT.cxx

+3
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,9 @@ Int_t TROOT::LoadClass(const char * /*classname*/, const char *libname,
22022202
// TSystem::Load returns 1 when the library was already loaded, return success in this case.
22032203
if (err == 1)
22042204
err = 0;
2205+
if (err == 0)
2206+
// Register the Autoloading of the library
2207+
gCling->RegisterAutoLoadedLibrary(libname);
22052208
return err;
22062209
}
22072210
} else {

Diff for: core/meta/inc/TInterpreter.h

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class TInterpreter : public TNamed {
194194
virtual void AddAvailableIndentifiers(TSeqCollection&) = 0;
195195
virtual void RegisterTClassUpdate(TClass *oldcl,DictFuncPtr_t dict) = 0;
196196
virtual void UnRegisterTClassUpdate(const TClass *oldcl) = 0;
197+
virtual void RegisterAutoLoadedLibrary(const char *libname) = 0;
197198
virtual Int_t SetClassSharedLibs(const char *cls, const char *libs) = 0;
198199
virtual void SetGetline(const char*(*getlineFunc)(const char* prompt),
199200
void (*histaddFunc)(const char* line)) = 0;

Diff for: core/metacling/src/TCling.cxx

+14
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,11 @@ void TCling::Print(Option_t *option) const
26762676
for (auto & cls : fAutoParseClasses) {
26772677
std::cout << " " << cls << std::endl;
26782678
}
2679+
} else if (!strcmp(option, "autoloaded")) {
2680+
std::cout << "Auto loaded libraries:" << std::endl;
2681+
for (auto & lib : fAutoLoadedLibraries) {
2682+
std::cout << " " << lib << std::endl;
2683+
}
26792684
} else {
26802685
::Error("TCling::Print", "Unknown option '%s'", option);
26812686
}
@@ -3455,6 +3460,14 @@ static bool StartsWithStrLit(const char *haystack, const char (&needle)[N]) {
34553460
}
34563461
}
34573462

3463+
////////////////////////////////////////////////////////////////////////////////
3464+
/// Register that a library was autoloaded either to provide a 'missing' symbol
3465+
/// or to provide a class (see TClass::GetClass and TROOT::LoadClass).
3466+
void TCling::RegisterAutoLoadedLibrary(const char *libname)
3467+
{
3468+
fAutoLoadedLibraries.insert(libname);
3469+
}
3470+
34583471
////////////////////////////////////////////////////////////////////////////////
34593472
/// Register a new shared library name with the interpreter; add it to
34603473
/// fSharedLibs.
@@ -6671,6 +6684,7 @@ void* TCling::LazyFunctionCreatorAutoload(const std::string& mangled_name) {
66716684
if (!LibLoader(libName))
66726685
return nullptr;
66736686

6687+
fAutoLoadedLibraries.insert(libName);
66746688
return llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(dlsym_mangled_name);
66756689
}
66766690

Diff for: core/metacling/src/TCling.h

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class TCling final : public TInterpreter {
122122
std::set<size_t> fPayloads; // Set of payloads
123123
std::set<const char*> fParsedPayloadsAddresses; // Set of payloads which were parsed
124124
std::set<std::string> fAutoParseClasses; // Set of classes for which we autoparsed a header
125+
std::set<std::string> fAutoLoadedLibraries; // Set of libraries that were autoloaded
125126
std::hash<std::string> fStringHashFunction; // A simple hashing function
126127
std::unordered_set<const clang::NamespaceDecl*> fNSFromRootmaps; // Collection of namespaces fwd declared in the rootmaps
127128
TObjArray* fRootmapFiles; // Loaded rootmap files.
@@ -259,6 +260,8 @@ class TCling final : public TInterpreter {
259260
void RegisterTClassUpdate(TClass *oldcl,DictFuncPtr_t dict) final;
260261
void UnRegisterTClassUpdate(const TClass *oldcl) final;
261262

263+
void RegisterAutoLoadedLibrary(const char *libname) final;
264+
262265
Int_t SetClassSharedLibs(const char *cls, const char *libs) final;
263266
void SetGetline(const char * (*getlineFunc)(const char* prompt),
264267
void (*histaddFunc)(const char* line)) final;

0 commit comments

Comments
 (0)