2

I am creating an 8080 emulator using C when I received this error from my debugger:

Starting program: /Users/khalid/prog/8080_emulator/emulator 
[New Thread 0x1003 of process 35249]
[New Thread 0x1303 of process 35249]
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.

I get this output when I do use a breakpoint and when I don't. Before it crashed, the program would start four threads and then begin running. I'm not sure what could have caused this, but any help is appreciated!

I am running macOS High Sierra 10.13.1 and my GitHub repo for the emulator is here: https://github.com/khalludi/8080emulator.

This is my gdb configuration:

configure --host=x86_64-apple-darwin17.3.0 --target=x86_64-apple-darwin17.3.0
         --with-auto-load-dir=:${prefix}/share/auto-load
         --with-auto-load-safe-path=:${prefix}/share/auto-load
         --with-expat
         --with-gdb-datadir=/usr/local/Cellar/gdb/8.1/share/gdb (relocatable)
         --with-jit-reader-dir=/usr/local/Cellar/gdb/8.1/lib/gdb (relocatable)
         --without-libunwind-ia64
         --without-lzma
         --with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
         --without-guile
         --with-separate-debug-dir=/usr/local/Cellar/gdb/8.1/lib/debug (relocatable)
         --without-babeltrace

Also, these are the debug symbols:

khalid$ nm emulator
0000000100001020 T _Emulate8080Op
0000000100007640 T _MachineIN
00000001000076f0 T _MachineOUT
0000000100000f20 T _Parity
00000001000080c4 D _SCREEN_HEIGHT
00000001000080c0 D _SCREEN_WIDTH
                 U _SDL_AllocPalette
                 U _SDL_CreateWindow
                 U _SDL_DestroyWindow
                 U _SDL_FreeSurface
                 U _SDL_GetError
                 U _SDL_GetWindowSurface
                 U _SDL_Init
                 U _SDL_Quit
                 U _SDL_UpdateWindowSurface
                 U _SDL_UpperBlit
0000000100000fa0 T _UnimplementedInstruction
                 U ___stack_chk_fail
                 U ___stack_chk_guard
0000000100000000 T __mh_execute_header
0000000100007600 T _closeMedia
                 U _exit
                 U _fopen
                 U _fread
                 U _fseek
                 U _ftell
00000001000080e0 S _gImage
00000001000080d8 S _gScreenSurface
00000001000080d0 S _gWindow
0000000100007760 T _getMicrotime
                 U _gettimeofday
0000000100007470 T _init
00000001000080cb S _int_enable
00000001000075e0 T _loadMedia
0000000100007790 T _main
                 U _malloc
                 U _memset
                 U _printf
                 U _rewind
00000001000080c8 S _shift0
00000001000080c9 S _shift1
00000001000080ca S _shift_offset
00000001000080e8 S _state
                 U dyld_stub_binder

I read somewhere else that adding strip --strip-debug libpthread.so.0 to the C-flags of gcc would help but I have tried this and it doesn't work.

Or, is there a better way to debug the 8080 emulator? Again, any help is appreciated!

ks1322
  • 33,961
  • 14
  • 109
  • 164
Kharrid
  • 71
  • 8
  • Does your emulator make any use of `SIGTRAP` itself? In fact, does it ever call `sigaction` or `signal` itself? The `SIGTRAP` signal is part of the API for debugging, so I am suspicious of either a bug in GDB itself, or that your program is doing something unusual that GDB doesn't (perhaps _can't_) handle. And emulators often have to do unusual things... – zwol Mar 05 '18 at 21:05
  • No, my emulator does not use `SIGTRAP` or `sigaction` at all. It is possible that SDL is doing something unusual since this is my first time using the graphics library. – Kharrid Mar 05 '18 at 21:12
  • I have the very same problem with High Sierra. Can't successfully gdb any C or C++ application, getting the same error. I created the certificate for gdb, codesigned it, ran the echo command to create the git file as in other suggestions, etc – Kevin Mar 06 '18 at 05:00
  • 1
    Try to downgrade to gdb 8.0.1, see https://stackoverflow.com/a/49104154/72178. – ks1322 Mar 06 '18 at 10:07
  • That worked ks1322! A simple downgrade with `brew switch gdb 8.0.1` had it working again. I must have missed the upgrade when brew auto-upgraded the packages. Thanks again. – Kharrid Mar 06 '18 at 12:56
  • 1
    Possible duplicate of [gdb doesn't work on macos High Sierra 10.13.3](https://stackoverflow.com/questions/49001329/gdb-doesnt-work-on-macos-high-sierra-10-13-3) – ks1322 Mar 06 '18 at 15:49

0 Answers0