aboutsummaryrefslogtreecommitdiff
path: root/src/citra_qt/debugger/ipc/record_dialog.cpp
blob: d4668a33de9ddd78eb5b9fe3b29480ebec0391e3 (plain) (blame)
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
// Copyright 2019 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <fmt/format.h>
#include "citra_qt/debugger/ipc/record_dialog.h"
#include "common/assert.h"
#include "core/hle/kernel/ipc_debugger/recorder.h"
#include "ui_record_dialog.h"

QString RecordDialog::FormatObject(const IPCDebugger::ObjectInfo& object) const {
    if (object.id == -1) {
        return tr("null");
    }

    return QStringLiteral("%1 (0x%2)")
        .arg(QString::fromStdString(object.name))
        .arg(object.id, 8, 16, QLatin1Char('0'));
}

QString RecordDialog::FormatCmdbuf(std::span<const u32> cmdbuf) const {
    QString result;
    for (std::size_t i = 0; i < cmdbuf.size(); ++i) {
        result.append(
            QStringLiteral("[%1]: 0x%2\n").arg(i).arg(cmdbuf[i], 8, 16, QLatin1Char('0')));
    }
    return result;
}

RecordDialog::RecordDialog(QWidget* parent, const IPCDebugger::RequestRecord& record,
                           const QString& service, const QString& function)
    : QDialog(parent), ui(std::make_unique<Ui::RecordDialog>()) {

    ui->setupUi(this);

    ui->clientProcess->setText(FormatObject(record.client_process));
    ui->clientThread->setText(FormatObject(record.client_thread));
    ui->clientSession->setText(FormatObject(record.client_session));

    ui->serverProcess->setText(FormatObject(record.server_process));
    ui->serverThread->setText(FormatObject(record.server_thread));
    ui->serverSession->setText(FormatObject(record.server_session));

    ui->clientPort->setText(FormatObject(record.client_port));
    ui->service->setText(std::move(service));
    ui->function->setText(std::move(function));

    cmdbufs = {record.untranslated_request_cmdbuf, record.translated_request_cmdbuf,
               record.untranslated_reply_cmdbuf, record.translated_reply_cmdbuf};

    UpdateCmdbufDisplay();

    connect(ui->cmdbufSelection, qOverload<int>(&QComboBox::currentIndexChanged), this,
            &RecordDialog::UpdateCmdbufDisplay);
    connect(ui->okButton, &QPushButton::clicked, this, &QDialog::close);
}

RecordDialog::~RecordDialog() = default;

void RecordDialog::UpdateCmdbufDisplay() {
    int index = ui->cmdbufSelection->currentIndex();

    ASSERT_MSG(0 <= index && index <= 3, "Index out of bound");
    ui->cmdbuf->setPlainText(FormatCmdbuf(cmdbufs[index]));
}