This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC] redebug - error reporting.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Fri, 25 Oct 2013 10:17:50 +0200
- Subject: [RFC] redebug - error reporting.
- Authentication-results: sourceware.org; auth=none
- References: <20131021193617 dot GA29829 at domone dot podge>
Hi, when I thougth about reporting of undefined and best was to run
process in gdb with set breakpoints when undefined behaviour is
detected.
Ideally we would run this in reversible debugger which could answer
queries like 'rewind to time just before this variable was freed' for
use after free/double free.
We can almost support queries like this with following techique. It
requires that user has program with deterministic inputs.
We add a counter in various points of execution which will be passed as
ordinary variable.
When a error happens we print a watch command that user will pass back
to gdb. User then runs program again which causes gdb to stop when
original countpoint was assigned.
This functionality could be wrapped in gdb scripts, for now a output
could look like
free: double free, to rewind to first free use watchpoint:
watch *0x123432 == 1354332
I do not know yet how best handle multithreaded environment, If address
of thread-local variable stays same for multiple runs of program it
would do a job.
Comments?
A simple implementation what I described is following. A determinism
requirement could be relaxed by making separate counter for each caller
which would make implementation more technical.
#include <stdint.h>
struct redebug {
uint64_t __addr;
uint64_t __cnt;
};
#define redebug_countpoint() ({ \
static __thread uint64_t __count; \
__count++; \
struct redebug __r; \
__r.__addr = (uint64_t) (&__count); \
__r.__cnt = __count; \
__r; \
})
#define redebug_print(fd, countpoint) fprintf (fd, "'watch *%lx == %lx'\n" ,\
countpoint.__addr, \
countpoint.__cnt)