MCPcopy Index your code
hub / github.com/python/cpython / run_gdb

Function run_gdb

Lib/test/test_gdb/util.py:33–72  ·  view source on GitHub ↗

Runs gdb in --batch mode with the additional arguments given by *args. Returns its (stdout, stderr) decoded from utf-8 using the replace handler.

(*args, exitcode=0, check=True, **env_vars)

Source from the content-addressed store, hash-verified

31GDB_VERSION = (0, 0)
32
33def run_gdb(*args, exitcode=0, check=True, **env_vars):
34 """Runs gdb in --batch mode with the additional arguments given by *args.
35
36 Returns its (stdout, stderr) decoded from utf-8 using the replace handler.
37 """
38 env = clean_environment()
39 if env_vars:
40 env.update(env_vars)
41
42 cmd = [GDB_PROGRAM,
43 # Batch mode: Exit after processing all the command files
44 # specified with -x/--command
45 '--batch',
46 # -nx: Do not execute commands from any .gdbinit initialization
47 # files (gh-66384)
48 '-nx']
49 if GDB_VERSION >= (7, 4):
50 cmd.extend(('--init-eval-command',
51 f'add-auto-load-safe-path {CHECKOUT_HOOK_PATH}'))
52 cmd.extend(args)
53
54 proc = subprocess.run(
55 cmd,
56 # Redirect stdin to prevent gdb from messing with the terminal settings
57 stdin=subprocess.PIPE,
58 stdout=subprocess.PIPE,
59 stderr=subprocess.PIPE,
60 encoding="utf8", errors="backslashreplace",
61 env=env)
62
63 stdout = proc.stdout
64 stderr = proc.stderr
65 if check and proc.returncode != exitcode:
66 cmd_text = shlex.join(cmd)
67 raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
68 f"expected exit code {exitcode}:\n"
69 f"stdout={stdout!r}\n"
70 f"stderr={stderr!r}")
71
72 return (stdout, stderr)
73
74
75def get_gdb_version():

Callers 5

gdb_has_frame_selectFunction · 0.85
test_stringsMethod · 0.85
get_gdb_versionFunction · 0.85
check_usable_gdbFunction · 0.85
get_stack_traceMethod · 0.85

Calls 5

clean_environmentFunction · 0.85
updateMethod · 0.45
extendMethod · 0.45
runMethod · 0.45
joinMethod · 0.45

Tested by 2

gdb_has_frame_selectFunction · 0.68
test_stringsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…