- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2020-07-23T23:44:33+00:00","","")
#author("2021-05-19T14:58:54+00:00","","")
#topicpath
///////////////////////////////////////////////////////////////////////////////
* 目次 [#ye0653a6]
#contents();
///////////////////////////////////////////////////////////////////////////////
* cscope [#u92561d9]
- debian では、 cscope は cscope パッケージに入っている
- ソースコードは Linux ディストリビューションなどが配布しているもの、若しくは開発元の git repository から取得出来る
-- git repository
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 を対象外とするように動作する実装になっているためである。
- SymLink も DB 化の対象にしたい場合は、ソースパッケージを取ってきて、以下のように修正する。
++ cscope-indexer で SymLink をリスト対象とするように変更する
diff --git a/cscope-15.8a/contrib/xcscope/cscope-indexer b/cscope-15.8a/contrib/xcscope/cscope-indexer
index 13c0ae2..31e3956 100644
--- a/cscope-15.8a/contrib/xcscope/cscope-indexer
+++ b/cscope-15.8a/contrib/xcscope/cscope-indexer
@@ -134,7 +134,7 @@ fi
echo "$DIR/$f"
done
else
- find $DIR \( -type f -o -type l \)
+ find -L $DIR \( -xtype f -o -xtype l \)
fi
) | \
egrep -i '\.([chly](xx|pp)*|cc|hh)$' | \
~
また、cscope-indexer は内部で環境変数 PATH を独自に設定している(起動したshell の環境変数変数PATHは引き継がれない)ため、下記で修正する cscope の配置先が cscope-indexer から見える場所にあるかどうかを確認しておくこと。
++ cscope の中で使われている lstat() を stat() に置き換える
--- ソース上の lstat() を全て置き換えてもいいが、configure を走らせる前に config.h.in を1行修正する方がスマート。 HAVE_LSTAT が定義されないようにすれば良い(下記)。
diff --git a/cscope-15.8a/config.h.in b/cscope-15.8a/config.h.in
index 2219be7..b0fff54 100644
--- a/cscope-15.8a/config.h.in
+++ b/cscope-15.8a/config.h.in
@@ -53,7 +53,7 @@
#undef HAVE_LONG_LONG_INT
/* Define to 1 if you have the `lstat' function. */
-#undef HAVE_LSTAT
+// #undef HAVE_LSTAT
/* Define to 1 if you have the `memcpy' function. */
#undef HAVE_MEMCPY
~
但し、global.h も手直しが必要。
diff --git a/cscope-15.8a/src/global.h b/cscope-15.8a/src/global.h
index cda29aa..1919277 100644
--- a/cscope-15.8a/src/global.h
+++ b/cscope-15.8a/src/global.h
@@ -189,6 +189,7 @@ int rpl_asprintf(char **, const char *, ...);
/* This can happen on only vaguely Unix-ish platforms... */
#ifndef HAVE_LSTAT
+#include <sys/stat.h>
# define lstat(file,buf) stat(file,buf)
#endif
--- 修正後、ビルドする
$ configure
$ make
--- 実行ファイルをパスの通った所へ配置する。
--- パッケージをインストールしている場合は、念の為削除しておいた方が良いだろう。
//==============================================================================
** 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 | |
//------------------------------------------------------------------------------
*** 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]
- 取得元
-- https://git.code.sf.net/p/cscope/cscope.git
- ビルド方法
-- EADME.git を参照
- ビルド手順
$ autoreconf -i -s
$ ./configure
$ make
src/cscope が出来ていれば成功。
//==============================================================================
** 参考リンク [#o3814046]
- [[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]]