OSDN Git Service

[UI][Qt][DEBUGGER] Fix crash/lockup with closing debugger window.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 21 Feb 2018 15:20:26 +0000 (00:20 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 21 Feb 2018 15:20:26 +0000 (00:20 +0900)
12 files changed:
source/src/debugger.cpp
source/src/emu.h
source/src/qt/common/qt_utils.cpp
source/src/qt/debugger/CMakeLists.txt
source/src/qt/debugger/debugger_thread.cpp
source/src/qt/debugger/debugger_thread.h
source/src/qt/debugger/qt_debugger.cpp
source/src/qt/debugger/qt_debugger.h
source/src/qt/osd_base.h
source/src/qt/osd_console.cpp
source/src/qt/osd_screen.cpp
source/src/vm/fm7/fm7.cpp

index 54b7f72..6b957e5 100644 (file)
@@ -127,7 +127,9 @@ break_point_t *get_break_point(DEBUGGER *debugger, const _TCHAR *command)
        }
        return NULL;
 }
-
+#if defined(OSD_QT)
+#include "../debugger/debugger_thread.h"
+#endif
 #ifdef _MSC_VER
 unsigned __stdcall debugger_thread(void *lpx)
 #else
@@ -157,6 +159,7 @@ void* debugger_thread(void *lpx)
                }
                p->osd->sleep(10);
        }
+       
        uint32_t prog_addr_mask = cpu->get_debug_prog_addr_mask();
        uint32_t data_addr_mask = cpu->get_debug_data_addr_mask();
        uint32_t dump_addr = 0;
@@ -1103,6 +1106,7 @@ void* debugger_thread(void *lpx)
 void EMU::initialize_debugger()
 {
        now_debugging = false;
+       hDebugger = NULL;
 }
 
 void EMU::release_debugger()
index b1d6c87..935905a 100644 (file)
@@ -64,6 +64,9 @@ class FILEIO;
 class OSD;
 
 #ifdef USE_DEBUGGER
+#if defined(OSD_QT)
+class CSP_DebuggerThread;
+#endif
 typedef struct {
        OSD *osd;
        VM *vm;
index 3a0995d..3ab992e 100644 (file)
@@ -805,11 +805,12 @@ void Ui_MainWindow::OnOpenDebugger(int no)
        //emu->open_debugger(no);
        VM *vm = emu->get_vm();
 
-       if(emu->now_debugging)  this->OnCloseDebugger();
+       if((emu->now_debugging ) || (emu->hDebugger != NULL)) this->OnCloseDebugger();
        if(!(emu->now_debugging && emu->debugger_thread_param.cpu_index == no)) {
                //emu->close_debugger();
                if(vm->get_cpu(no) != NULL && vm->get_cpu(no)->get_debugger() != NULL) {
-                       
+                       QString windowName = QString::fromUtf8(vm->get_cpu(no)->get_device_name());
+                       windowName = QString::fromUtf8("Debugger ") + windowName;
                        emu->hDebugger = new CSP_Debugger(this);
                        QString objNameStr = QString("EmuDebugThread");
                        emu->hDebugger->setObjectName(objNameStr);
@@ -818,7 +819,7 @@ void Ui_MainWindow::OnOpenDebugger(int no)
                        emu->hDebugger->debugger_thread_param.cpu_index = no;
                        emu->stop_record_sound();
                        emu->stop_record_video();
-                       emu->now_debugging = true;
+                       //emu->now_debugging = true;
                        connect(this, SIGNAL(quit_debugger_thread()), emu->hDebugger, SLOT(doExit()));
                        connect(this, SIGNAL(destroyed()), emu->hDebugger, SLOT(do_destroy_thread()));
                        //connect(this, SIGNAL(quit_debugger_thread()), emu->hDebugger, SLOT(close()));
@@ -826,6 +827,7 @@ void Ui_MainWindow::OnOpenDebugger(int no)
                        connect(emu->hDebugger, SIGNAL(sig_put_string(QString)), emu->hDebugger, SLOT(put_string(QString)));
                        emu->hDebugger->show();
                        emu->hDebugger->run();
+                       emu->hDebugger->setWindowTitle(windowName);
                }
        }
 }
index ca42765..d87848a 100644 (file)
@@ -2,7 +2,6 @@ message("* qt/debugger")
 
 set(s_qt_debugger_headers
          qt_debugger.h
-         debugger_thread.h
 )
 
 if(USE_QT_5)
@@ -13,7 +12,6 @@ endif()
  
 add_library(qt_debugger
                  qt_debugger.cpp
-          debugger_thread.cpp
                  ${s_qt_debugger_headers_MOC}
 )
 
index 2b4f789..0c6c214 100644 (file)
 
 void CSP_DebuggerThread::quit_debugger()
 {
-#if defined(USE_DEBUGGER)      
-       debugger->now_going = false;
-       d_params->request_terminate = true;
-       try {
-               debugger->now_debugging = debugger->now_going = debugger->now_suspended = false;
-       } catch(...) {
-       }
-       d_params->running = false;
+#if defined(USE_DEBUGGER)
+       emu->close_debugger();
        // release console
 #endif 
        emit quit_debugger_thread();
@@ -31,21 +25,9 @@ void CSP_DebuggerThread::quit_debugger()
 extern void *debugger_thread(void *p);
 #endif
 
-void CSP_DebuggerThread::run()
+void CSP_DebuggerThread::run_debugger(void)
 {
-       QString str = QString::fromUtf8(_T("Debugger CPU #")) + QString::number(cpu_index);
-       emit sig_set_title(str);
-
-       pausing = false;
-#if defined(USE_DEBUGGER)      
-       d_params->running = true;
-       d_params->request_terminate = false;
-       dasm_addr = cpu->get_next_pc();
-       debugger->now_going = false;
-       debugger->now_debugging = true;
-       debugger_thread((void *)d_params);
-#endif 
-       //this->quit();
+//     emu->open_debugger(cpu_index);
 }
 
 CSP_DebuggerThread::CSP_DebuggerThread(QObject *parent, void *th) : QThread(parent)
@@ -60,9 +42,25 @@ CSP_DebuggerThread::CSP_DebuggerThread(QObject *parent, void *th) : QThread(pare
        cpu_index = d_params->cpu_index;
        debugger = (DEBUGGER *)cpu->get_debugger();
 #endif 
-       connect(this, SIGNAL(started()), this, SLOT(run()));
+       //connect(this, SIGNAL(started()), this, SLOT(run()));
+       QString str = QString::fromUtf8(_T("Debugger CPU #")) + QString::number(cpu_index);
+       emit sig_set_title(str);
+
+       pausing = false;
+#if defined(USE_DEBUGGER)      
+       d_params->running = true;
+       d_params->request_terminate = false;
+       dasm_addr = cpu->get_next_pc();
+       //debugger->now_going = false;
+       //debugger->now_debugging = true;
+       emu->open_debugger(cpu_index);
+       //debugger_thread((void *)d_params);
+#endif
+       //this->exec();
+       //this->quit();
 }
 
 CSP_DebuggerThread::~CSP_DebuggerThread()
 {
+       emu->close_debugger();
 }
index d7ab290..38a9de9 100644 (file)
@@ -47,7 +47,7 @@ public:
        CSP_DebuggerThread(QObject *parent, void *th);
        ~CSP_DebuggerThread();
 public slots:
-       void run();
+       void run_debugger();
        void quit_debugger();
 signals:
        int quit_debugger_thread();
index 4737144..4accc6b 100644 (file)
@@ -14,6 +14,7 @@
 #include <fcntl.h>
 #include <QObject>
 #include <QMetaObject>
+#include <QApplication>
 
 #include "qt_debugger.h"
 
@@ -39,43 +40,44 @@ void CSP_Debugger::call_debugger(void)
 void CSP_Debugger::run(void)
 {
        connect(text_command, SIGNAL(editingFinished()), this, SLOT(call_debugger()));
-       connect(this, SIGNAL(sig_finished()), this, SLOT(close()));
-       connect(this, SIGNAL(destroyed()), this, SLOT(doExit()));
        connect(parent_object, SIGNAL(quit_debugger_thread()), this, SLOT(close()));
        
 #if defined(USE_DEBUGGER)
-       main_thread = new CSP_DebuggerThread(NULL, &debugger_thread_param);
        OSD *osd = debugger_thread_param.osd;
-       main_thread->setObjectName(QString::fromUtf8("Debugger"));
-       main_thread->moveToThread(main_thread);
+       connect(osd, SIGNAL(sig_close_console()), this, SLOT(do_destroy_thread()));
        connect(this, SIGNAL(sig_call_debugger(QString)), osd, SLOT(do_set_input_string(QString)));
        connect(osd, SIGNAL(sig_put_string_debugger(QString)), this, SLOT(put_string(QString)));
-       
-       connect(main_thread, SIGNAL(finished()), this, SLOT(doExit()));
-       connect(main_thread, SIGNAL(quit_debugger_thread()), this, SLOT(doExit()));
-       connect(this, SIGNAL(sig_close_debugger()), main_thread, SLOT(quit_debugger()));
-       main_thread->start();
+       if(emu != NULL) {
+               emu->open_debugger(debugger_thread_param.cpu_index);
+       } else {
+               QString mes = QApplication::translate("Debugger", "Emulator still not start\nPlease wait.", 0);
+               put_string(mes);
+       }
 #endif
 }
 
 void CSP_Debugger::closeEvent(QCloseEvent *event)
 {
        //emit sig_close_debugger();
-       event->ignore();
+       //event->ignore();
+#if 1
+       debugger_thread_param.request_terminate = true;
+       if(emu != NULL) {
+               debugger_thread_t *d_params = &debugger_thread_param;
+               DEVICE *cpu = d_params->vm->get_cpu(d_params->cpu_index);
+               uint32_t cpu_index = d_params->cpu_index;
+               DEBUGGER *debugger = (DEBUGGER *)cpu->get_debugger();
+               if(emu->is_debugger_enabled(cpu_index)) {
+                       emu->close_debugger();
+                       //      debugger->now_debugging = false;
+               }
+       }
+#endif
+       event->accept();
 }
 
 void CSP_Debugger::do_destroy_thread(void)
 {
-#if defined(USE_DEBUGGER)
-       if(main_thread != NULL) {
-               if(main_thread->isRunning()) {
-                       main_thread->quit_debugger();
-                       main_thread->terminate();
-               }
-               delete main_thread;
-       }
-       main_thread = NULL;
-#endif
        this->close();
 }
 
@@ -89,13 +91,7 @@ CSP_Debugger::CSP_Debugger(QWidget *parent) : CSP_Debugger_Tmpl(parent)
 CSP_Debugger::~CSP_Debugger()
 {
 #if defined(USE_DEBUGGER)
-       if(main_thread != NULL) {
-               if(main_thread->isRunning()) {
-                       main_thread->quit_debugger();
-                       main_thread->terminate();
-               }
-               delete main_thread;
-       }
+       if(emu != NULL) emu->close_debugger();
 #endif
 }
 
index 801abce..b1c6a5d 100644 (file)
@@ -56,6 +56,7 @@ signals:
        void sig_call_debugger(QString);
        void sig_close_debugger(void);
        void sig_stop_debugger(void);
+       void sig_run_debugger(void);
 };
 
 QT_END_NAMESPACE       
index 1cfad7a..ceac0e2 100644 (file)
@@ -514,6 +514,7 @@ signals:
        int sig_update_device_node_name(int id, const _TCHAR *name);
        int sig_enable_mouse(void);
        int sig_disable_mouse(void);
+       int sig_close_console(void);
 };
 QT_END_NAMESPACE
 
index 6d6f68d..800a364 100644 (file)
@@ -66,6 +66,7 @@ void OSD_BASE::close_console()
        //DebugSemaphore->release(DebugSemaphore->available());
        console_cmd_str.clear();
        osd_console_opened = false;
+       emit sig_close_console();
 }
 
 unsigned int OSD_BASE::get_console_code_page()
index 62aec13..9a51c4b 100644 (file)
@@ -93,14 +93,14 @@ int OSD_BASE::draw_screen()
 {
        // draw screen
        screen_mutex->lock();
-       lock_vm();
+       //lock_vm();
        if(vm_screen_buffer.width != vm_screen_width || vm_screen_buffer.height != vm_screen_height) {
                //emit sig_movie_set_width(vm_screen_width);
                //emit sig_movie_set_height(vm_screen_height);
                initialize_screen_buffer(&vm_screen_buffer, vm_screen_width, vm_screen_height, 0);
        }
        this->vm_draw_screen();
-       unlock_vm();
+       //unlock_vm();
        screen_mutex->unlock();
        // screen size was changed in vm->draw_screen()
        if(vm_screen_buffer.width != vm_screen_width || vm_screen_buffer.height != vm_screen_height) {
index 81b53cd..eeeccaf 100644 (file)
@@ -1061,9 +1061,7 @@ void VM::rec_tape(int drv, const _TCHAR* file_path)
 
 void VM::close_tape(int drv)
 {
-       emu->lock_vm();
        if(drec != NULL) drec->close_tape();
-       emu->unlock_vm();
 }
 
 bool VM::is_tape_inserted(int drv)