views:

26

answers:

2

I'm working on writing an OS and I'm running into problems trying to debug my code. I'm using GDB to connect to Bochs' GDB stub to "remotely" debug my kernel. Connecting works fine, as does loading debugging symbols from the kernel file. I set a breakpoint for the kmain function, which is successfully located, and the debugger breaks correctly (inside my kernel). However, I can't "step" or "next" through my code, nor can GDB apparently determine which line of code is the current line.

When I try to "step", I get the following message: "Cannot find bounds of current function". This is the only error message I get at any point.

My code is being compiled in GCC with the -g flag (I've tried other types of debugging information using GCC options; none have worked.) I have tried looking through the GDB manual , as well as searching for the answer, and I'm totally stumped. Any help would be amazing.

Thanks!

A: 

Googling throws up "This is because when you attached to gdbserver, the process under debug has not completed the C start-up code" http://www.cygwin.com/ml/gdb/2005-03/msg00237.html... http://www.bravegnu.org/gnu-eprog/c-startup.html describes the process for when you are coding for embedded devices, maybe this will help?

If you find the answer please post here as I'd like to know what the solution to the problem is too.

Steve
I came across that first link already, and the solution suggested is pretty much what I'm doing with gdb (except breaking at my kmain instead of "main"). I know that it is breaking inside my kernel, too. The second link basically made me re-examine that everything's ok with my stack, and as far as I can tell, it is. Thanks for the response!
TheArcher
+1  A: 

Well, I got debugging working, but I had to switch emulators. I was able to get GDB working with Qemu, even though I also had problems doing that. To get GDB to connect to the Qemu gdbserver, I had to pass the following option to Qemu: "-gdb tcp::1234,ipv4". Took me forever to figure that out... Debugging works perfectly now!

TheArcher
Thanks for posting the answer. Good luck with the OS.
Steve