Why we get the core file and also how can we debug it in unix(using sun C++ compiler)

Dani AI

Generated

Core files are a snapshot of a process (memory + registers) written when the program is terminated by a fatal condition (segfault, abort/assert, illegal instruction, divide-by-zero, bus error, etc.). As pointed out, their existence means the program hit an abnormal runtime condition; the core lets a debugger show exactly where and what state led to that condition.

Make cores usable

  • Ensure the shell will create them:

    # sh/ksh/bash
    ulimit -c unlimited
    
    # csh/tcsh
    limit coredumpsize unlimited
  • Compile with debug symbols and without optimization so frames and locals are visible:

    CC -g -o myprog myprog.cpp

    Do not strip the binary; verify with file myprog.

Quick debugging workflow

  • A quick stack-only snapshot tool (as suggested) is useful for triage.

  • For full inspection, run a debugger against the executable and the core:

    # gdb
    gdb myprog core
    (gdb) bt
    (gdb) frame 0
    (gdb) print someVar
    
    # dbx (Solaris)
    dbx myprog core
    (dbx) where
    (dbx) frame 0
    (dbx) print someVar

Practical tips and gotchas

  • If no core appears, check ulimit, setuid/setgid restrictions, file permissions, available disk space, and any OS core configuration (system utilities or kernel settings can redirect/disable cores).
  • Optimization can hide or inline frames; rebuild without optimizations if line-accurate traces are needed.
  • Core files can be large and contain secrets (stack contents, passwords); treat them as sensitive before sharing.

This fills out the short answers in the thread: use a quick stack tool for triage, but for definitive diagnosis build with -g and debug the core in dbx/gdb to inspect frames, locals and the failing instruction.

Recommended Answers

All 2 Replies

>>Why we get the core file
Because you made errors in the program.

>>how can we debug it in unix
tutorial

use >pstack core

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.