From 4a939004d66e53fb0a2ccaa3b22653f1804676e6 Mon Sep 17 00:00:00 2001 From: Dreg Date: Tue, 15 Aug 2023 20:30:18 +0200 Subject: [PATCH] revert reg and th order fix #986 --- gef.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/gef.py b/gef.py index 023881259..c8fd7314c 100644 --- a/gef.py +++ b/gef.py @@ -6440,7 +6440,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([int(a) for a in argv]) + tids = self.check_thread_ids(argv) else: tids = [current_thread.num] @@ -6523,9 +6523,21 @@ def find_tcache() -> int: @staticmethod def check_thread_ids(tids: List[int]) -> List[int]: - """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) + """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) @staticmethod def tcachebin(tcache_base: int, i: int) -> Tuple[Optional[GlibcTcacheChunk], int]: @@ -6772,11 +6784,11 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: args : argparse.Namespace = kwargs["arguments"] if args.registers and args.registers[0]: - requested_regs = set(args.registers) - valid_regs = set(gef.arch.all_registers) & requested_regs + required_regs = set(args.registers) + valid_regs = [reg for reg in gef.arch.all_registers if reg in required_regs] if valid_regs: regs = valid_regs - invalid_regs = requested_regs - valid_regs + invalid_regs = [reg for reg in required_regs if reg not in valid_regs] if invalid_regs: err(f"invalid registers for architecture: {', '.join(invalid_regs)}") @@ -7358,7 +7370,7 @@ def context_regs(self) -> None: if self["show_registers_raw"] is False: regs = set(gef.arch.all_registers) - printable_registers = " ".join(regs - ignored_registers) + printable_registers = " ".join(list(regs - ignored_registers)) gdb.execute(f"registers {printable_registers}") return