Skip to content

Commit

Permalink
Small cleanup - sets
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed Jul 22, 2023
1 parent 9170ac0 commit 5fd2387
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6412,11 +6412,12 @@ def do_invoke(self, argv: List[str]) -> None:

# As a nicety, we want to display threads in ascending order by gdb number
threads = sorted(gdb.selected_inferior().threads(), key=lambda t: t.num)
# existing_tids = [t.num for t in gdb.selected_inferior().threads()]
if argv:
if "all" in argv:
tids = [t.num for t in threads]
else:
tids = self.check_thread_ids(argv)
tids = self.check_thread_ids([int(a) for a in argv])
else:
tids = [current_thread.num]

Expand Down Expand Up @@ -6499,21 +6500,9 @@ def find_tcache() -> int:

@staticmethod
def check_thread_ids(tids: List[int]) -> List[int]:
"""Check the validity, dedup, and return all valid tids."""
existing_tids = [t.num for t in gdb.selected_inferior().threads()]
valid_tids = set()
for tid in tids:
try:
tid = int(tid)
except ValueError:
err(f"Invalid thread id {tid:d}")
continue
if tid in existing_tids:
valid_tids.add(tid)
else:
err(f"Unknown thread {tid}")

return list(valid_tids)
"""Return the subset of tids that are currently valid."""
existing_tids = set(t.num for t in gdb.selected_inferior().threads())
return list(set(tids) & existing_tids)

@staticmethod
def tcachebin(tcache_base: int, i: int) -> Tuple[Optional[GlibcTcacheChunk], int]:
Expand Down Expand Up @@ -6760,11 +6749,11 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None:

args : argparse.Namespace = kwargs["arguments"]
if args.registers and args.registers[0]:
required_regs = set(args.registers)
valid_regs = [reg for reg in gef.arch.all_registers if reg in required_regs]
requested_regs = set(args.registers)
valid_regs = set(gef.arch.all_registers) & requested_regs
if valid_regs:
regs = valid_regs
invalid_regs = [reg for reg in required_regs if reg not in valid_regs]
invalid_regs = requested_regs - valid_regs
if invalid_regs:
err(f"invalid registers for architecture: {', '.join(invalid_regs)}")

Expand Down Expand Up @@ -7346,7 +7335,7 @@ def context_regs(self) -> None:

if self["show_registers_raw"] is False:
regs = set(gef.arch.all_registers)
printable_registers = " ".join(list(regs - ignored_registers))
printable_registers = " ".join(regs - ignored_registers)
gdb.execute(f"registers {printable_registers}")
return

Expand Down Expand Up @@ -9596,10 +9585,10 @@ def add_context_pane(self, pane_name: str, display_pane_function: Callable, pane

def load(self) -> None:
"""Load all the commands and functions defined by GEF into GDB."""
current_commands = set( self.commands.keys() )
new_commands = set( [x._cmdline_ for x in __registered_commands__] ) - current_commands
current_functions = set( self.functions.keys() )
new_functions = set([x._function_ for x in __registered_functions__]) - current_functions
current_commands = set(self.commands.keys())
new_commands = set(x._cmdline_ for x in __registered_commands__) - current_commands
current_functions = set(self.functions.keys())
new_functions = set(x._function_ for x in __registered_functions__) - current_functions
self.missing.clear()
self.__load_time_ms = time.time()* 1000

Expand Down

0 comments on commit 5fd2387

Please sign in to comment.