简体   繁体   English

如何知道Linux中的程序崩溃的地址?

[英]How to know what address a program in Linux crashes at?

I have a program running in Linux and It's been mysteriously crashing. 我有一个在Linux上运行的程序,它崩溃了。 I already know one way to know where it crashes at is to use GDB. 我已经知道了解崩溃的一种方法是使用GDB。 But I don't want to attach to it every time I restart it (do this a lot since I'm testing it). 但是我不想每次重新启动时都附加到它上(因为我正在测试它,所以要做很多事情)。 Is there an alternative way to do this? 有替代方法吗?

First use ulimit -c unlimited to allow crashed programs to write core dumps. 首先使用ulimit -c unlimited允许崩溃的程序编写核心转储。

After the program crashes, you'll find a core dump file, called core , or perhaps core.<pid> if your program is multithreaded. 程序崩溃后,您将找到一个名为corecore.<pid>的核心转储文件(如果您的程序是多线程的)。

You can load this into GDB to examine the state at the point of the crash with gdb program core . 您可以使用gdb program core将其加载到GDB中,以检查崩溃时的状态。

First do a ulimit -c unlimited , so the program will leave a core dump. 首先执行ulimit -c unlimited ,这样程序将离开核心转储。 Then, when it crashes, invoke gdb with the core dump, to read the state of the program at the moment of the crash. 然后,当它崩溃时,请使用核心转储调用gdb以在崩溃时读取程序的状态。

You can configure your OS to dump a core file any time a program crashes. 您可以将操作系统配置为在程序崩溃时转储核心文件。 You can then examine the core to determine the crash location. 然后,您可以检查核心以确定崩溃位置。

-> compile the code with gdb flags enabled. ->在启用gdb标志的情况下编译代码。

gcc -o < binary name > -g < file.c > (assuming it is ac/c++ program) gcc -o <二进制名称> -g <file.c>(假设它是ac / c ++程序)

-> run the executable withing gdb. ->使用gdb运行可执行文件。 gdb < binary name > gdb <二进制名称>

after this there are ways to find the crash location: 1. stepwise execution. 之后,有几种方法可以找到崩溃位置:1.逐步执行。 2. run the code, it crashes (as expected), type "where" within gdb (without quotes) it gives the backtrace. 2.运行代码,它崩溃(按预期方式),在gdb中键入“ where”(不带引号),它给出回溯。 from that, you can find out the address. 由此,您可以找到地址。

here is a nice quick guide to gdb : http://www.cs.cmu.edu/~gilpin/tutorial/ 这是gdb的不错的快速指南: http : //www.cs.cmu.edu/~gilpin/tutorial/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何知道IP地址在Linux服务器上是否为本地 - How to Know an IP Address is Local or not on Linux Server 如何知道Linux中C / C ++中的被调用程序路径? - How to know the called program path in C/C++ in Linux? 在Linux环境程序中访问地址之前,如何检查地址的有效性? - How can I check the validity of an address before accessing the address in a Linux environment program?linux? 当显示“程序已停止工作”的显示器运行时,如何知道当程序崩溃时是否是内存错误 - How to know if it is a memory bug when a program crashes while running whith a display “the program has stopped working” Windows如何知道使用什么程序打开文件? - How does Windows know what program to open a file with? (linux)如何在c ++程序中知道是否支持Opengl 4? - (linux) How can I know inside a c++ program if Opengl 4 is supported? 如何知道方法中的对象地址? - How to know an object address in a method? 如果程序崩溃,如何释放资源 - How to release resources if a program crashes 将局部变量地址传递给C ++中的共享指针时程序崩溃 - Program crashes on passing local variable address to shared pointer in c++ 我的程序在Windows机器上崩溃,但在Linux上运行正常 - My program crashes on the Windows machine yet it works fine on the Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM