#author("2023-03-27T00:52:56+09:00","","") #author("2025-02-15T23:45:57+09:00","","") #topicpath /////////////////////////////////////////////////////////////////////////////// * 目次 [#ye0653a6] #contents(); /////////////////////////////////////////////////////////////////////////////// * cscope [#u92561d9] - debian では、 cscope は cscope パッケージに入っている - ソースコードは Linux ディストリビューションなどが配布しているもの、若しくは開発元の git repository から取得出来る -- git repository git://git.code.sf.net/p/cscope/cscope https://git.code.sf.net/p/cscope/cscope https://github.com/welash/cscope.git -- debian $ apt-get source cscope //============================================================================== ** tag の生成 [#se927a08] - コンソールから $ cscope-indexer -r - cscope-indexer のオプション |~option |~description | |-f <database-file> |出力先データベースのファイル名を指定する(default: cscope.out)| |-i <list-file> |リストファイル(ファイルのインデックスを記録したファイル)の名前を指定する(default: cscope.files)| |-l |データベースファイルの生成・更新を抑制する。&br;但し、リストファイルが生成済みであること | |-r |再帰的にディレクトリを走査する。&br;このオプションがない場合、走査対象はカレントディレクトリに限定される。| |-v |冗長モード | //============================================================================== ** cscope で SymLink になっているファイルを扱えるようにする(要コード修正・ビルド) [#q38ed002] - ソースコード・ヘッダが SymLink になっている場合、cscope では正しく DB 化出来ない。これは、cscope が DB 作成処理の際、 SymLink を対象外とするように動作する為である。 - 事前準備として、以下が必要となる gcc bison flex libncurses5 - SymLink も DB 化の対象にしたい場合は、ソースを取ってきて、以下のように修正する。 + cscsope の修正 ++ README.git の記述に従って autoconf を実行する $ autoreconf -i -s ++ 生成された config.h.in を編集 /* Define to 1 if you have the `lstat' function. */ #undef HAVE_LSTAT // この行を /* */ でコメントアウトする ++ configure を実行 $ ./configure ++ global.h を修正 /* This can happen on only vaguely Unix-ish platforms... */ #ifndef HAVE_LSTAT #include <sys/stat.h> # この include文が足りてないので追加する。 # define lstat(file,buf) stat(file,buf) #endif ++ ビルドする $ make + cscope-indexer の修正 -- 修正前 find $DIR \( -type f -o -type l \) -- 修正後 if [ "X$EXCLUDE" = "X" ] then find -L $DIR \( -xtype f -o -xtype l \) else find -L $DIR \( -xtype f -o -xtype l \) | grep -v $EXCLUDE fi --- cscsope, cscope-indexer をパスの通った所へ配置する。 --- パッケージをインストールしている場合は、念の為削除するか、自前の cscope, cscope-indexer が優先されるよう、環境変数 PATH を調整する。 //============================================================================== ** xcscope.el [#oe856328] - cscope を emacs で使用するのに xcscope.el を使う。そのために cscope-el パッケージを導入する - emacs起動時に問題がなくても xcscope.el が正しく動作しない時は、''cscope-minor-mode'' に正しく入れていない可能性がある。その場合には (setq c++-mode-hook '(lambda () (setq cscope-minor-mode t) )) のように ${HOME}/.emacs などの適切な初期設定ファイルに記述しておく。 - xcscope.el では、タグファイルを生成してあっても、リストを表示させるたびに grep が走る。そのため表示は速くない。速度が問題になる場合は、xcscope.el ではなく [[ascope>#ascope]] の使用を検討する余地がある。 - emacs 上の xcscope.el から tag ファイルを生成する C-c s L //------------------------------------------------------------------------------ *** シンボルを探す [#f5de474a] |~key |~description |~remark | |C-c s s |シンボルを指定して探す(定義・呼び出し箇所等の一覧をリストアップする)| | |C-c s C |指定したシンボルの呼び出し箇所をリストアップ | | |C-c s G |指定したシンボルの定義(宣言ではなく)、またはそれに関する定義をリストアップする | | |C-c s n |次のシンボルへ Jump | | |C-c s p |前のシンボルへ Jump | | |C-c s t |テキストを検索 |symbol や定義意外のテキスト全般はこれで検索する | |C-c s f |ファイルを検索 |1つだけ見つかればそれを自動的に開く | |C-c s i |そのファイルを include している include 文を検索 | | //------------------------------------------------------------------------------ *** xcscope のキーバインド一覧(xcscope.el ver.1.0) [#gb6bc7b4] ;; * Keybindings: ;; ;; All keybindings use the "C-c s" prefix, but are usable only while ;; editing a source file, or in the cscope results buffer: ;; ;; C-c s s Find symbol. ;; C-c s = Find assignments to this symbol ;; C-c s d Find global definition. ;; C-c s g Find global definition (alternate binding). ;; C-c s G Find global definition without prompting. ;; C-c s c Find functions calling a function. ;; C-c s C Find called functions (list functions called ;; from a function). ;; C-c s t Find text string. ;; C-c s e Find egrep pattern. ;; C-c s f Find a file. ;; C-c s i Find files #including a file. ;; ;; These pertain to navigation through the search results: ;; ;; C-c s b Display *cscope* buffer. ;; C-c s B Auto display *cscope* buffer toggle. ;; C-c s n Next symbol. ;; C-c s N Next file. ;; C-c s p Previous symbol. ;; C-c s P Previous file. ;; C-c s u Pop mark. ;; ;; These pertain to setting and unsetting the variable, ;; `cscope-initial-directory', (location searched for the cscope database ;; directory): ;; ;; C-c s a Set initial directory. ;; C-c s A Unset initial directory. ;; ;; These pertain to cscope database maintenance: ;; ;; C-c s L Create list of files to index. ;; C-c s I Create list and index. ;; C-c s E Edit list of files to index. ;; C-c s W Locate this buffer's cscope directory ;; ("W" --> "where"). ;; C-c s S Locate this buffer's cscope directory. ;; (alternate binding: "S" --> "show"). ;; C-c s T Locate this buffer's cscope directory. ;; (alternate binding: "T" --> "tell"). ;; C-c s D Dired this buffer's directory. ;; //------------------------------------------------------------------------------ *** xcscope のキーバインドが正しく動作しない場合 [#aa1fc78a] - xcscope.el を組み込んだ後、 C-c s と打っても C-c s is undefined とメッセージが出て動作しない場合は、xcscope.el が提供するマイナーモードに入れていない可能性がある。~ その場合は、c-mode-hook, c++-mode-hook に引っ掛けて ''cscope-minor-mode'' を呼び出すようにすると良い。 ; c-mode での設定 (setq c-mode-hook '(lambda () (cscope-minor-mode) )) ; c++-mode でも同様に... (setq c++-mode-hook '(lambda () (cscope-minor-mode) )) //------------------------------------------------------------------------------ *** 参考リンク [#fa5e1efc] - [[cscope Home Page>http://cscope.sourceforge.net/]] - [[Emacsからcscopeソースコードナビゲータを使ってみよう>http://prog.quarklink.org/linux/xcscope/]] - [[[Emacs] id-utils と cscope 導入してみた>http://d.hatena.ne.jp/khiker/20071018/cscope]] //============================================================================== ** acscope.el [#ub6ff3d4] - ascope.el は cscope の emacs 用 I/F の一つ。 - [[xcscope.el>#cscope]] と比べて -- 機能は少ない -- xcscope.el と違って毎回検索を行わない分、 --- 結果表示までの時間は早い --- 対象のソースコードに変更があった場合、検索結果に正しく反映されない場合がある - debian では、 cscope は cscope パッケージに入っている - この他、 emacs で使用するのに acscope.el を使う。debian8 にはパッケージはない。 //------------------------------------------------------------------------------ *** 導入 [#q2a6c78b] - debian8 のようにディストリビューションからパッケージが提供されていない場合は、[[GitHub>https://github.com/ameyp/ascope/blob/master/ascope.el]] または [[EmacsWiki>https://www.emacswiki.org/emacs/ascope.el]] などから Download して組み込む。~ 但し [[EmacsWiki>https://www.emacswiki.org/emacs/ascope.el]] に掲載されているものは、 GitHub の最新版より大分古いようなので注意が必要。 -- GitHub から取得する場合 $ git clone https://github.com/ameyp/ascope - キーバインドを設定する -- ascope.el ではキーバインドが設定されてない一方、関数名が xcscope.el と同じなので、xcscope.el から流用して設定する。~ #ただ、xcscope.el にあって ascope.el にないものが多い。 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/ascope") load-path)) (load-library "~/.emacs.d/site-lisp/ascope/ascope.el") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Original is from xcscope.el (defvar cscope-minor-mode-keymap (let ((map (make-sparse-keymap))) ;; xemacs has various issues with (cscope-mouse-popup-menu-or-search), so I ;; don't use that function for xemacs. Its popup menu support won't be as ;; good (cscope will still prompt for the search term) ;(if cscope-running-in-xemacs ; (progn ; (define-key map [(shift button3)] 'cscope-mouse-search-again)) ; (define-key map [mouse-3] 'cscope-mouse-popup-menu-or-search) ; (define-key map [S-mouse-3] 'cscope-mouse-search-again)) ;; The following line corresponds to be beginning of the "Cscope" menu. (define-key map "\C-css" 'cscope-find-this-symbol) (define-key map "\C-csd" 'cscope-find-global-definition) (define-key map "\C-csg" 'cscope-find-global-definition) ; (define-key map "\C-csG" 'cscope-find-global-definition-no-prompting) ; (define-key map "\C-cs=" 'cscope-find-assignments-to-this-symbol) (define-key map "\C-csc" 'cscope-find-functions-calling-this-function) (define-key map "\C-csC" 'cscope-find-called-functions) (define-key map "\C-cst" 'cscope-find-this-text-string) ; (define-key map "\C-cse" 'cscope-find-egrep-pattern) (define-key map "\C-csf" 'cscope-find-this-file) (define-key map "\C-csi" 'cscope-find-files-including-file) ;; --- (The '---' indicates that this line corresponds to a menu separator.) ; (define-key map "\C-csb" 'cscope-display-buffer) ; (define-key map "\C-csB" 'cscope-display-buffer-toggle) ; (define-key map "\C-csn" 'cscope-history-forward-line-current-result) ; (define-key map "\C-csN" 'cscope-history-forward-file-current-result) ; (define-key map "\C-csp" 'cscope-history-backward-line-current-result) ; (define-key map "\C-csP" 'cscope-history-backward-file-current-result) ; (define-key map "\C-csu" 'cscope-pop-mark) ;; --- ; (define-key map "\C-csa" 'cscope-set-initial-directory) ; (define-key map "\C-csA" 'cscope-unset-initial-directory) ;; --- ; (define-key map "\C-csL" 'cscope-create-list-of-files-to-index) ; (define-key map "\C-csI" 'cscope-index-files) ; (define-key map "\C-csE" 'cscope-edit-list-of-files-to-index) ; (define-key map "\C-csW" 'cscope-tell-user-about-directory) ; (define-key map "\C-csS" 'cscope-tell-user-about-directory) ; (define-key map "\C-csT" 'cscope-tell-user-about-directory) ; (define-key map "\C-csD" 'cscope-dired-directory) ;; The previous line corresponds to be end of the "Cscope" menu. ;; (START Add) -------------------------------------- ;; ここは xcscope.el にないものを追加 (define-key map "\C-csa" 'cscope-setup) ;; (END Add) -------------------------------------- map) "The global cscope keymap") (require 'ascope) //------------------------------------------------------------------------------ *** tagの生成 [#l1f49acc] - emacs 上のインターフェースが異なるのみで、cscope を使うという意味では [[xcscope.el>#xcscope]]と変わりない。&br; tag の生成については [[tag の生成(xcscope.el)>#cscope-indexer]] を参照のこと。 //------------------------------------------------------------------------------ *** 参考リンク [#ub3f4202] - [[Erlcscope and ascope.el>http://masayuki038.github.io/blog/2013/09/23/erlcscope-and-ascope-el/]] - [[ascope.el@github>https://github.com/ameyp/ascope/blob/master/ascope.el]] - [[EmacsWiki>https://www.emacswiki.org/emacs/ascope.el]] //============================================================================== ** ソースからのビルド [#n9346135] - 取得元 //------------------------------------------------------------------------------ *** ビルドに必要なパッケージ [#n755baaf] autoconf gcc make yacc flex - ※ yacc は、Debian では上位互換である bison パッケージに含まれる //------------------------------------------------------------------------------ *** ソース取得元 [#ue1ebbca] -- https://git.code.sf.net/p/cscope/cscope.git - ビルド方法 //------------------------------------------------------------------------------ *** ビルド方法 [#za061870] -- EADME.git を参照 - ビルド手順 $ autoreconf -i -s $ ./configure $ make src/cscope が出来ていれば成功。 //============================================================================== ** 参考リンク [#links] - [[Cscope Home Page>https://cscope.sourceforge.net/]] --- cscope 開発元 - [[CscopeとSilentBobによるソースコードの解析>https://mag.osdn.jp/07/03/13/0115244]] - [[Using Cscope on large projects (example: the Linux kernel)>http://cscope.sourceforge.net/large_projects.html]]