Files
exim-encrypt-dlfunc/src/debug_helpers.c
2021-09-11 02:26:39 +02:00

26 lines
918 B
C

/*
* Convert a string to its hexadecimal representation.
*
* Use like this:
* log_write(0, LOG_MAIN, "DEBUG: %s", string2hex(var, var_len));
*/
char *string2hex(unsigned char *input, size_t length) {
const int growth = 3;
char *outstring = store_get(growth * length + 1);
memset(outstring, 0, 3 * length + 1);
for (int i = 0; i < length; i++) {
sprintf(outstring + i * growth, "%02x ", input[i]);
}
return outstring;
}
/*
* How to debug this library:
*
* 1. Add this code to the first “breakpoint”:
* log_write(0, LOG_MAIN, "pid: %d", getpid()); int busywait = 0; while (busywait == 0) {}
* 2. Compile.
* 3. Run “exim -be […]” to call the lib; see test_libexim-encrypt-dlfunc.sh for details.
* 4. Read exim pid from log output. Attach to the looping exim process with “gdb -p PID”
* 5. Prepare breakpoints, watches, etc. Set busywait to 1 and continue.
*/