Sunday, April 9, 2017

Coredump analyze with GDB

A segmentation fault (often shortened to segfault) is a particular error condition that can occur during the operation of computer software. In short, a segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (e.g., attempts to write to a read-only location, or to overwrite part of the operating system). Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, "segmentation fault" being an example. Some operating systems still have segmentation at some logical level although paging is used as the main memory management policy. On Unix-like operating systems, a process that accesses invalid memory receives the SIGSEGV signal.

coredump
has executing view (program headers), not linking view (section headers); it includes data/stack/heap/frame, not code segment (threads/registers info in PT_NOTE segment);
kernel\fs\binfmt_elf.c
elf_core_dump(current->mm->map_count)
 -> fill_note_info(info->thread_list) -> elf_dump_thread_status -> fill_prstatus -> elf_core_copy_task_regs -> compress_coredump
kernel\arch\arm\kernel\binfmt_elfo32.c
elf32_core_copy_regs -> elf_core_copy_task_fpregs

gdb.c
main() -> gdb_main() -> captured_main() -> captured_command_loop() -> gdb_init() -> initialize_all_files()[initialize_file_ftype: init.c] -> add_cmd()
corefile.c
_initialize_core() -> core_file_command() -> find_core_target()
corelow.c
core_open() -> bfd_fopen() -> build_section_table() -> push_target() -> post_create_inferior() -> init_thread_list() -> target_fetch_registers() -> print_stack_frame()
exec.c
file_command() -> xxx_command()
solib_add() ->  update_solib_list() ->  ops->current_sos() -> svr4_current_sos() -> locate_base() -> elf_locate_base() -> scan_dyntag()[DT_DEBUG; .dynamic; .rld_map]

ulimit -c
echo "ulimit -c unlimited" >> /etc/profile(~/.bash_profile)
echo "ulimit -c 1024" >> /etc/profile #ulimit -S -c 0 > /dev/null 2>&1
/proc/sys/kernel/core_pattern
/sbin/sysctl -w kernel.core_pattern=/var/log/%e.core.%p(/etc/sysctl.conf)
echo "/cache/core-%e-%p-%t" > proc/sys/kernel/core_pattern
%e - insert coredumping executable name into filename
%s - insert signal that caused the coredump into the filename
%t - insert UNIX time that the coredump occurred into filename
%p - insert pid into filename
%u - insert current uid into filename
%g - insert current gid into filename
%h - insert hostname where the coredump happened into filename
/proc/sys/kernel/core_uses_pid
echo 1 > /proc/sys/kernel/core_uses_pid



coredump analyze
prog_release
Compiled without -g
core. prog _release.30254
Coredump for prog _release
prog_debug
Compiled with -g using the same source codes for prog_release
gdb prog_debug core.prog_release.30254
objcopy --only-keep-debug prog_debug projectsymbol.dbg   #create the same symbols
gdb -q --symbol=projectsymbol.dbg -exec=prog_release      #load the symbols


No comments:

Post a Comment