Skip to contentSkip to conversation

unable to find function definition

DISCUSSION Nijam Haider 9 participants 14 messages Apr 20, 2016 – Apr 28, 2016

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 4 lines · Nijam Haider

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.

#2 lore raw
Quoted 11 lines · Cihangir Akturk
Quoted 4 lines · Nijam Haider

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 ?

Quoted 5 lines

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Signature · 2 lines
Thanks and Regards,
Aurabindo J
#3 lore raw

Ctags can help. Ctags -R on the entire source.

Quoted 30 lines · Jay Aurabind
Quoted 3 lines · Cihangir Akturk
Quoted 2 lines · Nijam Haider

i was going through the code leds-gpio.c.
i found a function "platform_gpio_blink_set" declared under private

data of

Quoted 1 line
Quoted 1 line

"gpio_led_data",and was trying to get through this function. But hardly

i can

Quoted 7 lines
Quoted 1 line

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 ?

Quoted 5 lines

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

--

Quoted 8 lines

Thanks and Regards,
Aurabindo J

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160426/02bff7d7/attachment.html

#4 lore raw

Am 2016-04-26 10:50, schrieb Gadre Nayan:

Quoted 1 line

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.

Cheers,

Silvan

#5 lore raw
Quoted 11 lines · Silvan Jegen

Am 2016-04-26 10:50, schrieb Gadre Nayan:

Quoted 2 lines

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.

Quoted 6 lines

Cheers,

Silvan

Signature · 2 lines
Thanks and Regards,
Aurabindo J
#6 lore raw

Am 2016-04-26 14:56, schrieb Jay Aurabind:

Quoted 10 lines · Silvan Jegen
Quoted 9 lines

Am 2016-04-26 10:50, schrieb Gadre Nayan:

Quoted 2 lines

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

Quoted 8 lines
Quoted 3 lines

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

#7 lore raw
Quoted 3 lines · Silvan Jegen

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...)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160426/6af6fd75/attachment-0001.bin

#8 lore raw
Quoted 8 lines · Valdis.Kletnieks at vt.edu
Quoted 3 lines · Silvan Jegen

A simple but naive approach would be a grep command like this.

grep "function_pointer =" find . -iname '*.c' -o -iname '*.h'

Two better ways:

Quoted 7 lines

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 ?='

Quoted 3 lines

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.

Quoted 3 lines

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...

Quoted 6 lines

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

Quoted 8 lines

#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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160426/ba81f255/attachment.bin

#11 lore raw
In reply to Jay Aurabind
Quoted 9 lines · Jay Aurabind
Quoted 8 lines · Cihangir Akturk
Quoted 4 lines · Nijam Haider

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,

Quoted 8 lines
Quoted 3 lines

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.

#12 lore raw
Quoted 14 lines · John de la Garza
Quoted 13 lines · Jay Aurabind
Quoted 11 lines · Cihangir Akturk
Quoted 4 lines · Nijam Haider

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.

Quoted 7 lines
Quoted 4 lines

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!

Signature · 2 lines
Thanks and Regards,
Aurabindo J
#13 lore raw

Thank you all for replies.
sure these are helping a lot.

Quoted 25 lines · Jay Aurabind,
Quoted 5 lines · John de la Garza
Quoted 4 lines · Jay Aurabind
Quoted 3 lines · Cihangir Akturk
Quoted 2 lines · Nijam Haider

i was going through the code leds-gpio.c.
i found a function "platform_gpio_blink_set" declared under private

data of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"gpio_led_data",and was trying to get through this function. But

hardly i can

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 1 line

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.

Quoted 7 lines
Quoted 4 lines

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.

Quoted 7 lines

Thank you all for the smart answers!

--

Thanks and Regards,
Aurabindo J

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160427/c03702ea/attachment.html

#9 lore raw
In reply to Silvan Jegen
Quoted 9 lines · Silvan Jegen

Am 2016-04-26 10:50, schrieb Gadre Nayan:

Quoted 1 line

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

#10 lore raw
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

[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