<commit_before># SPDX-License-Identifier: BSD-2-Clause
# pylint: disable=unused-wildcard-import

import gdb # pylint: disable=import-error
from . import base_utils as bu

fixhex16 = bu.fixhex16
fixhex32 = bu.fixhex32

class printer_regs:

   def __init__(self, val):
      self.val = val

   def to_string(self):
      r = self.val
      return "(struct x86_regs *) {}".format(fixhex32(int(r.address)))

   def children(self):

      r = self.val
      resume_eip = gdb.parse_and_eval(
         "(void *){}".format(r["kernel_resume_eip"])
      )

      eip = r["eip"]
      eip_str = None

      if eip < bu.config.KERNEL_BASE_VA:
         eip_str = fixhex32(r["eip"])
      else:
         eip_str = gdb.parse_and_eval(
         "(void *){}".format(eip)
      )

      cs = r["cs"] & 0xffff
      ds = r["ds"] & 0xffff
      ss = r["ss"] & 0xffff
      es = r["es"] & 0xffff
      fs = r["fs"] & 0xffff
      gs = r["gs"] & 0xffff

      return [
         ("resume_eip  ", resume_eip),
         ("custom_flags", fixhex32(r["custom_flags"])),
         ("gs          ", fixhex16(gs)),
         ("es          ", fixhex16(es)),
         ("ds          ", fixhex16(ds)),
         ("fs          ", fixhex16(fs)),
         ("edi         ", fixhex32(r["edi"])),
         ("esi         ", fixhex32(r["esi"])),
         ("ebp         ", fixhex32(r["ebp"])),
         ("esp         ", fixhex32(r["esp"])),
         ("ebx         ", fixhex32(r["ebx"])),
         ("edx         ", fixhex32(r["edx"])),
         ("ecx         ", fixhex32(r["ecx"])),
         ("eax         ", fixhex32(r["eax"])),
         ("eip         ", eip_str),
         ("cs          ", fixhex16(cs)),
         ("eflags      ", fixhex32(r["eflags"])),
         ("useresp     ", fixhex32(r["useresp"])),
         ("ss          ", fixhex16(ss)),
      ]


bu.register_tilck_regex_pp(
   'regs_t', '^(regs_t|x86_regs)$', printer_regs
)
<commit_msg>[gdb] Make the regs printer calc the true EIP, when possible<commit_after># SPDX-License-Identifier: BSD-2-Clause
# pylint: disable=unused-wildcard-import

import gdb # pylint: disable=import-error
from . import base_utils as bu

fixhex16 = bu.fixhex16
fixhex32 = bu.fixhex32

class printer_regs:

   def __init__(self, val):
      self.val = val

   def to_string(self):
      r = self.val
      return "(struct x86_regs *) {}".format(fixhex32(int(r.address)))

   def children(self):

      r = self.val
      resume_eip = gdb.parse_and_eval(
         "(void *){}".format(r["kernel_resume_eip"])
      )
      resume_eip_str = str(resume_eip)

      eip = r["eip"]
      eip_str = None

      if eip < bu.config.KERNEL_BASE_VA:
         eip_str = fixhex32(r["eip"])
      else:
         eip_str = gdb.parse_and_eval(
         "(void *){}".format(eip)
      )

      cs = r["cs"] & 0xffff
      ds = r["ds"] & 0xffff
      ss = r["ss"] & 0xffff
      es = r["es"] & 0xffff
      fs = r["fs"] & 0xffff
      gs = r["gs"] & 0xffff

      res = [
         ("resume_eip  ", resume_eip),
         ("custom_flags", fixhex32(r["custom_flags"])),
         ("gs          ", fixhex16(gs)),
         ("es          ", fixhex16(es)),
         ("ds          ", fixhex16(ds)),
         ("fs          ", fixhex16(fs)),
         ("edi         ", fixhex32(r["edi"])),
         ("esi         ", fixhex32(r["esi"])),
         ("ebp         ", fixhex32(r["ebp"])),
         ("esp         ", fixhex32(r["esp"])),
         ("ebx         ", fixhex32(r["ebx"])),
         ("edx         ", fixhex32(r["edx"])),
         ("ecx         ", fixhex32(r["ecx"])),
         ("eax         ", fixhex32(r["eax"])),
         ("int_num     ", r["int_num"]),
         ("err_code    ", fixhex32(r["err_code"])),
         ("eip         ", eip_str),
         ("cs          ", fixhex16(cs)),
         ("eflags      ", fixhex32(r["eflags"])),
      ]

      if resume_eip_str.find("asm_kernel_yield") == -1:
         res += [
            ("useresp     ", fixhex32(r["useresp"])),
            ("ss          ", fixhex16(ss)),
         ]
      else:
         calc_eip = gdb.parse_and_eval("(void *){}".format(r["useresp"]))
         res.append(("[true_eip]  ", calc_eip))

      return res


bu.register_tilck_regex_pp(
   'regs_t', '^(regs_t|x86_regs)$', printer_regs
)

{'fraction_non_alphanumeric': 0.18188268684957426, 'fraction_numerical': 0.027672658467360455, 'mean_word_length': 1.861299052774019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4207762', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1508, 'n_words': 260}