ObjFW  Check-in [41716f97ed]

Overview
Comment:Add -[OFException backtrace].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 41716f97ed5c4d3b16350fd212de3af937642786155a2ae60891c2736094c0dc
User & Date: js on 2013-05-08 20:15:56
Other Links: manifest | tags
Context
2013-05-13
16:12
Get rid of a type warning on win32. check-in: 3e91cf6cef user: js tags: trunk
2013-05-08
20:15
Add -[OFException backtrace]. check-in: 41716f97ed user: js tags: trunk
2013-05-04
12:04
OFSet: Add -[allObjects] and -[anyObject]. check-in: d1a7509701 user: js tags: trunk
Changes

Modified configure.ac from [8a8597f0c7] to [6ce483001a].

612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
		AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue])
		AC_SUBST(OFSTREAMOBSERVER_KQUEUE_M, "OFStreamObserver_kqueue.m")
	])
	AC_CHECK_HEADER(poll.h, [
		AC_DEFINE(HAVE_POLL_H, 1, [Whether we have poll.h])
		AC_SUBST(OFSTREAMOBSERVER_POLL_M, "OFStreamObserver_poll.m")
	])
	AC_CHECK_HEADERS(sys/select.h, [
		AC_DEFINE(HAVE_SYS_SELECT_H, 1, [Whether we have sys/select.h])
		AC_SUBST(OFSTREAMOBSERVER_SELECT_M, "OFStreamObserver_select.m")
	])
	case "$host_os" in
		mingw*)
			AC_SUBST(OFSTREAMOBSERVER_SELECT_M,
				"OFStreamObserver_select.m")







|







612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
		AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue])
		AC_SUBST(OFSTREAMOBSERVER_KQUEUE_M, "OFStreamObserver_kqueue.m")
	])
	AC_CHECK_HEADER(poll.h, [
		AC_DEFINE(HAVE_POLL_H, 1, [Whether we have poll.h])
		AC_SUBST(OFSTREAMOBSERVER_POLL_M, "OFStreamObserver_poll.m")
	])
	AC_CHECK_HEADER(sys/select.h, [
		AC_DEFINE(HAVE_SYS_SELECT_H, 1, [Whether we have sys/select.h])
		AC_SUBST(OFSTREAMOBSERVER_SELECT_M, "OFStreamObserver_select.m")
	])
	case "$host_os" in
		mingw*)
			AC_SUBST(OFSTREAMOBSERVER_SELECT_M,
				"OFStreamObserver_select.m")
732
733
734
735
736
737
738


739
740
741
742
743
744
745
		])
		;;
esac
AS_IF([test x"$have_processes" = x"yes"], [
	AC_SUBST(OFPROCESS_M, "OFProcess.m")
	AC_DEFINE(OF_HAVE_PROCESSES, 1, [Whether we have processes])
])



AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
	AC_CHECK_HEADER(Foundation/NSObject.h, [
		AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m")
		AC_SUBST(BRIDGE, "bridge")

		AS_IF([test x"$enable_shared" != x"no"], [







>
>







732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
		])
		;;
esac
AS_IF([test x"$have_processes" = x"yes"], [
	AC_SUBST(OFPROCESS_M, "OFProcess.m")
	AC_DEFINE(OF_HAVE_PROCESSES, 1, [Whether we have processes])
])

AC_CHECK_HEADERS(execinfo.h)

AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
	AC_CHECK_HEADER(Foundation/NSObject.h, [
		AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m")
		AC_SUBST(BRIDGE, "bridge")

		AS_IF([test x"$enable_shared" != x"no"], [

Modified src/exceptions/OFException.h from [20ad317438] to [8c5ce69b79].

12
13
14
15
16
17
18


19


20
21
22
23
24
25
26
27
28
29



30
31
32
33
34
35
36
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"



@class OFString;



/*!
 * @brief The base class for all exceptions in ObjFW
 *
 * The OFException class is the base class for all exceptions in ObjFW, except
 * the OFAllocFailedException.
 */
@interface OFException: OFObject
{
	Class _inClass;



}

#ifdef OF_HAVE_PROPERTIES
@property (readonly) Class inClass;
#endif

/*!







>
>

>
>










>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"

#define OF_EXCEPTION_MAX_BACKTRACE_SIZE 32

@class OFString;
@class OFArray;
@class OFMutableArray;

/*!
 * @brief The base class for all exceptions in ObjFW
 *
 * The OFException class is the base class for all exceptions in ObjFW, except
 * the OFAllocFailedException.
 */
@interface OFException: OFObject
{
	Class _inClass;
	OFMutableArray *_backtrace;
	void *_backtraceBuffer[OF_EXCEPTION_MAX_BACKTRACE_SIZE];
	int _backtraceSize;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly) Class inClass;
#endif

/*!
58
59
60
61
62
63
64








65

/*!
 * @brief Returns a description of the exception.
 *
 * @return A description of the exception
 */
- (OFString*)description;








@end







>
>
>
>
>
>
>
>

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

/*!
 * @brief Returns a description of the exception.
 *
 * @return A description of the exception
 */
- (OFString*)description;

/*!
 * @brief Returns a backtrace of when the exception was created or nil if no
 *	  backtrace is available.
 *
 * @return A backtrace of when the exception was created
 */
- (OFArray*)backtrace;
@end

Modified src/exceptions/OFException.m from [5040476f6b] to [122354a46f].

13
14
15
16
17
18
19




20
21
22



23
24
25
26
27
28
29
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>





#import "OFException.h"
#import "OFString.h"




@implementation OFException
+ (instancetype)exceptionWithClass: (Class)class
{
	return [[[self alloc] initWithClass: class] autorelease];
}








>
>
>
>



>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>

#ifdef HAVE_EXECINFO_H
# include <execinfo.h>
#endif

#import "OFException.h"
#import "OFString.h"
#import "OFArray.h"

#import "autorelease.h"

@implementation OFException
+ (instancetype)exceptionWithClass: (Class)class
{
	return [[[self alloc] initWithClass: class] autorelease];
}

40
41
42
43
44
45
46




47
48
49







50
51
52
53
54
55
56
57
58
59
60
61








































62
}

- initWithClass: (Class)class
{
	self = [super init];

	_inClass = class;





	return self;
}








- (Class)inClass
{
	return _inClass;
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"An exception of class %@ occurred in class %@!",
	    object_getClass(self), _inClass];
}








































@end







>
>
>
>



>
>
>
>
>
>
>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
}

- initWithClass: (Class)class
{
	self = [super init];

	_inClass = class;
#ifdef HAVE_EXECINFO_H
	_backtraceSize = backtrace(_backtraceBuffer,
	    OF_EXCEPTION_MAX_BACKTRACE_SIZE);
#endif

	return self;
}

- (void)dealloc
{
	[_backtrace release];

	[super dealloc];
}

- (Class)inClass
{
	return _inClass;
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"An exception of class %@ occurred in class %@!",
	    object_getClass(self), _inClass];
}

- (OFArray*)backtrace
{
#ifdef HAVE_EXECINFO_H
	char **symbols;

	if (_backtrace != nil)
		return _backtrace;

	if (_backtraceSize < 1)
		return nil;

	symbols = backtrace_symbols(_backtraceBuffer, _backtraceSize);
	@try {
		int i;

		_backtrace = [[OFMutableArray alloc] init];

		for (i = 0; i < _backtraceSize; i++) {
			void *pool = objc_autoreleasePoolPush();
			OFString *symbol;

			symbol = [OFString
			    stringWithCString: symbols[i]
				     encoding: OF_STRING_ENCODING_NATIVE];
			[_backtrace addObject: symbol];

			objc_autoreleasePoolPop(pool);
		}
	} @finally {
		free(symbols);
	}

	[_backtrace makeImmutable];

	return _backtrace;
#else
	return nil;
#endif
}
@end