How can I find the definition of a structure with cscope

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I find the definition of a structure with cscope

wiseker

In vim + cscope, we can use command ":cs find g name" to find the definition of a function or structure. But there are some problems for structures.

For example, when we want to find the definition of struct device in linux kernel tree,the result is:
   #   line  filename / context / line
   1    115  Documentation/lguest/lguest.c <<device>>
             struct device
   2     32  Documentation/spi/spidev_test.c <<device>>
             static const char *device = "/dev/spidev1.1";
   3    117  arch/x86/kernel/early-quirks.c <<device>>
             u32 device;
   4     48  arch/x86/kernel/reboot_fixups_32.c <<device>>
             unsigned int device;
   5     46  arch/x86/pci/irq.c <<device>>
             u16 vendor, device;
   6     53  arch/x86/pci/irq.c <<device>>
             int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);\
        ......

That is because: 1) there are lots of "struct device" in header files (to avoid including headers); 2) Some locale variables with same name exists.

How can we avoid this and find the right definition quickly?

Thanks!

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How can I find the definition of a structure with cscope

Gary Johnson

On 2008-04-29, wiseker <[hidden email]> wrote:

> In vim + cscope, we can use command ":cs find g name" to find the
> definition of a function or structure. But there are some problems
> for structures.
>
> For example, when we want to find the definition of struct device
> in linux kernel tree,the result is:
>    #   line  filename / context / line
>    1    115  Documentation/lguest/lguest.c <<device>>
>              struct device
>    2     32  Documentation/spi/spidev_test.c <<device>>
>              static const char *device = "/dev/spidev1.1";
>    3    117  arch/x86/kernel/early-quirks.c <<device>>
>              u32 device;
>    4     48  arch/x86/kernel/reboot_fixups_32.c <<device>>
>              unsigned int device;
>    5     46  arch/x86/pci/irq.c <<device>>
>              u16 vendor, device;
>    6     53  arch/x86/pci/irq.c <<device>>
>              int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);\
> ......
>
> That is because: 1) there are lots of "struct device" in header
> files (to avoid including headers); 2) Some locale variables with
> same name exists.
>
> How can we avoid this and find the right definition quickly?

If you want to limit the scope of the search to just those files
included by the current source file, you may find what you're
looking for in

   :help include-search

HTH,
Gary


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How can I find the definition of a structure with cscope

wiseker


On Fri, May 2, 2008 at 4:05 AM, Gary Johnson <[hidden email]> wrote:

On 2008-04-29, wiseker <[hidden email]> wrote:
>
> That is because: 1) there are lots of "struct device" in header
> files (to avoid including headers); 2) Some locale variables with
> same name exists.
>
> How can we avoid this and find the right definition quickly?

If you want to limit the scope of the search to just those files
included by the current source file, you may find what you're
looking for in


  :help include-search

        Thanks!
 


HTH,
Gary





--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How can I find the definition of a structure with cscope

Mark Wilden
On May 4, 2008, at 6:27 PM, Jason Lau wrote:

On Fri, May 2, 2008 at 4:05 AM, Gary Johnson <[hidden email]> wrote:

On 2008-04-29, wiseker <[hidden email]> wrote:
>
> That is because: 1) there are lots of "struct device" in header
> files (to avoid including headers); 2) Some locale variables with
> same name exists.
>
> How can we avoid this and find the right definition quickly?

If you want to limit the scope of the search to just those files
included by the current source file, you may find what you're
looking for in


  :help include-search

Unfortunately, I think the desire is actually the opposite - to search includes that -aren't- included in the current file. The current file includes a line like

struct foo;

and what's needed is to find the file that has

struct foo {
   // foo's definition
};

///ark

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How can I find the definition of a structure with cscope

Baroudi Safwen
In reply to this post by wiseker
Le mardi 29 avril 2008 07:21:43 UTC+2, wiseker a écrit :

> In vim + cscope, we can use command ":cs find g name" to find the definition of a function or structure. But there are some problems for structures.
>
> For example, when we want to find the definition of struct device in linux kernel tree,the result is:
>    #   line  filename / context / line
>    1    115  Documentation/lguest/lguest.c <<device>>
>              struct device
>    2     32  Documentation/spi/spidev_test.c <<device>>
>              static const char *device = "/dev/spidev1.1";
>    3    117  arch/x86/kernel/early-quirks.c <<device>>
>              u32 device;
>    4     48  arch/x86/kernel/reboot_fixups_32.c <<device>>
>              unsigned int device;
>    5     46  arch/x86/pci/irq.c <<device>>
>              u16 vendor, device;
>    6     53  arch/x86/pci/irq.c <<device>>
>              int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);\
> ......
>
> That is because: 1) there are lots of "struct device" in header files (to avoid including headers); 2) Some locale variables with same name exists.
>
> How can we avoid this and find the right definition quickly?
>
> Thanks!
I wrote a patch for vim that will sort the matches returned by cscope to put the matches that end with '{' at the top. I work on the kernel and boy this was useful. I'll be happy to share the patch if anyone is interested.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I find the definition of a structure with cscope

Dominique Pellé
Baroudi Safwen <[hidden email]> wrote:

> Le mardi 29 avril 2008 07:21:43 UTC+2, wiseker a écrit :
>> In vim + cscope, we can use command ":cs find g name" to find the definition of a function or structure. But there are some problems for structures.
>>
>> For example, when we want to find the definition of struct device in linux kernel tree,the result is:
>>    #   line  filename / context / line
>>    1    115  Documentation/lguest/lguest.c <<device>>
>>              struct device
>>    2     32  Documentation/spi/spidev_test.c <<device>>
>>              static const char *device = "/dev/spidev1.1";
>>    3    117  arch/x86/kernel/early-quirks.c <<device>>
>>              u32 device;
>>    4     48  arch/x86/kernel/reboot_fixups_32.c <<device>>
>>              unsigned int device;
>>    5     46  arch/x86/pci/irq.c <<device>>
>>              u16 vendor, device;
>>    6     53  arch/x86/pci/irq.c <<device>>
>>              int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);\
>>       ......
>>
>> That is because: 1) there are lots of "struct device" in header files (to avoid including headers); 2) Some locale variables with same name exists.
>>
>> How can we avoid this and find the right definition quickly?
>>
>> Thanks!
>
> I wrote a patch for vim that will sort the matches returned by cscope to put the matches that end with '{' at the top. I work on the kernel and boy this was useful. I'll be happy to share the patch if anyone is interested.

cscope and ctags use heuristics which cannot tell for sure what is the
correct definition.

Instead of those tools, you can use rtags and/or YouCompleteMe which
are based on
the clang library.  Those tools understand c or c++ and can jump to the correct
definition.

See:

https://github.com/Valloric/YouCompleteMe

https://github.com/Andersbakken/rtags
https://github.com/lyuts/vim-rtags

Regards
Dominique

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.