Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F159148315
D56256.id175881.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D56256.id175881.diff
View Options
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -33,6 +33,7 @@
dirname \
dtc \
du \
+ dump2elf \
elfctl \
elfdump \
enigma \
diff --git a/usr.bin/dump2elf/Makefile b/usr.bin/dump2elf/Makefile
new file mode 100644
--- /dev/null
+++ b/usr.bin/dump2elf/Makefile
@@ -0,0 +1,4 @@
+PROG= dump2elf
+LIBADD+= kvm
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/dump2elf/dump2elf.1 b/usr.bin/dump2elf/dump2elf.1
new file mode 100644
--- /dev/null
+++ b/usr.bin/dump2elf/dump2elf.1
@@ -0,0 +1,86 @@
+.\"
+.\" Copyright (c) 2026 FreeBSD Foundation
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.\" Author: Minsoo Choo <minsoochoo0122@proton.me>
+.\"
+.Dd April 20, 2026
+.Dt DUMP2ELF 1
+.Os
+.Sh NAME
+.Nm dump2elf
+.Nd convert a kernel crash dump into an ELF core file
+.Sh SYNOPSIS
+.Nm
+.Op Fl r Ns | Ns Fl -raw
+.Fl k Ns | Ns Fl -kernel Ar kernel
+.Fl c Ns | Ns Fl -core Ar dump
+.Ar output
+.Sh DESCRIPTION
+The
+.Nm
+utility converts a FreeBSD kernel crash dump into an ELF core file
+that can be loaded directly by debuggers.
+.Pp
+The conversion is performed by the
+.Xr kvm_convert_to_elf 3
+library function.
+.Pp
+The options are as follows:
+.Bl -tag -width "--kernel kernel"
+.It Fl k Ar kernel , Fl -kernel Ar kernel
+Path to the kernel binary that produced the dump.
+This is typically
+.Pa /boot/kernel/kernel
+or a
+.Pa kernel.full
+file with debug symbols.
+.It Fl c Ar dump , Fl -core Ar dump
+Path to the crash dump, usually found under
+.Pa /var/crash/
+as
+.Pa vmcore.N .
+.It Fl r , Fl -raw
+Preserve the raw runtime virtual addresses from the crash dump without
+adjusting for kernel displacement.
+By default,
+.Nm
+subtracts the kernel displacement so that addresses in the output
+match the linked symbol addresses in the kernel binary.
+Use this option if you need the actual runtime addresses as they
+were at the time of the crash.
+.El
+.Pp
+The
+.Ar output
+argument specifies the path for the generated ELF core file.
+.Ss Kernel Displacement
+When the kernel was booted with displacement enabled, the runtime addresses
+in the crash dump differ from the linked addresses in the kernel binary.
+.Nm
+automatically adjusts all virtual addresses in the output core by
+subtracting the kernel displacement obtained via
+.Xr kvm_kerndisp 3 ,
+so that debuggers can resolve symbols without manual adjustment.
+.Sh EXIT STATUS
+.Ex -std
+.Sh EXAMPLES
+Convert a crash dump to an ELF core:
+.Bd -literal -offset indent
+dump2elf -k /boot/kernel/kernel -c /var/crash/vmcore.0 vmcore.0.elf
+dump2elf --kernel kernel.full --core /var/crash/vmcore.0 vmcore.0.elf
+.Ed
+.Sh SEE ALSO
+.Xr kvm 3 ,
+.Xr kvm_convert_to_elf 3 ,
+.Xr kvm_kerndisp 3 ,
+.Xr crash 8 ,
+.Xr savecore 8
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 15.1 .
+.Sh AUTHORS
+.An Minsoo Choo Aq Mt minsoochoo0122@proton.me
diff --git a/usr.bin/dump2elf/dump2elf.c b/usr.bin/dump2elf/dump2elf.c
new file mode 100644
--- /dev/null
+++ b/usr.bin/dump2elf/dump2elf.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2026 FreeBSD Foundation
+ *
+ * This software was developed by Minsoo Choo under sponsorship from the
+ * FreeBSD Foundation.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <err.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <kvm.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static char kvm_errbuf[_POSIX2_LINE_MAX];
+
+static const struct option longopts[] = {
+ { "kernel", required_argument, NULL, 'k' },
+ { "core", required_argument, NULL, 'c' },
+ { "raw", no_argument, NULL, 'r' },
+ { NULL, 0, NULL, 0 }
+};
+
+static void __dead2
+usage(void)
+{
+
+ fprintf(stderr,
+ "usage: md2elf [-r] -k kernel -c dump output\n"
+ " md2elf [--raw] --kernel kernel --core dump output\n");
+ exit(EXIT_FAILURE);
+}
+
+int
+main(int argc, char **argv)
+{
+ kvm_t *kvm;
+ const char *kernel, *vmcore, *output;
+ int ch, raw;
+
+ kernel = NULL;
+ vmcore = NULL;
+ raw = 0;
+
+ while ((ch = getopt_long(argc, argv, "k:c:r", longopts,
+ NULL)) != -1) {
+ switch (ch) {
+ case 'k':
+ kernel = optarg;
+ break;
+ case 'c':
+ vmcore = optarg;
+ break;
+ case 'r':
+ raw = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (kernel == NULL || vmcore == NULL || argc != 1)
+ usage();
+
+ output = argv[0];
+
+ if ((kvm = kvm_openfiles(kernel, vmcore, NULL, O_RDONLY,
+ kvm_errbuf)) == NULL)
+ errx(EXIT_FAILURE, "kvm_openfiles: %s", kvm_errbuf);
+
+ if (kvm_convert_to_elf(kvm, output, !raw) != 0) {
+ unlink(output);
+ errx(EXIT_FAILURE, "kvm_convert_to_elf: %s",
+ kvm_geterr(kvm));
+ }
+
+ kvm_close(kvm);
+ return (0);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jun 11, 3:46 PM (9 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33883493
Default Alt Text
D56256.id175881.diff (4 KB)
Attached To
Mode
D56256: usr.bin: introduce dump2elf(1)
Attached
Detach File
Event Timeline
Log In to Comment