@@ -155,18 +155,23 @@ def handle_exclaim(subcmd: str) -> Reply:
155155
156156
157157 def handle_qmark (subcmd : str ) -> Reply :
158+ """Request status.
159+
160+ @see: https://sourceware.org/gdb/current/onlinedocs/gdb/Stop-Reply-Packets.html
161+ """
162+
158163 from unicorn .x86_const import UC_X86_REG_EBP
159164 from unicorn .x86_const import UC_X86_REG_RBP
160165 from unicorn .arm_const import UC_ARM_REG_R11
161166 from unicorn .arm64_const import UC_ARM64_REG_X29
162- from unicorn .mips_const import UC_MIPS_REG_29
167+ from unicorn .mips_const import UC_MIPS_REG_INVALID
163168
164169 arch_uc_bp = {
165170 QL_ARCH .X86 : UC_X86_REG_EBP ,
166171 QL_ARCH .X8664 : UC_X86_REG_RBP ,
167172 QL_ARCH .ARM : UC_ARM_REG_R11 ,
168173 QL_ARCH .ARM64 : UC_ARM64_REG_X29 ,
169- QL_ARCH .MIPS : UC_MIPS_REG_29 ,
174+ QL_ARCH .MIPS : UC_MIPS_REG_INVALID , # skipped
170175 QL_ARCH .A8086 : UC_X86_REG_EBP ,
171176 QL_ARCH .CORTEX_M : UC_ARM_REG_R11
172177 }[self .ql .arch .type ]
@@ -179,20 +184,23 @@ def __get_reg_idx(ucreg: int) -> int:
179184
180185 return next ((i for i , (regnum , _ , _ ) in enumerate (self .regsmap ) if regnum == ucreg ), - 1 )
181186
182- # FIXME: a8086 should use 'esp' and 'eip' here instead of 'sp' and 'ip' set by its arch instance
183- bp_idx = __get_reg_idx (arch_uc_bp )
184- sp_idx = __get_reg_idx (self .ql .arch .regs .uc_sp )
185- pc_idx = __get_reg_idx (self .ql .arch .regs .uc_pc )
187+ def __get_reg_info (ucreg : int ) -> str :
188+ """Retrieve register info and pack it as a pair.
189+ """
190+
191+ regnum = __get_reg_idx (ucreg )
192+ hexval = __get_reg_value (* self .regsmap [regnum ])
186193
187- bp_val = __get_reg_value (* self .regsmap [bp_idx ])
188- sp_val = __get_reg_value (* self .regsmap [sp_idx ])
189- pc_val = __get_reg_value (* self .regsmap [pc_idx ])
194+ return f'{ regnum :02x} :{ hexval } ;'
190195
191- bp_info = f'{ bp_idx :02x} :{ bp_val } ;'
192- sp_info = f'{ sp_idx :02x} :{ sp_val } ;'
193- pc_info = f'{ pc_idx :02x} :{ pc_val } ;'
196+ # mips targets skip this reg info pair
197+ bp_info = '' if self .ql .arch .type == QL_ARCH .MIPS else __get_reg_info (arch_uc_bp )
198+
199+ # FIXME: a8086 should use 'esp' and 'eip' here instead of 'sp' and 'ip' set by its arch instance
200+ sp_info = __get_reg_info (self .ql .arch .regs .uc_sp )
201+ pc_info = __get_reg_info (self .ql .arch .regs .uc_pc )
194202
195- return f'T{ SIGTRAP :02x} { "" if self . ql . arch . type == QL_ARCH . MIPS else bp_info } { sp_info } { pc_info } '
203+ return f'T{ SIGTRAP :02x} { bp_info } { sp_info } { pc_info } '
196204
197205
198206 def handle_c (subcmd : str ) -> Reply :
0 commit comments