The information on this page is very outdated and concerns the mingw target only. Just use lldb for native builds.
When debugging with winedbg, you probably found out that you can't:
- Set break/watch points (not even using the literal address),
- Use debug symbols.
To debug OpenRCT2 with these features, a particularly strange setup has to be used. I've been searching for ways to debug cross-compiled MinGW executables, and finally found this StackOverflow post: https://stackoverflow.com/questions/3720434/can-gdb-be-used-on-a-cross-compiled-win32-application-on-the-target-platform
In summary, the setup is as follows:
- Use a
gdbserverexecutable compiled with i686-w64-mingw32 as host (So when you've compiledgdbserver, the result isgdbserver.exe) - Use a
gdbexecutable compiled with i686-w64-mingw32 as target (So the "host" is native) - Start
gdbserver.exeusing wine, e.g.:wine gdbserver.exe :0 openrct2.exeA port number will now be shown, this is the port you should connect to in step 4. - Start
gdband connect to the server withtarget remote :[gdbserver-port-number] - run
set sysroot /path/to/sysroot(most of the time this is~/.wine/drive_c) in GDB - run
set solib-search-pathin GDB
After this, you can set breakpoints as you like!
Compiling gdbserver and gdb
-
Compiling gdb
First, we compile gdb. To do this, we need a gcc compiler and the gdb source code. On later versions on OSX, gcc has been replaced with clang. So use a gcc compiler installed with MacPorts or HomeBrew. I used MacPorts' gcc49 package.
- Grab the gdb source from GNU: https://www.gnu.org/software/gdb/download/. I used version 7.8.
- Configure gdb using the following command in the root directory. That is, in the directory gcc-[version], and not gcc-[version]/gcc:
$ CXX=g++-mp-4.9 CC=/opt/local/bin/gcc-mp-4.9 CFLAGS="-I/opt/local/include -L/opt/local/lib" ./configure --target=i686-w64-mingw32 --disable-werrorI set the
CFLAGSvariable so that it also includes/opt/local/includeand/opt/local/libin its library/header search paths. These are for MacPorts, but you have to set it to the correct directory yourself if you use a different system.Replace
gcc-mp-4.9andg++-mp-4.9with your own C and C++ compilers.-
Then, build it using
make.Running this, you may run into an error looking like this:
Undefined symbols _bfd_mach_o_lookup_command in machoread.oThis is because
bfd(located in the subdirectory calledbfd) hasn't been compiled with Mach-O, because we specified a custom target.To workaround this problem, go to the
bfdsubdirectory, and run the same configure command above, except with--enable-targets=all. Then, still in thebfdsubdirectory, runmake.When that's done, go to the top-level directory again (
cd ..) and run make again. Now it should compile. -
When it's done, you can find
gdbin thegdbsubdirectory. Place the executable wherever you want. I placed it alongside the other MinGW toolchain binaries. (located in/usr/local/mingw-w32-bin_i686-darwin/binif you ran theinstall.shscript for OpenRCT2):$ sudo cp gdb /usr/local/mingw-w32-bin_i686-darwin/bin/i686-w64-mingw32-gdb -
(optional) For more ease of use, I also used
--with-sysroot=/path/to/your/.wine/drive_cas option with theconfigurescript. To do this, go to the gdb subdirectory and run the same configure command as above, but now additionally with--with-sysroot=/path/to/your/.wine/drive_c. Now, still in thegdbsubdirectory, runmakeagain.Having done this, you don't have to set the
sysrootpath everytime you startgdb. It will locate wine's DLLs automatically.
-
Compiling gdbserver
Next, we compile
gdbserver. This should be relatively painless, unlike the previous step.$ cd gdb/gdbserver $ ./configure --host=i686-w64-mingw32 $ makei686-w64-mingw32-gccshould be used automatically. If not, check if it's in your path.The result is
gdbserver.exe. I copied this to/usr/local/cross-tools/i686-w64-mingw32/bin, to keep everything organized.
Running the server and connecting
- To run the server:
$ wine /path/to/gdbserver.exe :0 openrct2.exe - Then, run gdb:
$ i686-w64-mingw32-gdb openrct2.exe - Once in gdb, run:
target remote :[gdbserver-port-number] - Be sure to load OpenRCT2 debug symbols, which are compiled with openrct2.dll:
set solib-search-path
- Home
- FAQ & Common Issues
- Roadmap
- Installation
- Building
- Features
- Development
- Benchmarking & stress testing OpenRCT2
- Coding Style
- Commit Messages
- Overall program structure
- Data Structures
- CSS1.DAT
- Custom Music and Ride Music Objects
- Game Actions
- G1 Elements Layout
- game.cfg structure
- Maps
- Music Cleanup
- Objects
- Official extended scenery set
- Peep AI
- Peep Sprite Type
- RCT1 ride and vehicle types and their RCT2 equivalents
- RCT12_MAX_SOMETHING versus MAX_SOMETHING
- Ride rating calculation
- SV6 Ride Structure
- Settings in config.ini
- Sizes and angles in the game world
- Sprite List csg1.dat
- Sprite List g1.dat
- Strings used in RCT1
- Strings used in the game
- TD6 format
- Terminology
- Track Data
- Track Designs
- Track drawers, RTDs and vehicle types
- Track types
- Vehicle Sprite Layout
- Widget colours
- Debugging OpenRCT2 on macOS
- OpenGL renderer
- Rebase and Sync fork with OpenRCT2
- Release Checklist
- Replay System
- Using minidumps from crash reports
- Using Track Block Get Previous
- History
- Testing