查找损坏的共享库错误的原因(Qt5 C ++) [英] Finding cause of corrupted shared library error (Qt5 C++)

查看:428
本文介绍了查找损坏的共享库错误的原因(Qt5 C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段相当简单的代码可以启动QProcess:

I have a fairly simple piece of code which launches a QProcess:

launchResultCode = ELaunchOk;
QDateTime beginTimeStamp = QDateTime::currentDateTime();
command->start(commandpath, myParameters);
if (command->waitForStarted(waitToStart)) {
    if (!myStdIn.isEmpty()) command->write(myStdIn.toLatin1());
    command->closeWriteChannel();
    qDebug() << "P1";
    if (command->waitForFinished(waitToFinish)) {
        myStdOut = command->readAllStandardOutput();
        myStdErr = command->readAllStandardError();
    } else {
        launchResultCode = ELaunchFinishFailed;
    }
} else {
    launchResultCode = ELaunchStartFailed;
}
qDebug() << "postcorrupt";

这会导致损坏的共享库错误.当我运行此代码时,我从下面的gdb获取输出.我正在尝试找出错误中提到的任一内存位置,但是那里没有变量!有人可以帮我了解这里出了什么问题吗?

And it is causing a corrupted shared library error. When I run this code I get the output from gdb below. I'm trying to figure out what is at either memory location mentioned in the error, but there are no variables there! Can someone help me understand what is going wrong here?

(gdb) c
Continuing.
precorrupt
Detaching after fork from child process 21667.
P1
warning: Corrupted shared library list: 0x7fffe8008970 != 0x7ffff691b000
postcorrupt
[New Thread 0x7fffed453700 (LWP 21668)]

Breakpoint 1, RunProcessWorker::run (this=0x7fffffffcc30, whichMutex=RunProcessWorker::EMutexIP, activityID=..., commandFriendlyName=..., commandpath=..., 
    enableDebug=true, showDebugCommandLine=true, debugFilenameTemplate=..., myEnvironment=..., myParameters=..., myStdIn=..., myStdOut=..., myStdErr=..., 
    waitToStart=5000, waitToFinish=5000, actualRunTime=@0x7fffffffca58: 85, launchResultCode=@0x7fffffffca54: RunProcessWorker::ELaunchOk, 
    qprocessErrorCode=@0x7fffffffca50: QProcess::UnknownError, qprocessesExitCode=@0x7fffffffca6c: 0)
    at ../../src/external-sharedfiles/systemcommands/runprocessworker.cpp:292
292         command->deleteLater();
(gdb) info symbol 0x7fffe8008970
No symbol matches 0x7fffe8008970.
(gdb) info symbol 0x7ffff691b000
No symbol matches 0x7ffff691b000.
(gdb) 

请注意,该错误有时会在我的P1输出之前发生,所以这是该区域中的某物,但我不知道是什么!分叉的过程是一个Qt库,所以我看不到该库(并且可能无法理解)...这是否意味着它是Qt库中的错误?

Note that the error sometimes occurs before my P1 output, so it's something in that area but I can't figure out what! The process forked is a Qt library so I can't see into that library (and probably couldn't understand it)...does this mean it's a bug in Qt library?

可能相关,但是valgrind显示QProcess启动函数上的内存丢失:

Perhaps related, but valgrind shows memory lost on the QProcess start function:

30 (24 direct, 6 indirect) bytes in 1 blocks are definitely lost in loss record 837 of 2,936
  in RunProcessWorker::run(RunProcessWorker::EMutex, QString, QString, QString, bool, bool, QString, QStringList, QStringList, QString, QString&amp;, QString&amp;, unsigned int, unsigned int, unsigned long long&amp;, RunProcessWorker::ELaunchResultCodes&amp;, QProcess::ProcessError&amp;, int&amp;) in /mnt/lserver2/data/development/sharedfiles/systemcommands/runprocessworker.cpp:241
  1: operator new[](unsigned long) in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
  2: /opt/Qt/5.3/gcc_64/lib/libQt5Core.so.5.3.1
  3: /opt/Qt/5.3/gcc_64/lib/libQt5Core.so.5.3.1
  4: QProcess::start(QString const&amp;, QStringList const&amp;, QFlags&lt;QIODevice::OpenModeFlag&gt;) in /opt/Qt/5.3/gcc_64/lib/libQt5Core.so.5.3.1

推荐答案

请注意,您的错误消息不是说损坏的共享库",而是损坏的共享库列表".也就是说,进程内存空间中共享库的列表是损坏的,而不是共享库本身.因此,我的怀疑不是您的共享库已损坏,而是某些东西正在覆盖程序的内存空间中的内存并导致损坏而恰好破坏了该列表.

Note that your error message doesn't say "corrupted shared library" but rather "corrupted shared library list". That is, the list of shared libraries in your process's memory space is what is corrupted, rather than the shared libraries themselves. So my suspicion is not that you have a corrupted shared library, but rather that something is overwriting memory in your program's memory space and causing corruption that happens to damage that list.

有趣的是,您的调试器将其指定为崩溃的站点:

Also it's interesting that your debugger specifies this as the site of the crash:

292         command->deleteLater();

如您所知,deleteLater()是一种Qt方法,用于导致稍后删除QObject(即,在Qt事件循环的下一次迭代中).程序在此处崩溃的最可能原因是,调用该方法的(命令)指针无效(NULL或悬空).在这种情况下,(命令)与您在发布的示例代码中调用的QProcess对象是否相同?如果是这样,是否有可能已经在某个地方删除了QProcess对象,而使上面崩溃的代码悬空了呢? (如果不确定,可以对QProcess进行子类化,然后在子类的析构函数中放入qDebug()语句,以便可以在stdout/stderr输出中看到销毁QProcess对象的位置和时间……以及是否debug-print在崩溃之前发生,那么这是崩溃发生原因的一个很好的线索.

As you may know, deleteLater() is a Qt method for causing a QObject to be deleted later (i.e. on the next iteration of the Qt event loop). The most likely reason why the program would crash here is that the (command) pointer that the method is being called on is invalid (either NULL or dangling). Is (command) in this case the same QProcess object as the one you are calling in your posted example code? If so, is it possible that you already deleted that QProcess object somewhere, leaving the crashing code above with a dangling pointer? (If you're not sure, you could subclass QProcess and put a qDebug() statement in your subclass's destructor, so that you could see in your stdout/stderr output just where and when the QProcess object was destroyed... and if that debug-print happens before the crash, then that's a good clue as to why the crash occurred).

另一个可能的问题是,如果您正在运行以上代码独立",而没有QApplication(或QThread)对象在同一线程中执行exec().由于deleteLater()将消息发布到Qt事件循环,因此,如果没有Qt事件循环并在同一线程中执行,它将无法正常工作.

Another possible problem would be if you are running the above code "stand-alone", without a QApplication (or QThread) object executing exec() in the same thread. Since deleteLater() posts a message to the Qt event loop, it won't work properly if there isn't a Qt event loop present and executing in the same thread.

这篇关于查找损坏的共享库错误的原因(Qt5 C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆