Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't jump to source after commands that don't progress the program #214

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/gdb_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ def __init__(self):
self.thrd = None
self.fallback_to_parsing = False
self.state = "stopped"
self.exited_or_ran = False

def handle_continue(event):
self.state = "running"
self.exited_or_ran = True
gdb.events.cont.connect(handle_continue)
def handle_stop(event):
self.state = "stopped"
def handle_exit(event):
self.state = "stopped"
self.exited_or_ran = True
gdb.events.stop.connect(handle_stop)
gdb.events.exited.connect(handle_stop)
gdb.events.exited.connect(handle_exit)

def invoke(self, arg, from_tty):
if not self.thrd:
Expand Down Expand Up @@ -84,6 +89,9 @@ def _handle_command(self, command, sock, addr):
elif request == "get-current-frame-location":
self._send_response(self._get_current_frame_location(),
req_id, sock, addr)
elif request == "has-exited-or-ran":
self._send_response(self._get_reset_exited_or_ran(),
req_id, sock, addr)
elif request == "handle-command":
# pylint: disable=broad-except
try:
Expand Down Expand Up @@ -119,6 +127,12 @@ def _send_response(self, response, req_id, sock, addr):
def _get_process_state(self):
return self.state

def _get_reset_exited_or_ran(self):
if (self.exited_or_ran):
self.exited_or_ran = False
return True
return False

def _get_current_frame_location(self):
try:
frame = gdb.selected_frame()
Expand Down
10 changes: 9 additions & 1 deletion lua/nvimgdb/backend/gdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function C.create_parser(actions, proxy)
local self = setmetatable({}, P)
self:_init(actions)

P.prev_fname = nil
P.prev_line = nil

function P:query_paused()
log.debug({"P:query_paused"})
coroutine.resume(coroutine.create(function()
Expand All @@ -40,7 +43,12 @@ function C.create_parser(actions, proxy)
if #location == 2 then
local fname = location[1]
local line = location[2]
self.actions:jump_to_source(fname, line)
if (fname ~= self.prev_fname or line ~= self.prev_line) or
proxy:query('has-exited-or-ran') then
self.prev_line = line
self.prev_fname = fname
self.actions:jump_to_source(fname, line)
end
end
end
self.actions:query_breakpoints()
Expand Down
Loading