From d53ace06cf7d7e6cf6e9fe27dd5c19a97c3a0a5e Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Mar 2025 15:54:04 -0500 Subject: [PATCH] debuging --- flake.nix | 2 +- src/App.cpp | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 60f224b..bccdde0 100755 --- a/flake.nix +++ b/flake.nix @@ -66,7 +66,7 @@ ];*/ buildPhase = '' - g++ modules/print/src/*.cpp -fpic -shared -I src -I include -o $name + g++ modules/print/src/*.cpp src/App.cpp -fpic -shared -I src -I include -o $name ''; installPhase = '' diff --git a/src/App.cpp b/src/App.cpp index de2528b..73d22a7 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -19,12 +19,16 @@ App::App(const int& argc, char* argv[]) { App::~App() { - std::cout << "\nExiting..."; + std::cout << "\nExiting...\n"; for(auto it = modules.begin(); it != modules.end(); it++) { void* handle = (*it)->getHandle(); + std::cout << "retrieved handle\n"; delete *it; + std::cout << "deleted module\n"; dlclose(handle); - modules.erase(it); + std::cout << "closed lib\n"; + it = modules.erase(it); + std::cout << "erased list node\n"; } } @@ -34,28 +38,30 @@ void App::run() { // Main loop while (!done && !modules.empty()) { - for(auto it = modules.begin(); it != modules.end(); it++) + for(auto it = modules.begin(); it != modules.end(); it++) { + std::cout << "Running module: " << (*it)->getName() << std::endl; (*it)->run(); + } } } void App::load(std::string lib) { - void* handle = dlopen(lib.c_str(), RTLD_LAZY); + void* h = dlopen(lib.c_str(), RTLD_NOW); - if(!handle) { - std::cout << "could not open lib!\n"; + if(!h) { + std::cout << "could not open lib: \"" << lib.c_str() << "\"\nError: " << dlerror() << std::endl; return; } - Module::create_t* create = (Module::create_t*) dlsym(handle, "create"); + Module::create_t* create = (Module::create_t*) dlsym(h, "create"); if(dlerror()) { std::cout << "error finding create function in file: " << lib << std::endl; } - Module* m = create(handle); + Module* m = create(h); for(auto it = modules.begin(); it != modules.end(); it++) { @@ -96,7 +102,7 @@ void App::handleArgs(const int& argc, char* argv[]) { } while(i < argc) { - + std::cout << "Attempting to load: " << argv[i] << std::endl; load(argv[i]); i++;