Skip to content

Commit 9ed65f5

Browse files
committed
feat: dependency diagnostic for NativePlugin
1 parent 88945d5 commit 9ed65f5

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/ll/core/plugin/NativePluginManager.cpp

+49-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,57 @@
22
#include "ll/api/utils/ErrorUtils.h"
33
#include "ll/core/LeviLamina.h"
44

5+
#include <demangler/Demangle.h>
6+
#include <pl/dependency/DependencyWalker.h>
7+
58
#include "windows.h"
69

710
namespace ll::plugin {
811

912
NativePluginManager::NativePluginManager() : PluginManager(NativePluginManagerName) {}
1013
NativePluginManager::~NativePluginManager() = default;
1114

15+
static void printDependencyError(
16+
const std::unique_ptr<pl::dependency_walker::DependencyIssueItem>& item,
17+
std::ostream& stream,
18+
size_t depth = 0
19+
) {
20+
std::string indent(depth * 3 + 3, ' ');
21+
if (item->mContainsError) {
22+
stream << indent << fmt::format("module: {}", string_utils::u8str2str(item->mPath.u8string())) << std::endl;
23+
if (!item->mMissingModule.empty()) {
24+
stream << indent << "missing module:" << std::endl;
25+
for (const auto& missingModule : item->mMissingModule) {
26+
stream << indent << "|- " << missingModule << std::endl;
27+
}
28+
}
29+
if (!item->mMissingProcedure.empty()) {
30+
stream << indent << "missing procedure:" << std::endl;
31+
for (const auto& [module, missingProcedure] : item->mMissingProcedure) {
32+
stream << indent << "|- " << module << std::endl;
33+
for (const auto& procedure : missingProcedure) {
34+
stream << indent << "|---- " << procedure << std::endl;
35+
36+
auto de = demangler::demangle(procedure);
37+
if (de != procedure) stream << indent << "| " << de << std::endl;
38+
}
39+
}
40+
}
41+
if (!item->mDependencies.empty()) {
42+
for (const auto& [module, subItem] : item->mDependencies) {
43+
printDependencyError(subItem, stream, depth + 1);
44+
}
45+
}
46+
}
47+
}
48+
49+
std::string diagnosticDependency(const std::filesystem::path& path) {
50+
auto result = pl::dependency_walker::pl_diagnostic_dependency(path);
51+
std::stringstream stream;
52+
printDependencyError(result, stream);
53+
return stream.str();
54+
}
55+
1256
bool NativePluginManager::load(Manifest manifest) {
1357
auto l(lock());
1458
if (hasPlugin(manifest.name)) {
@@ -17,7 +61,11 @@ bool NativePluginManager::load(Manifest manifest) {
1761
auto entry = getPluginsRoot() / manifest.name / manifest.entry;
1862
auto lib = LoadLibrary(entry.c_str());
1963
if (!lib) {
20-
error_utils::printException(logger, error_utils::getWinLastError());
64+
auto e = error_utils::getWinLastError();
65+
error_utils::printException(logger, e);
66+
if (e.code().value() == 126 || e.code().value() == 127) {
67+
logger.error("Dependency diagnostic:\n{}", diagnosticDependency(entry));
68+
}
2169
return false;
2270
}
2371
auto plugin = std::make_shared<NativePlugin>(std::move(manifest), lib);

0 commit comments

Comments
 (0)