r""" Start GDB in a new terminal and attach to `target`. Arguments: target: The target to attach to. gdbscript(:obj:`str` or :obj:`file`): GDB script to run after attaching. exe(str): The path of the target binary. arch(str): Architechture of the target binar
(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysroot = None, api = False)
| 922 | |
| 923 | @LocalContext |
| 924 | def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysroot = None, api = False): |
| 925 | r""" |
| 926 | Start GDB in a new terminal and attach to `target`. |
| 927 | |
| 928 | Arguments: |
| 929 | target: The target to attach to. |
| 930 | gdbscript(:obj:`str` or :obj:`file`): GDB script to run after attaching. |
| 931 | exe(str): The path of the target binary. |
| 932 | arch(str): Architechture of the target binary. If `exe` known GDB will |
| 933 | detect the architechture automatically (if it is supported). |
| 934 | gdb_args(list): List of additional arguments to pass to GDB. |
| 935 | sysroot(str): Set an alternate system root. The system root is used to |
| 936 | load absolute shared library symbol files. This is useful to instruct |
| 937 | gdb to load a local version of binaries/libraries instead of downloading |
| 938 | them from the gdbserver, which is faster |
| 939 | api(bool): Enable access to GDB Python API. |
| 940 | |
| 941 | Returns: |
| 942 | PID of the GDB process (or the window which it is running in). |
| 943 | When ``api=True``, a (PID, :class:`Gdb`) tuple. |
| 944 | |
| 945 | Notes: |
| 946 | |
| 947 | The ``target`` argument is very robust, and can be any of the following: |
| 948 | |
| 949 | :obj:`int` |
| 950 | PID of a process |
| 951 | :obj:`str` |
| 952 | Process name. The youngest process is selected. |
| 953 | :obj:`tuple` |
| 954 | Host, port pair of a listening ``gdbserver`` |
| 955 | Tries to look up the target exe from the ``gdbserver`` commandline, |
| 956 | requires explicit ``exe`` argument if the target exe is not in the commandline. |
| 957 | :class:`.process` |
| 958 | Process to connect to |
| 959 | :class:`.sock` |
| 960 | Connected socket. The executable on the other end of the connection is attached to. |
| 961 | Can be any socket type, including :class:`.listen` or :class:`.remote`. |
| 962 | :class:`.ssh_channel` |
| 963 | Remote process spawned via :meth:`.ssh.process`. |
| 964 | This will use the GDB installed on the remote machine. |
| 965 | If a password is required to connect, the ``sshpass`` program must be installed. |
| 966 | |
| 967 | Examples: |
| 968 | |
| 969 | Attach to a process by PID |
| 970 | |
| 971 | >>> pid = gdb.attach(1234) # doctest: +SKIP |
| 972 | |
| 973 | Attach to the youngest process by name |
| 974 | |
| 975 | >>> pid = gdb.attach('bash') # doctest: +SKIP |
| 976 | |
| 977 | Attach a debugger to a :class:`.process` tube and automate interaction |
| 978 | |
| 979 | >>> io = process('bash') |
| 980 | >>> pid = gdb.attach(io, gdbscript=''' |
| 981 | ... call puts("Hello from process debugger!") |
no test coverage detected