Find where a specific method gets called

Is there a way to find all places in my code base where a specific method (not function!) gets called (or may get called)? The method in question for me is Base.*, so greping for * over the whole code base produces way to many hits and I really only want all the places where my specific implementation of Base.* for some custom types gets called.

Could I e.g. inside my method definition add some code to find out where it got called from and
print that and run the tests that I have? So something like:

function Base.*(a::MyType, b::MyType)
    return dostuff(a, b)

where whocalledme() returns where Base.* just got called from and probably involves some debugger magic. Is such a thing possible?


and read the back trace

1 Like

backtrace was indeed the word I was looking for, thanks for pointing me in that direction!

I do the following now

function Base.*(a::MyType, b::MyType)
    tr = backtrace()
    Base.show_backtrace(stdout, tr[1:2]) # I don't need the whole trace
    return dostuff(a, b)

which has the advantage that execution does not stop and prints only the interesting part of the stacktrace.