Skip to contentSkip to conversation

Debugging using GDB and gdbserver

DISCUSSION Justin Wojdacki 2 participants 10 messages Jun 15, 2002 MIPS

lore
Share & tools
lore
#0 lore raw

How does GDB work under MIPS Linux? I'm trying to do a bring-up of an embedded device, and it looks like the kernel is missing the code needed to handle software breakpoints. Are there patches that need to be applied to the kernel?

Signature · 4 lines
-------------------------------------------------
Justin Wojdacki        
[email protected]         (408) 350-5032
Communications Processors Group -- Analog Devices
#1 lore raw
Quoted 5 lines · Justin Wojdacki

How does GDB work under MIPS Linux? I'm trying to do a bring-up of an embedded device, and it looks like the kernel is missing the code needed to handle software breakpoints. Are there patches that need to be applied to the kernel?

No. If you use a current GDB (I recommend 5.2 or CVS) it should work just fine, if you are using a recent kernel (you didn't mention what version you were looking at).

Signature · 2 lines
Daniel Jacobowitz                           Debian GNU/Linux Developer
MontaVista Software                         Carnegie Mellon University
#2 lore raw
Quoted 8 lines · Daniel Jacobowitz
Quoted 5 lines · Justin Wojdacki

How does GDB work under MIPS Linux? I'm trying to do a bring-up of an embedded device, and it looks like the kernel is missing the code needed to handle software breakpoints. Are there patches that need to be applied to the kernel?

Quoted 7 lines

No. If you use a current GDB (I recommend 5.2 or CVS) it should work just fine, if you are using a recent kernel (you didn't mention what version you were looking at).

--
Daniel Jacobowitz Debian GNU/Linux Developer
MontaVista Software Carnegie Mellon University

Sorry, I'm using the 2.4.10 kernel and GDB 5.2. What I see happening is the BREAK 5 instruction from a software breakpoint is hit, and the kernel loops continuously on that, as it appears to have no way to deal with that exception. I'm running gdbserver on the MIPS target and gdb as a cross-debugger on an x86 host (RedHat 7.1). To me, it looks like when the debugging breakpoint is hit, gdbserver should get scheduled to run and handle the breakpoint, but instead the child keep's getting scheduled.

Signature · 4 lines
-------------------------------------------------
Justin Wojdacki        
[email protected]         (408) 350-5032
Communications Processors Group -- Analog Devices
#3 lore raw
Quoted 17 lines · Justin Wojdacki
Quoted 8 lines · Daniel Jacobowitz
Quoted 5 lines · Justin Wojdacki

How does GDB work under MIPS Linux? I'm trying to do a bring-up of an embedded device, and it looks like the kernel is missing the code needed to handle software breakpoints. Are there patches that need to be applied to the kernel?

Quoted 7 lines

No. If you use a current GDB (I recommend 5.2 or CVS) it should work just fine, if you are using a recent kernel (you didn't mention what version you were looking at).

--
Daniel Jacobowitz Debian GNU/Linux Developer
MontaVista Software Carnegie Mellon University

Quoted 8 lines

Sorry, I'm using the 2.4.10 kernel and GDB 5.2. What I see happening is the BREAK 5 instruction from a software breakpoint is hit, and the kernel loops continuously on that, as it appears to have no way to deal with that exception. I'm running gdbserver on the MIPS target and gdb as a cross-debugger on an x86 host (RedHat 7.1). To me, it looks like when the debugging breakpoint is hit, gdbserver should get scheduled to run and handle the breakpoint, but instead the child keep's getting scheduled.

Software breakpoints have worked at least as far back as 2.4.2. This most likely means that the exception handling for your board is broken.

Signature · 2 lines
Daniel Jacobowitz                           Debian GNU/Linux Developer
MontaVista Software                         Carnegie Mellon University
#4 lore raw
Quoted 7 lines · Daniel Jacobowitz

Software breakpoints have worked at least as far back as 2.4.2. This most likely means that the exception handling for your board is broken.

--
Daniel Jacobowitz Debian GNU/Linux Developer
MontaVista Software Carnegie Mellon University

What exception handling is the board expected to provide?

Signature · 4 lines
-------------------------------------------------
Justin Wojdacki        
[email protected]         (408) 350-5032
Communications Processors Group -- Analog Devices
#5 lore raw
In reply to Daniel Jacobowitz
Quoted 4 lines · Daniel Jacobowitz

Software breakpoints have worked at least as far back as 2.4.2. This most likely means that the exception handling for your board is broken.

Sorry, originally misinterpretted your use of "board" as referring to the board itself, and perhaps PMON (I've found a number of references online to GDB talking to PMON, but not much else).

So what I've found by looking at other board-specific code revolves around GDB talking to an in-kernel stub via the serial port. As the board I'm working with has an unreliable serial port (and some incarnations don't even have that), what about ethernet-based debugging? Is that do-able, say via putDebugChar() (although I suspect this poses an initialization problem)?

Thanks for the info so far.

Signature · 4 lines
-------------------------------------------------
Justin Wojdacki        
[email protected]         (408) 350-5032
Communications Processors Group -- Analog Devices
#6 lore raw
Quoted 10 lines · Justin Wojdacki
Quoted 4 lines · Daniel Jacobowitz

Software breakpoints have worked at least as far back as 2.4.2. This most likely means that the exception handling for your board is broken.

Sorry, originally misinterpretted your use of "board" as referring to the board itself, and perhaps PMON (I've found a number of references online to GDB talking to PMON, but not much else).

Quoted 8 lines

So what I've found by looking at other board-specific code revolves around GDB talking to an in-kernel stub via the serial port. As the board I'm working with has an unreliable serial port (and some incarnations don't even have that), what about ethernet-based debugging? Is that do-able, say via putDebugChar() (although I suspect this poses an initialization problem)?

Thanks for the info so far.

Wait, wait. What are you trying to do? Originally you were talking about userspace debugging via gdbserver. Now you're talking about kernel debugging via kgdb. They're separate (and coexisting can cause problems if you are not careful with your exception handlers; I do not remember when my patches to make that work went into the tree, or if someone else did it).

gdbserver can just use TCP.

Signature · 2 lines
Daniel Jacobowitz                           Debian GNU/Linux Developer
MontaVista Software                         Carnegie Mellon University
#7 lore raw
Quoted 8 lines · Daniel Jacobowitz

Wait, wait. What are you trying to do? Originally you were talking about userspace debugging via gdbserver. Now you're talking about kernel debugging via kgdb. They're separate (and coexisting can cause problems if you are not careful with your exception handlers; I do not remember when my patches to make that work went into the tree, or if someone else did it).

Quoted 5 lines

gdbserver can just use TCP.

--
Daniel Jacobowitz Debian GNU/Linux Developer
MontaVista Software Carnegie Mellon University

Sorry for the confusion. I've been discussing userspace debugging via gdbserver the entire time. However, I've noticed that gdbserver doesn't seem to be fully functional because the kernel doesn't seem to be handling the "BREAK 5" instruction correctly. You mentioned problems with board exception handling and I looked at the ddb series board support code. In there, I found handling for software breakpoints, and got the impression from the code that it was a general debugging interface, not just for kernel debugging. Again, sorry for the confusion.

As it stands right now, when I get hit a "BREAK 5" instruction, gdbserver never get's a chance to handle it, as the kernel keeps scheduling the child process I'm trying to debug, and hitting the "BREAK 5" instruction over and over again. What I can't seem to find out is how gdbserver is supposed to get scheduled again.

Signature · 4 lines
-------------------------------------------------
Justin Wojdacki        
[email protected]         (408) 350-5032
Communications Processors Group -- Analog Devices
#8 lore raw
Quoted 25 lines · Justin Wojdacki
Quoted 8 lines · Daniel Jacobowitz

Wait, wait. What are you trying to do? Originally you were talking about userspace debugging via gdbserver. Now you're talking about kernel debugging via kgdb. They're separate (and coexisting can cause problems if you are not careful with your exception handlers; I do not remember when my patches to make that work went into the tree, or if someone else did it).

Quoted 5 lines

gdbserver can just use TCP.

--
Daniel Jacobowitz Debian GNU/Linux Developer
MontaVista Software Carnegie Mellon University

Sorry for the confusion. I've been discussing userspace debugging via gdbserver the entire time. However, I've noticed that gdbserver doesn't seem to be fully functional because the kernel doesn't seem to be handling the "BREAK 5" instruction correctly. You mentioned problems with board exception handling and I looked at the ddb series board support code. In there, I found handling for software breakpoints, and got the impression from the code that it was a general debugging interface, not just for kernel debugging. Again, sorry for the confusion.

Quoted 5 lines

As it stands right now, when I get hit a "BREAK 5" instruction, gdbserver never get's a chance to handle it, as the kernel keeps scheduling the child process I'm trying to debug, and hitting the "BREAK 5" instruction over and over again. What I can't seem to find out is how gdbserver is supposed to get scheduled again.

What should happen is that the child receives a signal (SIGTRAP) after the exception. Then it is scheduled again, drops into do_signal, and the kernel notices that the traced bit is set and wakes the tracer. I'd guess your board needs to do something different to deliver the SIGTRAP properly, if that isn't happening.

Signature · 2 lines
Daniel Jacobowitz                           Debian GNU/Linux Developer
MontaVista Software                         Carnegie Mellon University
#9 lore raw
Quoted 10 lines · Daniel Jacobowitz

What should happen is that the child receives a signal (SIGTRAP) after the exception. Then it is scheduled again, drops into do_signal, and the kernel notices that the traced bit is set and wakes the tracer. I'd guess your board needs to do something different to deliver the SIGTRAP properly, if that isn't happening.

--
Daniel Jacobowitz Debian GNU/Linux Developer
MontaVista Software Carnegie Mellon University

Okay, thanks for the clarification. :)

Signature · 4 lines
-------------------------------------------------
Justin Wojdacki        
[email protected]         (408) 350-5032
Communications Processors Group -- Analog Devices