From 42aff804cbe1bf57cd99fab232094e4758a0cde2 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 5 Jul 2018 12:33:10 +0800 Subject: [PATCH] partially completed pass 2 --- ...get a core dump for a segfault on Linux.md | 45 ++++--------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/sources/tech/20180428 How to get a core dump for a segfault on Linux.md b/sources/tech/20180428 How to get a core dump for a segfault on Linux.md index 20f224b918..83460e4eda 100644 --- a/sources/tech/20180428 How to get a core dump for a segfault on Linux.md +++ b/sources/tech/20180428 How to get a core dump for a segfault on Linux.md @@ -1,17 +1,10 @@ -translating by stenphenxs 在 Linux 上如何得到一个段错误的核心转储 ============================================================ -This week at work I spent all week trying to debug a segfault. I’d never done this before, and some of the basic things involved (get a core dump! find the line number that segfaulted!) took me a long time to figure out. So here’s a blog post explaining how to do those things! - -本周工作中,我花了整整一周的时间来尝试调试一个段错误。我以前从来没有这样做过,我花了很长时间才弄清楚其中涉及的一些基本事情(获得核心转储,找到导致段错误的行号!)。于是便有了这篇博客来解释如何做那些事情! +本周工作中,我花了整整一周的时间来尝试调试一个段错误。我以前从来没有这样做过,我花了很长时间才弄清楚其中涉及的一些基本事情(获得核心转储、找到导致段错误的行号)。于是便有了这篇博客来解释如何做那些事情! -At the end of this blog post, you should know how to go from “oh no my program is segfaulting and I have no idea what is happening” to “well I know what its stack / line number was when it segfaulted at at least!“. - -在这篇博客的最后,你应该知道如何从“哦,我的程序出现段错误,但我不知道正在发生什么”到“我知道它出现段错误时的堆栈/行号了! “。 - -### what’s a segfault? +在看完这篇博客后,你应该知道如何从“哦,我的程序出现段错误,但我不知道正在发生什么”到“我知道它出现段错误时的堆栈、行号了! “。 ### 什么是段错误? @@ -19,36 +12,20 @@ A “segmentation fault” is when your program tries to access memory that it 一个“段错误”是指你的程序尝试访问不允许访问或尝试访问的内存地址的情况。这可能是由于:(第二个tries to存疑) -* trying to dereference a null pointer (you’re not allowed to access the memory address `0`) +* 试图解引用空指针(你不被允许访问内存地址 `0`); -* 试图解引用空指针(你不被允许访问内存地址 `0`) +* 试图解引用其他一些不在你内存(译者注:指不在合法的内存地址区间内)中的指针; -* trying to dereference some other pointer that isn’t in your memory +* 一个已被破坏并且指向错误的地方的 C++ 虚表指针,这导致程序尝试执行没有执行权限的内存地址; -* 试图解引用其他一些不在你内存(译者注:指合法的内存地址空间)中的指针 +* 其他一些我不明白的事情,比如我认为访问未对齐的内存地址也可能会导致段错误(译者注:在要求自然边界对齐的体系结构,如MIPS、ARM中更容易因非对齐访问产生段错误)。 -* a C++ vtable pointer that got corrupted and is pointing to the wrong place, which causes the program to try to execute some memory that isn’t executable - -* 一个被破坏并且指向错误的地方的 C++ 虚表指针,它导致程序尝试把一些没有执行权限的内存地址空间当成指令执行 - -* some other things that I don’t understand, like I think misaligned memory accesses can also segfault - -* 其他一些我不明白的事情,比如我认为访问未对齐的内存地址也可能会导致段错误 - -This “C++ vtable pointer” thing is what was happening to my segfaulting program. I might explain that in a future blog post because I didn’t know any C++ at the beginning of this week and this vtable lookup thing was a new way for a program to segfault that I didn’t know about. - -这个“C++ 虚表指针”是我的程序发生段错误的情况。我可能会在未来的博客中解释,因为我最初并不知道任何关于 C++的知识,并且这种虚表查找导致程序段错误的情况也是我所不了解的。 - -But! This blog post isn’t about C++ bugs. Let’s talk about the basics, like, how do we even get a core dump? +这个“C++ 虚表指针”是我的程序发生段错误的情况。我可能会在未来的博客中解释这个,因为我最初并不知道任何关于 C++ 的知识,并且这种虚表查找导致程序段错误的情况也是我所不了解的。 但是!这篇博客后不是关于 C++ 问题的。让我们谈论的基本的东西,比如,我们如何得到一个核心转储? -### step 1: run valgrind - ### 步骤1:运行 valgrind -I found the easiest way to figure out why my program is segfaulting was to use valgrind: I ran - 我发现找出为什么我的程序出现段错误的最简单的方式是使用valgrind:我运行 ``` @@ -56,16 +33,10 @@ valgrind -v your-program ``` -and this gave me a stack trace of what happened. Neat! - -这给了我一个(故障时的)堆栈调用序列。 简洁! - -But I wanted also wanted to do a more in-depth investigation and find out more than just what valgrind was telling me! So I wanted to get a core dump and explore it. +这给了我一个故障时的堆栈调用序列。 简洁! 但我想也希望做一个更深入调查,并找出些valgrind没告诉我的信息! 所以我想获得一个核心转储并探索它。 -### How to get a core dump - ### 如何获得一个核心转储 A core dump is a copy of your program’s memory, and it’s useful when you’re trying to debug what went wrong with your problematic program.