Skip to content

Commit

Permalink
Track readable names of vmethod hooks for diagnostic messages.
Browse files Browse the repository at this point in the history
Note that this changes the ABI of all plugins that use hooks.
  • Loading branch information
angavrilov committed Aug 22, 2013
1 parent 70a2ab9 commit 896cd11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions library/VTableInterpose.cpp
Expand Up @@ -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)
Expand All @@ -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();
}
Expand Down
11 changes: 7 additions & 4 deletions library/include/VTableInterpose.h
Expand Up @@ -141,7 +141,7 @@ namespace DFHack

#define IMPLEMENT_VMETHOD_INTERPOSE_PRIO(class,name,priority) \
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)

Expand All @@ -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
Expand All @@ -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<class Base, class Ptr>
Expand All @@ -198,13 +201,13 @@ namespace DFHack
operator Ptr () { return chain; }

template<class Ptr2>
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 */ }
};
Expand Down
6 changes: 3 additions & 3 deletions plugins/tweak.cpp
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 896cd11

Please sign in to comment.