当前位置:网站首页>QT environment generates dump to solve abnormal crash
QT environment generates dump to solve abnormal crash
2022-07-02 02:59:00 【Blank is nickname】
background
For regular use C/C++ For my partner , If there is a problem with the procedure, the problem of strike collapse is simply not familiar . For example, local tests are released through packaging release edition Qt Program , Abnormal crash may still occur in the customer environment . Generally, through customer feedback and analysis of system operation logs , Basically, all problems can be solved quickly . But there will always be some bug Hard to locate , In this case, by generating dump file , combination winDbg Program positioning will be a good solution .
Specific operation
One 、 Generate dump file
stay QtCreator Generation... Is not supported by default in dump file , And release release The mode does not contain debugging information , Therefore, the following two steps are required .
1. stay .pro Add the following statement to the file , To generate debugging information and pdb file
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
LIBS += -lDbgHelp
2. Adding in the program file can produce dump File code . Code can be copied directly , No more meaning
LONG crashHandler(EXCEPTION_POINTERS *pException)
{
QString curDataTime = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
QString dumpName = curDataTime + ".dmp";
HANDLE dumpFile = CreateFile((LPCWSTR)QString("./" + dumpName).utf16(),GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(dumpFile != INVALID_HANDLE_VALUE)
{
MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
dumpInfo.ExceptionPointers = pException;
dumpInfo.ThreadId = GetCurrentThreadId();
dumpInfo.ClientPointers = TRUE;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),dumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL);
CloseHandle(dumpFile);
}
else
{
qDebug() << "dumpFile not vaild";
}
return EXCEPTION_EXECUTE_HANDLER;
}
// prevent CRT(C runtime) Function error may not be caught
void DisableSetUnhandledExceptionFilter()
{
void* addr = (void*)GetProcAddress(LoadLibrary(L"kernel32.dll"), "SetUnhandledExceptionFilter");
if(addr)
{
unsigned char code[16];
int size = 0;
code[size++] = 0x33;
code[size++] = 0xC0;
code[size++] = 0xC2;
code[size++] = 0x04;
code[size++] = 0x00;
DWORD dwOldFlag, dwTempFlag;
VirtualProtect(addr, size, PAGE_READWRITE, &dwOldFlag);
WriteProcessMemory(GetCurrentProcess(), addr, code, size, NULL);
VirtualProtect(addr, size, dwOldFlag, &dwTempFlag);
}
}
int main(int argc, char *argv[])
{
// Register exception capture function
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)crashHandler);
DisableSetUnhandledExceptionFilter();
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
3. Clear and re qmake function , produce pdb Documents and running procedures . In this case, the application crash will occur at the predetermined location dump file .
Two 、 Use dump file
1. Suppose the program crashes and gets dump file , open winDbg Software ( You need to download , Easy to install ), Set the source code paths respectively 、pdb File path 、dump route , After confirmation, the software jumps to the analysis interface .
2. Click auto analysis (!anasyle -v), Generate stack information , Then you can see the number of error source code lines 
matters needing attention
The above provides an idea to solve the abnormal crash , Not the ultimate solution , Although there is no guarantee 100% solve the problem , But it may have miraculous effects , Personal suggestions are still based on logical analysis , Problems can be basically solved , It can also exercise the ability of analysis , Avoid writing similar bug.
Here are some points to note :
1. It should be packed exe,pdb, The source code version is consistent , Otherwise, there may be deviation in debugging .
2.dump Documents are not guaranteed to produce , Some errors may not be caught .
3.!anasyle -v After automatic analysis , Most of the time, you can directly locate the number of error lines , intuitive . But there are also cases where the number of rows cannot be found , But having clear stack information can help analyze the problem .
边栏推荐
- Which brand of sports headset is better? Bluetooth headset suitable for sports
- Learning notes of software testing -- theoretical knowledge of software testing
- C # use system data. The split mixed mode assembly is generated for the "v2.0.50727" version of the runtime, and it cannot be loaded in the 4.0 runtime without configuring other information
- Systemserver service and servicemanager service analysis
- Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field
- [JVM] detailed description of the process of creating objects
- Deployment practice and problem solving of dash application development environment based on jupyter Lab
- Which kind of sports headphones is easier to use? The most recommended sports headphones
- 自定义组件的 v-model
- V-model of custom component
猜你喜欢

图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
![[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)](/img/21/7bbf276b01f5a1056a22f5afc0af26.jpg)
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)

Actual battle of financial risk control - under Feature Engineering

Jvm-01 (phased learning)

Which brand of running headphones is good? How many professional running headphones are recommended

What is the principle of bone conduction earphones and who is suitable for bone conduction earphones

Mongodb base de données non relationnelle

Connected block template and variants (4 questions in total)

多线程查询,效率翻倍
![[JS reverse series] analysis of a customs publicity platform](/img/15/fdff7047e789d4e7c3c273a2f714f3.jpg)
[JS reverse series] analysis of a customs publicity platform
随机推荐
Redis cluster
Systemserver service and servicemanager service analysis
What is the difference between an intermediate human resource manager and an intermediate economist (human resources direction)?
Stack - es - official documents - filter search results
【无标题】
高并发场景下缓存处理方案
Baohong industry | 6 financial management models at different stages of life
连通块模板及变式(共4题)
Redis set command line operation (intersection, union and difference, random reading, etc.)
What are the characteristics of common web proxy IP
Formatting logic of SAP ui5 currency amount display
寻找重复数[抽象二分/快慢指针/二进制枚举]
CoordinatorLayout + TabLayout + ViewPager2(里面再嵌套一个RecyclerView),RecyclerView的滑动冲突解决
Qualcomm platform WiFi -- P2P issue (2)
2022 safety officer-c certificate examination questions and mock examination
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)
Xiaomi, a young engineer, was just going to make soy sauce
[Chongqing Guangdong education] Sichuan University concise university chemistry · material structure part introductory reference materials
2022-2028 global encryption software industry research and trend analysis report
2022-2028 global military computer industry research and trend analysis report