Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions NativeScript/runtime/SymbolLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
#include "SymbolLoader.h"
#include "Helpers.h"
#include <dlfcn.h>
#include <os/log.h>

namespace tns {

// Unified logging: create a dedicated log for the SymbolLoader
static os_log_t ns_symbolloader_log() {
// Function-local static initialization is thread-safe in C++11+.
static os_log_t log = os_log_create("@nativescript/ios", "SymbolLoader");
return log;
}

class SymbolResolver {
public:
virtual void* loadFunctionSymbol(const char* symbolName) = 0;
Expand Down Expand Up @@ -35,7 +43,7 @@ virtual bool load() override {
CFErrorRef error = nullptr;
bool loaded = CFBundleLoadExecutableAndReturnError(this->_bundle, &error);
if (error) {
NSLog(@"%s", [[(NSError*)error localizedDescription] UTF8String]);
os_log_error(ns_symbolloader_log(), "%{public}s", [[(NSError*)error localizedDescription] UTF8String]);
}

return loaded;
Expand Down Expand Up @@ -100,8 +108,6 @@ virtual bool load() override {
NSURL* bundleUrl = [NSURL URLWithString:frameworkPathStr relativeToURL:baseUrl];
if (CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, (CFURLRef)bundleUrl)) {
resolver = std::make_unique<CFBundleSymbolResolver>(bundle);
} else {
NSLog(@"NativeScript could not load bundle %s\n", bundleUrl.absoluteString.UTF8String);
}
} else if (module->libraries->count == 1) {
if (module->isSystem()) {
Expand All @@ -110,10 +116,9 @@ virtual bool load() override {
NSString* libraryPath = [NSString stringWithFormat:@"%@/lib%s.dylib", libsPath, module->libraries->first()->value().getName()];

if (void* library = dlopen(libraryPath.UTF8String, RTLD_LAZY | RTLD_LOCAL)) {
NSLog(@"NativeScript loaded library %s\n", libraryPath.UTF8String);
resolver = std::make_unique<DlSymbolResolver>(library);
} else if (const char* libraryError = dlerror()) {
NSLog(@"NativeScript could not load library %s, error: %s\n", libraryPath.UTF8String, libraryError);
os_log_debug(ns_symbolloader_log(), "NativeScript could not load library %{public}s, error: %{public}s", libraryPath.UTF8String, libraryError);
}
}
}
Expand Down