Skip to content

Commit d5e0f27

Browse files
author
Prakash Surya
authored
Merge pull request #25 from delphix/master
Merge branch 'master' into '6.0/stage'
2 parents 23f4407 + 546009c commit d5e0f27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+6121
-1796
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
sudo apt-get update
25-
sudo apt-get install busybox-static libelf-dev libdw-dev qemu-kvm zstd ${{ matrix.cc == 'clang' && 'libomp-dev' || '' }}
25+
sudo apt-get install busybox-static libelf-dev libdw-dev qemu-kvm zstd ${{ matrix.cc == 'clang' && 'libomp-$(clang --version | sed -rn "s/.*clang version ([0-9]+).*/\\1/p")-dev' || '' }}
2626
pip install mypy
2727
- name: Generate version.py
2828
run: python setup.py --version
2929
- name: Check with mypy
3030
run: mypy --strict --no-warn-return-any drgn _drgn.pyi
3131
- name: Build and test with ${{ matrix.cc }}
32-
run: python setup.py test
32+
run: python setup.py test -K
3333

3434
lint:
3535
runs-on: ubuntu-latest

.github/workflows/vmtest-build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: vmtest Build
2+
3+
on:
4+
schedule:
5+
- cron: '16 6 * * MON'
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
env:
12+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Install dependencies
16+
run: |
17+
sudo apt-get update
18+
sudo apt-get install libelf-dev
19+
pip install aiohttp uritemplate
20+
- name: Build and upload assets
21+
run: python3 -m vmtest.manage --kernel-directory build/vmtest/linux.git --build-directory build/vmtest/kbuild -K
22+
- name: Upload kernel build logs
23+
if: always()
24+
uses: actions/upload-artifact@v2
25+
with:
26+
name: kernel-build-logs
27+
path: build/vmtest/kbuild/*.log
28+
if-no-files-found: ignore

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ recursive-include examples *.py
33
recursive-include tests *.py
44
recursive-include tools *.py
55
recursive-include vmtest *.c *.py *.rst
6-
include util.py vmtest/config
6+
include COPYING util.py vmtest/config

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ scripting support, drgn aims to make scripting as natural as possible so that
4040
debugging feels like coding. This makes it well-suited for introspecting the
4141
complex, inter-connected state in large programs. It is also designed as a
4242
library that can be used to build debugging and introspection tools; see the
43-
official `tools <https://github.com/osandov/drgn/tree/master/tools>`_.
43+
official `tools <https://github.com/osandov/drgn/tree/main/tools>`_.
4444

4545
drgn was developed for debugging the Linux kernel (as an alternative to the
4646
`crash <http://people.redhat.com/anderson/>`_ utility), but it can also debug

_drgn.pyi

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ from typing import (
1919
Mapping,
2020
Optional,
2121
Sequence,
22+
Tuple,
2223
Union,
2324
overload,
2425
)
@@ -105,7 +106,15 @@ class Program:
105106
>>> prog['jiffies']
106107
Object(prog, 'volatile unsigned long', address=0xffffffff94c05000)
107108
108-
:param name: The object name.
109+
:param name: Object name.
110+
"""
111+
...
112+
def __contains__(self, name: str) -> bool:
113+
"""
114+
Implement ``name in self``. Return whether an object (variable,
115+
constant, or function) with the given name exists in the program.
116+
117+
:param name: Object name.
109118
"""
110119
...
111120
def variable(self, name: str, filename: Optional[str] = None) -> Object:
@@ -258,16 +267,16 @@ class Program:
258267
"""
259268
...
260269
def read_u8(self, address: IntegerLike, physical: bool = False) -> int:
261-
""
270+
""" """
262271
...
263272
def read_u16(self, address: IntegerLike, physical: bool = False) -> int:
264-
""
273+
""" """
265274
...
266275
def read_u32(self, address: IntegerLike, physical: bool = False) -> int:
267-
""
276+
""" """
268277
...
269278
def read_u64(self, address: IntegerLike, physical: bool = False) -> int:
270-
""
279+
""" """
271280
...
272281
def read_word(self, address: IntegerLike, physical: bool = False) -> int:
273282
"""
@@ -1374,30 +1383,63 @@ class StackTrace:
13741383
.. code-block:: python3
13751384
13761385
for frame in trace:
1377-
if frame.symbol().name == 'io_schedule':
1386+
if frame.name == 'io_schedule':
13781387
print('Thread is doing I/O')
13791388
13801389
:class:`str() <str>` returns a pretty-printed stack trace:
13811390
1382-
>>> print(prog.stack_trace(1))
1383-
#0 __schedule+0x25c/0x8ba
1384-
#1 schedule+0x3c/0x7e
1385-
#2 schedule_hrtimeout_range_clock+0x10c/0x118
1386-
#3 ep_poll+0x3ca/0x40a
1387-
#4 do_epoll_wait+0xb0/0xc6
1388-
#5 __x64_sys_epoll_wait+0x1a/0x1d
1389-
#6 do_syscall_64+0x55/0x17c
1390-
#7 entry_SYSCALL_64+0x7c/0x156
1391+
>>> prog.stack_trace(1)
1392+
#0 context_switch (kernel/sched/core.c:4339:2)
1393+
#1 __schedule (kernel/sched/core.c:5147:8)
1394+
#2 schedule (kernel/sched/core.c:5226:3)
1395+
#3 do_wait (kernel/exit.c:1534:4)
1396+
#4 kernel_wait4 (kernel/exit.c:1678:8)
1397+
#5 __do_sys_wait4 (kernel/exit.c:1706:13)
1398+
#6 do_syscall_64 (arch/x86/entry/common.c:47:14)
1399+
#7 entry_SYSCALL_64+0x7c/0x15b (arch/x86/entry/entry_64.S:112)
1400+
#8 0x4d49dd
13911401
1392-
The drgn CLI is set up so that stack traces are displayed with ``str()`` by
1393-
default.
1402+
The format is subject to change. The drgn CLI is set up so that stack
1403+
traces are displayed with ``str()`` by default.
13941404
"""
13951405

13961406
def __getitem__(self, idx: IntegerLike) -> StackFrame: ...
13971407

13981408
class StackFrame:
13991409
"""
14001410
A ``StackFrame`` represents a single *frame* in a thread's call stack.
1411+
1412+
:class:`str() <str>` returns a pretty-printed stack frame:
1413+
1414+
>>> prog.stack_trace(1)[0]
1415+
#0 at 0xffffffffb64ac287 (__schedule+0x227/0x606) in context_switch at kernel/sched/core.c:4339:2 (inlined)
1416+
1417+
This includes more information than when printing the full stack trace. The
1418+
format is subject to change. The drgn CLI is set up so that stack frames
1419+
are displayed with ``str()`` by default.
1420+
1421+
The :meth:`[] <.__getitem__>` operator can look up function parameters,
1422+
local variables, and global variables in the scope of the stack frame:
1423+
1424+
>>> prog.stack_trace(1)[0]['prev'].pid
1425+
(pid_t)1
1426+
>>> prog.stack_trace(1)[0]['scheduler_running']
1427+
(int)1
1428+
"""
1429+
1430+
name: Optional[str]
1431+
"""
1432+
Name of the function at this frame, or ``None`` if it could not be
1433+
determined.
1434+
"""
1435+
1436+
is_inline: bool
1437+
"""
1438+
Whether this frame is for an inlined call.
1439+
1440+
An inline frame shares the same stack frame in memory as its caller.
1441+
Therefore, it has the same registers (including program counter and thus
1442+
symbol).
14011443
"""
14021444

14031445
interrupted: bool
@@ -1413,8 +1455,36 @@ class StackFrame:
14131455
particular, the program counter is the return address, which is typically
14141456
the instruction after the call instruction.
14151457
"""
1458+
14161459
pc: int
14171460
"""Program counter at this stack frame."""
1461+
def __getitem__(self, name: str) -> Object:
1462+
"""
1463+
Implement ``self[name]``. Get the object (variable, function parameter,
1464+
constant, or function) with the given name in the scope of this frame.
1465+
1466+
If the object exists but has been optimized out, this returns an
1467+
:ref:`absent object <absent-objects>`.
1468+
1469+
:param name: Object name.
1470+
"""
1471+
...
1472+
def __contains__(self, name: str) -> bool:
1473+
"""
1474+
Implement ``name in self``. Return whether an object with the given
1475+
name exists in the scope of this frame.
1476+
1477+
:param name: Object name.
1478+
"""
1479+
...
1480+
def source(self) -> Tuple[str, int, int]:
1481+
"""
1482+
Get the source code location of this frame.
1483+
1484+
:return: Location as a ``(filename, line, column)`` triple.
1485+
:raises LookupError: if the source code location is not available
1486+
"""
1487+
...
14181488
def symbol(self) -> Symbol:
14191489
"""
14201490
Get the function symbol at this stack frame.
@@ -1952,11 +2022,14 @@ class FaultError(Exception):
19522022
accessing a memory address which is not valid in a program).
19532023
"""
19542024

1955-
def __init__(self, address: int) -> None:
2025+
def __init__(self, message: str, address: int) -> None:
19562026
"""
2027+
:param message: :attr:`FaultError.message`
19572028
:param address: :attr:`FaultError.address`
19582029
"""
19592030
...
2031+
message: str
2032+
"""Error message."""
19602033
address: int
19612034
"""Address that couldn't be accessed."""
19622035

@@ -1981,6 +2054,7 @@ class OutOfBoundsError(Exception):
19812054

19822055
...
19832056

2057+
_elfutils_version: str
19842058
_with_libkdumpfile: bool
19852059

19862060
def _linux_helper_read_vm(

docs/advanced_usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The core functionality of drgn is implemented in C and is available as a C
3535
library, ``libdrgn``. See |drgn.h|_.
3636

3737
.. |drgn.h| replace:: ``drgn.h``
38-
.. _drgn.h: https://github.com/osandov/drgn/blob/master/libdrgn/drgn.h.in
38+
.. _drgn.h: https://github.com/osandov/drgn/blob/main/libdrgn/drgn.h.in
3939

4040
Full documentation can be generated by running ``doxygen`` in the ``libdrgn``
4141
directory of the source code. Note that the API and ABI are not yet stable.

docs/user_guide.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ address it points to)::
139139
>>> print(hex(jiffiesp.value_()))
140140
0xffffffffbe405000
141141

142+
.. _absent-objects:
143+
142144
Absent Objects
143145
""""""""""""""
144146

@@ -317,5 +319,5 @@ Next Steps
317319

318320
Refer to the :doc:`api_reference`. Look through the :doc:`helpers`. Browse
319321
through the official `examples
320-
<https://github.com/osandov/drgn/tree/master/examples>`_ and `tools
321-
<https://github.com/osandov/drgn/tree/master/tools>`_.
322+
<https://github.com/osandov/drgn/tree/main/examples>`_ and `tools
323+
<https://github.com/osandov/drgn/tree/main/tools>`_.

drgn/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
TypeMember,
7474
TypeParameter,
7575
TypeTemplateParameter,
76+
_elfutils_version as _elfutils_version,
7677
_with_libkdumpfile as _with_libkdumpfile,
7778
cast,
7879
container_of,
@@ -195,7 +196,7 @@ def task_exe_path(task):
195196
:param args: Zero or more additional arguments to pass to the script. This
196197
is a :ref:`variable argument list <python:tut-arbitraryargs>`.
197198
"""
198-
# This is based on runpy.run_code, which we can't use because we want to
199+
# This is based on runpy.run_path(), which we can't use because we want to
199200
# update globals even if the script throws an exception.
200201
saved_module = []
201202
try:

drgn/internal/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def displayhook(value: Any) -> None:
2323
setattr(builtins, "_", None)
2424
if isinstance(value, drgn.Object):
2525
text = value.format_(columns=shutil.get_terminal_size((0, 0)).columns)
26-
elif isinstance(value, (drgn.StackTrace, drgn.Type)):
26+
elif isinstance(value, (drgn.StackFrame, drgn.StackTrace, drgn.Type)):
2727
text = str(value)
2828
else:
2929
text = repr(value)
@@ -43,7 +43,7 @@ def displayhook(value: Any) -> None:
4343
def main() -> None:
4444
python_version = ".".join(str(v) for v in sys.version_info[:3])
4545
libkdumpfile = f'with{"" if drgn._with_libkdumpfile else "out"} libkdumpfile'
46-
version = f"drgn {drgn.__version__} (using Python {python_version}, {libkdumpfile})"
46+
version = f"drgn {drgn.__version__} (using Python {python_version}, elfutils {drgn._elfutils_version}, {libkdumpfile})"
4747
parser = argparse.ArgumentParser(prog="drgn", description="Scriptable debugger")
4848

4949
program_group = parser.add_argument_group(

examples/linux/cgroup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env drgn
12
# Copyright (c) Facebook, Inc. and its affiliates.
23
# SPDX-License-Identifier: GPL-3.0-or-later
34

examples/linux/fs_inodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env drgn
12
# Copyright (c) Facebook, Inc. and its affiliates.
23
# SPDX-License-Identifier: GPL-3.0-or-later
34

examples/linux/lsmod.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env drgn
12
# Copyright (c) Facebook, Inc. and its affiliates.
23
# SPDX-License-Identifier: GPL-3.0-or-later
34

examples/linux/ps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env drgn
12
# Copyright (c) Facebook, Inc. and its affiliates.
23
# SPDX-License-Identifier: GPL-3.0-or-later
34

examples/linux/tcp_sock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env drgn
12
# Copyright (c) Facebook, Inc. and its affiliates.
23
# SPDX-License-Identifier: GPL-3.0-or-later
34

libdrgn/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/config.log
1212
/config.status
1313
/configure
14+
/configure~
1415
/html
1516
/libtool
1617
/python/constants.c

libdrgn/configure.ac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dnl Copyright (c) Facebook, Inc. and its affiliates.
22
dnl SPDX-License-Identifier: GPL-3.0-or-later
33

4-
AC_INIT([libdrgn], [0.0.11],
4+
AC_INIT([libdrgn], [0.0.13],
55
[https://github.com/osandov/drgn/issues],,
66
[https://github.com/osandov/drgn])
77

@@ -15,6 +15,8 @@ AM_PROG_AR
1515

1616
LT_INIT
1717

18+
AC_SYS_LARGEFILE
19+
1820
AC_ARG_ENABLE([openmp],
1921
[AS_HELP_STRING([--enable-openmp@<:@=ARG@:>@],
2022
[use OpenMP. ARG may be yes, no, or the name of

0 commit comments

Comments
 (0)