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

Small cleanup - sets #972

Merged
merged 1 commit into from
Jul 22, 2023
Merged
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
36 changes: 12 additions & 24 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6416,7 +6416,7 @@ def do_invoke(self, argv: List[str]) -> None:
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])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a list of strings before, which didn't follow the type hint for check_thread_ids.

else:
tids = [current_thread.num]

Expand Down Expand Up @@ -6499,21 +6499,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 +6748,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 +7334,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 +9584,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
Loading