]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: LoongArch: Implement the get_syscall_number gdbarch method
authorTiezhu Yang <yangtiezhu@loongson.cn>
Wed, 31 Jan 2024 08:10:30 +0000 (16:10 +0800)
committerTiezhu Yang <yangtiezhu@loongson.cn>
Tue, 6 Feb 2024 10:40:40 +0000 (18:40 +0800)
In the current code, the feature 'catch syscall' is not supported
on LoongArch, implement the "get_syscall_number" gdbarch method to
get the system call number from the register a7.

Without this patch:

(gdb) catch syscall
The feature 'catch syscall' is not supported on this architecture yet.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
gdb/loongarch-linux-tdep.c

index 0e82c09b4ff23530bd36fae91c623bf44555cd5b..f1471d53ff4cb937f2a9bab51c4c19fd07a083bf 100644 (file)
@@ -534,6 +534,31 @@ loongarch_linux_syscall_next_pc (frame_info_ptr frame)
   return pc + 4;
 }
 
+/* Implement the "get_syscall_number" gdbarch method.  */
+
+static LONGEST
+loongarch_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
+{
+  struct regcache *regcache = get_thread_regcache (thread);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  int regsize = register_size (gdbarch, LOONGARCH_A7_REGNUM);
+  /* The content of a register.  */
+  gdb_byte buf[8];
+  /* The result.  */
+  LONGEST ret;
+
+  gdb_assert (regsize <= sizeof (buf));
+
+  /* Getting the system call number from the register.
+     When dealing with the LoongArch architecture, this information
+     is stored at the a7 register.  */
+  regcache->cooked_read (LOONGARCH_A7_REGNUM, buf);
+
+  ret = extract_signed_integer (buf, regsize, byte_order);
+
+  return ret;
+}
+
 /* Initialize LoongArch Linux ABI info.  */
 
 static void
@@ -564,6 +589,9 @@ loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_iterate_over_regset_sections (gdbarch, loongarch_iterate_over_regset_sections);
 
   tdep->syscall_next_pc = loongarch_linux_syscall_next_pc;
+
+  /* Get the syscall number from the arch's register.  */
+  set_gdbarch_get_syscall_number (gdbarch, loongarch_linux_get_syscall_number);
 }
 
 /* Initialize LoongArch Linux target support.  */