From f29706e53885fdbed6e0377536c2f83b05889d9f Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Tue, 18 Jun 2019 08:09:54 -0700 Subject: [PATCH 1/2] cli: Assume --kernel if no target is specified cli currently requires one of --kernel, --core or --pid to be specified. Let's assume --kernel so that we can get away with older env(1) which doesn't understand -S option when writing debug scripts which uses drgn as the interpreter. While this is a bit of a kludge, other options aren't useful on the shebang lines anyway given that they need an extra dynamic argument. --- drgn/internal/cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drgn/internal/cli.py b/drgn/internal/cli.py index afb06df22..7e253b823 100644 --- a/drgn/internal/cli.py +++ b/drgn/internal/cli.py @@ -49,8 +49,8 @@ def main() -> None: program_group = parser.add_argument_group( title='program selection', - description='one of the following is required', - ).add_mutually_exclusive_group(required=True) + description='if unspecified --kernel is assumed', + ).add_mutually_exclusive_group() program_group.add_argument( '-c', '--core', metavar='PATH', type=str, help='debug the given core dump') @@ -81,10 +81,10 @@ def main() -> None: prog = drgn.Program() if args.core is not None: prog.set_core_dump(args.core) - elif args.kernel: - prog.set_kernel() - else: + elif args.pid is not None: prog.set_pid(args.pid or os.getpid()) + else: + prog.set_kernel() if args.default_symbols: try: prog.load_default_debug_info() From fa13ad4e9f64cb70e129f509b5ff61556521baca Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Tue, 18 Jun 2019 08:22:06 -0700 Subject: [PATCH 2/2] doc: Drop -k and explanations on env -S cli assumes -k by default now. Drop explicit -k and explanations on env -S. --- docs/user_guide.rst | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/docs/user_guide.rst b/docs/user_guide.rst index 0109f26d7..62d35199e 100644 --- a/docs/user_guide.rst +++ b/docs/user_guide.rst @@ -206,31 +206,20 @@ along with any arguments: pid = int(sys.argv[1]) uid = find_task(prog, pid).cred.uid.val.value_() print(f'PID {pid} is being run by UID {uid}') - $ sudo drgn -k script.py 601 + $ sudo drgn script.py 601 PID 601 is being run by UID 1000 It's even possible to run drgn scripts directly with the proper `shebang `_:: $ cat script2.py - #!/usr/bin/drgn -k + #!/usr/bin/env drgn mounts = prog['init_task'].nsproxy.mnt_ns.mounts.value_() print(f'You have {mounts} filesystems mounted') $ sudo ./script2.py You have 36 filesystems mounted -You usually shouldn't depend on an executable being installed at a specific -absolute path. With newer versions of GNU coreutils (since v8.30), you can -use |env -S|_: - -.. |env -S| replace:: ``env --split-string`` -.. _env -S: https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#g_t_002dS_002f_002d_002dsplit_002dstring-usage-in-scripts - -.. code-block:: sh - - #!/usr/bin/env -S drgn -k - Interactive Mode ^^^^^^^^^^^^^^^^ @@ -268,7 +257,7 @@ In interactive mode, the drgn CLI automatically uses ``str()`` instead of ``repr()`` for objects and types, so you don't need to call ``print()`` explicitly:: - $ sudo drgn -k + $ sudo drgn >>> prog['jiffies'] (volatile unsigned long)4395387628 >>> prog.type('atomic_t')