-
Notifications
You must be signed in to change notification settings - Fork 2
/
gdb-reattach.py
35 lines (28 loc) · 1.15 KB
/
gdb-reattach.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import with_statement
import gdb
class ReattachCommand (gdb.Command):
"""Reattaches the new instance of the previous process.
First argument is the name of executable (enough to specify the first time)"""
def __init__ (self):
self.lastFn = ''
super (ReattachCommand, self).__init__ ("ra",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_FILENAME)
def invoke (self, arg, from_tty):
args = arg.split(' ')
fn = args[0].strip()
if len(fn) > 0:
self.lastFn = fn
if len(self.lastFn) == 0:
print 'You have to specify the name of the process (for pidof) for the first time (it will be cached for later)'
return
try:
pid = check_output(["pidof",self.lastFn]).strip()
except CalledProcessError as e:
if e.returncode == 1:
print 'Process not found :('
else:
raise e
gdb.execute('attach ' + pid)
gdb.execute('c')
ReattachCommand()