Skip to content

Commit

Permalink
cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanter2033 authored and Luca Bassi committed Nov 13, 2024
1 parent b6f0e38 commit 58c51e5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 52 deletions.
29 changes: 7 additions & 22 deletions src/frontends/qriscv/debug_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <cstdlib>
#include <list>


#include <QAction>
#include <QMessageBox>
#include <QTimer>
Expand Down Expand Up @@ -92,10 +91,7 @@ void DebugSession::setGdbStatus(bool newStatus){
void DebugSession::createActions() {
startMachineAction = new QAction("Power On", this);
startMachineAction->setShortcut(QKeySequence("F5"));

startMachineAction->setIcon(QIcon(":/icons/start-22.svg"));


startMachineAction->setIcon(QIcon(":/icons/start-22.svg"));
connect(startMachineAction, SIGNAL(triggered()), this, SLOT(startMachine()));
startMachineAction->setEnabled(false);

Expand Down Expand Up @@ -199,24 +195,18 @@ void DebugSession::initializeMachine() {
if (isGdbEnabled()) {
gts = std::thread([&]() {
gdb = new GDBServer(machine.get());
printf("server started \n");
fflush(stdout);
gdb->StartServer(); });
printf("thread initialize \n");
fflush(stdout);
gts.detach();
}
}
catch (const FileError &e) {
} catch (const FileError &e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QString("<b>Could not initialize machine:</b> "
"the file `%1' is nonexistent or inaccessible")
.arg(e.fileName.c_str()));
return;
}
catch (const InvalidCoreFileError &e) {
} catch (const InvalidCoreFileError &e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
Expand All @@ -226,24 +216,21 @@ void DebugSession::initializeMachine() {
"<code>umps3-elf2umps</code> utility")
.arg(e.fileName.c_str()));
return;
}
catch (const CoreFileOverflow &e) {
} catch (const CoreFileOverflow &e) {
QMessageBox::critical(Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
"<b>Could not initialize machine:</b> "
"the core file does not fit in memory; "
"please increase available RAM and try again");
return;
}
catch (const InvalidFileFormatError &e) {
} catch (const InvalidFileFormatError &e) {
QMessageBox::critical(Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QString("<b>Could not initialize machine:</b> "
"the file `%1' has wrong format")
.arg(e.fileName.c_str()));
return;
}
catch (const EthError &e) {
} catch (const EthError &e) {
QMessageBox::critical(Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QString("<b>Could not initialize machine:</b> "
Expand Down Expand Up @@ -280,7 +267,6 @@ void DebugSession::initializeMachine() {
setStatus(MS_STOPPED);

cpuStatusMap.reset(new CpuStatusMap(this));

}

void DebugSession::onMachineConfigChanged() {
Expand Down Expand Up @@ -485,5 +471,4 @@ void DebugSession::relocateStoppoints(const SymbolTable *newTable,
}

set = rset;
}

}
2 changes: 0 additions & 2 deletions src/frontends/qriscv/monitor_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ void MonitorWindow::createMenu() {
debugMenu->addSeparator();
QMenu *gdbMenu = debugMenu->addMenu("GDB Server");
gdbMenu->addAction(enableGDBserver); //power one the server
//gdbMenu->addAction(addTraceAction); //open in terminal

QMenu *settingsMenu = menuBar()->addMenu("Se&ttings");
QMenu *speedLevelsSubMenu = settingsMenu->addMenu("Simulation Speed");
Expand Down Expand Up @@ -878,4 +877,3 @@ void StatusDisplay::refreshTod() {
.arg(bus->getToDHI(), 8, 16, QLatin1Char('0'))
.arg(bus->getToDLO(), 8, 16, QLatin1Char('0')));
}

30 changes: 6 additions & 24 deletions src/gdb/gdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pthread_cond_t continue_cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t stopped_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t bp_mutex = PTHREAD_MUTEX_INITIALIZER;


GDBServer::GDBServer(Machine *mac) {
this->stopped = false;
this->mac = mac;
Expand All @@ -61,7 +60,7 @@ bool *killed_ptr = NULL;

int GDBServer::killServer() {
pthread_mutex_lock(&stopped_mutex);
stopped = true; // stop the machine
stopped = true; // stop the machine
pthread_mutex_unlock(&stopped_mutex);

pthread_mutex_lock(&continue_mutex);
Expand Down Expand Up @@ -263,7 +262,6 @@ std::string GDBServer::ReadData(const std::string &msg) {
stopped = false;
pthread_mutex_unlock(&stopped_mutex);


pthread_mutex_lock(&continue_mutex);
pthread_cond_signal(&continue_cond);
pthread_mutex_unlock(&continue_mutex);
Expand All @@ -281,10 +279,7 @@ std::string GDBServer::ReadData(const std::string &msg) {
} else if (body.c_str()[0] == 's'){
stepIn();
return OKReply;
} /*else if(body.c_str()[0] == 'D'){
this->killServer();
return OKReply;
} */else if (strcmp(body.c_str(), vContMsg) == 0) {
} else if (strcmp(body.c_str(), vContMsg) == 0) {
/* Not supported */
return emptyReply;
}
Expand All @@ -294,18 +289,14 @@ std::string GDBServer::ReadData(const std::string &msg) {

void *MachineStep(void *vargp) {



while (!(*killed_ptr)) { // evita di fare un ciclo se la macchina sta per essere distrutta

while (true) {
pthread_mutex_lock(&continue_mutex);
pthread_cond_wait(&continue_cond, &continue_mutex);
pthread_mutex_unlock(&continue_mutex);

if (*killed_ptr) {
break; // Exit the loop if killed
}

bool s = false;
do {
gdb->Step();
Expand Down Expand Up @@ -333,7 +324,6 @@ void GDBServer::sendMsg(const int &socket, const std::string &msg) {
send(socket, reply.c_str(), (reply).size(), 0);
}


void GDBServer::stepIn(){
gdb->Step();

Expand All @@ -342,11 +332,9 @@ void GDBServer::stepIn(){
pthread_mutex_unlock(&stopped_mutex);
}


void GDBServer::StartServer() {
DEBUGMSG("[GDB] Starting GDB Server\n");


int server_fd, new_socket, valread;
struct sockaddr_in address;
int opt = 1;
Expand Down Expand Up @@ -380,8 +368,7 @@ void GDBServer::StartServer() {
exit(EXIT_FAILURE);
}


gdb = (GDBServer *)(this);
gdb = (GDBServer *)(this);

killed_ptr = &killed;

Expand Down Expand Up @@ -430,16 +417,11 @@ void GDBServer::StartServer() {

DEBUGMSG("[GDB] GDB Session terminated\n");

//pthread_cond_wait(&continue_cond, &continue_mutex);
pthread_kill(tid, SIGTERM); // it was SIGTERM
pthread_kill(tid, SIGTERM);


// clong the connected socket
close(new_socket);


// closing the listening socket
shutdown(server_fd, SHUT_RDWR);
printf("thread terminated\n");

}
}
4 changes: 1 addition & 3 deletions src/include/qriscv/debug_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class QAction;
class Machine;
class QTimer;


class DebugSession : public QObject {
Q_OBJECT

Expand Down Expand Up @@ -157,5 +156,4 @@ private Q_SLOTS:
void skip();
};

#endif // QRISCV_DEBUG_SESSION_H

#endif // QRISCV_DEBUG_SESSION_H
1 change: 0 additions & 1 deletion src/include/qriscv/monitor_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,3 @@ private Q_SLOTS:
};

#endif // QRISCV_MONITOR_WINDOW_H

0 comments on commit 58c51e5

Please sign in to comment.