unable to find function definition
i was going through the code leds-gpio.c. i found a function "platform_gpio_blink_set" declared under private data of "gpio_led_data",and was trying to get through this function. But hardly i can find any link to definition for the same anywhere. Regards Nijam
On Wed, Apr 20, 2016 at 06:17:38AM +0000, Nijam Haider wrote:
i was going through the code leds-gpio.c. i found a function "platform_gpio_blink_set" declared under private data of "gpio_led_data",and was trying to get through this function. But hardly i can find any link to definition for the same anywhere.
Hi, That is a function pointer, so you should search assignments to that pointer. That way you can find the real function you are looking for.
On 20 April 2016 at 12:56, Cihangir Akturk <cakturk@gmail.com> wrote:
On Wed, Apr 20, 2016 at 06:17:38AM +0000, Nijam Haider wrote:
i was going through the code leds-gpio.c. i found a function "platform_gpio_blink_set" declared under private data of "gpio_led_data",and was trying to get through this function. But hardly i can find any link to definition for the same anywhere.
Hi,
That is a function pointer, so you should search assignments to that pointer. That way you can find the real function you are looking for.
I've spotted such usages in a lot of places, outside the kernel as well. Just wanted know if there is a smarted way of finding the assignments, like some tools or any other tips which people could use to make life easier ?
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Thanks and Regards, Aurabindo J
Ctags can help. Ctags -R on the entire source. On 26 Apr 2016 2:19 p.m., "Jay Aurabind" <jay.aurabind@gmail.com> wrote:
On 20 April 2016 at 12:56, Cihangir Akturk <cakturk@gmail.com> wrote:
On Wed, Apr 20, 2016 at 06:17:38AM +0000, Nijam Haider wrote:
i was going through the code leds-gpio.c. i found a function "platform_gpio_blink_set" declared under private data of "gpio_led_data",and was trying to get through this function. But hardly i can find any link to definition for the same anywhere.
Hi,
That is a function pointer, so you should search assignments to that pointer. That way you can find the real function you are looking for.
I've spotted such usages in a lot of places, outside the kernel as well. Just wanted know if there is a smarted way of finding the assignments, like some tools or any other tips which people could use to make life easier ?
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
--
Thanks and Regards, Aurabindo J
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On 26 April 2016 at 16:15, Silvan Jegen <me@sillymon.ch> wrote:
Am 2016-04-26 10:50, schrieb Gadre Nayan:
Ctags can help. Ctags -R on the entire source.
In the Kernel Makefile there is actually a target for this. It's called either 'tags' or 'tag' so
make tags [or tag]
should create the ctag file for you.
I use ctags with vim. Mostly it takes me to declaration of the function pointer. Then i go grep for that function and look for its assignment. I was wondering if there is some plugin or script which can find assignments to such function pointers.
Cheers,
Silvan
-- Thanks and Regards, Aurabindo J
Am 2016-04-26 14:56, schrieb Jay Aurabind:
On 26 April 2016 at 16:15, Silvan Jegen <me@sillymon.ch> wrote:
Am 2016-04-26 10:50, schrieb Gadre Nayan:
Ctags can help. Ctags -R on the entire source.
In the Kernel Makefile there is actually a target for this. It's called either 'tags' or 'tag' so
make tags [or tag]
should create the ctag file for you.
I use ctags with vim. Mostly it takes me to declaration of the function pointer. Then i go grep for that function and look for its assignment. I was wondering if there is some plugin or script which can find assignments to such function pointers.
A simple but naive approach would be a grep command like this. grep "function_pointer =" `find . -iname '*.c' -o -iname '*.h'` Cheers, Silvan
On Tue, 26 Apr 2016 15:31:51 +0200, Silvan Jegen said:
A simple but naive approach would be a grep command like this.
grep "function_pointer =" `find . -iname '*.c' -o -iname '*.h'`
Two better ways: grep -r "function_pointer =' [A-Za-z]* find * -name '*.[ch]' | xargs grep 'function pointer =' Hint 1: Globbing * rather than . is a win at the top level of the kernel source, because * won't match .git, which is a gigabyte or so of stuff that you don't want to grep through Hint 2: You want -name rather than -iname because there shouldn't be any *.C or *.H files in the tree, and avoiding case-insensitive matches is a bit faster. And another winner if you have a git tree (which of course you should): git grep 'function_pointer =' One gotcha is that in some places, the kernel does evil pre-processor stuff like: #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i) #define ATOMIC_LONG_PFX(x) atomic ## x #endif #define ATOMIC_LONG_READ_OP(mo) static inline long atomic_long_read##mo(const atomic_long_t *l) { ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; return (long)ATOMIC_LONG_PFX(_read##mo)(v); } ATOMIC_LONG_READ_OP() ATOMIC_LONG_READ_OP(_acquire) (this example from include/asm-generic/atomic-long.h, but similar ## abuse happens elsewhere as well...)
On Tue, Apr 26, 2016 at 11:24:43AM -0400, Valdis.Kletnieks@vt.edu wrote:
On Tue, 26 Apr 2016 15:31:51 +0200, Silvan Jegen said:
A simple but naive approach would be a grep command like this.
grep "function_pointer =" `find . -iname '*.c' -o -iname '*.h'`
Two better ways:
grep -r "function_pointer =' [A-Za-z]*
find * -name '*.[ch]' | xargs grep 'function pointer ='
Hint 1: Globbing * rather than . is a win at the top level of the kernel source, because * won't match .git, which is a gigabyte or so of stuff that you don't want to grep through
Good idea! There may also be cases where there is no space before the assignment so using a regexp like this may be better. grep 'function_pointer ?='
Hint 2: You want -name rather than -iname because there shouldn't be any *.C or *.H files in the tree, and avoiding case-insensitive matches is a bit faster.
True, this was mostly muscle memory.
And another winner if you have a git tree (which of course you should):
git grep 'function_pointer ='
Looks useful but I hope they did not implement their own version of grep...
One gotcha is that in some places, the kernel does evil pre-processor stuff like:
#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i) #define ATOMIC_LONG_PFX(x) atomic ## x
#endif
#define ATOMIC_LONG_READ_OP(mo) static inline long atomic_long_read##mo(const atomic_long_t *l) { ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; return (long)ATOMIC_LONG_PFX(_read##mo)(v); } ATOMIC_LONG_READ_OP() ATOMIC_LONG_READ_OP(_acquire)
(this example from include/asm-generic/atomic-long.h, but similar ## abuse happens elsewhere as well...)
Yeah, I don't think there is much you can do about these cases... Cheers, Silvan
On Tue, Apr 26, 2016 at 12:45 PM CEST, Silvan Jegen <me@sillymon.ch> wrote:
Am 2016-04-26 10:50, schrieb Gadre Nayan:
Ctags can help. Ctags -R on the entire source.
In the Kernel Makefile there is actually a target for this. It's called either 'tags' or 'tag' so
make tags [or tag]
should create the ctag file for you.
An alternative would be to use cscope: $ # build the index (will take a moment) $ make cscope $ # find all assignments to a symbol $ cscope -d -L -9 platform_gpio_blink_set drivers/leds/leds-gpio.c <global> 130 led_dat->platform_gpio_blink_set = blink_set; $ # or find all occurrences of a symbol and grep for assignments $ cscope -d -L -0 platform_gpio_blink_set | grep = drivers/leds/leds-gpio.c <global> 130 led_dat->platform_gpio_blink_set = blink_set; The latter, for some reason, runs faster for me. -Jakub
[2016-04-28T01:56:26+0530]: "Jakub Sitnicki" (jakub-sitnicki): ,----[ jakub-sitnicki ] | An alternative would be to use cscope: | | $ # build the index (will take a moment) | $ make cscope `---- this ! cscope generally just works for way better than other 'manual' mechanisms. since it builds inverse database as well (the -q option), symbol lookups are pretty fast.
xcscope provides a seamless experience within emacs... -- kind regards anupam
On Tue, Apr 26, 2016 at 02:00:02PM +0530, Jay Aurabind wrote:
On 20 April 2016 at 12:56, Cihangir Akturk <cakturk@gmail.com> wrote:
On Wed, Apr 20, 2016 at 06:17:38AM +0000, Nijam Haider wrote:
i was going through the code leds-gpio.c. i found a function "platform_gpio_blink_set" declared under private data of "gpio_led_data",and was trying to get through this function. But hardly i can find any link to definition for the same anywhere.
Hi,
That is a function pointer, so you should search assignments to that pointer. That way you can find the real function you are looking for.
I've spotted such usages in a lot of places, outside the kernel as well. Just wanted know if there is a smarted way of finding the assignments, like some tools or any other tips which people could use to make life easier ?
I've been able to print the address of the functions (once it has been assigned), then check the System.map for the function name.
On 27 April 2016 at 07:05, John de la Garza <john@jjdev.com> wrote:
On Tue, Apr 26, 2016 at 02:00:02PM +0530, Jay Aurabind wrote:
On 20 April 2016 at 12:56, Cihangir Akturk <cakturk@gmail.com> wrote:
On Wed, Apr 20, 2016 at 06:17:38AM +0000, Nijam Haider wrote:
i was going through the code leds-gpio.c. i found a function "platform_gpio_blink_set" declared under private data of "gpio_led_data",and was trying to get through this function. But hardly i can find any link to definition for the same anywhere.
Hi,
That is a function pointer, so you should search assignments to that pointer. That way you can find the real function you are looking for.
I've spotted such usages in a lot of places, outside the kernel as well. Just wanted know if there is a smarted way of finding the assignments, like some tools or any other tips which people could use to make life easier ?
I've been able to print the address of the functions (once it has been assigned), then check the System.map for the function name.
Thank you all for the smart answers! -- Thanks and Regards, Aurabindo J
participants (9)
-
Anupam Kapoor -
Cihangir Akturk -
Gadre Nayan -
Jakub Sitnicki -
Jay Aurabind -
John de la Garza -
Nijam Haider -
Silvan Jegen -
Valdis.Kletnieks@vt.edu