public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add an optional "alias" attribute to syscall entries.
  2018-10-03 17:30 [PATCH 0/2] Update FreeBSD's syscall table John Baldwin
@ 2018-10-03 17:30 ` John Baldwin
  2018-10-12  6:13   ` Kevin Buettner
  2018-10-13  1:52   ` Sergio Durigan Junior
  2018-10-03 17:30 ` [PATCH 2/2] Update the FreeBSD system call table to match FreeBSD 12.0 John Baldwin
  1 sibling, 2 replies; 7+ messages in thread
From: John Baldwin @ 2018-10-03 17:30 UTC (permalink / raw)
  To: gdb-patches

When setting a syscall catchpoint by name, catch syscalls whose name
or alias matches the requested string.

When the ABI of a system call is changed in the FreeBSD kernel, this
is implemented by leaving a compatability system call using the old
ABI at the existing "slot" and allocating a new system call for the
version using the new ABI.  For example, new fields were added to the
'struct kevent' used by the kevent() system call in FreeBSD 12.  The
previous kevent() system call in FreeBSD 12 kernels is now called
freebsd11_kevent() and is still used by older binaries compiled
against the older ABI.  The freebsd11_kevent() system call can be
tagged with an "alias" attribute of "kevent" permitting 'catch syscall
kevent' to catch both system calls and providing the expected user
behavior for both old and new binaries.  It also provides the expected
behavior if GDB is compiled on an older host (such as a FreeBSD 11
host).

gdb/ChangeLog:

	* break-catch-syscall.c (catch_syscall_split_args): Update for
	get_syscalls_by_name returning a vector.
	* gdbarch.sh (UNKNOWN_SYSCALL): Remove.
	* gdbarch.h: Regenerate.
	* syscalls/gdb-syscalls.dtd (syscall): Add alias attribute.
	* xml-syscall.c [!HAVE_LIBEXPAT] (get_syscalls_by_name): Rename
	from get_syscall_by_name.  Now returns a vector of integers.
	[HAVE_LIBEXPAT] (struct syscall_desc): Add alias member.
	(syscall_create_syscall_desc): Add alias parameter and pass it to
	syscall_desc constructor.
	(syscall_start_syscall): Handle alias attribute.
	(syscall_attr): Add alias attribute.
	(xml_get_syscalls_by_name): Rename from xml_get_syscall_number.
	Now returns a vector of integers.  Add syscalls whose alias or
	name matches the requested name.
	(get_syscalls_by_name): Rename from get_syscall_by_name.  Now
	returns a vector of integers.
	* xml-syscall.h (get_syscalls_by_name): Likewise.
---
 gdb/ChangeLog                 | 21 +++++++++++++++
 gdb/break-catch-syscall.c     | 11 ++++----
 gdb/gdbarch.h                 |  3 ---
 gdb/gdbarch.sh                |  3 ---
 gdb/syscalls/gdb-syscalls.dtd |  1 +
 gdb/xml-syscall.c             | 49 +++++++++++++++++++----------------
 gdb/xml-syscall.h             |  8 +++---
 7 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e239f201fa..1f679b48ed 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,24 @@
+2018-10-03  John Baldwin  <jhb@FreeBSD.org>
+
+	* break-catch-syscall.c (catch_syscall_split_args): Update for
+	get_syscalls_by_name returning a vector.
+	* gdbarch.sh (UNKNOWN_SYSCALL): Remove.
+	* gdbarch.h: Regenerate.
+	* syscalls/gdb-syscalls.dtd (syscall): Add alias attribute.
+	* xml-syscall.c [!HAVE_LIBEXPAT] (get_syscalls_by_name): Rename
+	from get_syscall_by_name.  Now returns a vector of integers.
+	[HAVE_LIBEXPAT] (struct syscall_desc): Add alias member.
+	(syscall_create_syscall_desc): Add alias parameter and pass it to
+	syscall_desc constructor.
+	(syscall_start_syscall): Handle alias attribute.
+	(syscall_attr): Add alias attribute.
+	(xml_get_syscalls_by_name): Rename from xml_get_syscall_number.
+	Now returns a vector of integers.  Add syscalls whose alias or
+	name matches the requested name.
+	(get_syscalls_by_name): Rename from get_syscall_by_name.  Now
+	returns a vector of integers.
+	* xml-syscall.h (get_syscalls_by_name): Likewise.
+
 2018-10-02  Tom Tromey  <tom@tromey.com>
 
 	* aarch64-linux-tdep.c (aarch64_linux_sigframe_init): Use pulongest.
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 93ef74c249..e9e370f4bf 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -431,18 +431,19 @@ catch_syscall_split_args (const char *arg)
 	}
       else
 	{
-	  /* We have a name.  Let's check if it's valid and convert it
-	     to a number.  */
-	  get_syscall_by_name (gdbarch, cur_name, &s);
+	  /* We have a name.  Let's check if it's valid and fetch a
+	     list of matching numbers.  */
+	  std::vector<int> numbers = get_syscalls_by_name (gdbarch, cur_name);
 
-	  if (s.number == UNKNOWN_SYSCALL)
+	  if (numbers.empty ())
 	    /* Here we have to issue an error instead of a warning,
 	       because GDB cannot do anything useful if there's no
 	       syscall number to be caught.  */
 	    error (_("Unknown syscall name '%s'."), cur_name);
 
 	  /* Ok, it's valid.  */
-	  result.push_back (s.number);
+	  for (int number : numbers)
+	    result.push_back (number);
 	}
     }
 
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index fc2f1a84a1..6b7afe4a5c 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1569,9 +1569,6 @@ typedef ULONGEST (gdbarch_type_align_ftype) (struct gdbarch *gdbarch, struct typ
 extern ULONGEST gdbarch_type_align (struct gdbarch *gdbarch, struct type *type);
 extern void set_gdbarch_type_align (struct gdbarch *gdbarch, gdbarch_type_align_ftype *type_align);
 
-/* Definition for an unknown syscall, used basically in error-cases.  */
-#define UNKNOWN_SYSCALL (-1)
-
 extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
 
 
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 670ac30c03..ee74acfd2a 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1393,9 +1393,6 @@ done
 # close it off
 cat <<EOF
 
-/* Definition for an unknown syscall, used basically in error-cases.  */
-#define UNKNOWN_SYSCALL (-1)
-
 extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
 
 
diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd
index c2aa478aa4..6aa73f288a 100644
--- a/gdb/syscalls/gdb-syscalls.dtd
+++ b/gdb/syscalls/gdb-syscalls.dtd
@@ -12,4 +12,5 @@
 <!ATTLIST syscall
 	name			CDATA	#REQUIRED
 	number			CDATA	#REQUIRED
+	alias			CDATA	#IMPLIED
 	groups			CDATA	#IMPLIED>
diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
index bf17642911..a96d377fac 100644
--- a/gdb/xml-syscall.c
+++ b/gdb/xml-syscall.c
@@ -61,13 +61,11 @@ get_syscall_by_number (struct gdbarch *gdbarch,
   s->name = NULL;
 }
 
-void
-get_syscall_by_name (struct gdbarch *gdbarch, const char *syscall_name,
-		     struct syscall *s)
+std::vector<int>
+get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)
 {
   syscall_warn_user ();
-  s->number = UNKNOWN_SYSCALL;
-  s->name = syscall_name;
+  return std::vector<int> ();
 }
 
 const char **
@@ -96,8 +94,8 @@ get_syscall_group_names (struct gdbarch *gdbarch)
 /* Structure which describes a syscall.  */
 struct syscall_desc
 {
-  syscall_desc (int number_, std::string name_)
-  : number (number_), name (name_)
+  syscall_desc (int number_, std::string name_, std::string alias_)
+  : number (number_), name (name_), alias(alias_)
   {}
 
   /* The syscall number.  */
@@ -107,6 +105,10 @@ struct syscall_desc
   /* The syscall name.  */
 
   std::string name;
+
+  /* An optional alias.  */
+
+  std::string alias;
 };
 
 typedef std::unique_ptr<syscall_desc> syscall_desc_up;
@@ -206,10 +208,10 @@ syscall_group_add_syscall (struct syscalls_info *syscalls_info,
 
 static void
 syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
-			     const char *name, int number,
+			     const char *name, int number, const char *alias,
 			     char *groups)
 {
-  syscall_desc *sysdesc = new syscall_desc (number, name);
+  syscall_desc *sysdesc = new syscall_desc (number, name, alias ?: "");
 
   syscalls_info->syscalls.emplace_back (sysdesc);
 
@@ -234,6 +236,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
   /* syscall info.  */
   char *name = NULL;
   int number = 0;
+  char *alias = NULL;
   char *groups = NULL;
 
   for (const gdb_xml_value &attr : attributes)
@@ -242,6 +245,8 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
         name = (char *) attr.value.get ();
       else if (strcmp (attr.name, "number") == 0)
         number = * (ULONGEST *) attr.value.get ();
+      else if (strcmp (attr.name, "alias") == 0)
+        alias = (char *) attr.value.get ();
       else if (strcmp (attr.name, "groups") == 0)
         groups = (char *) attr.value.get ();
       else
@@ -250,7 +255,8 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
     }
 
   gdb_assert (name);
-  syscall_create_syscall_desc (data->syscalls_info, name, number, groups);
+  syscall_create_syscall_desc (data->syscalls_info, name, number, alias,
+			       groups);
 }
 
 
@@ -258,6 +264,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
 static const struct gdb_xml_attribute syscall_attr[] = {
   { "number", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "name", GDB_XML_AF_NONE, NULL, NULL },
+  { "alias", GDB_XML_AF_OPTIONAL, NULL, NULL },
   { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
@@ -389,21 +396,21 @@ syscall_group_get_group_by_name (const struct syscalls_info *syscalls_info,
   return NULL;
 }
 
-static int
-xml_get_syscall_number (struct gdbarch *gdbarch,
-                        const char *syscall_name)
+static std::vector<int>
+xml_get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)
 {
   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
+  std::vector<int> syscalls;
 
   if (syscalls_info == NULL
       || syscall_name == NULL)
-    return UNKNOWN_SYSCALL;
+    return syscalls;
 
   for (const syscall_desc_up &sysdesc : syscalls_info->syscalls)
-    if (sysdesc->name == syscall_name)
-      return sysdesc->number;
+    if (sysdesc->name == syscall_name || sysdesc->alias == syscall_name)
+      syscalls.push_back (sysdesc->number);
 
-  return UNKNOWN_SYSCALL;
+  return syscalls;
 }
 
 static const char *
@@ -522,14 +529,12 @@ get_syscall_by_number (struct gdbarch *gdbarch,
   s->name = xml_get_syscall_name (gdbarch, syscall_number);
 }
 
-void
-get_syscall_by_name (struct gdbarch *gdbarch,
-		     const char *syscall_name, struct syscall *s)
+std::vector<int>
+get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)
 {
   init_syscalls_info (gdbarch);
 
-  s->number = xml_get_syscall_number (gdbarch, syscall_name);
-  s->name = syscall_name;
+  return xml_get_syscalls_by_name (gdbarch, syscall_name);
 }
 
 const char **
diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
index 4429d66400..86713097b3 100644
--- a/gdb/xml-syscall.h
+++ b/gdb/xml-syscall.h
@@ -38,11 +38,11 @@ void set_xml_syscall_file_name (struct gdbarch *gdbarch,
 void get_syscall_by_number (struct gdbarch *gdbarch,
 			    int syscall_number, struct syscall *s);
 
-/* Function that retrieves the syscall number corresponding to the given
-   name.  It puts the requested information inside 'struct syscall'.  */
+/* Function that retrieves the syscall numbers corresponding to the given
+   name.  The list of syscall numbers are returned in a vector.  */
 
-void get_syscall_by_name (struct gdbarch *gdbarch,
-			  const char *syscall_name, struct syscall *s);
+std::vector<int> get_syscalls_by_name (struct gdbarch *gdbarch,
+				       const char *syscall_name);
 
 /* Function used to retrieve the list of syscalls in the system.  This list
    is returned as an array of strings.  Returns the list of syscalls in the
-- 
2.18.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] Update the FreeBSD system call table to match FreeBSD 12.0.
  2018-10-03 17:30 [PATCH 0/2] Update FreeBSD's syscall table John Baldwin
  2018-10-03 17:30 ` [PATCH 1/2] Add an optional "alias" attribute to syscall entries John Baldwin
@ 2018-10-03 17:30 ` John Baldwin
  1 sibling, 0 replies; 7+ messages in thread
From: John Baldwin @ 2018-10-03 17:30 UTC (permalink / raw)
  To: gdb-patches

Add a script to generate the FreeBSD XML system call table from the
sys/sys/syscall.h file in the kernel source tree.  For ABI
compatiblity system calls used by older binaries (such as
freebsd11_kevent()), the original system call name is used as an
alias.

Run this script against the current syscall.h file in FreeBSD's head
branch which is expected to be the file used in 12.0 (head is
currently in code freeze as part of the 12.0 release process).

gdb/ChangeLog:

	* syscalls/update-freebsd.sh: New file.
	* syscalls/freebsd.xml: Regenerate.
---
 gdb/ChangeLog                  |   5 ++
 gdb/syscalls/freebsd.xml       | 107 ++++++++++++++++++++++++++-------
 gdb/syscalls/update-freebsd.sh |  77 ++++++++++++++++++++++++
 3 files changed, 167 insertions(+), 22 deletions(-)
 create mode 100755 gdb/syscalls/update-freebsd.sh

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1f679b48ed..c359821fd2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-03  John Baldwin  <jhb@FreeBSD.org>
+
+	* syscalls/update-freebsd.sh: New file.
+	* syscalls/freebsd.xml: Regenerate.
+
 2018-10-03  John Baldwin  <jhb@FreeBSD.org>
 
 	* break-catch-syscall.c (catch_syscall_split_args): Update for
diff --git a/gdb/syscalls/freebsd.xml b/gdb/syscalls/freebsd.xml
index 810258a850..773e0be5f8 100644
--- a/gdb/syscalls/freebsd.xml
+++ b/gdb/syscalls/freebsd.xml
@@ -24,12 +24,14 @@
   <syscall name="wait4" number="7"/>
   <syscall name="link" number="9"/>
   <syscall name="unlink" number="10"/>
+  <syscall name="execv" number="11"/>
   <syscall name="chdir" number="12"/>
   <syscall name="fchdir" number="13"/>
-  <syscall name="mknod" number="14"/>
+  <syscall name="freebsd11_mknod" number="14" alias="mknod"/>
   <syscall name="chmod" number="15"/>
   <syscall name="chown" number="16"/>
   <syscall name="break" number="17"/>
+  <syscall name="freebsd4_getfsstat" number="18" alias="getfsstat"/>
   <syscall name="getpid" number="20"/>
   <syscall name="mount" number="21"/>
   <syscall name="unmount" number="22"/>
@@ -50,7 +52,7 @@
   <syscall name="kill" number="37"/>
   <syscall name="getppid" number="39"/>
   <syscall name="dup" number="41"/>
-  <syscall name="pipe" number="42"/>
+  <syscall name="freebsd10_pipe" number="42" alias="pipe"/>
   <syscall name="getegid" number="43"/>
   <syscall name="profil" number="44"/>
   <syscall name="ktrace" number="45"/>
@@ -69,12 +71,16 @@
   <syscall name="chroot" number="61"/>
   <syscall name="msync" number="65"/>
   <syscall name="vfork" number="66"/>
+  <syscall name="vread" number="67"/>
+  <syscall name="vwrite" number="68"/>
   <syscall name="sbrk" number="69"/>
   <syscall name="sstk" number="70"/>
-  <syscall name="vadvise" number="72"/>
+  <syscall name="freebsd11_vadvise" number="72" alias="vadvise"/>
   <syscall name="munmap" number="73"/>
   <syscall name="mprotect" number="74"/>
   <syscall name="madvise" number="75"/>
+  <syscall name="vhangup" number="76"/>
+  <syscall name="vlimit" number="77"/>
   <syscall name="mincore" number="78"/>
   <syscall name="getgroups" number="79"/>
   <syscall name="setgroups" number="80"/>
@@ -95,6 +101,8 @@
   <syscall name="bind" number="104"/>
   <syscall name="setsockopt" number="105"/>
   <syscall name="listen" number="106"/>
+  <syscall name="vtimes" number="107"/>
+  <syscall name="vtrace" number="115"/>
   <syscall name="gettimeofday" number="116"/>
   <syscall name="getrusage" number="117"/>
   <syscall name="getsockopt" number="118"/>
@@ -119,27 +127,42 @@
   <syscall name="quotactl" number="148"/>
   <syscall name="nlm_syscall" number="154"/>
   <syscall name="nfssvc" number="155"/>
+  <syscall name="freebsd4_statfs" number="157" alias="statfs"/>
+  <syscall name="freebsd4_fstatfs" number="158" alias="fstatfs"/>
   <syscall name="lgetfh" number="160"/>
   <syscall name="getfh" number="161"/>
+  <syscall name="freebsd4_getdomainname" number="162" alias="getdomainname"/>
+  <syscall name="freebsd4_setdomainname" number="163" alias="setdomainname"/>
+  <syscall name="freebsd4_uname" number="164" alias="uname"/>
   <syscall name="sysarch" number="165"/>
   <syscall name="rtprio" number="166"/>
   <syscall name="semsys" number="169"/>
   <syscall name="msgsys" number="170"/>
   <syscall name="shmsys" number="171"/>
+  <syscall name="freebsd6_pread" number="173" alias="pread"/>
+  <syscall name="freebsd6_pwrite" number="174" alias="pwrite"/>
   <syscall name="setfib" number="175"/>
   <syscall name="ntp_adjtime" number="176"/>
   <syscall name="setgid" number="181"/>
   <syscall name="setegid" number="182"/>
   <syscall name="seteuid" number="183"/>
-  <syscall name="stat" number="188"/>
-  <syscall name="fstat" number="189"/>
-  <syscall name="lstat" number="190"/>
+  <syscall name="lfs_bmapv" number="184"/>
+  <syscall name="lfs_markv" number="185"/>
+  <syscall name="lfs_segclean" number="186"/>
+  <syscall name="lfs_segwait" number="187"/>
+  <syscall name="freebsd11_stat" number="188" alias="stat"/>
+  <syscall name="freebsd11_fstat" number="189" alias="fstat"/>
+  <syscall name="freebsd11_lstat" number="190" alias="lstat"/>
   <syscall name="pathconf" number="191"/>
   <syscall name="fpathconf" number="192"/>
   <syscall name="getrlimit" number="194"/>
   <syscall name="setrlimit" number="195"/>
-  <syscall name="getdirentries" number="196"/>
+  <syscall name="freebsd11_getdirentries" number="196" alias="getdirentries"/>
+  <syscall name="freebsd6_mmap" number="197" alias="mmap"/>
   <syscall name="__syscall" number="198"/>
+  <syscall name="freebsd6_lseek" number="199" alias="lseek"/>
+  <syscall name="freebsd6_truncate" number="200" alias="truncate"/>
+  <syscall name="freebsd6_ftruncate" number="201" alias="ftruncate"/>
   <syscall name="__sysctl" number="202"/>
   <syscall name="mlock" number="203"/>
   <syscall name="munlock" number="204"/>
@@ -147,15 +170,16 @@
   <syscall name="futimes" number="206"/>
   <syscall name="getpgid" number="207"/>
   <syscall name="poll" number="209"/>
-  <syscall name="freebsd7___semctl" number="220"/>
+  <syscall name="freebsd7___semctl" number="220" alias="__semctl"/>
   <syscall name="semget" number="221"/>
   <syscall name="semop" number="222"/>
-  <syscall name="freebsd7_msgctl" number="224"/>
+  <syscall name="semconfig" number="223"/>
+  <syscall name="freebsd7_msgctl" number="224" alias="msgctl"/>
   <syscall name="msgget" number="225"/>
   <syscall name="msgsnd" number="226"/>
   <syscall name="msgrcv" number="227"/>
   <syscall name="shmat" number="228"/>
-  <syscall name="freebsd7_shmctl" number="229"/>
+  <syscall name="freebsd7_shmctl" number="229" alias="shmctl"/>
   <syscall name="shmdt" number="230"/>
   <syscall name="shmget" number="231"/>
   <syscall name="clock_gettime" number="232"/>
@@ -170,6 +194,7 @@
   <syscall name="ffclock_getcounter" number="241"/>
   <syscall name="ffclock_setestimate" number="242"/>
   <syscall name="ffclock_getestimate" number="243"/>
+  <syscall name="clock_nanosleep" number="244"/>
   <syscall name="clock_getcpuclockid2" number="247"/>
   <syscall name="ntp_gettime" number="248"/>
   <syscall name="minherit" number="250"/>
@@ -180,18 +205,19 @@
   <syscall name="aio_read" number="255"/>
   <syscall name="aio_write" number="256"/>
   <syscall name="lio_listio" number="257"/>
-  <syscall name="getdents" number="272"/>
+  <syscall name="freebsd11_getdents" number="272" alias="getdents"/>
   <syscall name="lchmod" number="274"/>
   <syscall name="netbsd_lchown" number="275"/>
   <syscall name="lutimes" number="276"/>
   <syscall name="netbsd_msync" number="277"/>
-  <syscall name="nstat" number="278"/>
-  <syscall name="nfstat" number="279"/>
-  <syscall name="nlstat" number="280"/>
+  <syscall name="freebsd11_nstat" number="278" alias="nstat"/>
+  <syscall name="freebsd11_nfstat" number="279" alias="nfstat"/>
+  <syscall name="freebsd11_nlstat" number="280" alias="nlstat"/>
   <syscall name="preadv" number="289"/>
   <syscall name="pwritev" number="290"/>
+  <syscall name="freebsd4_fhstatfs" number="297" alias="fhstatfs"/>
   <syscall name="fhopen" number="298"/>
-  <syscall name="fhstat" number="299"/>
+  <syscall name="freebsd11_fhstat" number="299" alias="fhstat"/>
   <syscall name="modnext" number="300"/>
   <syscall name="modstat" number="301"/>
   <syscall name="modfnext" number="302"/>
@@ -205,11 +231,17 @@
   <syscall name="getsid" number="310"/>
   <syscall name="setresuid" number="311"/>
   <syscall name="setresgid" number="312"/>
+  <syscall name="signanosleep" number="313"/>
   <syscall name="aio_return" number="314"/>
   <syscall name="aio_suspend" number="315"/>
   <syscall name="aio_cancel" number="316"/>
   <syscall name="aio_error" number="317"/>
+  <syscall name="freebsd6_aio_read" number="318" alias="aio_read"/>
+  <syscall name="freebsd6_aio_write" number="319" alias="aio_write"/>
+  <syscall name="freebsd6_lio_listio" number="320" alias="lio_listio"/>
   <syscall name="yield" number="321"/>
+  <syscall name="thr_sleep" number="322"/>
+  <syscall name="thr_wakeup" number="323"/>
   <syscall name="mlockall" number="324"/>
   <syscall name="munlockall" number="325"/>
   <syscall name="__getcwd" number="326"/>
@@ -222,12 +254,15 @@
   <syscall name="sched_get_priority_min" number="333"/>
   <syscall name="sched_rr_get_interval" number="334"/>
   <syscall name="utrace" number="335"/>
+  <syscall name="freebsd4_sendfile" number="336" alias="sendfile"/>
   <syscall name="kldsym" number="337"/>
   <syscall name="jail" number="338"/>
   <syscall name="nnpfs_syscall" number="339"/>
   <syscall name="sigprocmask" number="340"/>
   <syscall name="sigsuspend" number="341"/>
+  <syscall name="freebsd4_sigaction" number="342" alias="sigaction"/>
   <syscall name="sigpending" number="343"/>
+  <syscall name="freebsd4_sigreturn" number="344" alias="sigreturn"/>
   <syscall name="sigtimedwait" number="345"/>
   <syscall name="sigwaitinfo" number="346"/>
   <syscall name="__acl_get_file" number="347"/>
@@ -246,14 +281,26 @@
   <syscall name="getresuid" number="360"/>
   <syscall name="getresgid" number="361"/>
   <syscall name="kqueue" number="362"/>
-  <syscall name="kevent" number="363"/>
+  <syscall name="freebsd11_kevent" number="363" alias="kevent"/>
+  <syscall name="__cap_get_proc" number="364"/>
+  <syscall name="__cap_set_proc" number="365"/>
+  <syscall name="__cap_get_fd" number="366"/>
+  <syscall name="__cap_get_file" number="367"/>
+  <syscall name="__cap_set_fd" number="368"/>
+  <syscall name="__cap_set_file" number="369"/>
   <syscall name="extattr_set_fd" number="371"/>
   <syscall name="extattr_get_fd" number="372"/>
   <syscall name="extattr_delete_fd" number="373"/>
   <syscall name="__setugid" number="374"/>
+  <syscall name="nfsclnt" number="375"/>
   <syscall name="eaccess" number="376"/>
   <syscall name="afs3_syscall" number="377"/>
   <syscall name="nmount" number="378"/>
+  <syscall name="kse_exit" number="379"/>
+  <syscall name="kse_wakeup" number="380"/>
+  <syscall name="kse_create" number="381"/>
+  <syscall name="kse_thr_interrupt" number="382"/>
+  <syscall name="kse_release" number="383"/>
   <syscall name="__mac_get_proc" number="384"/>
   <syscall name="__mac_set_proc" number="385"/>
   <syscall name="__mac_get_fd" number="386"/>
@@ -265,10 +312,10 @@
   <syscall name="uuidgen" number="392"/>
   <syscall name="sendfile" number="393"/>
   <syscall name="mac_syscall" number="394"/>
-  <syscall name="getfsstat" number="395"/>
-  <syscall name="statfs" number="396"/>
-  <syscall name="fstatfs" number="397"/>
-  <syscall name="fhstatfs" number="398"/>
+  <syscall name="freebsd11_getfsstat" number="395" alias="getfsstat"/>
+  <syscall name="freebsd11_statfs" number="396" alias="statfs"/>
+  <syscall name="freebsd11_fstatfs" number="397" alias="fstatfs"/>
+  <syscall name="freebsd11_fhstatfs" number="398" alias="fhstatfs"/>
   <syscall name="ksem_close" number="400"/>
   <syscall name="ksem_post" number="401"/>
   <syscall name="ksem_wait" number="402"/>
@@ -304,6 +351,7 @@
   <syscall name="extattr_list_fd" number="437"/>
   <syscall name="extattr_list_file" number="438"/>
   <syscall name="extattr_list_link" number="439"/>
+  <syscall name="kse_switchin" number="440"/>
   <syscall name="ksem_timedwait" number="441"/>
   <syscall name="thr_suspend" number="442"/>
   <syscall name="thr_wake" number="443"/>
@@ -352,12 +400,12 @@
   <syscall name="fchmodat" number="490"/>
   <syscall name="fchownat" number="491"/>
   <syscall name="fexecve" number="492"/>
-  <syscall name="fstatat" number="493"/>
+  <syscall name="freebsd11_fstatat" number="493" alias="fstatat"/>
   <syscall name="futimesat" number="494"/>
   <syscall name="linkat" number="495"/>
   <syscall name="mkdirat" number="496"/>
   <syscall name="mkfifoat" number="497"/>
-  <syscall name="mknodat" number="498"/>
+  <syscall name="freebsd11_mknodat" number="498" alias="mknodat"/>
   <syscall name="openat" number="499"/>
   <syscall name="readlinkat" number="500"/>
   <syscall name="renameat" number="501"/>
@@ -373,6 +421,7 @@
   <syscall name="msgctl" number="511"/>
   <syscall name="shmctl" number="512"/>
   <syscall name="lpathconf" number="513"/>
+  <syscall name="cap_new" number="514"/>
   <syscall name="__cap_rights_get" number="515"/>
   <syscall name="cap_enter" number="516"/>
   <syscall name="cap_getmode" number="517"/>
@@ -407,4 +456,18 @@
   <syscall name="utimensat" number="547"/>
   <syscall name="numa_getaffinity" number="548"/>
   <syscall name="numa_setaffinity" number="549"/>
+  <syscall name="fdatasync" number="550"/>
+  <syscall name="fstat" number="551"/>
+  <syscall name="fstatat" number="552"/>
+  <syscall name="fhstat" number="553"/>
+  <syscall name="getdirentries" number="554"/>
+  <syscall name="statfs" number="555"/>
+  <syscall name="fstatfs" number="556"/>
+  <syscall name="getfsstat" number="557"/>
+  <syscall name="fhstatfs" number="558"/>
+  <syscall name="mknodat" number="559"/>
+  <syscall name="kevent" number="560"/>
+  <syscall name="cpuset_getdomain" number="561"/>
+  <syscall name="cpuset_setdomain" number="562"/>
+  <syscall name="getrandom" number="563"/>
 </syscalls_info>
diff --git a/gdb/syscalls/update-freebsd.sh b/gdb/syscalls/update-freebsd.sh
new file mode 100755
index 0000000000..8699faa873
--- /dev/null
+++ b/gdb/syscalls/update-freebsd.sh
@@ -0,0 +1,77 @@
+#! /bin/sh
+
+# Copyright (C) 2011-2018 Free Software Foundation, Inc.
+#
+# This file is part of GDB.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Usage: update-freebsd.sh <path-to-syscall.h>
+# Update the freebsd.xml file.
+#
+# FreeBSD uses the same list of system calls on all architectures.
+# The list is defined in the sys/kern/syscalls.master file in the
+# FreeBSD source tree.  This file is used as an input to generate
+# several files that are also stored in FreeBSD's source tree.  This
+# script parses one of those generated files (sys/sys/syscall.h)
+# rather than syscalls.master as syscall.h is easier to parse.
+
+if [ $# -ne 1 ]; then
+   echo "Error: Path to syscall.h missing. Aborting."
+   echo "Usage: update-gnulib.sh <path-to-syscall.h>"
+   exit 1
+fi
+
+cat > freebsd.xml.tmp <<EOF
+<?xml version="1.0"?>
+<!-- Copyright (C) 2009-2018 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-syscalls.dtd">
+
+<!-- This file was generated using the following file:
+
+     /usr/src/sys/sys/syscall.h
+
+     The file mentioned above belongs to the FreeBSD Kernel.  -->
+
+<syscalls_info>
+EOF
+
+awk '
+/MAXSYSCALL/ {
+    next
+}
+/^#define/ {
+    sub(/^SYS_/,"",$2);
+    printf "  <syscall name=\"%s\" number=\"%s\"", $2, $3
+    if (sub(/^freebsd[0-9]*_/,"",$2) != 0)
+        printf " alias=\"%s\"", $2
+    printf "/>\n"
+}
+/\/\* [0-9]* is obsolete [a-z_]* \*\// {
+    printf "  <syscall name=\"%s\" number=\"%s\"/>\n", $5, $2
+}
+/\/\* [0-9]* is freebsd[0-9]* [a-z_]* \*\// {
+    printf "  <syscall name=\"%s_%s\" number=\"%s\" alias=\"%s\"/>\n", $4, $5, $2, $5
+}' $1 >> freebsd.xml.tmp
+
+cat >> freebsd.xml.tmp <<EOF
+</syscalls_info>
+EOF
+
+../../move-if-change freebsd.xml.tmp freebsd.xml
-- 
2.18.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 0/2] Update FreeBSD's syscall table
@ 2018-10-03 17:30 John Baldwin
  2018-10-03 17:30 ` [PATCH 1/2] Add an optional "alias" attribute to syscall entries John Baldwin
  2018-10-03 17:30 ` [PATCH 2/2] Update the FreeBSD system call table to match FreeBSD 12.0 John Baldwin
  0 siblings, 2 replies; 7+ messages in thread
From: John Baldwin @ 2018-10-03 17:30 UTC (permalink / raw)
  To: gdb-patches

Mostly this patch just updates the list of syscalls to match FreeBSD 12.
However, it also adds an alias feature to try to provide the right user
experience given the way that FreeBSD handles ABI changes to syscalls,
which is to allocate new system calls if the ABI changes and name the
old syscall 'freebsdN_foo' where N is the last major release that used
the older ABI.  12 has several new system calls in this category since
the layout of both 'struct kevent' and 'struct stat' was changed.
I make use of aliases so that the compat system calls have an alias
of the original syscall name.  This means that 'catch syscall kevent'
will register a catchpoint for both freebsd11_kevent and the new
kevent system call in 12 for example, and will thus work fine for
any FreeBSD binary that calls 'kevent' regardless of the target OS
version.  I didn't want to use the 'group' stuff for this as I plan to
use groups for syscalls on FreeBSD eventually, and it would also make
the UI somewhat confusing I think (you would have to know to use
'catch syscall group kevent').

John Baldwin (2):
  Add an optional "alias" attribute to syscall entries.
  Update the FreeBSD system call table to match FreeBSD 12.0.

 gdb/ChangeLog                  |  26 ++++++++
 gdb/break-catch-syscall.c      |  11 ++--
 gdb/gdbarch.h                  |   3 -
 gdb/gdbarch.sh                 |   3 -
 gdb/syscalls/freebsd.xml       | 107 ++++++++++++++++++++++++++-------
 gdb/syscalls/gdb-syscalls.dtd  |   1 +
 gdb/syscalls/update-freebsd.sh |  77 ++++++++++++++++++++++++
 gdb/xml-syscall.c              |  49 ++++++++-------
 gdb/xml-syscall.h              |   8 +--
 9 files changed, 226 insertions(+), 59 deletions(-)
 create mode 100755 gdb/syscalls/update-freebsd.sh

-- 
2.18.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] Add an optional "alias" attribute to syscall entries.
  2018-10-03 17:30 ` [PATCH 1/2] Add an optional "alias" attribute to syscall entries John Baldwin
@ 2018-10-12  6:13   ` Kevin Buettner
  2018-10-17 18:49     ` John Baldwin
  2018-10-13  1:52   ` Sergio Durigan Junior
  1 sibling, 1 reply; 7+ messages in thread
From: Kevin Buettner @ 2018-10-12  6:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: John Baldwin

Hi John,

On Wed,  3 Oct 2018 10:30:04 -0700
John Baldwin <jhb@FreeBSD.org> wrote:

> When setting a syscall catchpoint by name, catch syscalls whose name
> or alias matches the requested string.
> 
> When the ABI of a system call is changed in the FreeBSD kernel, this
> is implemented by leaving a compatability system call using the old
> ABI at the existing "slot" and allocating a new system call for the
> version using the new ABI.  For example, new fields were added to the
> 'struct kevent' used by the kevent() system call in FreeBSD 12.  The
> previous kevent() system call in FreeBSD 12 kernels is now called
> freebsd11_kevent() and is still used by older binaries compiled
> against the older ABI.  The freebsd11_kevent() system call can be
> tagged with an "alias" attribute of "kevent" permitting 'catch syscall
> kevent' to catch both system calls and providing the expected user
> behavior for both old and new binaries.  It also provides the expected
> behavior if GDB is compiled on an older host (such as a FreeBSD 11
> host).

Very nice.

I read through your patch.  The only problem I found was this
use of a GNU extension involving the use of the ternary ?: operator
without the middle operand.

>  			     char *groups)
>  {
> -  syscall_desc *sysdesc = new syscall_desc (number, name);
> +  syscall_desc *sysdesc = new syscall_desc (number, name, alias ?: "");
>  
>    syscalls_info->syscalls.emplace_back (sysdesc);
>  

In addition, the GDB coding standard specifies that pointer variables
should have explicit comparisons against NULL or nullptr.  So, even if
it weren't a GNU extension, GDB's coding standard would force you to
write that expression using an explicit comparison - which in turn would
necessitate adding the middle argument.  (Which is kind of
unfortunate, because I like the compactness of that expression.)

Anyway, here's a link to the relevant section of the GDB coding standard:

https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Comparison_With_NULL_And_Zero

Kevin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] Add an optional "alias" attribute to syscall entries.
  2018-10-03 17:30 ` [PATCH 1/2] Add an optional "alias" attribute to syscall entries John Baldwin
  2018-10-12  6:13   ` Kevin Buettner
@ 2018-10-13  1:52   ` Sergio Durigan Junior
  2018-10-17 19:13     ` John Baldwin
  1 sibling, 1 reply; 7+ messages in thread
From: Sergio Durigan Junior @ 2018-10-13  1:52 UTC (permalink / raw)
  To: John Baldwin; +Cc: gdb-patches

On Wednesday, October 03 2018, John Baldwin wrote:

> When setting a syscall catchpoint by name, catch syscalls whose name
> or alias matches the requested string.

Thanks for the patch, John.

> When the ABI of a system call is changed in the FreeBSD kernel, this
> is implemented by leaving a compatability system call using the old
> ABI at the existing "slot" and allocating a new system call for the
> version using the new ABI.  For example, new fields were added to the
> 'struct kevent' used by the kevent() system call in FreeBSD 12.  The
> previous kevent() system call in FreeBSD 12 kernels is now called
> freebsd11_kevent() and is still used by older binaries compiled
> against the older ABI.  The freebsd11_kevent() system call can be
> tagged with an "alias" attribute of "kevent" permitting 'catch syscall
> kevent' to catch both system calls and providing the expected user
> behavior for both old and new binaries.  It also provides the expected
> behavior if GDB is compiled on an older host (such as a FreeBSD 11
> host).

OOC, do you envision the possibility of a syscall having more than 1
alias?

> gdb/ChangeLog:
>
> 	* break-catch-syscall.c (catch_syscall_split_args): Update for
> 	get_syscalls_by_name returning a vector.
> 	* gdbarch.sh (UNKNOWN_SYSCALL): Remove.
> 	* gdbarch.h: Regenerate.
> 	* syscalls/gdb-syscalls.dtd (syscall): Add alias attribute.
> 	* xml-syscall.c [!HAVE_LIBEXPAT] (get_syscalls_by_name): Rename
> 	from get_syscall_by_name.  Now returns a vector of integers.
> 	[HAVE_LIBEXPAT] (struct syscall_desc): Add alias member.
> 	(syscall_create_syscall_desc): Add alias parameter and pass it to
> 	syscall_desc constructor.
> 	(syscall_start_syscall): Handle alias attribute.
> 	(syscall_attr): Add alias attribute.
> 	(xml_get_syscalls_by_name): Rename from xml_get_syscall_number.
> 	Now returns a vector of integers.  Add syscalls whose alias or
> 	name matches the requested name.
> 	(get_syscalls_by_name): Rename from get_syscall_by_name.  Now
> 	returns a vector of integers.
> 	* xml-syscall.h (get_syscalls_by_name): Likewise.
> ---
>  gdb/ChangeLog                 | 21 +++++++++++++++
>  gdb/break-catch-syscall.c     | 11 ++++----
>  gdb/gdbarch.h                 |  3 ---
>  gdb/gdbarch.sh                |  3 ---
>  gdb/syscalls/gdb-syscalls.dtd |  1 +
>  gdb/xml-syscall.c             | 49 +++++++++++++++++++----------------
>  gdb/xml-syscall.h             |  8 +++---
>  7 files changed, 59 insertions(+), 37 deletions(-)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index e239f201fa..1f679b48ed 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,24 @@
> +2018-10-03  John Baldwin  <jhb@FreeBSD.org>
> +
> +	* break-catch-syscall.c (catch_syscall_split_args): Update for
> +	get_syscalls_by_name returning a vector.
> +	* gdbarch.sh (UNKNOWN_SYSCALL): Remove.
> +	* gdbarch.h: Regenerate.
> +	* syscalls/gdb-syscalls.dtd (syscall): Add alias attribute.
> +	* xml-syscall.c [!HAVE_LIBEXPAT] (get_syscalls_by_name): Rename
> +	from get_syscall_by_name.  Now returns a vector of integers.
> +	[HAVE_LIBEXPAT] (struct syscall_desc): Add alias member.
> +	(syscall_create_syscall_desc): Add alias parameter and pass it to
> +	syscall_desc constructor.
> +	(syscall_start_syscall): Handle alias attribute.
> +	(syscall_attr): Add alias attribute.
> +	(xml_get_syscalls_by_name): Rename from xml_get_syscall_number.
> +	Now returns a vector of integers.  Add syscalls whose alias or
> +	name matches the requested name.
> +	(get_syscalls_by_name): Rename from get_syscall_by_name.  Now
> +	returns a vector of integers.
> +	* xml-syscall.h (get_syscalls_by_name): Likewise.
> +
>  2018-10-02  Tom Tromey  <tom@tromey.com>
>  
>  	* aarch64-linux-tdep.c (aarch64_linux_sigframe_init): Use pulongest.
> diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
> index 93ef74c249..e9e370f4bf 100644
> --- a/gdb/break-catch-syscall.c
> +++ b/gdb/break-catch-syscall.c
> @@ -431,18 +431,19 @@ catch_syscall_split_args (const char *arg)
>  	}
>        else
>  	{
> -	  /* We have a name.  Let's check if it's valid and convert it
> -	     to a number.  */
> -	  get_syscall_by_name (gdbarch, cur_name, &s);
> +	  /* We have a name.  Let's check if it's valid and fetch a
> +	     list of matching numbers.  */
> +	  std::vector<int> numbers = get_syscalls_by_name (gdbarch, cur_name);
>  
> -	  if (s.number == UNKNOWN_SYSCALL)
> +	  if (numbers.empty ())
>  	    /* Here we have to issue an error instead of a warning,
>  	       because GDB cannot do anything useful if there's no
>  	       syscall number to be caught.  */
>  	    error (_("Unknown syscall name '%s'."), cur_name);
>  
>  	  /* Ok, it's valid.  */
> -	  result.push_back (s.number);
> +	  for (int number : numbers)
> +	    result.push_back (number);
>  	}
>      }
>  
> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
> index fc2f1a84a1..6b7afe4a5c 100644
> --- a/gdb/gdbarch.h
> +++ b/gdb/gdbarch.h
> @@ -1569,9 +1569,6 @@ typedef ULONGEST (gdbarch_type_align_ftype) (struct gdbarch *gdbarch, struct typ
>  extern ULONGEST gdbarch_type_align (struct gdbarch *gdbarch, struct type *type);
>  extern void set_gdbarch_type_align (struct gdbarch *gdbarch, gdbarch_type_align_ftype *type_align);
>  
> -/* Definition for an unknown syscall, used basically in error-cases.  */
> -#define UNKNOWN_SYSCALL (-1)
> -
>  extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
>  
>  
> diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
> index 670ac30c03..ee74acfd2a 100755
> --- a/gdb/gdbarch.sh
> +++ b/gdb/gdbarch.sh
> @@ -1393,9 +1393,6 @@ done
>  # close it off
>  cat <<EOF
>  
> -/* Definition for an unknown syscall, used basically in error-cases.  */
> -#define UNKNOWN_SYSCALL (-1)
> -
>  extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
>  
>  
> diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd
> index c2aa478aa4..6aa73f288a 100644
> --- a/gdb/syscalls/gdb-syscalls.dtd
> +++ b/gdb/syscalls/gdb-syscalls.dtd
> @@ -12,4 +12,5 @@
>  <!ATTLIST syscall
>  	name			CDATA	#REQUIRED
>  	number			CDATA	#REQUIRED
> +	alias			CDATA	#IMPLIED
>  	groups			CDATA	#IMPLIED>
> diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
> index bf17642911..a96d377fac 100644
> --- a/gdb/xml-syscall.c
> +++ b/gdb/xml-syscall.c
> @@ -61,13 +61,11 @@ get_syscall_by_number (struct gdbarch *gdbarch,
>    s->name = NULL;
>  }
>  
> -void
> -get_syscall_by_name (struct gdbarch *gdbarch, const char *syscall_name,
> -		     struct syscall *s)
> +std::vector<int>
> +get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)
>  {
>    syscall_warn_user ();
> -  s->number = UNKNOWN_SYSCALL;
> -  s->name = syscall_name;
> +  return std::vector<int> ();
>  }
>  
>  const char **
> @@ -96,8 +94,8 @@ get_syscall_group_names (struct gdbarch *gdbarch)
>  /* Structure which describes a syscall.  */
>  struct syscall_desc
>  {
> -  syscall_desc (int number_, std::string name_)
> -  : number (number_), name (name_)
> +  syscall_desc (int number_, std::string name_, std::string alias_)
> +  : number (number_), name (name_), alias(alias_)
                                            ^

Missing whitespace here.

>    {}
>  
>    /* The syscall number.  */
> @@ -107,6 +105,10 @@ struct syscall_desc
>    /* The syscall name.  */
>  
>    std::string name;
> +
> +  /* An optional alias.  */
> +
> +  std::string alias;
>  };
>  
>  typedef std::unique_ptr<syscall_desc> syscall_desc_up;
> @@ -206,10 +208,10 @@ syscall_group_add_syscall (struct syscalls_info *syscalls_info,
>  
>  static void
>  syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
> -			     const char *name, int number,
> +			     const char *name, int number, const char *alias,
>  			     char *groups)
>  {
> -  syscall_desc *sysdesc = new syscall_desc (number, name);
> +  syscall_desc *sysdesc = new syscall_desc (number, name, alias ?: "");

As pointed by Kevin, this use of the ternary operator is not common.

>  
>    syscalls_info->syscalls.emplace_back (sysdesc);
>  
> @@ -234,6 +236,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>    /* syscall info.  */
>    char *name = NULL;
>    int number = 0;
> +  char *alias = NULL;
>    char *groups = NULL;
>  
>    for (const gdb_xml_value &attr : attributes)
> @@ -242,6 +245,8 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>          name = (char *) attr.value.get ();
>        else if (strcmp (attr.name, "number") == 0)
>          number = * (ULONGEST *) attr.value.get ();
> +      else if (strcmp (attr.name, "alias") == 0)
> +        alias = (char *) attr.value.get ();
>        else if (strcmp (attr.name, "groups") == 0)
>          groups = (char *) attr.value.get ();
>        else
> @@ -250,7 +255,8 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>      }
>  
>    gdb_assert (name);
> -  syscall_create_syscall_desc (data->syscalls_info, name, number, groups);
> +  syscall_create_syscall_desc (data->syscalls_info, name, number, alias,
> +			       groups);
>  }
>  
>  
> @@ -258,6 +264,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>  static const struct gdb_xml_attribute syscall_attr[] = {
>    { "number", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
>    { "name", GDB_XML_AF_NONE, NULL, NULL },
> +  { "alias", GDB_XML_AF_OPTIONAL, NULL, NULL },
>    { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
>    { NULL, GDB_XML_AF_NONE, NULL, NULL }
>  };
> @@ -389,21 +396,21 @@ syscall_group_get_group_by_name (const struct syscalls_info *syscalls_info,
>    return NULL;
>  }
>  
> -static int
> -xml_get_syscall_number (struct gdbarch *gdbarch,
> -                        const char *syscall_name)
> +static std::vector<int>
> +xml_get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)
>  {
>    struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
> +  std::vector<int> syscalls;
>  
>    if (syscalls_info == NULL
>        || syscall_name == NULL)
> -    return UNKNOWN_SYSCALL;
> +    return syscalls;
>  
>    for (const syscall_desc_up &sysdesc : syscalls_info->syscalls)
> -    if (sysdesc->name == syscall_name)
> -      return sysdesc->number;
> +    if (sysdesc->name == syscall_name || sysdesc->alias == syscall_name)
> +      syscalls.push_back (sysdesc->number);

You can simplify this code by putting the "for" above inside an "if"
like:

  if (syscalls_info != NULL && syscall_name != NULL)
    for (const syscall_desc_up &sysdesc : syscalls_info->syscalls)
      if (sysdesc->name == syscall_name || sysdesc->alias == syscall_name)
	syscalls.push_back (sysdesc->number);

And then you can get rid of the first "if".

>  
> -  return UNKNOWN_SYSCALL;
> +  return syscalls;
>  }
>  
>  static const char *
> @@ -522,14 +529,12 @@ get_syscall_by_number (struct gdbarch *gdbarch,
>    s->name = xml_get_syscall_name (gdbarch, syscall_number);
>  }
>  
> -void
> -get_syscall_by_name (struct gdbarch *gdbarch,
> -		     const char *syscall_name, struct syscall *s)
> +std::vector<int>
> +get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)

I confess I don't feel very happy with this rename.  This function
expects the full name of the syscall to be passed via SYSCALL_NAME, and
it doesn't do any fuzzy matching, so it can be confusing to the reader
understanding why SYSCALL_NAME can map to more than 1 syscall number.
Of course one can put an explanation in the comment, but I'd rather see
a more explicit interface.  Maybe you can extend "struct syscall" and
include fields for an "alias_name" and "alias_number" there.

>  {
>    init_syscalls_info (gdbarch);
>  
> -  s->number = xml_get_syscall_number (gdbarch, syscall_name);
> -  s->name = syscall_name;
> +  return xml_get_syscalls_by_name (gdbarch, syscall_name);
>  }
>  
>  const char **
> diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
> index 4429d66400..86713097b3 100644
> --- a/gdb/xml-syscall.h
> +++ b/gdb/xml-syscall.h
> @@ -38,11 +38,11 @@ void set_xml_syscall_file_name (struct gdbarch *gdbarch,
>  void get_syscall_by_number (struct gdbarch *gdbarch,
>  			    int syscall_number, struct syscall *s);
>  
> -/* Function that retrieves the syscall number corresponding to the given
> -   name.  It puts the requested information inside 'struct syscall'.  */
> +/* Function that retrieves the syscall numbers corresponding to the given
> +   name.  The list of syscall numbers are returned in a vector.  */
>  
> -void get_syscall_by_name (struct gdbarch *gdbarch,
> -			  const char *syscall_name, struct syscall *s);
> +std::vector<int> get_syscalls_by_name (struct gdbarch *gdbarch,
> +				       const char *syscall_name);
>  
>  /* Function used to retrieve the list of syscalls in the system.  This list
>     is returned as an array of strings.  Returns the list of syscalls in the
> -- 
> 2.18.0

I confess I didn't run your code.  What's the output of "catch syscall"
when an alias is found?  I think it might be interesting to explicitly
mark the extra syscall as an alias.  It might take a bit more tweaking
to the code, but I like the idea of being explicit here.

If you decide to go this route, it's also good to update the "catch
syscall" documentation and testcase.

I'd like to know what you and others think, of course.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] Add an optional "alias" attribute to syscall entries.
  2018-10-12  6:13   ` Kevin Buettner
@ 2018-10-17 18:49     ` John Baldwin
  0 siblings, 0 replies; 7+ messages in thread
From: John Baldwin @ 2018-10-17 18:49 UTC (permalink / raw)
  To: Kevin Buettner, gdb-patches

On 10/11/18 11:13 PM, Kevin Buettner wrote:
> Hi John,
> 
> On Wed,  3 Oct 2018 10:30:04 -0700
> John Baldwin <jhb@FreeBSD.org> wrote:
> 
>> When setting a syscall catchpoint by name, catch syscalls whose name
>> or alias matches the requested string.
>>
>> When the ABI of a system call is changed in the FreeBSD kernel, this
>> is implemented by leaving a compatability system call using the old
>> ABI at the existing "slot" and allocating a new system call for the
>> version using the new ABI.  For example, new fields were added to the
>> 'struct kevent' used by the kevent() system call in FreeBSD 12.  The
>> previous kevent() system call in FreeBSD 12 kernels is now called
>> freebsd11_kevent() and is still used by older binaries compiled
>> against the older ABI.  The freebsd11_kevent() system call can be
>> tagged with an "alias" attribute of "kevent" permitting 'catch syscall
>> kevent' to catch both system calls and providing the expected user
>> behavior for both old and new binaries.  It also provides the expected
>> behavior if GDB is compiled on an older host (such as a FreeBSD 11
>> host).
> 
> Very nice.
> 
> I read through your patch.  The only problem I found was this
> use of a GNU extension involving the use of the ternary ?: operator
> without the middle operand.
> 
>>  			     char *groups)
>>  {
>> -  syscall_desc *sysdesc = new syscall_desc (number, name);
>> +  syscall_desc *sysdesc = new syscall_desc (number, name, alias ?: "");
>>  
>>    syscalls_info->syscalls.emplace_back (sysdesc);
>>  
> 
> In addition, the GDB coding standard specifies that pointer variables
> should have explicit comparisons against NULL or nullptr.  So, even if
> it weren't a GNU extension, GDB's coding standard would force you to
> write that expression using an explicit comparison - which in turn would
> necessitate adding the middle argument.  (Which is kind of
> unfortunate, because I like the compactness of that expression.)

Oof, I'll expand it out instead.
-- 
John Baldwin

                                                                            

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] Add an optional "alias" attribute to syscall entries.
  2018-10-13  1:52   ` Sergio Durigan Junior
@ 2018-10-17 19:13     ` John Baldwin
  0 siblings, 0 replies; 7+ messages in thread
From: John Baldwin @ 2018-10-17 19:13 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On 10/12/18 6:51 PM, Sergio Durigan Junior wrote:
> On Wednesday, October 03 2018, John Baldwin wrote:
> 
>> When setting a syscall catchpoint by name, catch syscalls whose name
>> or alias matches the requested string.
> 
> Thanks for the patch, John.
> 
>> When the ABI of a system call is changed in the FreeBSD kernel, this
>> is implemented by leaving a compatability system call using the old
>> ABI at the existing "slot" and allocating a new system call for the
>> version using the new ABI.  For example, new fields were added to the
>> 'struct kevent' used by the kevent() system call in FreeBSD 12.  The
>> previous kevent() system call in FreeBSD 12 kernels is now called
>> freebsd11_kevent() and is still used by older binaries compiled
>> against the older ABI.  The freebsd11_kevent() system call can be
>> tagged with an "alias" attribute of "kevent" permitting 'catch syscall
>> kevent' to catch both system calls and providing the expected user
>> behavior for both old and new binaries.  It also provides the expected
>> behavior if GDB is compiled on an older host (such as a FreeBSD 11
>> host).
> 
> OOC, do you envision the possibility of a syscall having more than 1
> alias?

I don't see a use case for more than one alias given the existing group
functionality.
 
>> @@ -96,8 +94,8 @@ get_syscall_group_names (struct gdbarch *gdbarch)
>>  /* Structure which describes a syscall.  */
>>  struct syscall_desc
>>  {
>> -  syscall_desc (int number_, std::string name_)
>> -  : number (number_), name (name_)
>> +  syscall_desc (int number_, std::string name_, std::string alias_)
>> +  : number (number_), name (name_), alias(alias_)
>                                             ^
> 
> Missing whitespace here.

Fixed.

>>    {}
>>  
>>    /* The syscall number.  */
>> @@ -206,10 +208,10 @@ syscall_group_add_syscall (struct syscalls_info *syscalls_info,
>>  
>>  static void
>>  syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
>> -			     const char *name, int number,
>> +			     const char *name, int number, const char *alias,
>>  			     char *groups)
>>  {
>> -  syscall_desc *sysdesc = new syscall_desc (number, name);
>> +  syscall_desc *sysdesc = new syscall_desc (number, name, alias ?: "");
> 
> As pointed by Kevin, this use of the ternary operator is not common.

Yes, I'll expand.
 
>> @@ -389,21 +396,21 @@ syscall_group_get_group_by_name (const struct syscalls_info *syscalls_info,
>>    return NULL;
>>  }
>>  
>> -static int
>> -xml_get_syscall_number (struct gdbarch *gdbarch,
>> -                        const char *syscall_name)
>> +static std::vector<int>
>> +xml_get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)
>>  {
>>    struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
>> +  std::vector<int> syscalls;
>>  
>>    if (syscalls_info == NULL
>>        || syscall_name == NULL)
>> -    return UNKNOWN_SYSCALL;
>> +    return syscalls;
>>  
>>    for (const syscall_desc_up &sysdesc : syscalls_info->syscalls)
>> -    if (sysdesc->name == syscall_name)
>> -      return sysdesc->number;
>> +    if (sysdesc->name == syscall_name || sysdesc->alias == syscall_name)
>> +      syscalls.push_back (sysdesc->number);
> 
> You can simplify this code by putting the "for" above inside an "if"
> like:
> 
>   if (syscalls_info != NULL && syscall_name != NULL)
>     for (const syscall_desc_up &sysdesc : syscalls_info->syscalls)
>       if (sysdesc->name == syscall_name || sysdesc->alias == syscall_name)
> 	syscalls.push_back (sysdesc->number);
> 
> And then you can get rid of the first "if".

Ok.

>>  
>> -  return UNKNOWN_SYSCALL;
>> +  return syscalls;
>>  }
>>  
>>  static const char *
>> @@ -522,14 +529,12 @@ get_syscall_by_number (struct gdbarch *gdbarch,
>>    s->name = xml_get_syscall_name (gdbarch, syscall_number);
>>  }
>>  
>> -void
>> -get_syscall_by_name (struct gdbarch *gdbarch,
>> -		     const char *syscall_name, struct syscall *s)
>> +std::vector<int>
>> +get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name)
> 
> I confess I don't feel very happy with this rename.  This function
> expects the full name of the syscall to be passed via SYSCALL_NAME, and
> it doesn't do any fuzzy matching, so it can be confusing to the reader
> understanding why SYSCALL_NAME can map to more than 1 syscall number.
> Of course one can put an explanation in the comment, but I'd rather see
> a more explicit interface.  Maybe you can extend "struct syscall" and
> include fields for an "alias_name" and "alias_number" there.

Alias fields wouldn't work as you can have N aliases.  For example in the
updated mapping for FreeBSD 12 there are 3 versions of "fhstatfs"
so that 'catch syscall fhstatfs' matches 3 syscalls:

(gdb) catch syscall fhstatfs
Catchpoint 1 (syscalls 'freebsd4_fhstatfs' [297] 'freebsd11_fhstatfs' [398] 'fhstatfs' [558])

The only caller of this function doesn't actually expect to get full
'struct syscall' objects back, but just integers.  I could instead return
a vector of 'struct syscall' perhaps but only the integers would be used.

That said, get_syscalls_by_group returns an array of 'struct syscall'
objects (it doesn't use a vector, but uses a plain C array).  We could
share some code in the consumer if we made get_syscalls_by_group and this
function follow the same convention.  I would probably want to use a
std::vector rather than a plain C array as the memory management/ownership
is cleaner.

> I confess I didn't run your code.  What's the output of "catch syscall"
> when an alias is found?  I think it might be interesting to explicitly
> mark the extra syscall as an alias.  It might take a bit more tweaking
> to the code, but I like the idea of being explicit here.

I posted some output above.  The aliases are kind of marked already due to
their name in the case of FreeBSD's syscall table.

-- 
John Baldwin

                                                                            

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-10-17 19:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-03 17:30 [PATCH 0/2] Update FreeBSD's syscall table John Baldwin
2018-10-03 17:30 ` [PATCH 1/2] Add an optional "alias" attribute to syscall entries John Baldwin
2018-10-12  6:13   ` Kevin Buettner
2018-10-17 18:49     ` John Baldwin
2018-10-13  1:52   ` Sergio Durigan Junior
2018-10-17 19:13     ` John Baldwin
2018-10-03 17:30 ` [PATCH 2/2] Update the FreeBSD system call table to match FreeBSD 12.0 John Baldwin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).