Repository navigation
Expand file tree
/
Copy pathDebugger.cpp
More file actions
137 lines (108 loc) · 3.45 KB
/
Copy pathDebugger.cpp
File metadata and controls
137 lines (108 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright (c) 2024 Quantag IT Solutions GmbH
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "Debugger.h"
#include "Log.h"
#include "qvm/QppQVM.h"
#ifdef ENABLE_CUDAQ
#include "qvm/CudaQVM.h"
#endif
#include "ConfigLoader.h"
Debugger::Debugger(const EventHandler& onEvent, ConfigLoader *cfg) : onEvent(onEvent), numSourceLines(0) {
LOGI("Debugger created");
std::string qvmType = cfg->getQvmType();
if (qvmType == "cudaq") {
#ifdef ENABLE_CUDAQ
qvm = new CudaQVM(cfg);
#else
LOGE("CudaQVM requested but not compiled with ENABLE_CUDAQ.");
// return 1;
#endif
}
qvm = new QppQVM(cfg);
}
Debugger::~Debugger() {
LOGI("Debugger destroyed");
delete qvm;
}
bool Debugger::continueDebugger() {
LOGI("***");
std::unique_lock<std::mutex> lock(mutex);
if (qvm->stepsByInstruction()) {
// Execute instructions until the next one is on a breakpoint line or the
// circuit ends. At least one instruction runs, so continuing from a
// breakpoint moves on.
for (int guard = 0; guard < 1000000; guard++) {
if (qvm->stepForward() < 0) {
LOGI("program finished");
return true;
}
if (breakpoints.count(qvm->getCurrentLine())) {
lock.unlock();
onEvent(EventEnum::BreakpointHit);
return false;
}
}
return false;
}
for (int64_t i = 0; i < numSourceLines; i++) {
int64_t l = ((qvm->getCurrentLine() + i) % numSourceLines) + 1;
if (breakpoints.count(l)) {
qvm->setCurrentLine( (int)l);
lock.unlock();
onEvent(EventEnum::BreakpointHit);
return false;
}
}
return false;
}
int Debugger::launch(int isRun, const std::string& fileName, const std::string &sessionId, LaunchStatus& status) {
LOGI("noDebug = %d, file = [%s] [%s]", isRun, fileName.c_str(), sessionId.c_str());
int ret = ERR_OK;
if (isRun) {
ret = qvm->run(fileName, sessionId, status);
}
else {
ret = qvm->debug(fileName, sessionId, status);
}
if (ret==ERR_OK) {
this->numSourceLines = qvm->getSourceLines();
}
return ret;
}
void Debugger::pause() {
LOGI("***");
onEvent(EventEnum::Paused);
}
int64_t Debugger::currentLine() {
LOGI("*** line = %d", qvm->getCurrentLine());
std::unique_lock<std::mutex> lock(mutex);
return qvm->getCurrentLine();
}
double Debugger::stepForward() {
LOGI("*** line = %d, numSourceLines = %d", qvm->getCurrentLine(), numSourceLines);
std::unique_lock<std::mutex> lock(mutex);
auto executionTime = qvm->stepForward();
lock.unlock();
onEvent(EventEnum::Stepped);
return executionTime;
}
void Debugger::clearBreakpoints() {
LOGI("***");
std::unique_lock<std::mutex> lock(mutex);
this->breakpoints.clear();
}
void Debugger::addBreakpoint(int64_t l) {
LOGI("*** line = %d", l);
std::unique_lock<std::mutex> lock(mutex);
this->breakpoints.emplace(l);
}
std::vector<complexNumber> Debugger::getQVMVariables() {
return this->qvm->getCurrentState().states;
}
size_t Debugger::getQubitsCount() const {
return qvm->getQubitsCount();
}