• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision609c3040c2df944239d4d96644d736df605a6831 (tree)
Time2015-10-21 02:02:09
AuthorAleksandar Ristovski <aristovski@qnx....>
CommiterAleksandar Ristovski

Log Message

[nto] Fixes for nto procfs.

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.

Change Summary

Incremental Difference

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,15 @@
1+2015-10-20 Aleksandar Ristovski <aristovski@qnx.com>
2+
3+ * nto-procfs.c (nto_procfs_path): Rename to...
4+ (nodestr): ... this, and change type.
5+ (nto_node): Use new variable and logic accordingly.
6+ (procfs_open_1): Use new variable name. Use local buffer to construct
7+ procfrs path.
8+ (procfs_pidlist): Use NODESTR to construct procfs path.
9+ (procfs_files_info): Use NODESTR to output meaningful text.
10+ (do_attach): Construct procfs using NODESTR.
11+ (procfs_create_inferior): Compare pointer to NULL.
12+
113 2015-10-19 Josh Stone <jistone@redhat.com>
214
315 * linux-nat.c (linux_handle_syscall_trap): Always update entry/
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -73,7 +73,7 @@ static int procfs_stopped_by_watchpoint (struct target_ops *ops);
7373 referenced elsewhere. 'nto_procfs_node' is a flag used to say
7474 whether we are local, or we should get the current node descriptor
7575 for the remote QNX node. */
76-static char nto_procfs_path[PATH_MAX] = { "/proc" };
76+static char *nodestr;
7777 static unsigned nto_procfs_node = ND_LOCAL_NODE;
7878
7979 /* Return the current QNX Node, or error out. This is a simple
@@ -85,10 +85,11 @@ nto_node (void)
8585 {
8686 unsigned node;
8787
88- if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) == 0)
88+ if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) == 0
89+ || nodestr == NULL)
8990 return ND_LOCAL_NODE;
9091
91- node = netmgr_strtond (nto_procfs_path, 0);
92+ node = netmgr_strtond (nodestr, 0);
9293 if (node == -1)
9394 error (_("Lost the QNX node. Debug session probably over."));
9495
@@ -108,12 +109,12 @@ procfs_is_nto_target (bfd *abfd)
108109 static void
109110 procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
110111 {
111- char *nodestr;
112112 char *endstr;
113113 char buffer[50];
114114 int fd, total_size;
115115 procfs_sysinfo *sysinfo;
116116 struct cleanup *cleanups;
117+ char nto_procfs_path[PATH_MAX];
117118
118119 /* Offer to kill previous inferiors before opening this target. */
119120 target_preopen (from_tty);
@@ -123,8 +124,11 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
123124 /* Set the default node used for spawning to this one,
124125 and only override it if there is a valid arg. */
125126
127+ xfree (nodestr);
128+ nodestr = NULL;
129+
126130 nto_procfs_node = ND_LOCAL_NODE;
127- nodestr = arg ? xstrdup (arg) : NULL;
131+ nodestr = (arg != NULL) ? xstrdup (arg) : NULL;
128132
129133 init_thread_list ();
130134
@@ -149,10 +153,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
149153 *endstr = 0;
150154 }
151155 }
152- snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s", nodestr ? nodestr : "",
153- "/proc");
154- if (nodestr)
155- xfree (nodestr);
156+ snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s",
157+ (nodestr != NULL) ? nodestr : "", "/proc");
156158
157159 fd = open (nto_procfs_path, O_RDONLY);
158160 if (fd == -1)
@@ -174,7 +176,7 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
174176 {
175177 total_size = sysinfo->total_size;
176178 sysinfo = alloca (total_size);
177- if (!sysinfo)
179+ if (sysinfo == NULL)
178180 {
179181 printf_filtered ("Memory error: %d (%s)\n", errno,
180182 safe_strerror (errno));
@@ -359,7 +361,7 @@ procfs_pidlist (char *args, int from_tty)
359361 {
360362 DIR *dp = NULL;
361363 struct dirent *dirp = NULL;
362- char buf[512];
364+ char buf[PATH_MAX];
363365 procfs_info *pidinfo = NULL;
364366 procfs_debuginfo *info = NULL;
365367 procfs_status *status = NULL;
@@ -367,12 +369,16 @@ procfs_pidlist (char *args, int from_tty)
367369 pid_t pid;
368370 char name[512];
369371 struct cleanup *cleanups;
372+ char procfs_dir[PATH_MAX];
370373
371- dp = opendir (nto_procfs_path);
374+ snprintf (procfs_dir, sizeof (procfs_dir), "%s%s",
375+ (nodestr != NULL) ? nodestr : "", "/proc");
376+
377+ dp = opendir (procfs_dir);
372378 if (dp == NULL)
373379 {
374380 fprintf_unfiltered (gdb_stderr, "failed to opendir \"%s\" - %d (%s)",
375- nto_procfs_path, errno, safe_strerror (errno));
381+ procfs_dir, errno, safe_strerror (errno));
376382 return;
377383 }
378384
@@ -395,7 +401,9 @@ procfs_pidlist (char *args, int from_tty)
395401 do_cleanups (cleanups);
396402 return;
397403 }
398- snprintf (buf, 511, "%s/%s/as", nto_procfs_path, dirp->d_name);
404+ snprintf (buf, sizeof (buf), "%s%s/%s/as",
405+ (nodestr != NULL) ? nodestr : "",
406+ "/proc", dirp->d_name);
399407 pid = atoi (dirp->d_name);
400408 }
401409 while (pid == 0);
@@ -406,8 +414,7 @@ procfs_pidlist (char *args, int from_tty)
406414 {
407415 fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n",
408416 buf, errno, safe_strerror (errno));
409- do_cleanups (cleanups);
410- return;
417+ continue;
411418 }
412419 inner_cleanup = make_cleanup_close (fd);
413420
@@ -431,11 +438,16 @@ procfs_pidlist (char *args, int from_tty)
431438 status = (procfs_status *) buf;
432439 for (status->tid = 1; status->tid <= num_threads; status->tid++)
433440 {
434- if (devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0) != EOK
435- && status->tid != 0)
436- break;
437- if (status->tid != 0)
438- printf_filtered ("%s - %d/%d\n", name, pid, status->tid);
441+ const int err
442+ = devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0);
443+ printf_filtered ("%s - %d", name, pid);
444+ if (err == EOK && status->tid != 0)
445+ printf_filtered ("/%d\n", status->tid);
446+ else
447+ {
448+ printf_filtered ("\n");
449+ break;
450+ }
439451 }
440452
441453 do_cleanups (inner_cleanup);
@@ -599,7 +611,8 @@ procfs_files_info (struct target_ops *ignore)
599611
600612 printf_unfiltered ("\tUsing the running image of %s %s via %s.\n",
601613 inf->attach_flag ? "attached" : "child",
602- target_pid_to_str (inferior_ptid), nto_procfs_path);
614+ target_pid_to_str (inferior_ptid),
615+ (nodestr != NULL) ? nodestr : "local node");
603616 }
604617
605618 /* Attach to process PID, then initialize for debugging it. */
@@ -653,8 +666,8 @@ do_attach (ptid_t ptid)
653666 struct sigevent event;
654667 char path[PATH_MAX];
655668
656- snprintf (path, PATH_MAX - 1, "%s/%d/as", nto_procfs_path,
657- ptid_get_pid (ptid));
669+ snprintf (path, PATH_MAX - 1, "%s%s/%d/as",
670+ (nodestr != NULL) ? nodestr : "", "/proc", ptid_get_pid (ptid));
658671 ctl_fd = open (path, O_RDWR);
659672 if (ctl_fd == -1)
660673 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,
11211134 }
11221135
11231136 args = xstrdup (allargs);
1124- breakup_args (args, exec_file ? &argv[1] : &argv[0]);
1137+ breakup_args (args, (exec_file != NULL) ? &argv[1] : &argv[0]);
11251138
11261139 argv = nto_parse_redirection (argv, &in, &out, &err);
11271140