From b4ab256ded5020a82ff7ce8dc485e7882fc5b6a7 Mon Sep 17 00:00:00 2001 From: Hui Zhu Date: Fri, 21 Mar 2014 10:25:41 +0800 Subject: [PATCH] Fix internal warning when "gdb -p xxx" ps -e | grep a.out 28886 pts/12 00:00:00 a.out gdb -p 28886 Loaded symbols for /lib64/ld-linux-x86-64.so.2 0x0000003b0ccbc970 in __nanosleep_nocancel () from /lib64/libc.so.6 ../../binutils-gdb/gdb/cleanups.c:265: internal-warning: restore_my_cleanups has found a stale cleanup A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) The backtrace of this issue: (gdb) bt file=0x8b0c10 "s' failed.", line=265, fmt=0x8b0c38 "nutils-gdb/gdb/cleanups.c", ap=0x7fff803e3ed8) at ../../binutils-gdb/gdb/utils.c:748 fmt=0x8b0c38 "nutils-gdb/gdb/cleanups.c", ap=0x7fff803e3ed8) at ../../binutils-gdb/gdb/utils.c:799 string=0x8b0c38 "nutils-gdb/gdb/cleanups.c") at ../../binutils-gdb/gdb/utils.c:809 at ../../binutils-gdb/gdb/cleanups.c:265 at ../../binutils-gdb/gdb/cleanups.c:276 at ../../binutils-gdb/gdb/exceptions.c:142 at ../../binutils-gdb/gdb/exceptions.c:203 command=0x5d5fb8 , arg=0x7fff803e525b "2914", from_tty=1, mask=RETURN_MASK_ALL) at ../../binutils-gdb/gdb/exceptions.c:549 ---Type to continue, or q to quit--- func_args=0x7fff803e4280, errstring=0x8cf2e4 "/local/bin", mask=RETURN_MASK_ALL) at ../../binutils-gdb/gdb/exceptions.c:522 This is a new issue. It is introduced by commit https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=8bc2fe488957946d2cdccda3ce8d4f39e4003ea0 It removed the discard_cleanups (back_to) inside attach_command. Then restore_my_cleanups will throw a internal_warning. https://sourceware.org/ml/gdb-patches/2014-03/msg00374.html 2014-03-21 Hui Zhu Pedro Alves * darwin-nat.c (darwin_pid_to_exec_file): Change xmalloc to static buffer. * fbsd-nat.c (fbsd_pid_to_exec_file): Ditto. * linux-nat.c (linux_child_pid_to_exec_file): Ditto. * nbsd-nat.c (nbsd_pid_to_exec_file): Ditto. --- gdb/ChangeLog | 9 +++++++++ gdb/darwin-nat.c | 5 +---- gdb/fbsd-nat.c | 18 +++++++++--------- gdb/linux-nat.c | 18 +++++++----------- gdb/nbsd-nat.c | 18 +++++++++--------- 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f2e4a815024..ba2ca31f3ce 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2014-03-21 Hui Zhu + Pedro Alves + + * darwin-nat.c (darwin_pid_to_exec_file): Change xmalloc to + static buffer. + * fbsd-nat.c (fbsd_pid_to_exec_file): Ditto. + * linux-nat.c (linux_child_pid_to_exec_file): Ditto. + * nbsd-nat.c (nbsd_pid_to_exec_file): Ditto. + 2014-03-20 Maciej W. Rozycki * mi/mi-interp.c (mi_memory_changed): Avoid using the ISO C99 diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 88cecf3acc6..23a921d80ee 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1991,12 +1991,9 @@ set_enable_mach_exceptions (char *args, int from_tty, static char * darwin_pid_to_exec_file (struct target_ops *self, int pid) { - char *path; + static char path[PATH_MAX]; int res; - path = xmalloc (PATH_MAX); - make_cleanup (xfree, path); - res = proc_pidinfo (pid, PROC_PIDPATHINFO, 0, path, PATH_MAX); if (res >= 0) return path; diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index a2a1f60ec4b..9f30edf4b27 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -39,9 +39,9 @@ char * fbsd_pid_to_exec_file (struct target_ops *self, int pid) { - size_t len = PATH_MAX; - char *buf = xcalloc (len, sizeof (char)); - char *path; + ssize_t len = PATH_MAX; + static char buf[PATH_MAX]; + char name[PATH_MAX]; #ifdef KERN_PROC_PATHNAME int mib[4]; @@ -54,15 +54,15 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid) return buf; #endif - path = xstrprintf ("/proc/%d/file", pid); - if (readlink (path, buf, PATH_MAX - 1) == -1) + xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); + len = readlink (name, buf, PATH_MAX - 1); + if (len != -1) { - xfree (buf); - buf = NULL; + buf[len] = '\0'; + return buf; } - xfree (path); - return buf; + return NULL; } static int diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index b615423fafd..d08cb1357cc 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4011,19 +4011,15 @@ linux_nat_thread_name (struct target_ops *self, struct thread_info *thr) static char * linux_child_pid_to_exec_file (struct target_ops *self, int pid) { - char *name1, *name2; + static char buf[PATH_MAX]; + char name[PATH_MAX]; - name1 = xmalloc (PATH_MAX); - name2 = xmalloc (PATH_MAX); - make_cleanup (xfree, name1); - make_cleanup (xfree, name2); - memset (name2, 0, PATH_MAX); + xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); + memset (buf, 0, PATH_MAX); + if (readlink (name, buf, PATH_MAX - 1) <= 0) + strcpy (buf, name); - xsnprintf (name1, PATH_MAX, "/proc/%d/exe", pid); - if (readlink (name1, name2, PATH_MAX - 1) > 0) - return name2; - else - return name1; + return buf; } /* Records the thread's register state for the corefile note diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c index 72c471b4c2f..133de619001 100644 --- a/gdb/nbsd-nat.c +++ b/gdb/nbsd-nat.c @@ -27,17 +27,17 @@ char * nbsd_pid_to_exec_file (struct target_ops *self, int pid) { - size_t len = PATH_MAX; - char *buf = xcalloc (len, sizeof (char)); - char *path; + ssize_t len; + static char buf[PATH_MAX]; + char name[PATH_MAX]; - path = xstrprintf ("/proc/%d/exe", pid); - if (readlink (path, buf, PATH_MAX - 1) == -1) + xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); + len = readlink (name, buf, PATH_MAX - 1); + if (len != -1) { - xfree (buf); - buf = NULL; + buf[len] = '\0'; + return buf; } - xfree (path); - return buf; + return NULL; } -- 2.30.2