Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the principle of debug? [duplicate]

I have learned programming for a couple of years, and used debug frequently.But I still don't understand the core principle of debug, how it works?How does singe line debugging(step into) implement?

take the java language for example.

What does CPU do for debug implementation?

what does JVM do for debug implementation?

what does eclipse do for debug implementation?

May be the three stuff I listed above have nothing to do with debug. I only guessed it.I have googled for some time and gained nothing useful for me(of course,debug itself is complicated), I hope more simple interpretation.

Thanks.

like image 514
liam xu Avatar asked Oct 29 '12 07:10

liam xu


2 Answers

Each processor has its own design of debugging mechanism.

For the case of x86 CPU, the processor has 6 debug registers which store the debug break-points and break-conditions. Have a brief look at this article for Intel x86 CPU debugging mechanism: http://en.wikipedia.org/wiki/X86_debug_register

For the case of Java debugging mechanism, see: http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/architecture.html as pointed out by Mukul Goel in the comment stream under the question.

like image 166
jondinham Avatar answered Nov 18 '22 12:11

jondinham


In order to facilitate debugging (using break points and such), the compiler inserts certain additional information into the complied output it generates (i.e. the binary file or the JVM bytecode file in case of Java). This extra information allows mapping each line of the compiled output to the corresponding source file.

I haven't answered all parts of your question, but hopefully enough to help you get started. Check out these resources:

http://en.wikipedia.org/wiki/Debug_symbol

How does a debugger work?

like image 36
4 revs, 2 users 85% Avatar answered Nov 18 '22 11:11

4 revs, 2 users 85%