LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2246|回复: 4

LXR

[复制链接]
发表于 2003-5-31 15:49:46 | 显示全部楼层 |阅读模式
linux的lxr怎么样用的
我想在用来分析内核代码
发表于 2003-6-3 02:46:49 | 显示全部楼层

lxr安装

www.lisoleg.net上有篇专门 ... 意权限.试试吧!搞不定,和我联系,wd.stevens@china139.com.
发表于 2003-6-3 02:54:11 | 显示全部楼层

lxr

说实话,自从用了global以后,我很少再用lxr.毕竟global可与多种软件协作(emacs,vi,bash,mozilla).
 楼主| 发表于 2003-6-3 14:13:19 | 显示全部楼层

lxr和global 有什么不同吗

global 是不是比lxr更好呀
我现在已经安装好了
发表于 2003-6-10 03:37:47 | 显示全部楼层

reply lxr使用?邮件已回复,请插手!

一、lxr是什么?可参见 (http://www.lisoleg.net/cgi-bin/lisoleg.pl?view=software.html)
=====================================================阅读linux源代码的工具---lxr和glimpse简介 作者: sea_cloud@263.net
我们在阅读linux源代码时都有这样的体会:核心的组织相对松散,在看一个文件时往往要牵涉到其他的头文件、源代码文件。如此来回跳转寻找变量、常量、函数的定义十分不方便,这样折腾几次,便使读代码的心情降到了低点。
lxr(linux cross reference)就是一个解决这个问题的工具:他对你指定的源代码文件建立索引数据库,利用perl脚本CGI动态生成包含源码的web页面,你可以用任何一种浏览器查阅。在此web页中,所有的变量、常量、函数都以超连接的形式给出,十分方便查阅。比如你在阅读/usr/src/linux/net/socket.c的源代码,发现函数get_empty_inode不知道是如何以及在哪里定义的,这时候你只要点击 get_empty_inode,lxr将返回此函数的定义、实现以及各次引用是在什么文件的哪一行,注意,这些信息也是超连接,点击将直接跳转到相应的文件相应的行。另外lxr还提供标识符搜索、文件搜索,结合程序glimpse还可以提供对所有的源码文件进行全文检索,甚至包括注释!
下面将结合实例介绍一下lxr和glimpse的基本安装和使用,由于glimpse比较简单,就从它开始:
0〉首先访问站点: http://glimpse.cs.arizona.edu/ 得到glimpse 的源码,比如我得到的是glimpse-4.12.5.tar.gz .
用root登录,在: 任一目录下用tar zxvf glimpse-4.12.5.tar.gz解开压缩包,在当前目录下出现新目录glimpse-4.12.5 .进入该目录,执行make即可。进入bin目录,将文件glimpse和glimpseindex拷贝到/bin或/usr/bin下即可。如果单独使用glimpse,那么只要简单的执行glimpseindex foo 即可,其中foo是你想要索引的目录,比如说是/usr/src/linux .glimpseindex 的执行结果是在你的起始目录下产生若干.glimpse*的索引文件。然后你只要执行glimpse yourstring即可查找/usr/src/linux下所有包含字符串yourstring的文件。
对于lxr,你可以访问 http://lxr.linux.no/得到它的 ... 循如下步骤:
/*下面的文字来源于lxr的帮助文档以及本人的安装体会*/
1)修改Makefile中的变量PERLBIN和INSTALLPREFIX,使它们分别为 perl程序的位置和你想lxr安装的位置.在我的机器上,PERLBIN的值为 /usr/bin/perl .至于INSTALLPREFIX,有如下原则,lxr的安装路径必须是web服务器能有权限访问。因此它的值简单一点可取 /home/httpd/html/lxr (对于Apache web server)。
2)执行 make install
3)修改$INSTALLPREFIX/http/lxr.conf :
baseurl : http://yourIP/lxr/http/
htmlhead: /usr/local/apache/html/lxr/http/template-head
htmltail: /usr/local/apache/html/lxr/http/template-tail
htmldir: /usr/local/apache/html/lxr/http/template-dir
sourceroot : /usr/src/linux # 假如对linux核心代码索引
dbdir : /usr/local/apache/html/lxr/dbdir/ #dbdir可任意起名,且位置任意
glimpsebin: /usr/local/bin/glimpse #可执行程序glimpse的位置
4)在$INSTALLPREFIX/http/下增加一个文件.htaccess 内容:
SetHandler cgi-script
上面这个文件保证Apache server将几个perl文件作为cgi-script.
5)按照lxr.conf中的设置建立dbdir ,按照上例,建立目录 /usr/local/apache/html/lxr/dbdir
进入这个目录执行$INSTALLPREFIX/bin/genxref yourdir
其中yourdir是源码目录,比如/usr/src/linux
如果要结合glimpse,则执行glimpseindex -H . yourdir
6)修改 /usr/local/apache/conf/access.conf ,加入
《Directory /usr/local/apache/html/lxr/http》
Options All
AllowOverride All
order allow,deny
allow from all
《/Directory》
7)进入/etc/rc.d/init.d/ 执行
killall httpd
./httpd start
进入X ,用浏览器 http://yourIP/lxr/http/blurb.html
大功告成 ,这下你可以舒心的读源码了。
注意:以上只是lxr和glimpse的基本用法,进一步的说明可以参考连机文档。如有问题请与 sea_cloud@263.net 联系。
***文中的“《”“》”,实际为“<”“>”,sorry,不这么写就不显示了
======================================================
我说过它的过程基本正确,因为我照套他的过程中,发现:
0>首先glimpse无论如何都无法从源码正确编译安装,后来一想,干脆直接用rpm包,"rpm -ivh glimpse*.rpm",才发现glimpse依赖agrep*.rpm,将两者依序装好后。试一下,可用。从此以后,程序能用rpm安装,我就不从源码编译安装。人家做过优化的rpm为何不用,近来更饱尝gentoo编译时间长的可怕(http://rpmfind.net 寻找rpm最好的引擎)。
3)修改$INSTALLPREFIX/http/lxr.conf
4〉$INSTALLPREFIX/http/.htaccess一定要依照lxr安装包里的INSTALL 修改;
5〉我在初使用glimpseindex对源码建立索引后,却发现无法支持检索关键字,后来我想既然cgi是程序,就"chmod a+x . .*",在跑到apache的cgi-bin建一同名目录,再与lxr下的索引目录作一联接,宣告完工;
6〉apache-1.3.*以将access.conf合并到httpd.conf,所以将修改作入httpd.conf,当然cgi要被激活;
7> 如今的apache是用apachectl(start | stop)控制起停;
8>多版本支持(个人补充)
#A.(条件1)
|-sourceroot : /usr/src/$v # 假如对linux核心代码索引
|-dbdir : /home//html/lxr/dbdir/$v #dbdirk可任意起
|-incprefix: incprefix: /usr/src/$v/include
这三者三位一体,若想让你的本地lxr像lxr.no一样支持linux的多版本显示,必要使他们结伴出现,并且前两者的目录名称必须完全一致
#B.(条件2)
dbdir/versions: 加入你想索引的linux版本号;
dbdir/defversion: 最关注的缺省版本。(结合书籍Bach86,0.01读来最轻松,除了它的汇编代码到处穿插)
9〉apache随便找一1.3版装吧!我就不三八啦!不过最好放到他推荐的/usr/local/apache
======================================================
配置好,当然该享受读源码的乐趣,不过回想过程,lxr实在烦人,而且lxr只限于浏览器使用,对于向我这样更喜欢bash+emacs的人,实在有些嫌它...
======================================================

二.global可参见(http://gnu.j1b.org/software/global/global.html)
简介(我懒得翻):
GNU GLOBAL is a source code tag system that works the same way across diverse environments. You can locate a specified function in the source files and move there easily. It is useful for hacking a large project containing many subdirectories, many #ifdef and many main() functions.

GNU GLOBAL has following features:

support C, C++, Yacc and Java.
work the same way across diverse environments. Currently, support followings:
Shell command line
Nvi editor (vi clone)
Elvis editor (vi clone)
Emacs editor
Web browser
find the locations of a specified object quickly.
locate not only object definitions but also object references.
allows duplicate objects.
locate also path which includes specified pattern.
treat a source tree containing subdirectories as a logical scope. You can get the relative path of objects from anywhere within that scope.
search not only in a source tree but also in library paths.
understand POSIX 1003.2 regular expressions.
support external search engine (grep and idutils).
generate hypertext of source code.
tag files are independent of machine architecture.
plugged-in parser is available to treat new language.
compact format is available to save disk space.
support incremental updating of tag files.
support customizing with global.conf.
generate completion list for completing input method.
If you have a plan to make a yet another editor with tag facility then you can use GLOBAL as the tag system. GLOBAL home page is http://www.tamacom.com/global/.
------------------------------------------------------
若说lxr给我带来的是烦恼,那global就是给我解脱,我不必为了读源码,在gnome和bash间来回切换(完全用emacs工作的感觉,真爽!);并且它自带的info也提供了完备的描述。如果你更喜欢使用浏览器,我推荐用"htags -fcFnvta"生成ghtml,并将它们放入apache的html目录。 -f(支持cgi动态搜索) -c(压缩生成html) -F(使用frame风格) -n(行号) -a(制作Function索引) -t(欢迎标题:随意输入"Welcome into kernel tour"). 其中选项(f|c)与apache的CGI有关,可采用lxr使用cgi的同样方法:即在cgi-bin建一同名目录,在与刚才生成的ghtml目录中的HTML\cgi-bin\作联接.当然,你还要修改修改它的HTML/.htaccess的cgi目录,粘上你在cgi-bin中自建的目录名,应该可以了。
我已提了所有要注意的地方,剩下的,就要你自己去读文档了,我没有太多的时间去打字。
附上我自己用的apache-1.3.27的conf、cgi-bin目录打包,lxr.tgz、glimpse.tgz、agrep.tgz。默认解压到/usr/local/、/usr/local/apache.(tar zxvf *.tgz -C /)
祝学习愉快!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表