Professional Web Applications Themes

(1) cscope & gvim; (2) ctags & C++/STL - UNIX Programming

================================================== ========================= Question (1): cscope choosese wrong match from list ================================================== ========================= I'm using gvim 6.2 on solaris 8. I've posted question (1) to the vim group comp.editors, as well as the vim mailing list org. I haven't gotten much response yet. I'm using cscope 15.5 with the cscope plugin file attached at the very end of this posting. I'm pretty new to cscope, but am very pleased with what it can do. Especially for C++/STL, where you have things defined all over the place. My problem is that when I do a cscope query for symbols and get multiple ...

  1. #1

    Default (1) cscope & gvim; (2) ctags & C++/STL

    ================================================== =========================
    Question (1): cscope choosese wrong match from list
    ================================================== =========================

    I'm using gvim 6.2 on solaris 8. I've posted question
    (1) to the vim group comp.editors, as well as the vim
    mailing list org. I haven't gotten much
    response yet. I'm using cscope 15.5 with the cscope
    plugin file attached at the very end of this posting.
    I'm pretty new to cscope, but am very pleased with what
    it can do. Especially for C++/STL, where you have
    things defined all over the place.

    My problem is that when I do a cscope query for symbols
    and get multiple matching results, I get warped to the
    wrong occurance of that symbol. That is, if I choose
    the 7th occurance, I end up at the 5th occurance. The
    offset is usually (but not always) 2 positions up in
    the match list; sometimes, it's 2 positions down,
    depending on the symbol queried. The matching list
    isn't particularly long (less than 10 items), though
    the offset doesn't occur if the list contains only 2
    matches. The offset only seems to happen with symbols,
    not if I search for functions that call the function
    under the cursor (the "c" option for a query).

    I tried killing the connection to cscope.out and adding
    it again, but the behaviour was the same. I also tried
    killing the connection, rebuilding cscope.out using
    "cscope -b *.?pp" and adding it again (same result).
    This build command builds a cscope database from files
    client.cpp, Routines.hpp, and Routines.cpp in the
    current directory.

    I never tried ":cs reset" because I can't find enough
    doentation what it exactly does (not in the cscope
    man page either). If anyone knows about this command,
    I'd appreciate a pointer to a better explanation.

    The offset occurs regardless of whether I use hot keys
    or full command line commands.

    I tried to see if the offset happens when I call cscope
    outside of gvim, but it doesn't.

    The behaviour is not changed by the cst and csto
    options.

    Has anyone experienced this problem or have any comment
    on it?

    ================================================== =========================
    Question (2): C++ object declarations being missed
    ================================================== =========================

    I recently installed Ctags 5.5.2 on solaris 8. After
    posting about how to get it to tag local variables, I
    was told to use "ctags --c-types=+l", which seemed to
    work. The problem I'm seeing now is that only some
    local variables are tagged. And it isn't just a
    problem with local variables. Only some global
    variables are tagged too. I've posted to the
    ctags-users mailing list about this. It seems that
    this problem with potentially untagged variables only
    afflicts types which I've defined as classes. I am
    using C++/STL. For example, the following local
    variables are tagged:

    Any native type (int, double, bool, etc.)
    typedef vecstatvec<double> vsvd; //vecstatvec is a template
    vector<int> IdxGenes2swap;

    The following local variables are not tagged:

    vsvd m3_ChromCost (nc_m3,LimlessStart);
    string KidRankLabl[]= { "Max", "Mean", "Min", "MeanMax", "MeanMin" };

    Of the following two global declarations:

    myrand RndGenr( myrand::ZERO_SEED );
    RandInt RandIntGenr;

    only the 2nd one is tagged. They are both nontemplate
    structs, and the 2nd one is much simpler. However, the
    2nd one is derived from a template:

    struct RandInt: public unary_function<int,int> {...};

    while the first one is not:

    struct myrand { public: ... };

    Since I'm using C++/STL, is this to be expected? If so,
    why would the above "struct myrand" be ignroed? I know
    there are more C++ specific code ysis tools like
    source navigator, but I really need a tool that I can
    use with gvim. Thanks for any feedback.

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6


    ================================================== =========================
    cscope plugin file for vim (for question#1)
    ================================================== =========================

    """""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""
    " CSCOPE settings for vim
    """""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""
    "
    " This file contains some boilerplate settings for vim's cscope interface,
    " plus some keyboard mappings that I've found useful.
    "
    " USAGE:
    " -- vim 6: Stick this file in your ~/.vim/plugin directory (or in a
    " 'plugin' directory in some other directory that is in your
    " 'runtimepath'.
    "
    " -- vim 5: Stick this file somewhere and 'source cscope.vim' it from
    " your ~/.vimrc file (or cut and paste it into your .vimrc).
    "
    " NOTE:
    " These key maps use multiple keystrokes (2 or 3 keys). If you find that vim
    " keeps timing you out before you can complete them, try changing your timeout
    " settings, as explained below.
    "
    " Happy cscoping,
    "
    " Jason Duell princeton.edu 2002/3/7
    """""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""


    " This tests to see if vim was configured with the '--enable-cscope' option
    " when it was compiled. If it wasn't, time to recompile vim...
    if has("cscope")

    """"""""""""" Standard cscope/vim boilerplate

    " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
    set nocscopetag

    " check cscope for definition of a symbol before checking ctags: set to 1
    " if you want the reverse search order.
    set csto=0

    " add any cscope database in current directory
    if filereadable("cscope.out")
    cs add cscope.out
    " else add the database pointed to by environment variable
    elseif $CSCOPE_DB != ""
    cs add $CSCOPE_DB
    endif

    " show msg when any other cscope db added
    set cscopeverbose


    """"""""""""" My cscope/vim key mappings
    "
    " The following maps all invoke one of the following cscope search types:
    "
    " 's' symbol: find all references to the token under cursor
    " 'g' global: find global definition(s) of the token under cursor
    " 'c' calls: find all calls to the function name under cursor
    " 't' text: find all instances of the text under cursor
    " 'e' egrep: egrep search for the word under cursor
    " 'f' file: open the filename under cursor
    " 'i' includes: find files that include the filename under cursor
    " 'd' called: find functions that function under cursor calls
    "
    " Below are three sets of the maps: one set that just jumps to your
    " search result, one that splits the existing vim window horizontally and
    " diplays your search result in the new window, and one that does the same
    " thing, but does a vertical split instead (vim 6 only).
    "
    " I've used CTRL-\ and CTRL- as the starting keys for these maps, as it's
    " unlikely that you need their default mappings (CTRL-\'s default use is
    " as part of CTRL-\ CTRL-N typemap, which basically just does the same
    " thing as hitting 'escape': CTRL- doesn't seem to have any default use).
    " If you don't like using 'CTRL-' or CTRL-\, , you can change some or all
    " of these maps to use other keys. One likely candidate is 'CTRL-_'
    " (which also maps to CTRL-/, which is easier to type). By default it is
    " used to switch between Hebrew and English keyboard mode.
    "
    " All of the maps involving the <cfile> macro use '^<cfile>$': this is so
    " that searches over '#include <time.h>" return only references to
    " 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
    " files that contain 'time.h' as part of their name).


    " To do the first type of search, hit 'CTRL-\', followed by one of the
    " cscope search types above (s,g,c,t,e,f,i,d). The result of your cscope
    " search will be displayed in the current window. You can use CTRL-T to
    " go back to where you were before the search.
    "

    nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
    nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>


    " Using 'CTRL-spacebar' (intepreted as CTRL-Space by vim) then a search type
    " makes the vim window split horizontally, with search result displayed in
    " the new window.
    "
    " (Note: earlier versions of vim may not have the :scs command, but it
    " can be simulated roughly via:
    " nmap <C-Space>s <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR>

    nmap <C-Space>s :scs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space>g :scs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space>c :scs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space>t :scs find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space>e :scs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
    nmap <C-Space>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-Space>d :scs find d <C-R>=expand("<cword>")<CR><CR>


    " Hitting CTRL-space *twice* before the search type does a vertical
    " split instead of a horizontal one (vim 6 and up only)
    "
    " (Note: you may wish to put a 'set splitright' in your .vimrc
    " Oif you prefer the new window on the right instead of the left

    nmap <C-Space><C-Space>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-Space><C-Space>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>
    nmap <C-Space><C-Space>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-Space><C-Space>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>


    """"""""""""" key map timeouts
    "
    " By default Vim will only wait 1 second for each keystroke in a mapping.
    " You may find that too short with the above typemaps. If so, you should
    " either turn off mapping timeouts via 'notimeout'.
    "
    "set notimeout
    "
    " Or, you can keep timeouts, by uncommenting the timeoutlen line below,
    " with your own personal favorite value (in milliseconds):
    "
    "set timeoutlen=4000
    "
    " Either way, since mapping timeout settings by default also set the
    " timeouts for multicharacter 'keys codes' (like <F1>), you should also
    " set ttimeout and ttimeoutlen: otherwise, you will experience strange
    " delays as vim waits for a keystroke after you hit ESC (it will be
    " waiting to see if the ESC is actually part of a key code like <F1>).
    "
    "set ttimeout
    "
    " personally, I find a tenth of a second to work well for key code
    " timeouts. If you experience problems and have a slow terminal or network
    " connection, set it higher. If you don't set ttimeoutlen, the value for
    " timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
    "
    "set ttimeoutlen=100

    map <F11> :sp tags<CR>:%s/^\([^ :]*:\)\=\([^ ]*\).*/syntax keyword Tag \2/<CR>:wq! tags.vim<CR>/^<CR><F12>
    map <F12> :so tags.vim<CR>

    endif
    Fred Guest

  2. #2

    Default cscope & gvim (was: Re: (1) cscope & gvim; (2) ctags & C++/STL)

    Fred Ma <carleton.ca> wrote:
     

    Please try to avoid posting two rather unrelated questions in a single
    article. I'll answer only to the first, and change the Subj
    accordingly.
     

    A note of caution is needed here: cscope is designed for C, not C++.
    It manages to catch some C++ syntax, but please don't expect it to be
    reliable. It's not.
     

    I rather strongly suspect the problem is with that vim plugin for
    cscope, which is maintained by the vim people. But you may want to
    check the results generated by cscope itself, too, to see if there's
    anything that sticks out. Run cscope on your existing cscope.out
    file, like vim does it:

    cscope -ld

    from the directory cscope.out is in, and type the line '0foo' to
    search for all occurances of symbol 'foo'. Include the output of this
    in any report you make to the vim guys, or here. It's extremely hard
    to debug such problems without a complete, reproducable example or at
    least some hard data to inspect.
     

    It can't be in the cscope man page --- the VIM interface is none of
    cscope's business.

    --
    Hans-Bernhard Broeker (rwth-aachen.de)
    Even if all the snow were burnt, ashes would remain.
    Hans-Bernhard Guest

  3. #3

    Default Re: cscope & gvim (was: Re: (1) cscope & gvim; (2) ctags & C++/STL)

    Hans-Bernhard Broeker wrote: 

    Sorry. cscope is separate from ctags, despite their similarities
    from within gvim.
     

    Yes, actually I mentioned that cscope worked fine when
    used outside of gvim. It will take some time to come up
    with a code case, since I don't want to send out large
    chunks of my own code at this time (I don't have lots
    of different code). As a first step, I was checking
    to see if my experience with the gvim plugin was an isolated
    one. If so, then it was time to find a suitable chunk of
    code that reproduces the problem, though that will be
    sleighted somewhat into the future, after a deadline I'm
    working toward at the moment.
     

    Got it. I should have emphasized that the problem was
    with the gvim plugin.

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

  4. #4

    Default Re: cscope & gvim

    Fred Ma <carleton.ca> wrote:
     

    That's not quite the same thing --- cscope works with an internal
    representation of its query results, which is quite unlikely to be
    broken in the way indicated here.

    The vim interface, OTOH, relies on the _printed_ representation of
    those results, which you only get to see for yourself if you run
    cscope in -l or -L mode. Possible gotchas here would include line
    breaks or blanks in the wrong places, or anything else that s up
    the vim interface's pr of cscope line-mode output. Since you
    seemed to imply that the problem only happend sometimes, but not
    reliably, that's why I suggested cscope -ld output as the next thing
    to test. If you're worried about too public an exposure, you can
    still send samples to me by email.

    BTW: There is an open bug report from last week, posted anonymously to
    the cscope bug tracker about this, too. Was that you, or somebody
    else? That report mentioned an important additional detail: the
    problem only happened with vim 6.2, but not with 6.0.

    --
    Hans-Bernhard Broeker (rwth-aachen.de)
    Even if all the snow were burnt, ashes would remain.
    Hans-Bernhard Guest

  5. #5

    Default Re: cscope & gvim

    I'm not a user of either package so this is strictly a guess, but it
    sure smells like a problem caused by not handling whitespace in
    pathnames correctly (a very common problem). Fred might want to take a
    quick look and see if any of his files have whitespace or other special
    characters.

    MB

    Mohun Guest

  6. #6

    Default Re: cscope & gvim

    Hans-Bernhard Broeker wrote: 
    >
    > That's not quite the same thing --- cscope works with an internal
    > representation of its query results, which is quite unlikely to be
    > broken in the way indicated here.
    >
    > The vim interface, OTOH, relies on the _printed_ representation of
    > those results, which you only get to see for yourself if you run
    > cscope in -l or -L mode. Possible gotchas here would include line
    > breaks or blanks in the wrong places, or anything else that s up
    > the vim interface's pr of cscope line-mode output. Since you
    > seemed to imply that the problem only happend sometimes, but not
    > reliably, that's why I suggested cscope -ld output as the next thing
    > to test. If you're worried about too public an exposure, you can
    > still send samples to me by email.
    >
    > BTW: There is an open bug report from last week, posted anonymously to
    > the cscope bug tracker about this, too. Was that you, or somebody
    > else? That report mentioned an important additional detail: the
    > problem only happened with vim 6.2, but not with 6.0.[/ref]

    There's been alot of installation, reinstallation, upgrades, and
    troubleshooting lately that I really didn't remember whether I might
    have submitted a bug. But I found the bug report and can say with
    certainty that it wasn't me.

    I looked at the man page for -l. I'll spend a bit of time playing
    with it. It's probably as you say, some parsing problem with the
    gvim plugin. The matching list shows, but selection of a particular
    match causes gvim to jump to the wrong place. I will look at it
    tomorrow, as I have been up for a long time right now. If it comes
    down to it, would you mind receiving 3 longish files, as well as a
    description of what gvim queries give the wrong jumps? Or would
    you prefer not to delve into the gvim side of things? After enough
    of a look at it, I can submit a bug report to vim, as you suggested.

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

  7. #7

    Default Re: cscope & gvim

    Fred Ma <carleton.ca> wrote:
     

    Turns out not to be necessary --- I could reproduce a problem like
    that using cscope's own C source code and VIM 6.1 I found on some
    RedHat box.

    A little digging in VIM's CVS repository shows what looks like a patch
    exactly for this problem having been applied to VIM, recently. It's
    revision 1.29 of src/if_cscope.c, checked in September 2003. Indeed,
    plugging that version of this source file into the distributed vim62
    source tarball fixes the problem for me.

    The problem is caused by vim trying to move tags in the currently
    viewed file to the top of the list, but forgetting to update the
    internal counts. It's a genuine internal VIM bug, unrelated to the
    cscope output format and VIM's parsing of it. They solved it by
    removing that sorting step entirely.

    --
    Hans-Bernhard Broeker (rwth-aachen.de)
    Even if all the snow were burnt, ashes would remain.
    Hans-Bernhard Guest

  8. #8

    Default Re: cscope & gvim

    Hans-Bernhard Broeker wrote: 
    >
    > I could reproduce a problem like
    > that using cscope's own C source code and VIM 6.1 I found on some
    > RedHat box.
    >
    > A little digging in VIM's CVS repository shows what looks like a patch
    > exactly for this problem having been applied to VIM, recently. It's
    > revision 1.29 of src/if_cscope.c, checked in September 2003. Indeed,
    > plugging that version of this source file into the distributed vim62
    > source tarball fixes the problem for me.
    >
    > The problem is caused by vim trying to move tags in the currently
    > viewed file to the top of the list, but forgetting to update the
    > internal counts. It's a genuine internal VIM bug, unrelated to the
    > cscope output format and VIM's parsing of it. They solved it by
    > removing that sorting step entirely.[/ref]

    I checked the vim 6.2 patches (and installed gnu patch
    utility, since the solaris patch seems to be unable to
    process the vim patches). I applied the patches in the
    specified vim build directory. The "make" step stops
    with fatal errors, so I untarred the entire vim source
    from the originally downloaded tarball. Then I ran
    configure, applied the patches, and reran "make". Same
    errors. I'll search the vim mailing list before either
    posting to comp.editors or the vim list. Thanks for
    pointing out the patches.

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

  9. #9

    Default Re: cscope & gvim

    Fred Ma wrote: 

    Hans-Bernhard,

    It worked. I had to remove the build directory, unpack
    the tarball, run configure, and then run only the patches
    related to cscope. These I picked from the patches
    README file. Thanks alot for your help. Now it's time
    to follow up on my posts at comp.editors and vim user
    mailing list (can't remember if cscope had a list, but
    I'll check).

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

  10. #10

    Default Re: cscope & gvim

    Mohun Biswas wrote: 


    Mohun,

    Thanks for the suggestion. Hans-Bernhard found a vim patch
    that fixed the problem. I installed all vim6.2 patches that
    had anything to do with cscope, then rebuilt gvim. Just as
    a note, it took several tries. In the end, build
    errors were avoided by not running all 6.2 patches (just
    the ones related to cscope), as well as erasing the build
    directory and unpacking it anew. The patches were applied
    after running "configure" (with --enable-cscope, of course).
    I haven't run into the problem since (recall that the
    problem was that I was warped to the wrong occurance of
    the matching list for a cscope query).

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

Similar Threads

  1. cscope 15.5
    By Fred in forum UNIX Programming
    Replies: 17
    Last Post: February 13th, 10:34 PM
  2. exuberant Ctags and local variables
    By Fred in forum UNIX Programming
    Replies: 4
    Last Post: January 22nd, 03:13 AM
  3. Gvim and Xinerama
    By Andrew in forum Debian
    Replies: 3
    Last Post: August 21st, 08:40 AM
  4. problem with gvim from AIX Toolbox
    By Massimiliano Adamo in forum AIX
    Replies: 1
    Last Post: August 12th, 10:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139