GDB - 动态创建压缩核心文件

问题描述 投票:0回答:1

GDB 提供了创建正在运行的进程的 coredump 的功能,并且有一个很好的脚本 - 'gcore' 来提供简单的抽象。如果有人想要压缩的“核心”文件,则需要两个步骤:

  1. 创建正在运行的进程的核心转储
  2. 使用 gzip 或类似实用程序来压缩 coredump。

但是,如果压缩可用磁盘空间,最好在将文件写入磁盘之前在第 1 步进行压缩。我对 gdb 的初始例程进行了更改,使其仅通过跳转到 gcore_command() 例程来创建 coredump:

#0  0x00007f48876bb140 in write () from /lib64/libc.so.6
#1  0x00007f48876461a3 in _IO_new_file_write () from /lib64/libc.so.6
#2  0x00007f4887646a40 in __GI__IO_file_xsputn () from /lib64/libc.so.6
#3  0x00007f488763b692 in fwrite () from /lib64/libc.so.6
#4  0x000000000072c04d in cache_bwrite (abfd=<optimized out>, from=0x1fe0ba0, nbytes=16384) at cache.c:387
#5  0x000000000072b44a in bfd_bwrite (ptr=ptr@entry=0x1fe0ba0, size=size@entry=16384, abfd=abfd@entry=0x1f13800) at bfdio.c:233
#6  0x0000000000751f6e in _bfd_elf_set_section_contents (abfd=0x1f13800, section=0x1fff950, location=0x1fe0ba0, offset=<optimized out>, count=16384) at elf.c:8878
#7  0x0000000000731264 in bfd_set_section_contents (abfd=0x1f13800, section=0x1fff950, location=0x1fe0ba0, offset=<optimized out>, count=<optimized out>) at section.c:1512
#8  0x00000000005b654c in gcore_copy_callback (obfd=0x1f13800, osec=0x1fff950, ignored=<optimized out>) at gcore.c:576
#9  0x000000000073110c in bfd_map_over_sections (abfd=0x1f13800, operation=0x5b64d0 <gcore_copy_callback(bfd*, asection*, void*)>, user_storage=0x0) at section.c:1374
#10 0x00000000005b6923 in gcore_memory_sections (obfd=0x1f13800) at gcore.c:604
#11 write_gcore_file_1 (obfd=0x1f13800) at gcore.c:102
#12 write_gcore_file (obfd=0x1f13800) at gcore.c:123
#13 0x00000000005b6b2e in gcore_command (args=<optimized out>, from_tty=<optimized out>) at gcore.c:169
#14 0x0000000000459049 in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>) at cli/cli-decode.c:1857
#15 0x00000000006bcd9f in execute_command (p=<optimized out>, p@entry=0xcf14e0 <lc_gcore_cmd_str> "gcore /tmp/server.core.15.29219", from_tty=from_tty@entry=0) at top.c:630
#16 0x0000000000604c78 in catch_command_errors (command=0x6bc990 <execute_command(char const*, int)>, arg=0xcf14e0 <lc_gcore_cmd_str> "gcore /tmp/server.core.15.29219", from_tty=0)
    at main.c:381
#17 0x0000000000605a18 in captured_main_1 (context=0x7, this=<optimized out>) at main.c:1129
#18 captured_main (data=0x7) at main.c:1155
#19 gdb_main (args=args@entry=0x7fff20538bc0) at main.c:1184

我可以在调用fwrite()之前在cache_bwrite()中调用压缩API吗?或者还有其他更好的办法吗?

c linux gdb compression gzip
1个回答
0
投票

我最近开源了这个项目corepipe,为了将coredump到管道,你可以尝试一下吗?

© www.soinside.com 2019 - 2024. All rights reserved.