Skip to content

Commit

Permalink
Fix #201: track the state of the inferior with events
Browse files Browse the repository at this point in the history
  • Loading branch information
sakhnik committed Oct 2, 2023
1 parent 5b5dc35 commit 78bf4df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/gdb_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def __init__(self):
self.quit = True
self.thrd = None
self.fallback_to_parsing = False
self.state = "stopped"

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

def invoke(self, arg, from_tty):
if not self.thrd:
Expand Down Expand Up @@ -108,17 +117,7 @@ def _send_response(self, response, req_id, sock, addr):
sock.sendto(response_json, 0, addr)

def _get_process_state(self):
try:
inferior = gdb.selected_inferior()
if inferior.is_valid():
threads = inferior.threads()
is_running = any((t.is_valid() and t.is_running()
for t in threads))
state = "running" if is_running else "stopped"
return state
except gdb.error:
...
return "other"
return self.state

def _get_current_frame_location(self):
try:
Expand Down
1 change: 1 addition & 0 deletions lua/nvimgdb/backend/gdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function C.create_parser(actions, proxy)
self:_init(actions)

function P:query_paused()
log.debug({"P:query_paused"})
coroutine.resume(coroutine.create(function()
local process_state = proxy:query('get-process-state')
log.debug({"process state", process_state})
Expand Down

0 comments on commit 78bf4df

Please sign in to comment.