1

I am trying to debug javadoc tool. I want to step in and see how javadoc (or even javac or other jdk tools) is actually working (and find potential bugs). Here are the steps I followed:

  1. Downloaded the openjdk src
  2. compiled successfully using ./configure --with-debug-level=slowdebug --with-boot-jdk=~/Downloads/jdk-18.0.2_linux-x64_bin/jdk-18.0.2 and thenmake images
  3. used the compiled javadoc to create javadoc. This executes correctly.
  4. But when used gdb I got SIGSEGV: gdb --args ~/Downloads/openjdk-18.0.2_src/openjdk/build/linux-x86_64-server-slowdebug/jdk/bin/javadoc "~/Downloads/Test.java"

This is what I got when used gdb:

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ~/Downloads/openjdk-18.0.2_src/openjdk/build/linux-x86_64-server-slowdebug/jdk/bin/javadoc...
Reading symbols from ~/Downloads/openjdk-18.0.2_src/openjdk/build/linux-x86_64-server-slowdebug/jdk/bin/javadoc.debuginfo...
(gdb) l
84  int WINAPI
85  WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int cmdshow)
86  {
87      int margc;
88      char** margv;
89      int jargc;
90      char** jargv;
91      const jboolean const_javaw = JNI_TRUE;
92  
93      __initenv = _environ;
(gdb) r
Starting program: ~/Downloads/openjdk-18.0.2_src/openjdk/build/linux-x86_64-server-slowdebug/jdk/bin/javadoc ~/Downloads/Test.java
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff5a10700 (LWP 65100)]

Thread 2 "javadoc" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff5a10700 (LWP 65100)]
0x00007fffe100064d in ?? ()
(gdb) 

Probably I am using gbd the wrong way. Any help would be appreciated! Thanks.

anupamD
  • 862
  • 1
  • 8
  • 21
  • 1
    You have to ignore `SIGSEGV` inside `GDB` while debugging `JDK` tools: https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_38.html - https://www.ateam-oracle.com/post/why-am-i-seeing-sigsegv-when-i-strace-a-java-application-on-linux – Oo.oO Aug 05 '22 at 05:42
  • Yes thanks @Slaw, I wanted to know how the control flow is when java tools are fired. If there is any link how to debug java with/without gdb, it would be helpful – anupamD Aug 05 '22 at 07:10
  • Personally, if I wanted to debug the Java side of the code, I would just write a quick program that invokes the Javadoc tool and run it in an IDE (e.g., IntelliJ, Eclipse, etc.), and use that IDE's debugging features. The program does not have to be complex. It could just be `ToolProvider.findFirst("javadoc").orElseThrow().run(System.out, System.err, args)`, where `args` is the arguments to the tool (see [ToolProvider](https://stackoverflow.com/q/72415805/6395627); Java 9+). – Slaw Aug 05 '22 at 07:31
  • Thanks @Slaw. You were of great help. ! – anupamD Aug 05 '22 at 08:19

1 Answers1

1

Thanks @Oo.oO using handle SIGSEGV nostop worked

anupamD
  • 862
  • 1
  • 8
  • 21