MCPcopy Create free account
hub / github.com/KDE/kdevelop / generateCoreFile

Function generateCoreFile

plugins/debuggercommon/tests/debuggertestbase.cpp:1476–1515  ·  view source on GitHub ↗

* @return the name of a core dump file * * @param reuseExisting whether to reuse an existing file at the location of a core file; * if @c false, the existing file (if any) is removed and a new core dump is generated * * Call RETURN_IF_TEST_RESOLVED() after this function. */

Source from the content-addressed store, hash-verified

1474 * Call RETURN_IF_TEST_RESOLVED() after this function.
1475 */
1476[[nodiscard]] static QString generateCoreFile(bool reuseExisting)
1477{
1478 QFileInfo f("core");
1479 f.setCaching(false); // don't cache information
1480 if (f.exists()) {
1481 if (reuseExisting) {
1482 qDebug() << "reusing an existing core file";
1483 return f.canonicalFilePath();
1484 }
1485 qDebug() << "removing an existing core file to generate a new one";
1486 QVERIFY_RETURN(QFile::remove(f.canonicalFilePath()), QString{});
1487 }
1488
1489 KProcess debugeeProcess;
1490 debugeeProcess.setOutputChannelMode(KProcess::MergedChannels);
1491 debugeeProcess << "bash" << "-c"
1492 << "ulimit -c unlimited; " + findExecutable("debuggee_crash").toLocalFile();
1493 debugeeProcess.start();
1494 debugeeProcess.waitForFinished();
1495 qDebug() << "Debuggee output:\n" << debugeeProcess.readAll();
1496
1497 auto coreFileFound = f.exists();
1498 if (!coreFileFound) {
1499 qDebug() << "try to use coredumpctl";
1500 const auto coredumpctl = QStandardPaths::findExecutable("coredumpctl");
1501 if (!coredumpctl.isEmpty()) {
1502 KProcess::execute(coredumpctl, {"-1", "-o", f.absoluteFilePath(), "dump", "debuggee_crash"}, 5000);
1503 // coredumpctl seems to create an empty file "core" even if no cores can be delivered
1504 // (like when run inside docker containers as on KDE CI or with kernel.core_pattern=|/dev/null)
1505 // so also check for size != 0
1506 coreFileFound = f.exists() && (f.size() > 0);
1507 }
1508 }
1509 if (!coreFileFound) {
1510 QSKIP_RETURN("No core dump found, check your system configuration (see /proc/sys/kernel/core_pattern)",
1511 QString{});
1512 }
1513
1514 return f.canonicalFilePath();
1515}
1516
1517void DebuggerTestBase::testCoreFile_data()
1518{

Callers 1

testCoreFileMethod · 0.85

Calls 7

executeFunction · 0.85
existsMethod · 0.80
toLocalFileMethod · 0.80
findExecutableFunction · 0.70
startMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected