Production Debugging & Incident Response Playbook · บทเรียน

การแก้ไขข้อบกพร่องย้อนหลังด้วยดัมป์แกนหน่วยความจำ

เรียนรู้การวิเคราะห์ดัมป์แกนหน่วยความจำและรายงานการล่ม เพื่อแก้ไขปัญหาที่เกิดขึ้นในอดีตโดยไม่ต้องเข้าถึงระบบที่กำลังทำงาน

บทเรียน 2 จาก 411 ขั้นตอน

การแก้ไขข้อบกพร่องย้อนหลังด้วยดัมป์แกนหน่วยความจำ เป็นบทเรียน Production Debugging & Incident Response Playbook ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Production Debugging & Incident Response Playbook และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Production Debugging & Incident Response Playbook มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Debugging After the Fact

Welcome! In this lesson, we'll explore post-mortem debugging. This powerful technique lets you investigate software failures after they've occurred, without needing to reproduce the issue live.

It's incredibly useful when you can't attach a debugger directly to a crashing application, especially in production environments.

What's a Core Dump?

The cornerstone of post-mortem debugging is the core dump. Think of it as a snapshot of a program's entire memory space and CPU state at the exact moment it crashed.

  • It's a file generated by the operating system.
  • It contains critical information about the program's execution.
  • It helps you understand why a crash happened.

When Do Core Dumps Happen?

Core dumps are typically generated when a program encounters a severe, unhandled error that causes it to terminate unexpectedly. Common scenarios include:

  • Segmentation Faults (Segfaults): Accessing invalid memory.
  • Unhandled Exceptions: Language-specific errors not caught by the program.
  • Assertion Failures: When a program's internal assumptions are violated.
  • Program Crashes: Any abrupt, abnormal termination.

Enabling Core Dumps (Linux)

On Linux systems, core dump generation might be disabled by default or limited in size. You can enable it:

  • Temporarily: Use ulimit -c unlimited in your shell session.
  • System-wide: Modify /etc/sysctl.conf (e.g., kernel.core_pattern to specify output path and filename format).

Without proper configuration, your system might not save core dumps when crashes occur.

Core Dump Contents

A core dump is packed with forensic data. It typically includes:

  • Memory Image: A copy of the program's entire virtual memory.
  • CPU Register Values: The state of the CPU registers at the crash time.
  • Stack Trace: The sequence of function calls leading up to the crash.
  • Process Information: Process ID, signal that caused the crash, executable path.
  • Loaded Libraries: Information about shared libraries linked to the program.

Key Analysis Tools

To make sense of a core dump, you need specialized tools. Some popular ones include:

  • GDB (GNU Debugger): Widely used for C/C++ programs on Linux/Unix.
  • WinDbg: Microsoft's powerful debugger for Windows applications.
  • jstack/jmap: For Java applications, these tools can extract thread dumps and memory maps that act as a form of 'core dump'.
  • Delve: A debugger for Go programs.

We'll focus on GDB as a common example.

Crash Program Demo

Let's look at a simple C program that will intentionally cause a segmentation fault. This will generate a core dump file if your system is configured to do so.

Try compiling and running this code:

#include <stdio.h>
#include <stdlib.h>

int main() {
  int *ptr = NULL; // Declare a null pointer
  printf("Attempting to dereference a null pointer...\n");
  *ptr = 10;       // This line will cause a segmentation fault
  printf("This line will not be reached.\n");
  return 0;
}

Basic GDB Usage: Backtrace

After the program crashes and creates a core dump (e.g., core or core.PID), you can load it into GDB. Assuming your executable is a.out:

gdb ./a.out core
bt

The bt (backtrace) command is essential. It shows the call stack leading to the crash, helping you pinpoint the exact function and line number where the error occurred.

Inspecting Variables with GDB

Once you have the backtrace, you can navigate the stack frames (e.g., using frame N where N is the frame number). Then, you can inspect variable values at that point in time:

  • print variable_name: Shows the value of a specific variable.
  • info locals: Lists all local variables in the current stack frame and their values.

This helps you understand the state of the program's data when it crashed.

Core Dump Quiz

Let's check your understanding of core dumps.

Recap: Post-mortem Power

Great work! You've learned about the power of post-mortem debugging using core dumps.

  • Core dumps are memory snapshots of crashed programs.
  • They contain vital info like stack traces and variable states.
  • Tools like GDB help analyze them without live access.

This technique is indispensable for debugging hard-to-reproduce or production-only issues, enabling you to fix problems even after the event.

เริ่มต้นได้ฟรี

เรียนรู้ Production Debugging & Incident Response Playbook ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การแก้ไขข้อบกพร่องย้อนหลังด้วยดัมป์แกนหน่วยความจำ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การแก้ไขข้อบกพร่องย้อนหลังด้วยดัมป์แกนหน่วยความจำ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Production Debugging & Incident Response Playbook ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Production Debugging & Incident Response Playbook มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การแก้ไขข้อบกพร่องย้อนหลังด้วยดัมป์แกนหน่วยความจำ”

เรียนรู้การวิเคราะห์ดัมป์แกนหน่วยความจำและรายงานการล่ม เพื่อแก้ไขปัญหาที่เกิดขึ้นในอดีตโดยไม่ต้องเข้าถึงระบบที่กำลังทำงาน คุณปฏิบัติ Production Debugging & Incident Response Playbook ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Production Debugging & Incident Response Playbook หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Production Debugging & Incident Response Playbook บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การแก้ไขข้อบกพร่องย้อนหลังด้วยดัมป์แกนหน่วยความจำ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Production Debugging & Incident Response Playbook นี้ได้ไหม

ได้ บทเรียน Production Debugging & Incident Response Playbook ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การแก้ไขข้อบกพร่องของแอปพลิเคชันที่กำลังทำงานจากระยะไกล
  2. การแก้ไขข้อบกพร่องย้อนหลังด้วยดัมป์แกนหน่วยความจำ
  3. เทคนิคการทำโปรไฟล์หน่วยความจำและ CPU
  4. การติดตามแบบกระจายเพื่อค้นหาจุดหน่วงเวลา
← กลับไปที่ Production Debugging & Incident Response Playbook