Track readable names of vmethod hooks for diagnostic messages.

Note that this changes the ABI of all plugins that use hooks.
develop
Alexander Gavrilov 2013-08-22 12:14:45 +04:00
parent 70a2ab9141
commit 896cd11fe9
3 changed files with 14 additions and 11 deletions

@ -288,9 +288,9 @@ void VMethodInterposeLinkBase::set_chain(void *chain)
addr_to_method_pointer_(chain_mptr, 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), : 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) applied(false), saved_chain(NULL), next(NULL), prev(NULL)
{ {
if (vmethod_idx < 0 || interpose_method == 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_ * - interpose_method comes from method_pointer_to_addr_
*/ */
fprintf(stderr, "Bad VMethodInterposeLinkBase arguments: %d %08x\n", fprintf(stderr, "Bad VMethodInterposeLinkBase arguments: %d %08x (%s)\n",
vmethod_idx, unsigned(interpose_method)); vmethod_idx, unsigned(interpose_method), name_str);
fflush(stderr); fflush(stderr);
abort(); abort();
} }

@ -141,7 +141,7 @@ namespace DFHack
#define IMPLEMENT_VMETHOD_INTERPOSE_PRIO(class,name,priority) \ #define IMPLEMENT_VMETHOD_INTERPOSE_PRIO(class,name,priority) \
DFHack::VMethodInterposeLink<class::interpose_base,class::interpose_ptr_##name> \ DFHack::VMethodInterposeLink<class::interpose_base,class::interpose_ptr_##name> \
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) #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 *interpose_method; // Pointer to the code of the interposing method
void *chain_mptr; // Pointer to the chain field in the subclass below void *chain_mptr; // Pointer to the chain field in the subclass below
int priority; // Higher priority hooks are called earlier 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 bool applied; // True if this hook is currently applied
void *saved_chain; // Pointer to the code of the original vmethod or next hook 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); VMethodInterposeLinkBase *get_first_interpose(virtual_identity *id);
bool find_child_hosts(virtual_identity *cur, void *vmptr); bool find_child_hosts(virtual_identity *cur, void *vmptr);
public: 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(); ~VMethodInterposeLinkBase();
bool is_applied() { return applied; } bool is_applied() { return applied; }
bool apply(bool enable = true); bool apply(bool enable = true);
void remove(); void remove();
const char *name() { return name_str; }
}; };
template<class Base, class Ptr> template<class Base, class Ptr>
@ -198,13 +201,13 @@ namespace DFHack
operator Ptr () { return chain; } operator Ptr () { return chain; }
template<class Ptr2> template<class Ptr2>
VMethodInterposeLink(Ptr target, Ptr2 src, int priority) VMethodInterposeLink(Ptr target, Ptr2 src, int priority, const char *name)
: VMethodInterposeLinkBase( : VMethodInterposeLinkBase(
&Base::_identity, &Base::_identity,
vmethod_pointer_to_idx(target), vmethod_pointer_to_idx(target),
method_pointer_to_addr(src), method_pointer_to_addr(src),
&chain, &chain,
priority priority, name
) )
{ src = target; /* check compatibility */ } { src = target; /* check compatibility */ }
}; };

@ -937,14 +937,14 @@ static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vect
if (vector_get(parameters, 1) == "disable") if (vector_get(parameters, 1) == "disable")
{ {
hook.remove(); 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 else
{ {
if (hook.apply()) 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 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());
} }
} }