Skip to content

Commit

Permalink
pcap: Add settings to Emu->Devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
liclac committed Aug 29, 2024
1 parent 40a0856 commit c3f171f
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/frontend/qt_sdl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ LegacyEntry LegacyFile[] =
{"GdbARM7BreakOnStartup", 1, "Gdb.ARM7.BreakOnStartup", true},
{"GdbARM9BreakOnStartup", 1, "Gdb.ARM9.BreakOnStartup", true},
#endif
{"PcapEnabled", 1, "Pcap.Enabled", false},
{"PcapPath", 2, "Pcap.Path", false},

{"Camera0_InputType", 0, "DSi.Camera0.InputType", false},
{"Camera0_ImagePath", 2, "DSi.Camera0.ImagePath", false},
Expand Down
11 changes: 7 additions & 4 deletions src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,13 +2056,16 @@ void EmuInstance::animatedROMIcon(const u8 (&data)[8][512], const u16 (&palette)

void EmuInstance::startPacketCapture()
{
if (!pcap)
pcap = melonDS::LibPCap::New();

if (packetCapture != nullptr || packetCaptureDumper != nullptr)
stopPacketCapture();

std::string pcapPath = getAssetPath(false, globalCfg.GetString("PacketCapturePath"), instanceFileSuffix() + ".pcap");
if (!globalCfg.GetBool("Pcap.Enabled"))
return;

if (!pcap)
pcap = melonDS::LibPCap::New();

std::string pcapPath = getAssetPath(false, globalCfg.GetString("Pcap.Path"), instanceFileSuffix() + ".pcap");
Log(LogLevel::Debug, "Starting packet capture: %s\n", pcapPath.c_str());

packetCapture = pcap->open_dead(DLT_IEEE802_11, 1024);
Expand Down
30 changes: 30 additions & 0 deletions src/frontend/qt_sdl/EmuSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <QFileDialog>
#include <QMessageBox>
#include <QTemporaryFile>

#include "types.h"
#include "Platform.h"
Expand Down Expand Up @@ -107,9 +108,12 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new
ui->cbGdbBOSA7->setDisabled(true);
ui->cbGdbBOSA9->setDisabled(true);
#endif
ui->cbPcapEnabled->setChecked(cfg.GetBool("Pcap.Enabled"));
ui->txtPcapPath->setText(cfg.GetQString("Pcap.Path"));

on_chkEnableJIT_toggled();
on_cbGdbEnabled_toggled();
on_cbPcapEnabled_toggled();
on_chkExternalBIOS_toggled();

const int imgsizes[] = {256, 512, 1024, 2048, 4096, 0};
Expand Down Expand Up @@ -292,6 +296,8 @@ void EmuSettingsDialog::done(int r)
instcfg.SetBool("Gdb.ARM7.BreakOnStartup", ui->cbGdbBOSA7->isChecked());
instcfg.SetBool("Gdb.ARM9.BreakOnStartup", ui->cbGdbBOSA9->isChecked());
#endif
cfg.SetBool("Pcap.Enabled", ui->cbPcapEnabled->isChecked());
cfg.SetQString("Pcap.Path", ui->txtPcapPath->text());

cfg.SetInt("Emu.ConsoleType", ui->cbxConsoleType->currentIndex());
cfg.SetBool("Emu.DirectBoot", ui->chkDirectBoot->isChecked());
Expand Down Expand Up @@ -565,6 +571,30 @@ void EmuSettingsDialog::on_cbGdbEnabled_toggled()
ui->cbGdbBOSA9->setDisabled(disabled);
}

void EmuSettingsDialog::on_cbPcapEnabled_toggled()
{
bool disabled = !ui->cbPcapEnabled->isChecked();
ui->txtPcapPath->setDisabled(disabled);
ui->btnPcapBrowse->setDisabled(disabled);
}

void EmuSettingsDialog::on_btnPcapBrowse_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this,
"Select packet captures path...",
lastBIOSFolder);

if (dir.isEmpty()) return;

if (!QTemporaryFile(dir).open())
{
QMessageBox::critical(this, "melonDS", "Unable to write to packet captures directory.\nPlease check file/folder write permissions.");
return;
}

ui->txtPcapPath->setText(dir);
}

void EmuSettingsDialog::on_chkExternalBIOS_toggled()
{
bool disabled = !ui->chkExternalBIOS->isChecked();
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/qt_sdl/EmuSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ private slots:
void on_chkExternalBIOS_toggled();

void on_cbGdbEnabled_toggled();
void on_cbPcapEnabled_toggled();
void on_btnPcapBrowse_clicked();

private:
void verifyFirmware();
Expand Down
110 changes: 74 additions & 36 deletions src/frontend/qt_sdl/EmuSettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>575</width>
<height>416</height>
<height>456</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -21,7 +21,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
<enum>QLayout::SizeConstraint::SetFixedSize</enum>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
Expand Down Expand Up @@ -59,7 +59,7 @@
<item row="3" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -99,7 +99,7 @@
<item row="4" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -457,7 +457,7 @@
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -539,7 +539,7 @@
<item row="5" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -573,17 +573,38 @@
<string>Devtools</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="label_16">
<item row="2" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>ARM9 port</string>
<string>ARM7 port</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="2" column="5">
<widget class="QCheckBox" name="cbGdbBOSA7">
<property name="text">
<string>Break on startup</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="6">
<widget class="QLabel" name="label_23">
<property name="text">
<string>Packet captures are stored in .pcap format, by default in the same directory as the ROM.</string>
</property>
</widget>
</item>
<item row="7" column="5">
<widget class="QPushButton" name="btnPcapBrowse">
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
<item row="11" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -593,10 +614,10 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_17">
<item row="1" column="5">
<widget class="QCheckBox" name="cbGdbBOSA9">
<property name="text">
<string>ARM7 port</string>
<string>Break on startup</string>
</property>
</widget>
</item>
Expand All @@ -607,28 +628,14 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="7">
<item row="4" column="0" colspan="6">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Note: melonDS must be restarted in order for these changes to have effect</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="7">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Note: GDB stub cannot be used together with the JIT recompiler</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QCheckBox" name="cbGdbBOSA9">
<property name="text">
<string>Break on startup</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="5">
<item row="1" column="1" colspan="4">
<widget class="QSpinBox" name="intGdbPortA9">
<property name="minimum">
<number>1000</number>
Expand All @@ -641,7 +648,21 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="5">
<item row="1" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>ARM9 port</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_22">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1" colspan="4">
<widget class="QSpinBox" name="intGdbPortA7">
<property name="minimum">
<number>1000</number>
Expand All @@ -654,10 +675,27 @@
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QCheckBox" name="cbGdbBOSA7">
<item row="3" column="0" colspan="6">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Break on startup</string>
<string>Note: GDB stub cannot be used together with the JIT recompiler</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="4">
<widget class="QPathInput" name="txtPcapPath"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Directory:</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="6">
<widget class="QCheckBox" name="cbPcapEnabled">
<property name="text">
<string>Enable network packet capture</string>
</property>
</widget>
</item>
Expand All @@ -668,10 +706,10 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
Expand Down

0 comments on commit c3f171f

Please sign in to comment.