Re: [PATCH] Use backtrace() instead of __builtin_return_address()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bernhard Walle wrote:
When crash is compiled with gcc 4.3 and -O2, the __builtin_return_address()
causes crash to crash. See also [1] for a discussion about that.

It appears that [1] only describes a problem if you ask for more frames
than exist.  Given the usage in crash, it's impossible to have a frame count
of less than 4.  So it must be some other bug, no?

Dave

The gcc documentation [2] says

	__builtin_return_address()

	On some machines it may be impossible to determine the return address of
	any function other than the current one; in such cases, or when the top
	of the stack has been reached, this function will return 0 or a random
	value. In addition, __builtin_frame_address may be used to determine if
	the top of the stack has been reached.
	
	This function should only be used with a nonzero argument for debugging
	purposes.

Even the __builtin_frame_address() does not work here. Instead of checking
if the crash is built with -O2 and introducing new preprocessor checks here,
I use the backtrace() function which is available via glibc. This works here
(tested without the other patch which brought my attention to this bug).

Since crash only runs on Linux (IIRC), the glibc dependency should not be
a problem.

Signed-off-by: Bernhard Walle <bwalle@xxxxxxx>


[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=165992
[2] http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html

---
 defs.h |   10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

--- a/defs.h
+++ b/defs.h
@@ -1803,15 +1803,7 @@ struct alias_data {                 /* c
 static inline void
 save_return_address(ulong *retaddr)
 {
-	retaddr[0] = (ulong) __builtin_return_address(0);
-#if defined(X86) || defined(PPC) || defined(X86_64) || defined(PPC64)
-	if (__builtin_frame_address(1))
-		retaddr[1] = (ulong) __builtin_return_address(1);
-	if (__builtin_frame_address(2))
-                retaddr[2] = (ulong) __builtin_return_address(2);
-	if (__builtin_frame_address(3))
-                retaddr[3] = (ulong) __builtin_return_address(3);
-#endif
+	backtrace(retaddr, 4);
 }
#endif /* !GDB_COMMON */

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux