Get Calling Object HashCode?

It may be a duplicate, but I have not seen this exact question or a similar question asked / answered with a date later than the release of .Net 4.

I am looking for a temporary hack that allows me to view the call stack and get all the calling objects (not methods, but instances that store the methods) on the stack. Ultimately, I need their hash codes.

Is it possible?

EDIT:

If this concerned my question or not, I really asked if there is a simple / built-in way to do this. In fact, only a stop-logical correction until I can make changes to other parts of the system. Thanks for the great answers. Seeing them, I think I'll wait. :)

+3
source share
4 answers

?

, : EIP ?. . , (+1 ).

, , "" , : , AOP . .

Caveat 1: .NET

- . : MONO Object:: GetHash (mono/metadata/monitor.c)

#else
/*
 * Wang address-based hash function:
 *   http://www.concentric.net/~Ttwang/tech/addrhash.htm
 */
    return (GPOINTER_TO_UINT (obj) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
#endif

, , , : , - .

Caveat 2:

, -, , "". , . , , - LINQ, , , ; () , JIT , .

Takeaway: : API, .

:

.

  • ( , ); , : ( ?), .
  • , , VM CLR.
  • , API (, API- , : " " )
  • , , AOP
+5

, StackTrace StackFrame . , , , , .

+1

This is only possible with unmanaged APIs, in particular with the CLR profiling API. I know that this is nothing, except that it is used to implement profiling and debugging tools. You need to do this, and you will be comfortable burning 1 week, bringing it to production. If at all possible, abandon your plan and find an alternative. Tell us what you want to do, and we can help!

+1
source
0
source

All Articles