add logging
This commit is contained in:
46
src/hiload.c
46
src/hiload.c
@@ -1,6 +1,7 @@
|
||||
#include "hiload/hiload.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "logger/sc_log.h"
|
||||
#include "memory.h"
|
||||
#include "symbols.h"
|
||||
#include "types.h"
|
||||
@@ -31,24 +32,27 @@ static ModuleInfos *module_infos = 0;
|
||||
// Callback function for dl_iterate_phdr
|
||||
static int gather_module_infos_callback(struct dl_phdr_info *info, size_t size,
|
||||
void *data) {
|
||||
|
||||
ModuleInfos *infos = (ModuleInfos *)data;
|
||||
{
|
||||
// Resize arrays if needed
|
||||
if (infos->count >= infos->capacity) {
|
||||
infos->capacity *= 2;
|
||||
char **new_names =
|
||||
realloc(infos->names, infos->capacity * sizeof(char *));
|
||||
void **new_handles =
|
||||
realloc(infos->handles, infos->capacity * sizeof(void *));
|
||||
SymbolInfos *new_symbols =
|
||||
realloc(infos->symbols, infos->capacity * sizeof(SymbolInfos));
|
||||
|
||||
// Resize arrays if needed
|
||||
if (infos->count >= infos->capacity) {
|
||||
infos->capacity *= 2;
|
||||
char **new_names = realloc(infos->names, infos->capacity * sizeof(char *));
|
||||
void **new_handles =
|
||||
realloc(infos->handles, infos->capacity * sizeof(void *));
|
||||
SymbolInfos *new_symbols =
|
||||
realloc(infos->symbols, infos->capacity * sizeof(SymbolInfos));
|
||||
if (!new_names || !new_handles || !new_symbols) {
|
||||
return 1; // Stop iteration on error
|
||||
}
|
||||
|
||||
if (!new_names || !new_handles || !new_symbols) {
|
||||
return 1; // Stop iteration on error
|
||||
infos->names = new_names;
|
||||
infos->handles = new_handles;
|
||||
infos->symbols = new_symbols;
|
||||
}
|
||||
|
||||
infos->names = new_names;
|
||||
infos->handles = new_handles;
|
||||
infos->symbols = new_symbols;
|
||||
}
|
||||
|
||||
// Store the module name
|
||||
@@ -57,12 +61,21 @@ static int gather_module_infos_callback(struct dl_phdr_info *info, size_t size,
|
||||
return 1; // Stop iteration on error
|
||||
}
|
||||
|
||||
sc_log_info("Processing: %s\n", info->dlpi_name);
|
||||
|
||||
// Try to get the handle
|
||||
infos->handles[infos->count] =
|
||||
dlopen(info->dlpi_name, RTLD_LAZY | RTLD_NOLOAD);
|
||||
|
||||
if (hi_create_symbol_info(&infos->symbols[infos->count], info) !=
|
||||
CREATE_SUCCESS) {
|
||||
sc_log_debug(" size: %u\n", size);
|
||||
sc_log_debug(" handle: %p\n", infos->handles[infos->count]);
|
||||
sc_log_debug(" dlpi_addr: %p\n", info->dlpi_addr);
|
||||
sc_log_debug(" dlpi_tls_modid: %zu\n", info->dlpi_tls_modid);
|
||||
sc_log_debug(" dlpi_tls_data: %p\n", info->dlpi_tls_data);
|
||||
|
||||
|
||||
if (hi_create_symbol_info(&infos->symbols[infos->count],
|
||||
&context.memory_regions, info) != CREATE_SUCCESS) {
|
||||
fprintf(stderr, "Failed to create symbol info for %s\n",
|
||||
infos->names[infos->count]);
|
||||
}
|
||||
@@ -266,7 +279,6 @@ int hi_init() {
|
||||
}
|
||||
sc_log_set_level("DEBUG");
|
||||
|
||||
|
||||
if (read_memory_maps_self(&context.memory_regions) != HILOAD_OK) {
|
||||
sc_log_error("Could not populate program memory maps.\n");
|
||||
return HILOAD_FAIL;
|
||||
|
||||
Reference in New Issue
Block a user