Production Debugging & Incident Response Playbook · Lekcja

Debugowanie po fakcie za pomocą zrzutów pamięci

Naucz się analizować zrzuty pamięci i raporty awarii, aby debugować problemy, które wystąpiły wcześniej, bez dostępu do działającego systemu.

Lekcja 2 z 411 kroki

Debugowanie po fakcie za pomocą zrzutów pamięci to bezpłatna lekcja Production Debugging & Incident Response Playbook na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Production Debugging & Incident Response Playbook, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Production Debugging & Incident Response Playbook zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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.

Bezpłatny start

Ucz się Production Debugging & Incident Response Playbook dzięki korepetycjom AI — za darmo

Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.

Kursy
12
Lekcje
48

Często zadawane pytania

Czy lekcja „Debugowanie po fakcie za pomocą zrzutów pamięci” jest bezpłatna?

Tak — pełny tekst „Debugowanie po fakcie za pomocą zrzutów pamięci” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Production Debugging & Incident Response Playbook, przejdź na CoddyKit PRO. Kurs Production Debugging & Incident Response Playbook zawiera 4 lekcji w sumie.

Co nauczysz się w „Debugowanie po fakcie za pomocą zrzutów pamięci”?

Naucz się analizować zrzuty pamięci i raporty awarii, aby debugować problemy, które wystąpiły wcześniej, bez dostępu do działającego systemu. Ćwiczysz Production Debugging & Incident Response Playbook z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Production Debugging & Incident Response Playbook?

Nie wymagamy żadnego doświadczenia. Production Debugging & Incident Response Playbook w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Debugowanie po fakcie za pomocą zrzutów pamięci”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Production Debugging & Incident Response Playbook?

Tak. Każda lekcja Production Debugging & Incident Response Playbook zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Zdalne debugowanie działających aplikacji
  2. Debugowanie po fakcie za pomocą zrzutów pamięci
  3. Techniki profilowania pamięci i procesora
  4. Distributed tracing dla wąskich gardeł opóźnień
← Powrót do Production Debugging & Incident Response Playbook