Skip to content

Commit

Permalink
Merge branch 'refs/heads/upstream-HEAD' into repo-HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Delphix Engineering committed Dec 24, 2024
2 parents 5049f1c + e2f82e2 commit 7cb48d4
Show file tree
Hide file tree
Showing 18 changed files with 2,160 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

ACLOCAL_AMFLAGS = -I m4

SUBDIRS = include src tests examples
SUBDIRS = include src tests tools examples
if BUILD_PYTHON_EXT
SUBDIRS += python
endif
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ next
* Parse QEMU CPU state ELF notes.
* Use kernel page tables when initializing X86-64 Linux with PTI from
CR3 register value.
* Include the kdumpid utility.
* Fix direct mapping if LDT PTI remapping is used in Linux on X86-64.
* Minor cache improvements and a NULL-pointer dereference fix.
* Fix test suite for 32-bit architectures.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ To compile this package, you'll need the following:
* [GCC](http://gcc.gnu.org/). The source uses a few construct specific
to GCC (such as variable attributes). Porting should be easy, though.

If you want to build kdumpid, you'll also need:

* [BFD](http://www.gnu.org/software/binutils/). Any version with
disassemblers for x86, ppc and s390 will do. This usually comes with
the distro packaged as binutils-devel or similar.

To create documentation files, you'll need:

* [Doxygen](http://www.doxygen.org/). Usually packaged as doxygen.
Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ m4_define([pkg_micro_version], [4])
m4_define([pkg_version],
[pkg_major_version.pkg_minor_version.pkg_micro_version])

dnl FIXME: kdumpid has a different versioning scheme
m4_define([kdumpid_major_version], [1])
m4_define([kdumpid_minor_version], [7])

AC_INIT([libkdumpfile],[pkg_version],[[email protected]])

AC_CONFIG_SRCDIR([src/kdumpfile/diskdump.c])
Expand Down Expand Up @@ -104,6 +108,11 @@ AS_IF([test "x$enable_debug" = xyes],
dnl check for Python
kdump_PYTHON([2.7.0])

dnl check whether to build optional tools
AC_SUBST(KDUMPID_VER_MAJOR, kdumpid_major_version)
AC_SUBST(KDUMPID_VER_MINOR, kdumpid_minor_version)
KDUMP_TOOL_KDUMPID

AC_CONFIG_FILES([
Makefile
examples/Makefile
Expand All @@ -114,6 +123,8 @@ AC_CONFIG_FILES([
src/kdumpfile/Makefile
python/Makefile
tests/Makefile
tools/Makefile
tools/kdumpid/Makefile
libaddrxlat.pc
libkdumpfile.pc
include/libkdumpfile/kdumpfile.h
Expand Down
100 changes: 100 additions & 0 deletions m4/tools.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# KDUMP_TRY_LINK(LIBRARIES)
# ---------------------------------------------------------
# Try to link the existing test source file with additional
# libraries.
# Set kdump_res to "yes" on success, else set it to "no".
# Standard error output is saved to conftest.linkerr.
AC_DEFUN([KDUMP_TRY_LINK],[dnl
kdump_save_LIBS="$LIBS"
kdump_save_ac_link="$ac_link"
LIBS="$1 $LIBS"
ac_link="$ac_link 2>conftest.linkerr"
AC_LINK_IFELSE([], kdump_res=yes, [kdump_res=no
$2])
LIBS="$kdump_save_LIBS"
ac_link="$kdump_save_ac_link"
])# KDUMP_TRY_LINK

AC_DEFUN([KDUMP_REPORT_LINKERR],[dnl
AS_ECHO("$as_me:$LINENO: all linker errors") >&AS_MESSAGE_LOG_FD
cat conftest.linkerr >&AS_MESSAGE_LOG_FD
])# KDUMP_REPORT_LINKERR

AC_DEFUN([KDUMP_TRY_LINK_UNDEF],[dnl
kdump_save_LDFLAGS="$LDFLAGS"
LDFLAGS="-z undefs $2 $LDFLAGS"
KDUMP_TRY_LINK($1, KDUMP_REPORT_LINKERR)
LDFLAGS="$kdump_save_LDFLAGS"
])# KDUMP_TRY_LINK_UNDEF

AC_DEFUN([KDUMP_DIS_ASM_CHECK_UNDEF],[dnl
AC_REQUIRE([AC_PROG_EGREP])dnl
AC_MSG_CHECKING([whether disassembler requires $1])
KDUMP_TRY_LINK($DIS_ASM_LIBS)
AS_ECHO("$as_me:$LINENO: matching linker errors") >&AS_MESSAGE_LOG_FD
AS_IF([$EGREP "@<:@^A-Za-z0-9_@:>@($2)" conftest.linkerr >&AS_MESSAGE_LOG_FD],
[AC_MSG_RESULT(yes)
DIS_ASM_LIBS="$DIS_ASM_LIBS $1"
KDUMP_TRY_LINK_UNDEF($DIS_ASM_LIBS)
AS_IF([test yes != "$kdump_res"],
[AC_MSG_FAILURE([Link fails with $1])])],
[AC_MSG_RESULT(no)])dnl
])# KDUMP_DIS_ASM_CHECK_UNDEF

AC_DEFUN([KDUMP_DIS_ASM_LIBS],[dnl determine disassembler libraries
DIS_ASM_LIBS=-lopcodes
AC_LANG_CONFTEST([AC_LANG_PROGRAM(
[#include <dis-asm.h>],
[disassembler(bfd_arch_i386, FALSE, bfd_mach_x86_64, NULL);])])
dnl ignore undefined symbols from missing linker dependencies
AC_MSG_CHECKING([for disassembler in $DIS_ASM_LIBS])
KDUMP_TRY_LINK_UNDEF($DIS_ASM_LIBS, [-Wl,--require-defined=disassembler])
AC_MSG_RESULT($kdump_res)
AS_IF([test yes = "$kdump_res"], [dnl
KDUMP_DIS_ASM_CHECK_UNDEF(-lbfd, bfd_)
KDUMP_DIS_ASM_CHECK_UNDEF(-lsframe, sframe_)
KDUMP_DIS_ASM_CHECK_UNDEF(-liberty, htab_create|splay_tree_new)
KDUMP_DIS_ASM_CHECK_UNDEF(-lz, inflate)
KDUMP_DIS_ASM_CHECK_UNDEF(-lzstd, ZSTD_)
KDUMP_DIS_ASM_CHECK_UNDEF(-ldl, dlopen)
AS_IF([test yes != "$kdump_res"],
[KDUMP_REPORT_LINKERR]
[AC_MSG_FAILURE([Tried everything, still cannot link disassembler.])])
AC_SUBST(DIS_ASM_LIBS)
])dnl
])# KDUMP_DIS_ASM_LIBS

AC_DEFUN([KDUMP_DIS_ASM],[dnl determine disassembler options
AC_CHECK_HEADERS(dis-asm.h, [],
[AC_MSG_ERROR([Disassembler headers not found])])
AC_MSG_CHECKING([whether disassembler supports syntax highlighting])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <dis-asm.h>
void fn(struct disassemble_info *info, void *stream,
fprintf_ftype fprintf_func, fprintf_styled_ftype fprintf_styled_func)
{
init_disassemble_info(info, stream, fprintf_func, fprintf_styled_func);
}
])],
[dnl
AC_MSG_RESULT(yes)
AC_DEFINE(DIS_ASM_STYLED_PRINTF, [1],
[Define if init_disassemble_info() has a printf_styled_func parameter])],
[AC_MSG_RESULT(no)])
KDUMP_DIS_ASM_LIBS
])# KDUMP_DIS_ASM

AC_DEFUN([KDUMP_TOOL_KDUMPID],[dnl enable/disable kdumpid build
AC_ARG_ENABLE(kdumpid,
[AS_HELP_STRING(--disable-kdumpid,
[do not build kdumpid])],
[],
[enable_kdumpid=yes])
AS_IF([test no != "$enable_kdumpid"], [dnl
KDUMP_DIS_ASM
AS_IF([test yes != "$kdump_res"],
[AC_MSG_FAILURE(
[disassembler test failed (--disable-kdumpid to disable)])]
)])
AM_CONDITIONAL(BUILD_KDUMPID, [test yes = "$enable_kdumpid"])
])# KDUMP_TOOL_KDUMPID
26 changes: 26 additions & 0 deletions tools/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Process this file with automake to create Makefile.in
## Configure input file for libkdumpfile.
##
## Copyright (C) 2024 Petr Tesarik <[email protected]>
##
## This file is part of libkdumpfile.
##
## This file is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## libkdumpfile is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##

SUBDIRS =

if BUILD_KDUMPID
SUBDIRS += kdumpid
endif
2 changes: 2 additions & 0 deletions tools/kdumpid/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Resulting binaries
kdumpid
45 changes: 45 additions & 0 deletions tools/kdumpid/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Process this file with automake to create Makefile.in
## Configure input file for libkdumpfile.
##
## Copyright (C) 2024 Petr Tesarik <[email protected]>
##
## This file is part of libkdumpfile.
##
## This file is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## libkdumpfile is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##

AM_CPPFLAGS = -I$(top_builddir)/include \
-DVER_MAJOR=$(KDUMPID_VER_MAJOR) \
-DVER_MINOR=$(KDUMPID_VER_MINOR)

LIBS = \
$(top_builddir)/src/kdumpfile/libkdumpfile.la \
$(DIS_ASM_LIBS)

kdumpid_SOURCES = \
main.c \
util.c \
search.c \
ppc.c \
ppc64.c \
s390.c \
x86.c

noinst_HEADERS = \
kdumpid.h \
endian.h

bin_PROGRAMS = kdumpid

dist_man_MANS = kdumpid.1
44 changes: 44 additions & 0 deletions tools/kdumpid/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef __KDUMP_ENDIAN_H
#define __KDUMP_ENDIAN_H

#include <endian.h>

/* Older glibc didn't have the byteorder macros */
#ifndef be16toh

#include <byteswap.h>

# if __BYTE_ORDER == __LITTLE_ENDIAN
# define htobe16(x) bswap_16(x)
# define htole16(x) (x)
# define be16toh(x) bswap_16(x)
# define le16toh(x) (x)

# define htobe32(x) bswap_32(x)
# define htole32(x) (x)
# define be32toh(x) bswap_32(x)
# define le32toh(x) (x)

# define htobe64(x) bswap_64(x)
# define htole64(x) (x)
# define be64toh(x) bswap_64(x)
# define le64toh(x) (x)
# else
# define htobe16(x) (x)
# define htole16(x) bswap_16(x)
# define be16toh(x) (x)
# define le16toh(x) bswap_16(x)

# define htobe32(x) (x)
# define htole32(x) bswap_32(x)
# define be32toh(x) (x)
# define le32toh(x) bswap_32(x)

# define htobe64(x) (x)
# define htole64(x) bswap_64(x)
# define be64toh(x) (x)
# define le64toh(x) bswap_64(x)
# endif
#endif

#endif /* __KDUMP_ENDIAN_H */
55 changes: 55 additions & 0 deletions tools/kdumpid/kdumpid.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.TH KDUMPID 1 "4 Nov 2011"
.SH NAME
KdumpID \- A tool to identify kernel memory dumps
.SH SYNOPSIS
.B kdumpid
.I [-v] <dumpfile>
.SH "DESCRIPTION"
.B kdumpid
provides a fast and reliable method to find out the most
important information about an unknown kernel crash dump,
such as the architecture and kernel release. Think of it
as a kind of "file" utility for kernel dumps.
.LP
At present,
.B kdumpid
can read:
.LP
\- LKCD files
.br
\- DISKDUMP/KDUMP files
.br
\- ELF dumps (including support for both Xen Dom0 and DomU).
.LP
The following architectures are fully supported:
.LP
\- x86
.br
\- x86-64
.br
\- ppc
.br
\- ppc64
.br
\- s390
.br
\- s390x.
.LP
Other architectures may produce some output if the information
can be found in the file header.
.SH "OPERATION"
By default,
.B kdumpid
will print the kernel dump's format, architecture and version.
.SH "OPTIONS"
.TP
\fB\-v\fR
Try to extract and print additional information from
the memory dump, such as: the machine type, the full
kernel banner string and the kernel configuration flavor.
.SH "SEE ALSO"
.BR crash (8),
.BR makedumpfile (8),
.BR kdump (7).
.SH AUTHOR
KdumpID was written by Petr Tesarik.
Loading

0 comments on commit 7cb48d4

Please sign in to comment.