diff --git a/src/main.cpp b/src/main.cpp index 4eec8b2..6ca3405 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,12 +69,21 @@ int main(int argc, char **argv) { auto var_info = symbol.find_global_var(dbg, var_name); if (!var_info) { - std::cerr << "Error: Variable '" << var_name << "' not found" << std::endl; + std::cerr << "Error: Variable '" << var_name << "' not found or is not a supported integer type" << std::endl; + std::cerr << "Supported types: int (32-bit), long (64-bit), and unsigned variants" << std::endl; dwarf_finish(dbg); close(fd); return 1; } + // Validate variable size (only 4 or 8 bytes) + if (var_info->size != 4 && var_info->size != 8) { + std::cerr << "Error: Variable '" << var_name << "' has unsupported size: " << var_info->size << " bytes" << std::endl; + std::cerr << "Supported sizes: 4 bytes (int) or 8 bytes (long)" << std::endl; + dwarf_finish(dbg); + close(fd); + return 1; + } // Close DWARF resources before forking dwarf_finish(dbg); @@ -82,8 +91,8 @@ int main(int argc, char **argv) { // Start watching the variable Tracer tracer; - tracer.watch_variable(var_info->name, exec_path.string(), var_info->address, - var_info->size, prog_args); + int exit_code = tracer.watch_variable(var_info->name, exec_path.string(), var_info->address, + var_info->size, prog_args); - return 0; + return exit_code; }