I'm currently struggling with debugging openjdk in Trusty Tahr. I already installed opejdk-7-jdk and openjdk-7-dbg. When I issue gdb java I see it reads the symbols properly, but when I ask to list the code it complains about main.c not found. I manage to get the debugging working in CentOS and I could list the file main.c but I want to get it to work on Ubuntu as it's my main distro.
Raw output:
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
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:
<
Find the GDB manual and other documentation resources online at:
<
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from java...Reading symbols from /usr/lib/debug//usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java...done.
done.
(gdb) l
85 ../../../../src/share/bin/main.c: No such file or directory.
(gdb) Do I need to do something extra to place the main.c where it can be found?
1 Answer
You should modify source path used by gdb to find out source file.
According to gdb manual:
Executable programs sometimes do not record the directories of the source files from which they were compiled, just the names. Even when they do, the directories could be moved between the compilation and your debugging session. GDB has a list of directories to search for source files; this is called the source path.
You first need to find out where source file are on your system:
locate main.cand than use dir dirname command to:
Add directory dirname to the front of the source path. Several directory names may be given to this command, separated by ‘:’ (‘;’ on MS-DOS and MS-Windows, where ‘:’ usually appears as part of absolute file names) or whitespace. You may specify a directory that is already in the source path; this moves it forward, so GDB searches it sooner.
Read carefully gdb manual's link above in order to know how this source path is used.