Commit 2d9ef257 authored by Héctor Mesa Jiménez's avatar Héctor Mesa Jiménez Committed by Christoph Cullmann
Browse files

gdbplugin: std::pair replaced for the sake of intelligiblity

parent 02136034
......@@ -398,7 +398,7 @@ const DAPTargetConf ConfigView::currentDAPTarget(bool full) const
cfg.variables[F_ARGS] = m_arguments->text();
// other
} else if (m_dapFields.contains(field)) {
cfg.variables[field] = m_dapFields[field].second->text();
cfg.variables[field] = m_dapFields[field].input->text();
}
}
return cfg;
......@@ -549,8 +549,8 @@ void ConfigView::resizeEvent(QResizeEvent *)
// additional dap fields
for (auto it = m_dapFields.cbegin(); it != m_dapFields.cend(); ++it) {
const bool visible = debuggerVariables.contains(it.key());
it->first->setVisible(visible);
it->second->setVisible(visible);
it->label->setVisible(visible);
it->input->setVisible(visible);
}
if (toVertical) {
......@@ -604,8 +604,8 @@ void ConfigView::resizeEvent(QResizeEvent *)
const auto &field = getDapField(fieldName);
layout->addWidget(field.first, ++row, 0, Qt::AlignLeft);
layout->addWidget(field.second, ++row, 0, 1, 4);
layout->addWidget(field.label, ++row, 0, Qt::AlignLeft);
layout->addWidget(field.input, ++row, 0, 1, 4);
}
layout->addWidget(m_takeFocus, ++row, 0, 1, 4);
......@@ -675,8 +675,8 @@ void ConfigView::resizeEvent(QResizeEvent *)
const auto &field = getDapField(fieldName);
layout->addWidget(field.first, ++row, 5, Qt::AlignRight);
layout->addWidget(field.second, row, 6);
layout->addWidget(field.label, ++row, 5, Qt::AlignRight);
layout->addWidget(field.input, row, 6);
}
layout->addLayout(m_checBoxLayout, ++row, 5, 1, 3);
......@@ -692,10 +692,10 @@ void ConfigView::resizeEvent(QResizeEvent *)
}
}
std::pair<QLabel *, QLineEdit *> &ConfigView::getDapField(const QString &fieldName)
ConfigView::Field &ConfigView::getDapField(const QString &fieldName)
{
if (!m_dapFields.contains(fieldName)) {
m_dapFields[fieldName] = std::make_pair(new QLabel(fieldName, this), new QLineEdit(this));
m_dapFields[fieldName] = Field{new QLabel(fieldName, this), new QLineEdit(this)};
}
return m_dapFields[fieldName];
}
......@@ -853,7 +853,7 @@ int ConfigView::loadFromIndex(int index)
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
const auto &field = getDapField(it.key());
field.second->setText(it.value().toString());
field.input->setText(it.value().toString());
}
return m_dapAdapterSettings[debuggerKey][debuggerProfile].index;
......
......@@ -103,7 +103,11 @@ private:
void saveCurrentToIndex(int index);
int loadFromIndex(int index);
void setAdvancedOptions();
std::pair<QLabel *, QLineEdit *> &getDapField(const QString &fieldName);
struct Field {
QLabel *label;
QLineEdit *input;
};
Field &getDapField(const QString &fieldName);
void refreshUI();
void readDAPSettings();
......@@ -140,7 +144,7 @@ private:
QLabel *m_processIdLabel;
KSelectAction *m_targetSelectAction = nullptr;
QHash<QString, std::pair<QLabel *, QLineEdit *>> m_dapFields;
QHash<QString, Field> m_dapFields;
QHash<QString, QHash<QString, DAPAdapterSettings>> m_dapAdapterSettings;
AdvancedGDBSettings *m_advanced;
......
......@@ -738,18 +738,17 @@ void Client::read()
while (true) {
// read headers
const auto segment = readHeader();
if (!segment) {
const auto info = readHeader();
if (!info) {
// incomplete header -> abort
break; // PENDING
}
// read payload
const auto &[start, length] = segment.value();
const auto data = m_buffer.mid(start, length);
if (data.size() < length) {
const auto data = m_buffer.mid(info->payloadStart, info->payloadLength);
if (data.size() < info->payloadLength) {
break; // PENDING
}
m_buffer.remove(0, start + length);
m_buffer.remove(0, info->payloadStart + info->payloadLength);
// parse payload
QJsonParseError jsonError;
......@@ -766,7 +765,7 @@ void Client::read()
}
}
std::optional<std::pair<int, int>> Client::readHeader()
std::optional<Client::HeaderInfo> Client::readHeader()
{
int length = -1;
int start = 0;
......@@ -827,7 +826,7 @@ std::optional<std::pair<int, int>> Client::readHeader()
return std::nullopt;
}
return std::make_pair(end, length);
return HeaderInfo{end, length};
}
void Client::start()
......
......@@ -125,12 +125,17 @@ private:
void setState(const State &state);
void bind();
void read();
struct HeaderInfo {
int payloadStart;
int payloadLength;
};
/**
* @brief readHeader
* @param headerEnd position of the header's end
* @return content length or -1
* @return info extracted from header or nullopt if incomplete
*/
std::optional<std::pair<int, int>> readHeader();
std::optional<HeaderInfo> readHeader();
void processProtocolMessage(const QJsonObject &msg);
......
......@@ -655,7 +655,7 @@ void DapDebugView::onSourceBreakpoints(const QString &path, int reference, const
}
// if runToCursor is pending, a bpoint with hit condition has been added
const bool withRunToCursor = m_runToCursor && (m_runToCursor->second == path);
const bool withRunToCursor = m_runToCursor && (m_runToCursor->path == path);
bool mustContinue = false;
const auto &wanted = m_wantedBreakpoints[path];
......@@ -673,7 +673,7 @@ void DapDebugView::onSourceBreakpoints(const QString &path, int reference, const
informBreakpointAdded(id, point);
}
if (withRunToCursor) {
if (wanted[pointIdx].line == m_runToCursor->first) {
if (wanted[pointIdx].line == m_runToCursor->line) {
mustContinue = point.line.has_value();
m_runToCursor = std::nullopt;
}
......@@ -891,7 +891,7 @@ void DapDebugView::runToCursor(QUrl const &url, int line)
m_breakpoints[path] << std::nullopt;
}
m_runToCursor = std::make_pair(line, path);
m_runToCursor = Cursor{line, path};
pushRequest();
m_client->requestSetBreakpoints(path, m_wantedBreakpoints[path], true);
}
......
......@@ -159,7 +159,11 @@ private:
void shutdownUntil(std::optional<State> state = std::nullopt);
bool continueShutdown() const;
std::optional<std::pair<int, QString>> m_runToCursor;
struct Cursor {
int line;
QString path;
};
std::optional<Cursor> m_runToCursor;
int m_requests;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment