From c574ca24bc991c8a48f780c7912eff3574b3c43a Mon Sep 17 00:00:00 2001 From: ZhaoLei <77103671+zhaolei0505@users.noreply.github.com> Date: Wed, 19 Oct 2022 14:24:00 +0800 Subject: [PATCH] feat: save Elf BuildId in corefile. (#204) --- src/platform/unix/core/linux/elfcore.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/platform/unix/core/linux/elfcore.cc b/src/platform/unix/core/linux/elfcore.cc index 076dc4c..7f59077 100644 --- a/src/platform/unix/core/linux/elfcore.cc +++ b/src/platform/unix/core/linux/elfcore.cc @@ -944,6 +944,14 @@ static int CreateElfCore(void* handle, mappings[i].end_address - mappings[i].start_address; } + /* We could save the first page of ELF to record the BuildId, + * let the debugger later find the corresponding binary it used. + */ + if (!dontdump && mappings[i].write_size == 0 && + (mappings[i].flags & PF_X) != 0) { + mappings[i].write_size = pagesize; + } + /* Remove mapping, if it was not readable, or completely zero * anyway. The former is usually the case of stack guard pages, and * the latter occasionally happens for unused memory.