OSDN Git Service

[DEBUGGER][Qt] (Maybe) Fix crash when closing a debugger window.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 4 Mar 2016 13:54:12 +0000 (22:54 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 4 Mar 2016 13:54:12 +0000 (22:54 +0900)
source/src/debugger.cpp
source/src/qt/osd.cpp
source/src/qt/osd.h
source/src/qt/osd_console.cpp

index 8f40c80..12a5841 100644 (file)
@@ -946,8 +946,8 @@ void EMU::open_debugger(int cpu_index)
                                        
                                        uint32_t prog_addr_mask = cpu->debug_prog_addr_mask();
                                        uint32_t data_addr_mask = cpu->debug_data_addr_mask();
-                                       uint32_t dump_addr = 0;
-                                       uint32_t dasm_addr = cpu->get_next_pc();
+                                       dump_addr = 0;
+                                       dasm_addr = cpu->get_next_pc();
        
                                        // initialize console
                                        _TCHAR buffer[1024];
index b13ec4b..35e4582 100644 (file)
 OSD::OSD() : QThread(0)
 {
        VMSemaphore = new QSemaphore(1);
+       DebugSemaphore = new QSemaphore(1);
        locked_vm = false;
 }
 
 OSD::~OSD()
 {
        delete VMSemaphore;
+       delete DebugSemaphore;
 }
 
 extern std::string cpp_homedir;
index 265ae11..1f0a280 100644 (file)
@@ -190,6 +190,7 @@ protected:
 //     EMU* emu;
        EmuThreadClass *parent_thread;
        QSemaphore *VMSemaphore;
+       QSemaphore *DebugSemaphore;
        sdl_snddata_t snddata;
        private:
        _TCHAR app_path[_MAX_PATH];
index 734d71d..aae67b4 100644 (file)
@@ -28,30 +28,44 @@ void OSD::do_write_inputdata(QString s)
 void OSD::do_set_input_string(QString s)
 {
        //if(s.empty()
+       DebugSemaphore->acquire(1);
        console_cmd_str.append(s);
        console_cmd_str.append(QString::fromUtf8("\n"));
+       DebugSemaphore->release();
 }
 
 _TCHAR *OSD::console_input_string(void)
 {
-       if(console_cmd_str.isEmpty()) return NULL;
-       return (_TCHAR *)console_cmd_str.toUtf8().constData();
+       DebugSemaphore->acquire(1);
+       if(console_cmd_str.isEmpty()) {
+               DebugSemaphore->release(1);
+               return NULL;
+       }
+       _TCHAR *p = (_TCHAR *)console_cmd_str.toUtf8().constData();
+       DebugSemaphore->release();
+       return p;
 }
 
 void OSD::clear_console_input_string(void)
 {
+       DebugSemaphore->acquire(1);
        console_cmd_str.clear();
+       DebugSemaphore->release();
 }
 
 void OSD::open_console(_TCHAR* title)
 {
        if(osd_console_opened) return;
+       DebugSemaphore->acquire(1);
        console_cmd_str.clear();
        osd_console_opened = true;
+       DebugSemaphore->release();
+
 }
 
 void OSD::close_console()
 {
+       DebugSemaphore->release(DebugSemaphore->available());
        console_cmd_str.clear();
        osd_console_opened = false;
 }
@@ -83,7 +97,9 @@ int OSD::read_console_input(_TCHAR* buffer)
        int i;
        int count = 0;
        QString tmps;
+       DebugSemaphore->acquire(1);
        tmps = console_cmd_str.left(16);
+       DebugSemaphore->release(1);
        if(buffer == NULL) return 0;
        
        memset(buffer, 0x00, 16);
@@ -99,10 +115,12 @@ int OSD::read_console_input(_TCHAR* buffer)
        count = tmps.length();
        if(tmps.isEmpty() || (count <= 0)) return 0; 
        if(count > 16) count = 16;
+       DebugSemaphore->acquire(1);
        int l = console_cmd_str.length();
        
        console_cmd_str = console_cmd_str.right(l - count);     
        strncpy(buffer, tmps.toLocal8Bit().constData(), count);
+       DebugSemaphore->release(1);
 
        return count;
 }