Debugging and traces for KOS application : how to ?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
sundance
DCEmu Newbie
DCEmu Newbie
Posts: 1
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Mar 29, 2020 3:09 pm
Has thanked: 0
Been thanked: 0

Debugging and traces for KOS application : how to ?

Post by sundance »

I'm currently trying to fix a bug in a module of DreamShell, a KOS application.

I'm familiar with C development, but not with DreamCast development, which seems closer to embedded dev.
So there are a ton of specific details I still need to learn.
Still, so far, I've managed to download and compile KOS, get a few simple programs running, both on hardware and emulator. I also managed to compile the DreamShell, including its target modules, test them on real hardware, and modify them. So basic elements seem in place.

Currently, my number 1 request would be to get a capability to write and read traces in order to debug an application.
I can guess where the bug might be, but in order to clearly identify the exact place where the error happens, and then fix it, I need detailed traces.

In a "normal" environment, I would expect a console, where I could at least printf() progresses.
This would be a great help to converge onto a root cause.
But right now, I've got nothing, just direct play on real hardware through SD Card, and an apparent stack overflow crash.

I would expect the ability to write and read traces to be a basic minimum for any serious development.
I'm looking for pointers on how to do that.
Note : I don't have any special developer cable.
Maybe if traces can't be printed on screen, writing on SDCard for later consultation could work, although I'm worried about implied complexity (incomplete flush, and messing with file system metadata during a crash, typically).

Also, I'm currently testing on real hardware directly, but past experiences told me that development stage, especially debugging, can be way more efficient on an emulator. Just, I haven't found any setup terribly useful so far.
Developing on a Linux environment, I'm trying to use lxdream. I could also try `redream`.
While it "works", i.e. simple working applications get loaded and run fine, I haven't yet found a way to harness that setup for DreamShell debugging. I'm starting to wonder if `DreamShell` can be run on emulator at all, since it seems to require low-level un-emulated commands, such as IDE and Serial port, with (apparently) terminating consequences.
User avatar
ThePerfectK
Insane DCEmu
Insane DCEmu
Posts: 147
Joined: Thu Apr 27, 2006 10:15 am
Has thanked: 27 times
Been thanked: 35 times

Re: Debugging and traces for KOS application : how to ?

Post by ThePerfectK »

There is no real way to get around the need for a console to output to. It appears you don't have any equipment to connect your dreamcast to a PC, and I'd assume from your post that you aren't necessarily interested in building a coder's cable, so the only alternative I can point to would be emulation. Before I go further, note that dreamcast emulation is not recommended, as you will never know if your stuff runs on real hardware. I've run into many situations where something would run in an emulator, but not on a real console, and vice versa. And when that happens, its really hard to fix the problem, for all the reasons you listed.

That said, if you want to debug and trace programs on the dreamcast, you need to use GDB. You can build gdb with python support to integrate it into an IDE like QTCreator if you'd like, but you'll still need to use GDB. But your first step should be to get console output from your emulator. The emulator I recommend for this is actually Redream in linux. Here's a post I made a long while ago that should help you use both gdb and get console output from Redream:

https://dcemulation.org/phpBB/viewtopic ... 4#p1056797

If you absolutely cannot use an emulator for some reason, there IS the debug font in the bios that KOS can call to. This manipulates the framebuffer of the dreamcast to put pixels representing font characters directly on the screen. This doesn't play well with the PVR hardware, however, so it's best used as it's own entire full screen mode. I.e. the debug font is best used as a crash dump screen. I would very honestly not recommend you use the debug font this way, as it has severe limitations.
Still Thinking!~~
Post Reply