Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5942505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:15:45+00:00 2026-05-22T16:15:45+00:00

This might be a duplicate, but I haven’t seen this exact question or a

  • 0

This might be a duplicate, but I haven’t seen this exact question or a similar one asked/answered with a date newer than the release of .Net 4.

I’m looking for a temporary hack that allows me to look through the call stack and get all calling objects (not methods, but the instances that hold the methods) in the stack. Ultimately I need their hashcodes.

Is this possible?

EDIT:

Whether it came across in my question or not, was really asking if there was a simple/built-in way to do this. Really, just a stop-gap fix until I can make breaking changes to other parts of the system. Thanks for the great answers. After seeing them, I think I’ll wait . . . 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:15:46+00:00Added an answer on May 22, 2026 at 4:15 pm

    What are you trying to achieve here?

    Have a look at a similar question I answered about a month ago: How to get current value of EIP in managed code?. You might get some inspiration from that. Or you might decide it is too ugly (+1 for the latter).

    If all you want to do is assemble ‘unique’ call paths within a program session, go right ahead: I’d be very sure to use an AOP weaver and thread local storage. It wouldn’t be too hard that way.

    Caveat 1: Hashes are not very useful for generic .NET objects

    A random object’s hashcode may vary with it’s location on the heap to begin with. For reference: on MONO, with the moving heap allocator disabled, Object::GetHash is this pretty blob of code (mono/metadata/monitor.c)

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

    Of course, with the moving allocator things are slightly more complex to guarantee a constant hash over the lifetime of the object, but you get the point: each runtime will generate different hashes, and the amount of allocations done will alter the future default hash codes of the identical objects.

    Caveat 2: Your stack will contain alien frames

    Even if you got that part fixed by supplying proper deterministic hash functions, you will require each stackframe to be of ‘recgonizable’ type. This is probably not going to be the case. Certainly not if you use anything akin to LINQ, anonymous types, static constructors, delegates; all kinds of things could be interleaving stack frames with those of (anonymous) helper types, or even performance trampolines invented by the JIT compiler to optimize tail recursion, a large switch jump table or sharing code between multiple overloads.

    Takeaway: stack analysis is hard: you should definitely use the proper API if you are going to undertake it.

    Conclusion:

    By all means have a ball. But heed the advice

    1. your requirements are non-standard (underlined by the runtime library not supporting it); This is usually a sign that: you are solving a unique problem (but reconsider the tool chosen?) or you are solving it the wrong way
    2. You could perhaps get a lot more info by generating a flow graph with some handwritten simulation code instead of trying to hook into the CLR VM
    3. if you’re gonna do it, use the proper API (probably the profiler API since a sampling profiler will save exactly this: stack ‘fingerprints’ every so-many instructions)
    4. If you really must do it by instrumenting your code, consider using AOP
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greets. I realize this might be seen as a duplicate question as this but
This might be a duplicate question but as you can see they didn't get
Now this might look like a duplicate thread, but my question is that I
This might seem like a duplicate question, but I can't find any information on
This might be a duplicate ( question ) but I am looking specifically for
I know that this might be a duplicate of this question but that was
Possible Duplicate: How is std::iostream buffered? This might sound ridiculous, but how can I
This is an extension of this question and probably might even be a duplicate
This might seem like a stupid question I admit. But I'm in a small
This might sound like a little bit of a crazy question, but how can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.