Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Aleksandar Ristovski <aristovski@qnx.com>
To: gdb-patches@sourceware.org
Cc: palves@redhat.com,	Aleksandar Ristovski <aristovski@qnx.com>
Subject: [PATCH 1/3] (patch 2/4, v2) [nto] Fixes for nto procfs.
Date: Tue, 20 Oct 2015 14:29:00 -0000	[thread overview]
Message-ID: <1445351294-18179-2-git-send-email-aristovski@qnx.com> (raw)
In-Reply-To: <1445351294-18179-1-git-send-email-aristovski@qnx.com>

Fix errnoeus construction of procfs path. The issue is, after the first
info pidlist or first run, the path for local node (the most common node)
will be reset to empty which makes subsequent queries and runs impossible.

gdb/ChangeLog:

	* nto-procfs.c (nto_procfs_path): Rename to...
	(nodestr): ... this, and change type.
	(nto_node): Use new variable and logic accordingly.
	(procfs_open_1): Use new variable name. Use local buffer to construct
	procfrs path.
	(procfs_pidlist): Use NODESTR to construct procfs path.
	(procfs_files_info): Use NODESTR to output meaningful text.
	(do_attach): Construct procfs using NODESTR.
	(procfs_create_inferior): Compare pointer to NULL.
---
 gdb/nto-procfs.c | 63 ++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 25 deletions(-)

diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c
index d659f79..264d88b 100644
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -73,7 +73,7 @@ static int procfs_stopped_by_watchpoint (struct target_ops *ops);
    referenced elsewhere.  'nto_procfs_node' is a flag used to say
    whether we are local, or we should get the current node descriptor
    for the remote QNX node.  */
-static char nto_procfs_path[PATH_MAX] = { "/proc" };
+static char *nodestr;
 static unsigned nto_procfs_node = ND_LOCAL_NODE;
 
 /* Return the current QNX Node, or error out.  This is a simple
@@ -85,10 +85,11 @@ nto_node (void)
 {
   unsigned node;
 
-  if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) == 0)
+  if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) == 0
+      || nodestr == NULL)
     return ND_LOCAL_NODE;
 
-  node = netmgr_strtond (nto_procfs_path, 0);
+  node = netmgr_strtond (nodestr, 0);
   if (node == -1)
     error (_("Lost the QNX node.  Debug session probably over."));
 
@@ -108,12 +109,12 @@ procfs_is_nto_target (bfd *abfd)
 static void
 procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
 {
-  char *nodestr;
   char *endstr;
   char buffer[50];
   int fd, total_size;
   procfs_sysinfo *sysinfo;
   struct cleanup *cleanups;
+  char nto_procfs_path[PATH_MAX];
 
   /* Offer to kill previous inferiors before opening this target.  */
   target_preopen (from_tty);
@@ -123,8 +124,11 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
   /* Set the default node used for spawning to this one,
      and only override it if there is a valid arg.  */
 
+  xfree (nodestr);
+  nodestr = NULL;
+
   nto_procfs_node = ND_LOCAL_NODE;
-  nodestr = arg ? xstrdup (arg) : NULL;
+  nodestr = (arg != NULL) ? xstrdup (arg) : NULL;
 
   init_thread_list ();
 
@@ -149,10 +153,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
 	    *endstr = 0;
 	}
     }
-  snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s", nodestr ? nodestr : "",
-	    "/proc");
-  if (nodestr)
-    xfree (nodestr);
+  snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s",
+	    (nodestr != NULL) ? nodestr : "", "/proc");
 
   fd = open (nto_procfs_path, O_RDONLY);
   if (fd == -1)
@@ -174,7 +176,7 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
     {
       total_size = sysinfo->total_size;
       sysinfo = alloca (total_size);
-      if (!sysinfo)
+      if (sysinfo == NULL)
 	{
 	  printf_filtered ("Memory error: %d (%s)\n", errno,
 			   safe_strerror (errno));
@@ -359,7 +361,7 @@ procfs_pidlist (char *args, int from_tty)
 {
   DIR *dp = NULL;
   struct dirent *dirp = NULL;
-  char buf[512];
+  char buf[PATH_MAX];
   procfs_info *pidinfo = NULL;
   procfs_debuginfo *info = NULL;
   procfs_status *status = NULL;
@@ -367,12 +369,16 @@ procfs_pidlist (char *args, int from_tty)
   pid_t pid;
   char name[512];
   struct cleanup *cleanups;
+  char procfs_dir[PATH_MAX];
 
-  dp = opendir (nto_procfs_path);
+  snprintf (procfs_dir, sizeof (procfs_dir), "%s%s",
+	    (nodestr != NULL) ? nodestr : "", "/proc");
+
+  dp = opendir (procfs_dir);
   if (dp == NULL)
     {
       fprintf_unfiltered (gdb_stderr, "failed to opendir \"%s\" - %d (%s)",
-			  nto_procfs_path, errno, safe_strerror (errno));
+			  procfs_dir, errno, safe_strerror (errno));
       return;
     }
 
@@ -395,7 +401,9 @@ procfs_pidlist (char *args, int from_tty)
 	      do_cleanups (cleanups);
 	      return;
 	    }
-	  snprintf (buf, 511, "%s/%s/as", nto_procfs_path, dirp->d_name);
+	  snprintf (buf, sizeof (buf), "%s%s/%s/as",
+		    (nodestr != NULL) ? nodestr : "",
+		    "/proc", dirp->d_name);
 	  pid = atoi (dirp->d_name);
 	}
       while (pid == 0);
@@ -406,8 +414,7 @@ procfs_pidlist (char *args, int from_tty)
 	{
 	  fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n",
 			      buf, errno, safe_strerror (errno));
-	  do_cleanups (cleanups);
-	  return;
+	  continue;
 	}
       inner_cleanup = make_cleanup_close (fd);
 
@@ -431,11 +438,16 @@ procfs_pidlist (char *args, int from_tty)
       status = (procfs_status *) buf;
       for (status->tid = 1; status->tid <= num_threads; status->tid++)
 	{
-	  if (devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0) != EOK
-	      && status->tid != 0)
-	    break;
-	  if (status->tid != 0)
-	    printf_filtered ("%s - %d/%d\n", name, pid, status->tid);
+	  const int err
+	    = devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0);
+	  printf_filtered ("%s - %d", name, pid);
+	  if (err == EOK && status->tid != 0)
+	    printf_filtered ("/%d\n", status->tid);
+	  else
+	    {
+	      printf_filtered ("\n");
+	      break;
+	    }
 	}
 
       do_cleanups (inner_cleanup);
@@ -599,7 +611,8 @@ procfs_files_info (struct target_ops *ignore)
 
   printf_unfiltered ("\tUsing the running image of %s %s via %s.\n",
 		     inf->attach_flag ? "attached" : "child",
-		     target_pid_to_str (inferior_ptid), nto_procfs_path);
+		     target_pid_to_str (inferior_ptid),
+		     (nodestr != NULL) ? nodestr : "local node");
 }
 
 /* Attach to process PID, then initialize for debugging it.  */
@@ -653,8 +666,8 @@ do_attach (ptid_t ptid)
   struct sigevent event;
   char path[PATH_MAX];
 
-  snprintf (path, PATH_MAX - 1, "%s/%d/as", nto_procfs_path,
-	    ptid_get_pid (ptid));
+  snprintf (path, PATH_MAX - 1, "%s%s/%d/as",
+	    (nodestr != NULL) ? nodestr : "", "/proc", ptid_get_pid (ptid));
   ctl_fd = open (path, O_RDWR);
   if (ctl_fd == -1)
     error (_("Couldn't open proc file %s, error %d (%s)"), path, errno,
@@ -1121,7 +1134,7 @@ procfs_create_inferior (struct target_ops *ops, char *exec_file,
     }
 
   args = xstrdup (allargs);
-  breakup_args (args, exec_file ? &argv[1] : &argv[0]);
+  breakup_args (args, (exec_file != NULL) ? &argv[1] : &argv[0]);
 
   argv = nto_parse_redirection (argv, &in, &out, &err);
 
-- 
1.9.1


  parent reply	other threads:[~2015-10-20 14:28 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-13 16:01 [PATCH 0/4] [nto] Nto fixes Aleksandar Ristovski
2015-10-13 16:01 ` [PATCH 3/4] [nto] Fix nto target stopped by watchpoint Aleksandar Ristovski
2015-10-16 16:10   ` Pedro Alves
2015-10-20 18:42     ` [PATCH 0/2] (patch 3/4 v2) Broken down patch 3/4 Aleksandar Ristovski
2015-10-20 19:24       ` [PATCH 2/2] [nto] Improve ABI sniffing Aleksandar Ristovski
2015-10-21 10:39         ` Pedro Alves
2015-10-21 14:47           ` Aleksandar Ristovski
2015-10-21 14:42             ` Aleksandar Ristovski
2015-10-21 15:17             ` Pedro Alves
2015-10-21 15:37               ` Aleksandar Ristovski
2015-10-21 16:13                 ` Aleksandar Ristovski
2015-10-21 16:39                 ` Pedro Alves
2015-10-21 18:23                   ` Aleksandar Ristovski
2015-10-21 18:10                     ` Aleksandar Ristovski
2015-10-21  8:18       ` [PATCH 1/2] [nto] Fix nto target stopped by watchpoint Aleksandar Ristovski
2015-10-21 10:39         ` Pedro Alves
2015-10-21 18:00           ` Aleksandar Ristovski
2015-10-21 17:51             ` Aleksandar Ristovski
2015-10-13 16:01 ` [PATCH 1/4] [nto] Fix nto build Aleksandar Ristovski
2015-10-15 17:34   ` Pedro Alves
2015-10-13 16:01 ` [PATCH 2/4] [nto] Fixes for nto procfs Aleksandar Ristovski
2015-10-15 17:41   ` Pedro Alves
2015-10-20 13:21     ` Aleksandar Ristovski
2015-10-20 12:43       ` Aleksandar Ristovski
2015-10-20 14:28       ` Pedro Alves
2015-10-20 14:28         ` [PATCH 0/3] (patch 2/4, v2) Break patch 2/4 into 3 Aleksandar Ristovski
2015-10-20 14:28           ` [PATCH 2/3] (patch 2/4, v2) [nto] Implement TARGET_OBJECT_AUXV Aleksandar Ristovski
2015-10-20 15:24             ` Pedro Alves
2015-10-20 16:03               ` Aleksandar Ristovski
2015-10-20 16:48                 ` Pedro Alves
2015-10-20 17:08                   ` Aleksandar Ristovski
2015-10-20 17:13                     ` Aleksandar Ristovski
2015-10-20 18:11                     ` Pedro Alves
2015-10-20 18:11                     ` Aleksandar Ristovski
2015-10-20 18:39                       ` Aleksandar Ristovski
2015-10-20 14:29           ` Aleksandar Ristovski [this message]
2015-10-20 15:20             ` [PATCH 1/3] (patch 2/4, v2) [nto] Fixes for nto procfs Pedro Alves
2015-10-20 17:13               ` Aleksandar Ristovski
2015-10-20 17:14                 ` Aleksandar Ristovski
2015-10-20 15:03           ` [PATCH 3/3] (patch 2/4, v2) [nto] Implement procfs_pid_to_exec_file Aleksandar Ristovski
2015-10-20 15:25             ` Pedro Alves
2015-10-20 18:11               ` Aleksandar Ristovski
2015-10-20 18:19                 ` Aleksandar Ristovski
2015-10-13 16:01 ` [PATCH 4/4] [nto] Setup signals Aleksandar Ristovski
2015-10-16 16:16   ` Pedro Alves
2015-10-22 15:57     ` Aleksandar Ristovski
2015-10-22 15:58       ` Aleksandar Ristovski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445351294-18179-2-git-send-email-aristovski@qnx.com \
    --to=aristovski@qnx.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox