java hotspot gdb调试时如何正确设置断点?

zgw06629 发布于 2015/05/29 17:21
阅读 870
收藏 0

终端中查询打开文件数是1024,如下所示:

$ ulimit -n
1024

通过Java 代码(Runtime.getRuntime().exec(cmdArray))执行同样的命令发现是4096, 显然jvm隐式改变了该值, 搜索Openjdk hotspot源码,发现很有可能在os_linux.cpp中对打开文件数做了改变,相应源码为:

4616   if (MaxFDLimit) {
4617     // set the number of file descriptors to max. print out error
4618     // if getrlimit/setrlimit fails but continue regardless.
4619     struct rlimit nbr_files;
4620     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
4621     if (status != 0) {
4622       if (PrintMiscellaneous && (Verbose || WizardMode))
4623         perror("os::init_2 getrlimit failed");
4624     } else {
4625       nbr_files.rlim_cur = nbr_files.rlim_max;
4626       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
4627       if (status != 0) {
4628         if (PrintMiscellaneous && (Verbose || WizardMode))
4629           perror("os::init_2 setrlimit failed");
4630       }
4631     }
4632   }

现在想在此处加上断点, 看运行java程序时, jvm是否进入此处。于是想到用GDB调试,

$ sh hotspot -gdb HelloWorld
...
(gdb) break os_linux.cpp:4619
No source file named os_linux.cpp.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) continue
Continuing.
[New Thread 0x7ffff471d700 (LWP 24138)]
[New Thread 0x7ffff461c700 (LWP 24139)]
[New Thread 0x7ffff451b700 (LWP 24140)]
[New Thread 0x7ffff441a700 (LWP 24141)]
[New Thread 0x7fffd7afa700 (LWP 24142)]
[New Thread 0x7fffd79f9700 (LWP 24143)]
[New Thread 0x7fffd78f8700 (LWP 24144)]
[New Thread 0x7fffd700f700 (LWP 24145)]
[New Thread 0x7fffd6f0e700 (LWP 24146)]
[New Thread 0x7fffd6e0d700 (LWP 24147)]
[New Thread 0x7fffd6d0c700 (LWP 24148)]
[New Thread 0x7fffd6c0b700 (LWP 24149)]
Hello World!
[Thread 0x7fffd6c0b700 (LWP 24149) exited]
[Thread 0x7fffd700f700 (LWP 24145) exited]
[Thread 0x7fffd7afa700 (LWP 24142) exited]
[Thread 0x7ffff7fd8700 (LWP 23803) exited]
[Thread 0x7ffff451b700 (LWP 24140) exited]
[Thread 0x7fffd6e0d700 (LWP 24147) exited]
[Thread 0x7fffd6f0e700 (LWP 24146) exited]
[Thread 0x7fffd78f8700 (LWP 24144) exited]
[Thread 0x7fffd79f9700 (LWP 24143) exited]
[Thread 0x7ffff441a700 (LWP 24141) exited]
[Thread 0x7ffff461c700 (LWP 24139) exited]
[Thread 0x7ffff471d700 (LWP 24138) exited]
[Thread 0x7ffff7fd9740 (LWP 23790) exited]
[Inferior 1 (process 23790) exited normally]

但是并没有进入该断点, 通过搜索源代码发现没有其他地方更改打开文件数了, 所以是我设置断点方式不对吗?


加载中
0
zgw06629
zgw06629

经过咨询HotSpot实战作者, 找到了解决方法,即在jvmg目录下有一个libjvm.diz文件, unzip它即可, 会产生一个libjvm.debuginfo文件。

然后执行调试就能进入断点,如下所示:

(gdb) break os_linux.cpp:4619
(gdb) c
Continuing.
Breakpoint 2, os::init_2 () at /openjdk-7u40-fcs-src-b43-26_aug_2013/hotspot/src/os/linux/vm/os_linux.cpp:4620
4620	    int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
(gdb) l
4615	
4616	  if (MaxFDLimit) {
4617	    // set the number of file descriptors to max. print out error
4618	    // if getrlimit/setrlimit fails but continue regardless.
4619	    struct rlimit nbr_files;
4620	    int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
4621	    if (status != 0) {
4622	      if (PrintMiscellaneous && (Verbose || WizardMode))
4623	        perror("os::init_2 getrlimit failed");
4624	    } else {




返回顶部
顶部