Looking for a command that will return the proc, func, etc that uses another proc, func, etc

1

Grep-ing for a function name to see where it's being used returns a list of rows and row numbers. Is there a smart way of using grep and awk to get the name of the calling procedure instead?

Thanks

Andreas

Posted 2012-03-22T10:50:37.750

Reputation: 71

What do you mean by name of the calling procedure? – soandos – 2012-03-22T10:55:17.020

When you find the file with the name you are looking for and you open it, you have to scroll up to find the procedure that calls it. I am using vi so the option of an IDE isn't a choice. – Andreas – 2012-03-22T10:56:25.293

I mean, for example, you are looking for instances of a function called "foo()" in all files in a tree. The calling procedure/function would be the function that uses foo(), or that has foo() as part of its definition. – Andreas – 2012-03-22T10:57:57.990

The aim of this is after finding the line that the function call appears in, to find the context in which it's being used. – Andreas – 2012-03-22T11:05:25.610

Answers

2

For jumping to the definition of an identifier: Exuberant Ctags

http://ctags.sourceforge.net/

For finding uses of an identifier: GNU ID-Utils (mkid indexer, lid query command)

http://www.gnu.org/software/idutils/

Kaz

Posted 2012-03-22T10:50:37.750

Reputation: 2 277

ctags also has hotkey support in vim at least (and I'm sure other editors) to quickly jump to function definitions while coding. – mikebabcock – 2012-05-30T16:06:15.497