Qt Creator Dreamcast Development Environment

From dreamcast.wiki
Revision as of 03:11, 27 May 2023 by GyroVorbis (talk | contribs)
Jump to navigation Jump to search

NOTE: This page is a work in progress! It will get you set up for compiling and 90% ready for debugging, but the final bit and screenshots are incoming still.

This is a guide to set up the Qt Creator IDE for compilation and source-level debugging on the Sega Dreamcast using the KallistiOS development environment and the GDB debugger. Choosing Qt Creator as your IDE has several strengths, such as being massively cross-platform, supporting a multitude of devices and toolchains (Windows, Mac, Linux, iOS, Android, WebAssembly, etc), and being extremely easy to add additional toolchains to. I (Falco Girgs) build all of my projects with standard CMake using the CMake toolchain file provided within KOS, and I can swap between targeting a multitude of platforms by simply changing an option in a drop-down menu. Not only that, but any active breakpoints or watch variables that I've set up on PC will seamlessly transition over to my Dreamcast and vice versa when changing between targets!

However, the downside is that as of the writing of this tutorial (Qt Creator version 10.0.1), there are a few places where we are forced to do things that are slightly less than ideal or a bit hacky to maneuver around limitations in the configurability of the IDE. In my personal opinion, these are not actually a big deal, and your resulting environment is almost as easy to use as debugging locally; however, there are tutorials for other IDEs if having to click two buttons instead of one to start a remote debugging session or any of the little nuances here rub you the wrong way.

Prerequisites

To start with, this tutorial makes the following assumptions:

  1. You have already installed and set up your KallistiOS development environment.
  2. You have already downloaded and installed Qt Creator (version 10.0.1 was used for this tutorial).

Setting up GDB

Before we can begin configuring Qt Creator, we must install GDB, which is not installed by default with the KOS toolchain build scripts.

Building

The first thing we need to do is additionally set up and install the GDB debugger for the Dreamcast's GCC SH toolchain. Open a bash shell or whatever terminal you use to compile KOS code with and navigate back to the `dc-chain` folder within KOS, which was previously used to install the toolchains:

cd /opt/toolchains/dc/kos/utils/dc-chain

Once there, check to see whether you have a `config.mk` file which was used to build your toolchain previously. If you do, you can proceed to the next step. If you don't, you need to copy one of the three sample configuration files as your new `config.mk` file, depending on which version of the toolchain you had set up previously. If you aren't sure, you can run `sh-gcc-elf --version` and check which version of the compiler you had chosen. Next run one of the following commands:

  • GCC 4.7.4:
cp config.mk.legacy.sample config.mk
  • GCC 9.3.0:
cp config.mk.stable.sample config.mk
  • GCC 13.1.0:
cp config.mk.testing.sample config.mk

Finally, we're ready to actually download and install it. You can do so by running the following command:

make gdb

You should see a bunch of scrolling text as the make scripts download, extract, and begin building GDB.

Verifying Installation

After awhile, GDB should be built and installed into your DC toolchain. You can verify this by checking to see whether you have the executable. It is located at:

/opt/toolchains/dc/sh-elf/bin/sh-elf-gdb 

Alternatively, if you're currently within a DC environment, simply checking to see if you can run:

sh-elf-gdb

If everything goes well, it should start up and leave you at a command prompt.

Verifying Python Support

Note that Qt Creator requires that GDB be built with support for Python scripting extensions. This should be automatically detected and handled by the Makefiles which are checking to see whether Python is installed or not based on your path. You can verify that it was properly built with Python support by running the following command:

gdb --batch -ex 'python import sys; print(sys.version)'

Configuring Qt Creator

Now that we have GDB downloaded and installed, it's time to tell Qt Creator how to use our shiny new Dreamcast toolchain.

Adding the Toolchain

First, select the "Preferences" option from the "Edit" file menu. A dialog window should open. Select first entry, "Kits" from the top of the navigator pane on the left.

Configuring GDB

Next select the right-most "Debuggers" tab from the main view. Depending upon what you installed with Qt Creator, you may or may not see some automatically detected debuggers that it has preconfigured for you.

Next click "Add" to add a new Debugger entry. Then fill out the following fields:

  • Name: Dreamcast GDB
  • Path: Browse to where your sh-elf-gdb binary wound up being installed. This is /opt/toolchains/dc/sh-elf/bin/sh-elf-gdb by default.

If everything is correct, you should see the following entries populated automatically:

  • Type: GDB
  • ABIs: sh-baremetal-generic-elf-32bit
  • Version: The correct version number corresponding to the toolchain you chose

Configuring Compilers

Next, select the "Compilers" tab on the main tab widget. Again, depending on your Qt installation, you may or may not have a bunch of automatically detected compilers in your list.

C Compiler

First, we add the C compiler from our toolchain. Click the "Add" button in the top-right and select "GCC" from the dropdown. This should create a new entry in the compiler list. Configure it with the following settings:

  • Name: Dreamcast GCC
  • Path: Browse to where your sh-elf-gcc binary wound up being installed. This is /opt/toolchains/dc/sh-elf/bin/sh-elf-gcc by default.

If everything is good, Qt Creator should auto populate the last two fields:

  • ABI: sh-baremetal-generic-elf-32bit
  • Target Triple: sh-elf
C++ Compiler

Next, we add the C++ compiler from our toolchain. Click the "Add" button again, select "GCC" again, and this time configure it as such:

  • Name: Dreamcast G++
  • Path: Browse to where your sh-elf-g++ binary wound up being installed. This is /opt/toolchains/dc/sh-elf/bin/sh-elf-g++ by default.

As with previously, if everything went well, you should see the "ABI" and "Target Triple" fields automatically populated with the same values as with the C compiler.

Configuring the Kit

Finally, select the "Kits" tab from the main tab view. Qt Creator has automatically set up a kit for every platform you've installed a toolchain for (which could be none or many). We now need to add a custom Kit for the Sega Dreamcast.

Click the "Add" button in the top-right of the main view to add an entry to the list of its. Configure it with the following fields:

  • Name: Dreamcast GCC-<VERSION>
  • Compiler:
    • C: Dreamcast GCC
    • C++: Dreamcast G++
  • Debugger: Dreamcast GDB
  • Qt Version: None
  • CMake Generator: Unix Makefiles

Click on the "change" button to the right of the Environment field, and add the following:

KOS_BASE=/opt/toolchains/dc/kos
KOS_CC_BASE=/opt/toolchains/dc/sh-elf
KOS_PORTS=/opt/toolchains/dc/kos-ports
KOS_SUBARCH=dreamcast

Click on the "change" button to the right of the CMake Configuration field. Append the following to the bottom of the textbox:

-DCMAKE_TOOLCHAIN_FILE:FILEPATH=/opt/toolchains/dc/kos/utils/cmake/dreamcast.toolchain.cmake

Finally, if you want your setup to be badass looking like mine, you can optionally click on the tiny box to the right of the Name field and specify an icon for your kit. Here is the Dreamcast logo I have used: Icon Used for our custom Dreamcast Qt Creator Kit


Click Apply and then OK to exit the dialog box. Congratulations! You can now build CMake projects for the Sega Dreamcast!