suzukiplan / micro-msx2p

MSX2+ emulator specialized for embedded use
MIT License
10 stars 0 forks source link

Cannot use MSX2 instance as local variable #2

Closed suzukiplan closed 1 year ago

suzukiplan commented 1 year ago

Crushed following simple program in macOS

#include "msx2.hpp"

int main()
{
    MSX2 msx2(0);
    return 0;
}

execute:

% clang++ --std=c++11 -I../../msx2-osx/core test.cpp emu2413.o
% ./a.out
zsh: segmentation fault  ./a.out
%

execute with lldb:

% lldb a.out
(lldb) target create "a.out"
Current executable set to '/Users/suzukiplan/dev/micro-msx2p/test/test/a.out' (x86_64).
(lldb) r
Process 33129 launched: '/Users/suzukiplan/dev/micro-msx2p/test/test/a.out' (x86_64)
Process 33129 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7ff7bf6ffff8)
    frame #0: 0x00007ff805d84c0f libsystem_pthread.dylib`___chkstk_darwin + 55
libsystem_pthread.dylib`:
->  0x7ff805d84c0f <+55>: testq  %rcx, -0x8(%rcx)
    0x7ff805d84c13 <+59>: cmpq   $0x1000, %rax             ; imm = 0x1000 
    0x7ff805d84c19 <+65>: jb     0x7ff805d84c35            ; <+93>
    0x7ff805d84c1b <+67>: pushq  %rax
Target 0: (a.out) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7ff7bf6ffff8)
  * frame #0: 0x00007ff805d84c0f libsystem_pthread.dylib`___chkstk_darwin + 55
    frame #1: 0x00007ff7bfeff638
    frame #2: 0x00007ff805a2f41f dyld`start + 1903
(lldb) 
suzukiplan commented 1 year ago

Perhaps lack of stacks. Mainly due to the V9958 and MMU instances being too big, so it may be necessary to make them into a heap holding form in the MSX2 class.

suzukiplan commented 1 year ago

corrected in https://github.com/suzukiplan/micro-msx2p/commit/6ffa5430bebccd47ff16c65ae9c6a780057379fa