Skip to content

Commit

Permalink
Fix cpu at 100% spinning bug (#72)
Browse files Browse the repository at this point in the history
Pygdbmis new API with multilevel timeout allows us to not spin at 100%
when waiting for responses, while not experience a performance degration
at the same time.
  • Loading branch information
mariusmue authored Feb 9, 2021
1 parent 90547c1 commit c392248
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions avatar2/protocols/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def run(self):

try:
responses = self._gdb_controller.get_gdb_response(
timeout_sec=0.0
timeout_sec=0.01
)
except:
continue
Expand Down Expand Up @@ -267,15 +267,16 @@ def __init__(
if local_arguments is not None:
gdb_args += [local_arguments]


if sys.version_info <= (3, 5):
self._gdbmi = pygdbmi.gdbcontroller.GdbController(
gdb_path=gdb_executable,
gdb_args=gdb_args,
verbose=verbose) # set to True for debugging
else:
self._gdbmi = pygdbmi.gdbcontroller.GdbController(
command=[gdb_executable] + gdb_args)
command=[gdb_executable] + gdb_args,
time_to_check_for_additional_output_sec=0)
queue = avatar.queue if avatar is not None else None
fast_queue = avatar.fast_queue if avatar is not None else None
self._communicator = GDBResponseListener(
Expand Down Expand Up @@ -386,7 +387,7 @@ def remote_connect(self, ip='127.0.0.1', port=3333):
if not ret:
self.log.critical("GDBProtocol was unable to connect to remote target")
raise Exception("GDBProtocol was unable to connect")

self.update_target_regs()

return ret
Expand Down Expand Up @@ -591,7 +592,7 @@ def set_syscall_cachpoint(self, syscall):
self.log.warning("Couldn't extract bp_num for catchpoint!")
return True
return int(expected_bp_num)




Expand Down Expand Up @@ -650,7 +651,7 @@ def read_memory(self, address, wordsize=4, num_words=1, raw=False):
"""reads memory
:param address: Address to write to
:param wordsize: the size of a read word (1, 2, 4 or 8)
:param wordsize: the size of a read word (1, 2, 4 or 8)
:param num_words: the amount of read words
:param raw: Whether the read memory should be returned unprocessed
:return: The read memory
Expand Down Expand Up @@ -693,7 +694,7 @@ def read_register(self, reg):
return self._read_special_reg_from_name(reg)
else:
reg_nr = (
self._origin.regs._get_nr_from_name(reg)
self._origin.regs._get_nr_from_name(reg)
if hasattr(self._origin, 'regs')
else self._arch.registers[reg])
return self.read_register_from_nr(reg_nr)
Expand Down Expand Up @@ -747,7 +748,7 @@ def write_register(self, reg, value):

fmt = "{:s}=" \
+ self._arch.special_registers[reg]['format'].replace(' ','')

ret, resp = self._sync_request(
["-data-evaluate-expression", fmt.format(
self._arch.special_registers[reg]['gdb_expression'], *value)
Expand Down

0 comments on commit c392248

Please sign in to comment.