restrict to 4-8 byte integer types only

This commit is contained in:
Gabriel Ionita 2025-10-27 22:20:00 +01:00
parent 433eae3ee8
commit 52710cf7d2
Signed by: gabi
SSH Key Fingerprint: SHA256:mrbYmB/SGtDvT3etRoS6pDrMYWxR0/B5GSF6rR3qhhc

View File

@ -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;
}