From 4979ec08bb6db7b7b8b02ce371dd1471baae1a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Sat, 8 Jun 2019 15:38:11 +0200 Subject: [PATCH] unw_step: add unique id debugging features --- src/x86_64/Ginit_remote.c | 5 ++++- src/x86_64/Gstep.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/x86_64/Ginit_remote.c b/src/x86_64/Ginit_remote.c index 93399143..8d8022f3 100644 --- a/src/x86_64/Ginit_remote.c +++ b/src/x86_64/Ginit_remote.c @@ -29,6 +29,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "../eh_elf/eh_elf.h" #include "unwind_i.h" +int init_id = 0; + PROTECTED int unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg) { @@ -42,7 +44,8 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg) if (!tdep_init_done) tdep_init (); - Debug (1, "(cursor=%p)\n", c); + init_id++; + Debug (1, "(init_id=%d, cursor=%p)\n", init_id, c); switch(eh_elf_acc->init_mode) { case UNW_EH_ELF_INIT_PID: diff --git a/src/x86_64/Gstep.c b/src/x86_64/Gstep.c index 5ed2568e..e7b03072 100644 --- a/src/x86_64/Gstep.c +++ b/src/x86_64/Gstep.c @@ -55,6 +55,18 @@ is_plt_entry (struct dwarf_cursor *c) return ret; } +extern int init_id; + +static int unw_step_id(unw_cursor_t *cursor) { + struct cursor *c = (struct cursor *) cursor; + return ( + ((c->dwarf.ip + c->dwarf.cfa * 257) % 1000003) + + (1000003 * init_id)) + % (1000000007); +} + +#define UnwDebug(lvl, fmt, ...) Debug(lvl, "[%X] " fmt, unw_step_id(cursor), ##__VA_ARGS__) + PROTECTED int unw_step (unw_cursor_t *cursor) {