3

I've been using the debugger in netbeans for a while but I don't know exactly how it works. What does the IDE means when says something like "attach debugger"? What is happening under the hood?

JHCS
  • 57
  • 1
  • 7

2 Answers2

4

What does it mean to attach a debugger?

Across multiple languages and development environments, running processes can be configured to have ways of interacting with the outside world. Think of the diagnostic connector in a car - you can plug into it and read sensor information coming from your engine, lights, emissions and so on.

A debugger is like a device that plugs into your program's "diagnostic port." It can read the state of memory, where the program currently is in its execution, and so on. Depending on the debugger, it can even stop the program and change its state in-flight. The term "attach" is used because this can happen after the program is started; you can "detach" a debugger and allow a program to continue on its merry way. This capability is key because sometimes you want to attach a debugger to a running process with critical state without disrupting its execution.

What's happening under the hood?

That's a more complicated question. A good starting point might be the documentation for the Debugger API.

Hope that helps!

Christian Ternus
  • 8,406
  • 24
  • 39
1

In Java "attaching a debugger" means exactly what you might expect. Java is a bit of a special case for the concept of debuggers, because of the JVM.

In Java there is the Java Debug Wire Protocol (JDWP). It is basically an API which lets you, for example, query the JVM for the value of a certain variable. It also offers you events to listen to. These events might be breakpoints, or exceptions.

So "attaching a debugger" means registering your debugger as a listener to these events and register it to be able to interact with your running program.

noone
  • 19,520
  • 5
  • 61
  • 76