-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Debugging OpenRCT2 on macOS
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
gdbserver
executable compiled with i686-w64-mingw32 as host (So when you've compiledgdbserver
, the result isgdbserver.exe
) - Use a
gdb
executable compiled with i686-w64-mingw32 as target (So the "host" is native) - Start
gdbserver.exe
using wine, e.g.:wine gdbserver.exe :0 openrct2.exe
A port number will now be shown, this is the port you should connect to in step 4. - Start
gdb
and 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-path
in GDB
After this, you can set breakpoints as you like!
-
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-werror
I set the
CFLAGS
variable so that it also includes/opt/local/include
and/opt/local/lib
in 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.9
andg++-mp-4.9
with 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.o
This 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
bfd
subdirectory, and run the same configure command above, except with--enable-targets=all
. Then, still in thebfd
subdirectory, 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
gdb
in thegdb
subdirectory. Place the executable wherever you want. I placed it alongside the other MinGW toolchain binaries. (located in/usr/local/mingw-w32-bin_i686-darwin/bin
if you ran theinstall.sh
script 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_c
as option with theconfigure
script. 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 thegdb
subdirectory, runmake
again.Having done this, you don't have to set the
sysroot
path everytime you startgdb
. It will locate wine's DLLs automatically.
-
Next, we compile
gdbserver
. This should be relatively painless, unlike the previous step.$ cd gdb/gdbserver $ ./configure --host=i686-w64-mingw32 $ make
i686-w64-mingw32-gcc
should 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.
- 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