Allen
Allen

Reputation: 4769

invoke gdb to debug java programs

i am pretty new to programming, and having some trouble with debugging java programs. I try to use gdb to debug my java program, but no matter how hard i try, it still does not work at all.

The error message in the minibuffer of emacs(GUI) is always "No such file or directory , gdb". I am sure that my currrent directory is the the same as the sourcefile and the compiled file(executable file compiled with "javac -g xx.java") .

So, my confusion is that: Does the error has something to do with: 1. wrong syntax of invoking gdb (used Meta gdb xx ) 2. what is the executable java file for gdb/ how gdb identify them 3. is it possible that my installation of EMACS is incomplete, as i input the gdb to the command line(Win8 system), NO gdb prompt appears at all(something like(gdb....))

Upvotes: 0

Views: 2380

Answers (1)

Christian Hujer
Christian Hujer

Reputation: 17945

Error No such file or directory, gdb

  • If the error message is coming from emacs, it means that gdb is not installed. To fix it, install gdb. Note that gdb is not part of emacs, it's a separate program. If you get gdb with a bundle, it would usually be part of gcc, the GNU Compiler Collection, not Emacs. The source is the same - FSF (Free Software Foundation) / GNU Project (GNU is Not Unix), but it is different / separate packages.
  • If the error message is coming from gdb, it means that gdb cannot find the executable. See next point for this.

However, looking at your description, it's more likely that gdb is not installed at all.

gdb cannot debug Java directly

gdb cannot be used to debug Java programs in general, it can only be used to debug Java programs that were compiled into binaries using gcj. See also Java Debugging with gdb from its manual.

You may want to go for jdb instead, which is the Java Debugger that comes with a JDK.

Emacs for Java? Use an IDE instead

Emacs is a great text editor indeed. The jokes that people make about Emacs, like "Actually Emacs is a Common Lisp implementation for developing computer games which happens to have one of the two best text editors as a demo app" are a pun on its greatness. I'm a vim user myself, and I have only the deepest respect for Emacs and what it contributes to computer science (i.e. Common Lisp).

But no matter how good Emacs and vim are, these days the IDEs beat them to it.

The three most popular Java IDEs

  • Eclipse
  • NetBeans
  • IntelliJ IDEA

I recommend IntelliJ IDEA and have my reasons for it, but you can't really choose wrong. They're all good!

What do the IDEs offer?

  • Syntax Highlighting
  • Bleeding edge with the latest Java versions
  • Hundreds of additional checks (especially IntelliJ IDEA: Inspections)
  • Lots of typical edits automated (especially IntelliJ IDEA: Intentions)
  • Refactoring
  • Java Debugging
  • Java Decompilation
  • Code Coverage
  • Code Completion
  • Integrated access to JavaDoc help
  • Integration with Unit Test frameworks
  • Integration with Version Control Systems
  • Integration with Android SDK and Emulator
  • Integration with the typical Java build tools Ant, Maven, Gradle
  • A lot more with those many plugins

Several of these things are also offered by Emacs or vim - but not all of them.

What about my Emacs (or vim) knowledge?

I'm a vim power user myself, but I wouldn't use vim for any Java that exceeds Hello, World, because an IDE like IntelliJ IDEA is just so much better. One argument that is often made is that we users invest a lot into editors like vim and emacs learning all their shortcuts for productivity. This knowledge does not need to be lost. IntelliJ IDEA has an IdeaVim plugin for Vim users and an emacsIDEA plugin for Emacs users. I don't know, but I could imagine that the other IDEs have similar plugins.

Upvotes: 2

Related Questions