• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 23376593730

21 Mar 2026 09:19AM UTC coverage: 73.671% (-0.2%) from 73.904%
23376593730

push

github

Arusekk
doctests

3880 of 6530 branches covered (59.42%)

0 of 1 new or added line in 1 file covered. (0.0%)

2802 existing lines in 106 files now uncovered.

13386 of 18170 relevant lines covered (73.67%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.23
/pwnlib/commandline/debug.py
1
import argparse
1✔
2
import sys
1✔
3

4
from pwn import *
1✔
5
from pwnlib.commandline import common
1✔
6

7
parser = common.parser_commands.add_parser(
1✔
8
    'debug',
9
    help = 'Debug a binary in GDB',
10
    description = 'Debug a binary in GDB'
11
)
12
parser.add_argument(
1✔
13
    '-x', metavar='GDBSCRIPT',
14
    type=argparse.FileType('r'),
15
    help='Execute GDB commands from this file.'
16
)
17
parser.add_argument(
1✔
18
    '--pid',
19
    type=int,
20
    help="PID to attach to"
21
)
22
parser.add_argument(
1✔
23
    '-c', '--context',
24
    metavar = 'context',
25
    action = 'append',
26
    type   = common.context_arg,
27
    choices = common.choices,
28
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
29
)
30
parser.add_argument(
1✔
31
    '--exec',
32

33
    # NOTE: Type cannot be "file" because we may be referring to a remote
34
    #       file, or a file on an Android device.
35
    type=str,
36

37
    dest='executable',
38
    help='File to debug'
39
)
40
parser.add_argument(
1✔
41
    '--process', metavar='PROCESS_NAME',
42
    help='Name of the process to attach to (e.g. "bash")'
43
)
44
parser.add_argument(
1✔
45
    '--sysroot', metavar='SYSROOT',
46
    type=str,
47
    default='',
48
    help="GDB sysroot path"
49
)
50

51
def main(args):
1✔
UNCOV
52
    gdbscript = ''
×
UNCOV
53
    if args.x:
×
UNCOV
54
        gdbscript = args.x.read()
×
55

56
    if context.os == 'android':
×
57
        context.device = adb.wait_for_device()
×
58

59
    if args.executable:
×
60
        if os.path.exists(args.executable):
×
UNCOV
61
            context.binary = ELF(args.executable)
×
62
            target = context.binary.path
×
63

64
        # This path does nothing, but avoids the "print_usage()"
65
        # path below.
UNCOV
66
        elif context.os == 'android':
×
UNCOV
67
            target = args.executable
×
UNCOV
68
    elif args.pid:
×
69
        target = int(args.pid)
×
70
    elif args.process:
×
71
        if context.os == 'android':
×
72
            target = adb.pidof(args.process)
×
73
        else:
74
            target = pidof(args.process)
×
75

76
        # pidof() returns a list
77
        if not target:
×
UNCOV
78
            log.error("Could not find a PID for %r", args.process)
×
79

80
        target = target[0]
×
81

82
        # pidof will sometimes return all PIDs, including init
83
        if target == 1:
×
UNCOV
84
            log.error("Got PID 1 from pidof.  Check the process name, or use --pid 1 to debug init")
×
85
    else:
86
        parser.print_usage()
×
87
        return 1
×
88

89
    if args.pid or args.process:
×
90
        pid = gdb.attach(target, gdbscript=gdbscript, sysroot=args.sysroot)
×
91

92
        # Since we spawned the gdbserver process, and process registers an
93
        # atexit handler to close itself, gdbserver will be terminated when
94
        # we exit.  This will manifest as a "remote connected ended" or
95
        # similar error message.  Hold it open for the user.
UNCOV
96
        log.info("GDB connection forwarding will terminate when you press enter")
×
UNCOV
97
        pause()
×
98
    else:
99
        gdb.debug(target, gdbscript=gdbscript, sysroot=args.sysroot).interactive()
×
100

101
if __name__ == '__main__':
1!
102
    pwnlib.commandline.common.main(__file__, main)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc