GNU Binutils with patches for OS216
Revision | 609c3040c2df944239d4d96644d736df605a6831 (tree) |
---|---|
Time | 2015-10-21 02:02:09 |
Author | Aleksandar Ristovski <aristovski@qnx....> |
Commiter | Aleksandar Ristovski |
[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.
@@ -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 | + | |
1 | 13 | 2015-10-19 Josh Stone <jistone@redhat.com> |
2 | 14 | |
3 | 15 | * linux-nat.c (linux_handle_syscall_trap): Always update entry/ |
@@ -73,7 +73,7 @@ static int procfs_stopped_by_watchpoint (struct target_ops *ops); | ||
73 | 73 | referenced elsewhere. 'nto_procfs_node' is a flag used to say |
74 | 74 | whether we are local, or we should get the current node descriptor |
75 | 75 | for the remote QNX node. */ |
76 | -static char nto_procfs_path[PATH_MAX] = { "/proc" }; | |
76 | +static char *nodestr; | |
77 | 77 | static unsigned nto_procfs_node = ND_LOCAL_NODE; |
78 | 78 | |
79 | 79 | /* Return the current QNX Node, or error out. This is a simple |
@@ -85,10 +85,11 @@ nto_node (void) | ||
85 | 85 | { |
86 | 86 | unsigned node; |
87 | 87 | |
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) | |
89 | 90 | return ND_LOCAL_NODE; |
90 | 91 | |
91 | - node = netmgr_strtond (nto_procfs_path, 0); | |
92 | + node = netmgr_strtond (nodestr, 0); | |
92 | 93 | if (node == -1) |
93 | 94 | error (_("Lost the QNX node. Debug session probably over.")); |
94 | 95 |
@@ -108,12 +109,12 @@ procfs_is_nto_target (bfd *abfd) | ||
108 | 109 | static void |
109 | 110 | procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) |
110 | 111 | { |
111 | - char *nodestr; | |
112 | 112 | char *endstr; |
113 | 113 | char buffer[50]; |
114 | 114 | int fd, total_size; |
115 | 115 | procfs_sysinfo *sysinfo; |
116 | 116 | struct cleanup *cleanups; |
117 | + char nto_procfs_path[PATH_MAX]; | |
117 | 118 | |
118 | 119 | /* Offer to kill previous inferiors before opening this target. */ |
119 | 120 | target_preopen (from_tty); |
@@ -123,8 +124,11 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) | ||
123 | 124 | /* Set the default node used for spawning to this one, |
124 | 125 | and only override it if there is a valid arg. */ |
125 | 126 | |
127 | + xfree (nodestr); | |
128 | + nodestr = NULL; | |
129 | + | |
126 | 130 | nto_procfs_node = ND_LOCAL_NODE; |
127 | - nodestr = arg ? xstrdup (arg) : NULL; | |
131 | + nodestr = (arg != NULL) ? xstrdup (arg) : NULL; | |
128 | 132 | |
129 | 133 | init_thread_list (); |
130 | 134 |
@@ -149,10 +153,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) | ||
149 | 153 | *endstr = 0; |
150 | 154 | } |
151 | 155 | } |
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"); | |
156 | 158 | |
157 | 159 | fd = open (nto_procfs_path, O_RDONLY); |
158 | 160 | if (fd == -1) |
@@ -174,7 +176,7 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) | ||
174 | 176 | { |
175 | 177 | total_size = sysinfo->total_size; |
176 | 178 | sysinfo = alloca (total_size); |
177 | - if (!sysinfo) | |
179 | + if (sysinfo == NULL) | |
178 | 180 | { |
179 | 181 | printf_filtered ("Memory error: %d (%s)\n", errno, |
180 | 182 | safe_strerror (errno)); |
@@ -359,7 +361,7 @@ procfs_pidlist (char *args, int from_tty) | ||
359 | 361 | { |
360 | 362 | DIR *dp = NULL; |
361 | 363 | struct dirent *dirp = NULL; |
362 | - char buf[512]; | |
364 | + char buf[PATH_MAX]; | |
363 | 365 | procfs_info *pidinfo = NULL; |
364 | 366 | procfs_debuginfo *info = NULL; |
365 | 367 | procfs_status *status = NULL; |
@@ -367,12 +369,16 @@ procfs_pidlist (char *args, int from_tty) | ||
367 | 369 | pid_t pid; |
368 | 370 | char name[512]; |
369 | 371 | struct cleanup *cleanups; |
372 | + char procfs_dir[PATH_MAX]; | |
370 | 373 | |
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); | |
372 | 378 | if (dp == NULL) |
373 | 379 | { |
374 | 380 | 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)); | |
376 | 382 | return; |
377 | 383 | } |
378 | 384 |
@@ -395,7 +401,9 @@ procfs_pidlist (char *args, int from_tty) | ||
395 | 401 | do_cleanups (cleanups); |
396 | 402 | return; |
397 | 403 | } |
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); | |
399 | 407 | pid = atoi (dirp->d_name); |
400 | 408 | } |
401 | 409 | while (pid == 0); |
@@ -406,8 +414,7 @@ procfs_pidlist (char *args, int from_tty) | ||
406 | 414 | { |
407 | 415 | fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n", |
408 | 416 | buf, errno, safe_strerror (errno)); |
409 | - do_cleanups (cleanups); | |
410 | - return; | |
417 | + continue; | |
411 | 418 | } |
412 | 419 | inner_cleanup = make_cleanup_close (fd); |
413 | 420 |
@@ -431,11 +438,16 @@ procfs_pidlist (char *args, int from_tty) | ||
431 | 438 | status = (procfs_status *) buf; |
432 | 439 | for (status->tid = 1; status->tid <= num_threads; status->tid++) |
433 | 440 | { |
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 | + } | |
439 | 451 | } |
440 | 452 | |
441 | 453 | do_cleanups (inner_cleanup); |
@@ -599,7 +611,8 @@ procfs_files_info (struct target_ops *ignore) | ||
599 | 611 | |
600 | 612 | printf_unfiltered ("\tUsing the running image of %s %s via %s.\n", |
601 | 613 | 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"); | |
603 | 616 | } |
604 | 617 | |
605 | 618 | /* Attach to process PID, then initialize for debugging it. */ |
@@ -653,8 +666,8 @@ do_attach (ptid_t ptid) | ||
653 | 666 | struct sigevent event; |
654 | 667 | char path[PATH_MAX]; |
655 | 668 | |
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)); | |
658 | 671 | ctl_fd = open (path, O_RDWR); |
659 | 672 | if (ctl_fd == -1) |
660 | 673 | 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, | ||
1121 | 1134 | } |
1122 | 1135 | |
1123 | 1136 | args = xstrdup (allargs); |
1124 | - breakup_args (args, exec_file ? &argv[1] : &argv[0]); | |
1137 | + breakup_args (args, (exec_file != NULL) ? &argv[1] : &argv[0]); | |
1125 | 1138 | |
1126 | 1139 | argv = nto_parse_redirection (argv, &in, &out, &err); |
1127 | 1140 |