进程终止 C++

发布于 2024-08-16 19:26:35 字数 302 浏览 9 评论 0原文

我有以下问题:我有一个用 C++ 编写的应用程序(永远不会结束的服务器)作为服务运行,主线程内还包含 3 个线程(主要执行 IO)。

在主循环中,我捕获所有可能的异常。

进程终止,主循环或线程本身没有打印任何内容。我在事件日志中看到该进程以代码 1000 停止。Windows

  1. 是否像 unix 中那样创建 Core 文件?
  2. 如果我从事件日志中获得内存地址,有什么方法可以知道它发生在应用程序的哪个部分?
  3. 也许这是一个线索:在它发生的同时,我启动了另一个应用程序(不是同一类型)。

I have the following problem: I have an application (server that never ends) written in C++ running as a service containing inside the main thread also 3 threads (mainly doing IO).

In the main loop I CATCH all possible exceptions.

The process terminated and nothing was printed either by the main loop or by the threads themselves. I saw in the event log that the process stopped with code 1000.

  1. Does Windows creates Core files like in unix ?
  2. If from the event log I get a memory address, is there any way of knowing in which part in the application it occurred?
  3. Maybe this is a clue: at the same time that it happened I started another application (not the same type).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

咽泪装欢 2024-08-23 19:26:35

尝试将 Windbg 设置为事后调试器。

  1. 从命令行安装 windbg
  2. 执行“windbg -I”
  3. 启动您的应用程序,然后当您的应用程序遇到未处理的异常时,
    将激活windbg。
  4. 从windbg中使用“kb”或“!uniqstack”查看堆栈跟踪。

    在此处查找更多命令。
    并查看这里 了解如何分析。

并尝试使用SEH:

#include "windows.h"
#include "stdio.h"

DWORD FilterFunction() 
{ 
 printf("you will see this message first.\n");
 return EXCEPTION_EXECUTE_HANDLER; 
} 


int main(char** argv, int c)
{
 __try
 {
  int this_will_be_zero = (c == 9999);
  int blowup = 1 / this_will_be_zero;
 }
 __except ( FilterFunction()) 
 {
  printf("you will see this message\n");
 }

 return 0;
}

try to set windbg as the postmortem debugger.

  1. install windbg
  2. from commandline execute "windbg -I"
  3. start you application, then you when your application get an unhandled exception,
    the windbg will be activated .
  4. from windbg use "kb" or "!uniqstack" to see the stacktrace.

    look here for more commands.
    and look here for how to analysis.

and try use SEH:

#include "windows.h"
#include "stdio.h"

DWORD FilterFunction() 
{ 
 printf("you will see this message first.\n");
 return EXCEPTION_EXECUTE_HANDLER; 
} 


int main(char** argv, int c)
{
 __try
 {
  int this_will_be_zero = (c == 9999);
  int blowup = 1 / this_will_be_zero;
 }
 __except ( FilterFunction()) 
 {
  printf("you will see this message\n");
 }

 return 0;
}
祁梦 2024-08-23 19:26:35

请记住,catch(...) 不会拦截代码中可能出错的所有内容,除非您使用结构化异常处理。例如

#include "stdio.h"
int main(char** argv, int c)
{
  try {
    int this_will_be_zero = (c == 9999);
    int blowup = 1 / this_will_be_zero;
  } catch (...) {
    printf("you won't see this message\n");
  }
}

Bear in mind that catch(...) does not intercept everything that can go wrong in your code, unless you are using Structured Exception Handling. Eg

#include "stdio.h"
int main(char** argv, int c)
{
  try {
    int this_will_be_zero = (c == 9999);
    int blowup = 1 / this_will_be_zero;
  } catch (...) {
    printf("you won't see this message\n");
  }
}
独﹏钓一江月 2024-08-23 19:26:35

在构建应用程序时,您需要使用 /EHa 编译器开关,以便使用 C++ try/catch 结构捕获 Windows 结构化异常(例如访问冲突)。

在 Visual Studio 中,这是在项目属性“配置属性”->“项目属性”中。 C/C++->代码生成->启用 C++ 异常。您想要“是,但有 SEH 例外 (/EHa)”。我记得读到的设置有一些明显的缺点,尽管我不记得它们到底是什么。

链接:MSDN on C++ 异常处理模型

编辑:As whunmr 建议,直接使用结构化异常可能比 /EHa 更好

You need to use the /EHa compiler switch when building your application in order to catch windows structured exceptions (such as access violation) with the C++ try/catch constructs.

In Visual Studio this is in project properties Configuration Properties -> C/C++ -> Code Generation -> Enable C++ Exceptions. You want "Yes With SEH Exceptions (/EHa)". I remember reading setting this has some significant drawbacks, although I cannot recall what they were exactly.

Link: MSDN on C++ exception handling model

Edit: As whunmr suggests, directly using structured exceptions is probably better idea than /EHa

少跟Wǒ拽 2024-08-23 19:26:35

Windows 是否像 unix 一样创建 Core 文件?

它不会自动地。但是您可以通过以下方式启用此类文件
在您的代码中实现它或使用外部应用程序
作为 Windbg,或 Dr.沃森

如果我从事件日志中获得内存地址,有什么方法可以知道它发生在应用程序的哪个部分?

一般来说,如果你不保留调试信息文件(pdb),就没有办法

也许这是一个线索:在这件事发生的同时,我启动了另一个应用程序(不是同一类型)。

这不是有用的信息,除非两个应用程序彼此交互

Does Windows creates Core files like in unix ?

it does not, automatically. however you can enable such a files by
either implementing it in your code or by using external application
as windbg, or Dr. Watson

If from the event log I get a memory address, is there any way of knowing in which part in the application it occurred?

There is no way if in general, if you don't keep debug information files (pdb)

Maybe this is a clue: at the same time that it happened I started another application (not the same type).

this is not helpful information, unless both of the applications are interacted each other

猫七 2024-08-23 19:26:35

Windows 将根据以下设置将您使用的任何程序用作调试器:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="0"
"Debugger"="My_Debugger" -p %ld -e %ld"
"UserDebuggerHotKey"=dword:00000000

您可以将 My_Debugger 更改为您用于调试的任何程序/IDE 的完整路径。

这通常设置为 Dr Watson,它将创建崩溃的日志条目,这不是您想要的。

Windows will whatever program you are using as a debugger depending on the setting in:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="0"
"Debugger"="My_Debugger" -p %ld -e %ld"
"UserDebuggerHotKey"=dword:00000000

You can change My_Debugger to the full path of whatever program/IDE you are using for debugging.

This is often set to Dr Watson which will create a log entry of the crash which is not what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文