removed a print and added another
[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
43 clientcmd = vim.eval("input('Client commando: ', '%s')" % clientcmd)
44 gdbterm, mainctrlwnd, statuswnd = pygdb.launchDebugger(clientcmd, False)
45
46 for bp in gdbBps:
47 statuswnd.breakpointsFrame.addBreakpoint(bp["file"], bp["lineno"], bp["cond"])
48
49 print "Started dbg session."
50 gtk.main()
51 print "Finished dbg session."
52
53
54 def gdbToggleBreakpoint(lineno=None, file=None):
55 global gdbBps
56
57 #Set lineno and file if not already set
58 if lineno==None:
59 lineno = vim.current.window.cursor[0]
60 if file==None:
61 file = vim.current.window.buffer.name
62
63 #Determine index of breakpoint
64 bpidx = gdbGetBreakpoint( file, lineno )
65
66 #Remove the breakpoint
67 if bpidx != None:
68 vim.command("sign unplace %(signnum)d" % gdbBps[bpidx])
69 del gdbBps[bpidx]
70
71 #Create the breakpoint
72 else:
73 #Determine a sign number
74 signnum = gdbNewSignnum()
75
76 #Create breakpoint and add sign
77 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : None}
78 vim.command("sign place %(signnum)d line=%(lineno)d name=BreakPoint file=%(file)s" % b)
79 gdbBps += [b]
80
81
82 def gdbBreakpointCond(lineno=None, file=None, cond=None):
83 global gdbBps
84
85 #Set lineno and file if not already set
86 if lineno==None:
87 lineno = vim.current.window.cursor[0]
88 if file==None:
89 file = vim.current.window.buffer.name
90
91 #Determine index of breakpoint
92 bpidx = gdbGetBreakpoint( file, lineno )
93
94 #Remove the breakpoint
95 if bpidx != None:
96 if cond == None:
97 cond = vim.eval("input('Breakpoint condition: ', '%s')" % gdbBps[bpidx]["cond"])
98 gdbBps[bpidx]["cond"] = cond
99
100 else:
101 #Determine a sign number
102 signnum = gdbNewSignnum()
103
104 #Get condition
105 if cond == None:
106 cond = vim.eval("input('Breakpoint condition: ', '')")
107
108 #Create breakpoint and add sign
109 b = {"signnum" : signnum, "lineno" : lineno, "file" : file, "cond" : cond}
110 vim.command("sign place %(signnum)d line=%(lineno)d name=CondBreakPoint file=%(file)s" % b)
111 gdbBps += [b]
112
113
114 def gdbNewSignnum():
115 global signnum
116 signnum += 1
117 return signnum
118
119
120 def gdbGetBreakpoint(file, lineno):
121 for i in range(len(gdbBps)):
122 if [gdbBps[i]["file"], gdbBps[i]["lineno"]] == [file,lineno]:
123 return i
124 return None
125
126
127 >>
128
129
130 highlight ExecutionLine term=bold ctermbg=DarkGreen ctermfg=White
131 highlight BreakPoint term=inverse ctermbg=DarkCyan ctermfg=Black
132
133 sign define ExecutionLine text==> texthl=ExecutionLine linehl=ExecutionLine
134 sign define BreakPoint text=! texthl=BreakPoint linehl=BreakPoint
135 sign define CondBreakPoint text=? texthl=BreakPoint linehl=BreakPoint
136
137
138
139 command! GDBLaunch :python gdbLaunch()
140 command! GDBToggleBreakpoint :python gdbToggleBreakpoint()
141 command! GDBBreakpointCond :python gdbBreakpointCond()
142
143
144
145 function! GDBMapDefaults()
146 nmap <silent> <F5> :GDBLaunch<CR>
147 nmap <silent> <F8> :GDBToggleBreakpoint<CR>
148 nmap <silent> <F9> :GDBBreakpointCond<CR>
149 endfunction
150
151
152
153 endif
154
155