- fixing problem of destroying windows -> segfault
[pygdb.git] / pygdb.vim
1 "shuber, 2008-06-08
2
3 if ! exists("g:pygdb")
4
5 let g:pygdb = 1
6 let s:ScriptLocation = expand("<sfile>")
7
8
9 python << >>
10
11 import gtk
12 import string
13 import sys
14 import threading
15
16 import vim
17
18 #Do not use a ~ for home directory
19 sys.path.append("/home/shuber/projekte/pygdb/")
20
21 import pygdb
22 import GdbTerminal
23 import MainControlWindow
24 import StatusWindow
25
26
27 #Breakpoint positions: List of dictionaries of form {"signnum" : , "file" : , "lineno":, "cond" : }
28 gdbBps = []
29 signnum = 0
30 clientcmd = ""
31
32 gdbterm = None
33 mainctrlwnd = None
34 statuswnd = None
35 gdbthread = None
36
37
38
39 def gdbLaunch():
40 global gdbterm, mainctrlwnd, statuswnd, gdbBps, clientcmd, gdbthread
41
42 if gdbterm == None:
43
44 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd)
45
46 gdbterm, mainctrlwnd, statuswnd = pygdb.launchDebugger(clientcmd, False)
47
48 for bp in gdbBps:
49 statuswnd.breakpointsFrame.addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
50
51 gtk.main()
52 gdbterm = None
53
54
55 def gdbToggleBreakpoint(lineno=None, file=None):
56 global gdbBps
57
58 #Set lineno and file if not already set
59 if lineno==None:
60 lineno = vim.current.window.cursor[0]
61 if file==None:
62 file = vim.current.window.buffer.name
63
64 #Determine index of breakpoint
65 bpidx = gdbGetBreakpoint( file, lineno )
66
67 #Remove the breakpoint
68 if bpidx != None:
69 vim.command("sign unplace %(signnum)d" % gdbBps[bpidx])
70 del gdbBps[bpidx]
71
72 #Create the breakpoint
73 else:
74 #Determine a sign number
75 signnum = gdbNewSignnum()
76
77 #Create breakpoint and add sign
78 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : None}
79 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
80 gdbBps += [b]
81
82
83 def gdbBreakpointCond(lineno=None, file=None, cond=None):
84 global gdbBps
85
86 #Set lineno and file if not already set
87 if lineno==None:
88 lineno = vim.current.window.cursor[0]
89 if file==None:
90 file = vim.current.window.buffer.name
91
92 #Determine index of breakpoint
93 bpidx = gdbGetBreakpoint( file, lineno )
94
95 #Remove the breakpoint
96 if bpidx != None:
97 if cond == None:
98 cond = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
99 gdbBps[bpidx]["cond"] = cond
100
101 else:
102 #Determine a sign number
103 signnum = gdbNewSignnum()
104
105 #Get condition
106 if cond == None:
107 cond = vim.eval("input('Breakpoint condition: ', '')")
108
109 #Create breakpoint and add sign
110 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
111 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
112 gdbBps += [b]
113
114
115 def gdbNewSignnum():
116 global signnum
117 signnum += 1
118 return signnum
119
120
121 def gdbGetBreakpoint(file, lineno):
122 for i in range(len(gdbBps)):
123 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
124 return i
125 return None
126
127
128 >>
129
130
131 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=White
132 highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black
133
134 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
135 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
136 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
137
138
139
140 command! GDBLaunch :python gdbLaunch()
141 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
142 command! GDBBreakpointCond :python gdbBreakpointCond()
143
144
145
146 function! GDBMapDefaults()
147 nmap <silent> <F5> :GDBLaunch<CR>
148 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
149 nmap <silent> <F9> :GDBBreakpointCond<CR>
150 endfunction
151
152
153
154 endif
155
156