Skip to content

Commit

Permalink
Merge pull request #12 from sdimitro/ldd_debian
Browse files Browse the repository at this point in the history
latest commit batch merge
  • Loading branch information
sdimitro authored Jul 22, 2020
2 parents 375baac + 9481e7a commit 9de7dc5
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 5 deletions.
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
savedump (0.1.0) UNRELEASED; urgency=medium

* Auto-generated entry.

-- Serapheim Dimitropoulos <[email protected]> Wed, 22 Jul 2020 16:24:43 +0000
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
17 changes: 17 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Source: savedump
Section: misc
Priority: optional
Maintainer: Delphix Engineering <[email protected]>
Standards-Version: 4.1.2
Build-Depends: debhelper (>= 9),
dh-python,
python3,
python3-distutils,
python3.6-dev,
zlib1g-dev
Suggests: libkdumpfile, drgn

Package: savedump
Architecture: any
Depends: ${shlibs:Depends}, ${python3:Depends}
Description: Kernel coredump file access
23 changes: 23 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: savedump
Source: https://github.com/sdimitro/savedump

Files: *
Copyright: Delphix Corp.
License: Apache-2.0

License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian systems, the complete text of the Apache License can be found in
the file `/usr/share/common-licenses/Apache-2.0'.
11 changes: 11 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/make -f

%:
dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_test:
#
# Don't run the tests when building the package. We'll enforce
# testing via another mechanism, so running it during package
# builds is unnecessary.
#
84 changes: 80 additions & 4 deletions savedump/prog.py → savedump/savedump.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import sys
from typing import List, Optional, Tuple

import kdumpfile


def shell_cmd(cmd_and_args: List[str]) -> Tuple[bool, str]:
"""
Expand Down Expand Up @@ -116,11 +114,38 @@ def get_dump_type(path: str) -> Optional[DumpType]:
return None


RUN_CRASH_SDB_CONTENTS = """#!/bin/bash
script_path=$(readlink -f "$0")
script_dir=$(dirname "$script_path")
sdb -s $script_dir/usr/lib/debug/lib/modules \\
$script_dir/{0} $script_dir/{1}
"""

RUN_PYCRASH_CONTENTS = """#!/bin/bash
script_path=$(readlink -f "$0")
script_dir=$(dirname "$script_path")
crash.sh -m $script_dir/usr/lib/debug/lib/modules \\
$script_dir/{0} $script_dir/{1}
"""


def archive_kernel_dump(path: str) -> None:
"""
Packages the dump together with its vmlinux and modules in a
gzipped archive in the working directory.
"""
#
# We import libkdumpfile specifically here and not
# in the top-level to allow users that don't have
# it installed to still be able to use savedump for
# core files.
#
import kdumpfile # pylint: disable=import-outside-toplevel

kdump_info = kdumpfile.kdumpfile(path)
dumpname = os.path.basename(path)
nodename = kdump_info.attr['linux.uts.nodename']
Expand All @@ -144,6 +169,26 @@ def archive_kernel_dump(path: str) -> None:
archive_extra_mod_path = f"{archive_dir}{extra_mod_path}"
distutils.dir_util.copy_tree(extra_mod_path, archive_extra_mod_path)

#
# Generate run-sdb.sh.
#
run_sdb_path = f"{archive_dir}/run-sdb.sh"
with open(run_sdb_path, "w") as sdb_script:
print(RUN_CRASH_SDB_CONTENTS.format(os.path.basename(vmlinux_path),
dumpname),
file=sdb_script)
os.chmod(run_sdb_path, 0o755)

#
# Generate run-pycrash.sh.
#
run_pycrash_path = f"{archive_dir}/run-pycrash.sh"
with open(run_pycrash_path, "w") as pycrash_script:
print(RUN_PYCRASH_CONTENTS.format(os.path.basename(vmlinux_path),
dumpname),
file=pycrash_script)
os.chmod(run_pycrash_path, 0o755)

msg = compress_archive(archive_dir)
shutil.rmtree(archive_dir)
if msg:
Expand Down Expand Up @@ -245,8 +290,39 @@ def get_libraries_through_ldd(bin_path: str) -> Optional[List[str]]:
print(output, file=sys.stderr)
return None

sys.exit("error: library detection through ldd(1) not implemented yet")
return []
#
# Example output of the above command:
# ```
# $ ldd /sbin/ztest
# linux-vdso.so.1 (0x00007ffeeb9ac000)
# libnvpair.so.1 => /lib/libnvpair.so.1 (0x00007f607a568000)
# libzpool.so.2 => /lib/libzpool.so.2 (0x00007f6079f3c000)
# libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6079b9e000)
# libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f607997f000)
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f607958e000)
# librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6079386000)
# libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007f6079139000)
# libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6078f35000)
# libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007f6078d17000)
# libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f6078b10000)
# libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f60788f3000)
# /lib64/ld-linux-x86-64.so.2 (0x00007f607a9a2000)
# ```
#
libraries = []
for line in output.splitlines():
line = line.strip()
if '=>' in line:
libraries.append(line.split()[2])
elif 'ld-linux-' in line:
#
# Outside of ouf userland-linked libraries that are not part of
# the runtime of the OS, we only care about the dynamic linker
# used (e.g. ld-linux-x86-64.so.2) and even that is mostly there
# for extreme situations.
#
libraries.append(line.split()[0])
return libraries


def binary_includes_debug_info(path: str) -> Optional[bool]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],

entry_points={
'console_scripts': ['savedump=savedump.prog:main'],
'console_scripts': ['savedump=savedump.savedump:main'],
},

author='Delphix Platform Team',
Expand Down

0 comments on commit 9de7dc5

Please sign in to comment.