Skip to content

Commit 936f3ff

Browse files
authored
Merge pull request #214 from Charlie-83/master
Don't jump to source after commands that don't progress the program
2 parents a8a5289 + 710e294 commit 936f3ff

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

lib/gdb_commands.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ def __init__(self):
2929
self.thrd = None
3030
self.fallback_to_parsing = False
3131
self.state = "stopped"
32+
self.exited_or_ran = False
3233

3334
def handle_continue(event):
3435
self.state = "running"
36+
self.exited_or_ran = True
3537
gdb.events.cont.connect(handle_continue)
3638
def handle_stop(event):
3739
self.state = "stopped"
40+
def handle_exit(event):
41+
self.state = "stopped"
42+
self.exited_or_ran = True
3843
gdb.events.stop.connect(handle_stop)
39-
gdb.events.exited.connect(handle_stop)
44+
gdb.events.exited.connect(handle_exit)
4045

4146
def invoke(self, arg, from_tty):
4247
if not self.thrd:
@@ -84,6 +89,9 @@ def _handle_command(self, command, sock, addr):
8489
elif request == "get-current-frame-location":
8590
self._send_response(self._get_current_frame_location(),
8691
req_id, sock, addr)
92+
elif request == "has-exited-or-ran":
93+
self._send_response(self._get_reset_exited_or_ran(),
94+
req_id, sock, addr)
8795
elif request == "handle-command":
8896
# pylint: disable=broad-except
8997
try:
@@ -119,6 +127,12 @@ def _send_response(self, response, req_id, sock, addr):
119127
def _get_process_state(self):
120128
return self.state
121129

130+
def _get_reset_exited_or_ran(self):
131+
if (self.exited_or_ran):
132+
self.exited_or_ran = False
133+
return True
134+
return False
135+
122136
def _get_current_frame_location(self):
123137
try:
124138
frame = gdb.selected_frame()

lua/nvimgdb/backend/gdb.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ function C.create_parser(actions, proxy)
2929
local self = setmetatable({}, P)
3030
self:_init(actions)
3131

32+
P.prev_fname = nil
33+
P.prev_line = nil
34+
3235
function P:query_paused()
3336
log.debug({"P:query_paused"})
3437
coroutine.resume(coroutine.create(function()
@@ -40,7 +43,12 @@ function C.create_parser(actions, proxy)
4043
if #location == 2 then
4144
local fname = location[1]
4245
local line = location[2]
43-
self.actions:jump_to_source(fname, line)
46+
if (fname ~= self.prev_fname or line ~= self.prev_line) or
47+
proxy:query('has-exited-or-ran') then
48+
self.prev_line = line
49+
self.prev_fname = fname
50+
self.actions:jump_to_source(fname, line)
51+
end
4452
end
4553
end
4654
self.actions:query_breakpoints()

0 commit comments

Comments
 (0)