OSDN Git Service

[Qt][DEBUGGER] Temporally revert changes around debugger, will use src/debugger.cpp .
[csp-qt/common_source_project-fm7.git] / source / src / qt / debugger / qt_debugger.cpp
1 /*
2         Skelton for retropc emulator
3
4         Author : K.Ohta <whatisthis.sowhat _at_ gmail.com>
5         Date   : 2015.04.09 -
6         History: 09 Apr, 2015 : Initial from Takeda.Toshiya's w32_debugger.cpp.
7         [ debugger console ]
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12
13 //#include <unistd.h>
14 #include <fcntl.h>
15 #include <QObject>
16 #include <QMetaObject>
17
18 //#include "res/resource.h"
19 #include "../../emu.h"
20 #include "../../vm/device.h"
21 #include "../../vm/debugger.h"
22 #include "../../vm/vm.h"
23 #include "../../fileio.h"
24 #include "qt_debugger.h"
25 //#include <QThread>
26 //#include <QMainWindow>
27
28
29 #ifdef USE_DEBUGGER
30
31 void CSP_Debugger::put_string(QString s)
32 {
33         text->insertPlainText(s);
34         text->moveCursor(QTextCursor::End);
35 }
36
37 void CSP_Debugger::cmd_clear()
38 {
39         text_command->clear();
40         text->moveCursor(QTextCursor::End);
41 }
42
43
44 void CSP_Debugger::doExit2(void)
45 {
46         emit sig_close_debugger();
47 }
48
49 void CSP_Debugger::doExit(void)
50 {
51         DEVICE *cpu = debugger_thread_param.vm->get_cpu(debugger_thread_param.cpu_index);
52         DEBUGGER *debugger = (DEBUGGER *)cpu->get_debugger();
53         debugger_thread_param.request_terminate = true;
54         
55         try {
56                 debugger->now_debugging = debugger->now_going = debugger->now_suspended = false;
57         } catch(...) {
58         }
59         // release console
60         debugger_thread_param.running = false;
61         emit sig_finished();
62 }
63
64 void CSP_Debugger::stop_polling()
65 {
66         //poll_stop = true;
67 }
68
69 void CSP_Debugger::call_debugger(void)
70 {
71         //emit sig_call_debugger(text_command->text());
72         main_thread->call_debugger(text_command->text());
73 }
74
75 void CSP_Debugger::run(void)
76 {
77         main_thread = new CSP_DebuggerThread(NULL, &debugger_thread_param);
78         main_thread->setObjectName(QString::fromUtf8("Debugger"));
79         main_thread->moveToThread(main_thread);
80         //main_thread = new CSP_DebuggerThread(this, &debugger_thread_param);
81         
82         connect(text_command, SIGNAL(editingFinished()), this, SLOT(call_debugger()));
83         connect(this, SIGNAL(sig_call_debugger(QString)), main_thread, SLOT(call_debugger(QString)));
84         
85         connect(main_thread, SIGNAL(sig_text_clear()), this, SLOT(cmd_clear()));
86         connect(main_thread, SIGNAL(sig_put_string(QString)), this, SLOT(put_string(QString)));
87         
88         connect(main_thread, SIGNAL(finished()), this, SLOT(doExit()));
89         connect(main_thread, SIGNAL(quit_debugger_thread()), this, SLOT(doExit()));
90         
91         connect(this, SIGNAL(sig_finished()), this, SLOT(close()));
92         connect(this, SIGNAL(destroyed()), this, SLOT(doExit()));
93         connect(this, SIGNAL(sig_close_debugger()), main_thread, SLOT(quit_debugger()));
94         
95         //connect(parent_object, SIGNAL(quit_debugger_thread()), this, SLOT(doExit2()));
96         connect(parent_object, SIGNAL(quit_debugger_thread()), this, SLOT(close()));
97                                                                   
98         connect(this, SIGNAL(sig_start_debugger()), main_thread, SLOT(start()));
99         main_thread->start();
100         //emit sig_start_debugger();
101 }
102
103 void CSP_Debugger::closeEvent(QCloseEvent *event)
104 {
105         main_thread->terminate();
106         doExit();
107 }
108
109 CSP_Debugger::CSP_Debugger(QWidget *parent) : QWidget(parent, Qt::Window)
110 {
111         widget = this;
112         
113         parent_object = parent;
114         text = new QTextEdit(this);
115         text->setReadOnly(true);
116         text->setLineWrapMode(QTextEdit::WidgetWidth);
117         //text->setCenterOnScroll(true);
118
119         text_command = new QLineEdit(this);
120         text_command->setEchoMode(QLineEdit::Normal);
121         text_command->setMaxLength(1024);
122         text_command->setReadOnly(false);
123         text_command->setEnabled(true);
124         text_command->clear();
125         //connect(text_command, SIGNAL(editingFinished()), this, SLOT(call_debugger()));
126         
127         VBoxWindow = new QVBoxLayout;
128
129         VBoxWindow->addWidget(text);
130         VBoxWindow->addWidget(text_command);
131         this->setLayout(VBoxWindow);
132         this->resize(640, 500);
133 }
134
135
136 CSP_Debugger::~CSP_Debugger()
137 {
138         
139 }
140    
141
142
143 #endif
144