From 896cd11fe92c5a069c0cdf14bdda17c7e286f0b0 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 22 Aug 2013 12:14:45 +0400 Subject: [PATCH] Track readable names of vmethod hooks for diagnostic messages. Note that this changes the ABI of all plugins that use hooks. --- library/VTableInterpose.cpp | 8 ++++---- library/include/VTableInterpose.h | 11 +++++++---- plugins/tweak.cpp | 6 +++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/library/VTableInterpose.cpp b/library/VTableInterpose.cpp index 0db5ac03c..1184865ac 100644 --- a/library/VTableInterpose.cpp +++ b/library/VTableInterpose.cpp @@ -288,9 +288,9 @@ void VMethodInterposeLinkBase::set_chain(void *chain) addr_to_method_pointer_(chain_mptr, chain); } -VMethodInterposeLinkBase::VMethodInterposeLinkBase(virtual_identity *host, int vmethod_idx, void *interpose_method, void *chain_mptr, int priority) +VMethodInterposeLinkBase::VMethodInterposeLinkBase(virtual_identity *host, int vmethod_idx, void *interpose_method, void *chain_mptr, int priority, const char *name) : host(host), vmethod_idx(vmethod_idx), interpose_method(interpose_method), - chain_mptr(chain_mptr), priority(priority), + chain_mptr(chain_mptr), priority(priority), name_str(name), applied(false), saved_chain(NULL), next(NULL), prev(NULL) { if (vmethod_idx < 0 || interpose_method == NULL) @@ -303,8 +303,8 @@ VMethodInterposeLinkBase::VMethodInterposeLinkBase(virtual_identity *host, int v * - interpose_method comes from method_pointer_to_addr_ */ - fprintf(stderr, "Bad VMethodInterposeLinkBase arguments: %d %08x\n", - vmethod_idx, unsigned(interpose_method)); + fprintf(stderr, "Bad VMethodInterposeLinkBase arguments: %d %08x (%s)\n", + vmethod_idx, unsigned(interpose_method), name_str); fflush(stderr); abort(); } diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h index 8e2541c55..f93eb4176 100644 --- a/library/include/VTableInterpose.h +++ b/library/include/VTableInterpose.h @@ -141,7 +141,7 @@ namespace DFHack #define IMPLEMENT_VMETHOD_INTERPOSE_PRIO(class,name,priority) \ DFHack::VMethodInterposeLink \ - class::interpose_##name(&class::interpose_base::name, &class::interpose_fn_##name, priority); + class::interpose_##name(&class::interpose_base::name, &class::interpose_fn_##name, priority, #class"::"#name); #define IMPLEMENT_VMETHOD_INTERPOSE(class,name) IMPLEMENT_VMETHOD_INTERPOSE_PRIO(class,name,0) @@ -161,6 +161,7 @@ namespace DFHack void *interpose_method; // Pointer to the code of the interposing method void *chain_mptr; // Pointer to the chain field in the subclass below int priority; // Higher priority hooks are called earlier + const char *name_str; // Name of the hook bool applied; // True if this hook is currently applied void *saved_chain; // Pointer to the code of the original vmethod or next hook @@ -179,12 +180,14 @@ namespace DFHack VMethodInterposeLinkBase *get_first_interpose(virtual_identity *id); bool find_child_hosts(virtual_identity *cur, void *vmptr); public: - VMethodInterposeLinkBase(virtual_identity *host, int vmethod_idx, void *interpose_method, void *chain_mptr, int priority); + VMethodInterposeLinkBase(virtual_identity *host, int vmethod_idx, void *interpose_method, void *chain_mptr, int priority, const char *name); ~VMethodInterposeLinkBase(); bool is_applied() { return applied; } bool apply(bool enable = true); void remove(); + + const char *name() { return name_str; } }; template @@ -198,13 +201,13 @@ namespace DFHack operator Ptr () { return chain; } template - VMethodInterposeLink(Ptr target, Ptr2 src, int priority) + VMethodInterposeLink(Ptr target, Ptr2 src, int priority, const char *name) : VMethodInterposeLinkBase( &Base::_identity, vmethod_pointer_to_idx(target), method_pointer_to_addr(src), &chain, - priority + priority, name ) { src = target; /* check compatibility */ } }; diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index 59465b99f..337759348 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -937,14 +937,14 @@ static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vect if (vector_get(parameters, 1) == "disable") { hook.remove(); - out.print("Disabled tweak %s\n", parameters[0].c_str()); + out.print("Disabled tweak %s (%s)\n", parameters[0].c_str(), hook.name()); } else { if (hook.apply()) - out.print("Enabled tweak %s\n", parameters[0].c_str()); + out.print("Enabled tweak %s (%s)\n", parameters[0].c_str(), hook.name()); else - out.printerr("Could not activate tweak %s\n", parameters[0].c_str()); + out.printerr("Could not activate tweak %s (%s)\n", parameters[0].c_str(), hook.name()); } }