Learned more about gdb's dprintf. Made some changes.

This commit is contained in:
Ernie Pasveer
2024-12-20 10:17:07 -06:00
parent bba66da1e7
commit 24fa6d6a7e
17 changed files with 195 additions and 14 deletions
+13
View File
@@ -327,6 +327,7 @@ SeerGdbWidget::SeerGdbWidget (QWidget* parent) : QWidget(parent) {
QObject::connect(_printpointsBrowserWidget, &SeerPrintpointsBrowserWidget::insertPrintpoint, this, &SeerGdbWidget::handleGdbPrintpointInsert);
QObject::connect(_printpointsBrowserWidget, &SeerPrintpointsBrowserWidget::addBreakpointCondition, this, &SeerGdbWidget::handleGdbBreakpointCondition);
QObject::connect(_printpointsBrowserWidget, &SeerPrintpointsBrowserWidget::addBreakpointIgnore, this, &SeerGdbWidget::handleGdbBreakpointIgnore);
QObject::connect(_printpointsBrowserWidget, &SeerPrintpointsBrowserWidget::addBreakpointCommand, this, &SeerGdbWidget::handleGdbBreakpointCommand);
QObject::connect(this, &SeerGdbWidget::stoppingPointReached, stackManagerWidget->stackFramesBrowserWidget(), &SeerStackFramesBrowserWidget::handleStoppingPointReached);
QObject::connect(this, &SeerGdbWidget::stoppingPointReached, stackManagerWidget->stackLocalsBrowserWidget(), &SeerStackLocalsBrowserWidget::handleStoppingPointReached);
@@ -2035,6 +2036,18 @@ void SeerGdbWidget::handleGdbBreakpointIgnore (QString breakpoint, QString count
handleGdbGenericpointList();
}
void SeerGdbWidget::handleGdbBreakpointCommand (QString breakpoint, QString command) {
if (executableLaunchMode() == "") {
return;
}
qDebug().noquote() << "XXX: " << breakpoint << command;
handleGdbCommand("-break-commands " + breakpoint + " \"" + command + "\"");
handleGdbGenericpointList();
}
void SeerGdbWidget::handleGdbBreakpointCommands (QString breakpoint, QStringList commands) {
if (executableLaunchMode() == "") {
+1
View File
@@ -276,6 +276,7 @@ class SeerGdbWidget : public QWidget, protected Ui::SeerGdbWidgetForm {
void handleGdbBreakpointInsert (QString breakpoint);
void handleGdbBreakpointCondition (QString breakpoint, QString condition);
void handleGdbBreakpointIgnore (QString breakpoint, QString count);
void handleGdbBreakpointCommand (QString breakpoint, QString commands);
void handleGdbBreakpointCommands (QString breakpoint, QStringList commands);
void handleGdbBreakpointReload (QStringList breakpointsText);
void handleGdbWatchpointReload (QStringList watchpointsText);
+30
View File
@@ -49,6 +49,7 @@ SeerPrintpointsBrowserWidget::SeerPrintpointsBrowserWidget (QWidget* parent) : Q
QObject::connect(disablePrintpointsToolButton, &QToolButton::clicked, this, &SeerPrintpointsBrowserWidget::handleDisableToolButton);
QObject::connect(conditionBreakpointToolButton, &QToolButton::clicked, this, &SeerPrintpointsBrowserWidget::handleConditionToolButton);
QObject::connect(ignoreBreakpointToolButton, &QToolButton::clicked, this, &SeerPrintpointsBrowserWidget::handleIgnoreToolButton);
QObject::connect(commandBreakpointToolButton, &QToolButton::clicked, this, &SeerPrintpointsBrowserWidget::handleCommandToolButton);
}
SeerPrintpointsBrowserWidget::~SeerPrintpointsBrowserWidget () {
@@ -378,6 +379,35 @@ void SeerPrintpointsBrowserWidget::handleIgnoreToolButton () {
emit addBreakpointIgnore(printpoint, QString::number(count));
}
void SeerPrintpointsBrowserWidget::handleCommandToolButton () {
// Get selected tree items. Only allow one.
QList<QTreeWidgetItem*> items = printpointsTreeWidget->selectedItems();
if (items.count() == 0) {
return;
}
if (items.count() > 1) {
QMessageBox::warning(this, "Seer", "Select only one printpoint when editing the command.", QMessageBox::Ok);
return;
}
// Get the ignore text.
bool ok;
QString command = QInputDialog::getText(this, "Seer", "Enter the command to execute for this printpoint.", QLineEdit::Normal, items.front()->text(9), &ok);
if (ok == false) {
return;
}
// Get the selected breakpoint number.
QString breakpoint = items.front()->text(0);
// Send the signal.
emit addBreakpointCommand(breakpoint, command);
}
void SeerPrintpointsBrowserWidget::showEvent (QShowEvent* event) {
QWidget::showEvent(event);
+2
View File
@@ -29,6 +29,7 @@ class SeerPrintpointsBrowserWidget : public QWidget, protected Ui::SeerPrintpoin
void handleDisableToolButton ();
void handleConditionToolButton ();
void handleIgnoreToolButton ();
void handleCommandToolButton ();
signals:
void refreshPrintpointsList ();
@@ -37,6 +38,7 @@ class SeerPrintpointsBrowserWidget : public QWidget, protected Ui::SeerPrintpoin
void disablePrintpoints (QString printpoints);
void addBreakpointCondition (QString printpoint, QString condition);
void addBreakpointIgnore (QString printpoint, QString count);
void addBreakpointCommand (QString breakpoint, QString command);
void insertPrintpoint (QString printpoint);
void selectedFile (QString file, QString fullname, int lineno);
+18 -4
View File
@@ -13,8 +13,8 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="printpointsTreeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -102,8 +102,8 @@
</column>
</widget>
</item>
<item row="0" column="1">
<layout class="QFormLayout" name="formLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QToolButton" name="addPrintpointToolButton">
<property name="toolTip">
@@ -180,6 +180,20 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QToolButton" name="commandBreakpointToolButton">
<property name="toolTip">
<string>Edit command to selected breakpoint.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resource.qrc">
<normaloff>:/seer/resources/RelaxLightIcons/go-next.svg</normaloff>:/seer/resources/RelaxLightIcons/go-next.svg</iconset>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QToolButton" name="deletePrintpointsToolButton">
<property name="toolTip">
+3
View File
@@ -1,2 +1,5 @@
hellodprintf
hellodprintf_call_channel
hellodprintf_call_nochannel
hellodprintf_call_fortran
*.o
+24 -6
View File
@@ -1,16 +1,34 @@
.PHONY: all
all: hellodprintf
all: hellodprintf hellodprintf_call_channel hellodprintf_call_nochannel hellodprintf_fortran
hellodprintf.o: hellodprintf.cpp
g++ -c -g hellodprintf.cpp
hellodprintf_fortran.o: hellodprintf_fortran.f
gfortran -c -g hellodprintf_fortran.f
hellodprintf_fortran.o: hellodprintf_fortran.cpp
g++ -c -g hellodprintf_fortran.cpp
hellodprintf: hellodprintf.o hellodprintf_fortran.o
g++ -g -o hellodprintf hellodprintf.o hellodprintf_fortran.o -lgfortran
hellodprintf_call_channel.o: hellodprintf_call_channel.cpp
g++ -c -g hellodprintf_call_channel.cpp
hellodprintf_call_nochannel.o: hellodprintf_call_nochannel.cpp
g++ -c -g hellodprintf_call_nochannel.cpp
fortran_function.o: fortran_function.f
gfortran -c -g fortran_function.f
hellodprintf: hellodprintf.o hellodprintf_fortran.o fortran_function.o
g++ -g -o hellodprintf hellodprintf.o fortran_function.o -lgfortran
hellodprintf_call_channel: hellodprintf_call_channel.o
g++ -g -o hellodprintf_call_channel hellodprintf_call_channel.o
hellodprintf_call_nochannel: hellodprintf_call_nochannel.o
g++ -g -o hellodprintf_call_nochannel hellodprintf_call_nochannel.o
hellodprintf_fortran: hellodprintf_fortran.o fortran_function.o
g++ -g -o hellodprintf_fortran hellodprintf_fortran.o fortran_function.o -lgfortran
.PHONY: clean
clean:
rm -f hellodprintf hellodprintf.o hellodprintf_fortran.o
rm -f hellodprintf hellodprintf_call_channel hellodprintf_call_nochannel hellodprintf_fortran *.o
-2
View File
@@ -1,2 +0,0 @@
dprintf -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf.cpp -line 44,"n=%d count=%d\n",n,count
break -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf.cpp -line 53
@@ -0,0 +1,3 @@
break -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_call_channel.cpp -line 9
break -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_call_channel.cpp -line 23
dprintf -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_call_channel.cpp -line 18,"C: n=%d count=%d\n",n,count
@@ -0,0 +1,3 @@
dprintf -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_call_nochannel.cpp -line 40,"C: n=%d count=%d\n",n,count
break -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_call_nochannel.cpp -line 27
break -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_call_nochannel.cpp -line 47
@@ -0,0 +1,3 @@
break -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_fortran.cpp -line 13
break -source /nas/erniep/Development/seer/tests/hellodprintf/hellodprintf_fortran.cpp -line 17
dprintf -source /nas/erniep/Development/seer/tests/hellodprintf/fortran_function.f -line 11,"FORT: n=%d count=%d\n",n,count
+2 -2
View File
@@ -7,7 +7,7 @@
FILE* logfile = NULL;
extern "C" {
int log_msgxxx (const char* format, ...) {
int log_msg (const char* format, ...) {
int n;
va_list args;
// init the variable length argument list
@@ -46,7 +46,7 @@ int main (int argc, char** argv) {
std::cout << std::setw(12) << n << std::setw(14) << nfact << std::endl;
}
// fortranfunction_(&count);
fortranfunction_(&count);
fclose(logfile);
@@ -0,0 +1,25 @@
#include <string>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdarg.h>
int main (int argc, char** argv) {
int count = 10;
int nfact = 1;
int n;
// Add the 'dprintf' function to the program's symbol
// table. So we can use it for gdb's 'dprintf' breakpoints.
dprintf(1, " C++ loop\n");
for (n=1; n<=count; n++) {
nfact = nfact * n;
// printing the value of n and its factorial
std::cout << std::setw(12) << n << std::setw(14) << nfact << std::endl;
}
return 0;
}
@@ -0,0 +1,49 @@
#include <string>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdarg.h>
FILE* logfile = NULL;
extern "C" {
int log_msg (const char* format, ...) {
int n;
va_list args;
// init the variable length argument list
va_start(args, format);
n = vfprintf(logfile, format, args);
// cleanup the variable length argument list
va_end(args);
return n;
}
}
int main (int argc, char** argv) {
const char* filename = "logfile.txt";
logfile = fopen(filename, "w");
if (logfile == NULL) {
fprintf(stderr, "Failed to open logfile: %s\n", filename);
return 1;
}
int count = 10;
int nfact = 1;
int n;
std::cout << " C++ loop" << std::endl;
for (n=1; n<=count; n++) {
nfact = nfact * n;
// printing the value of n and its factorial
std::cout << std::setw(12) << n << std::setw(14) << nfact << std::endl;
}
fclose(logfile);
return 0;
}
@@ -0,0 +1,19 @@
#include <string>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdarg.h>
extern "C" {
void fortranfunction_ (int* count);
}
int main (int argc, char** argv) {
int count = 10;
fortranfunction_(&count);
return 0;
}
View File