My favorites | Sign in
Logo
                
1
2
3
4
5
6
7
8
9
10
11
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
44
45
46
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
//
// GTMStackTrace.h
//
// Copyright 2007-2008 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
//

#include <CoreFoundation/CoreFoundation.h>
#import "GTMDefines.h"

#ifdef __cplusplus
extern "C" {
#endif

struct GTMAddressDescriptor {
const void *address; // address
const char *symbol; // nearest symbol to address
const char *class_name; // if it is an obj-c method, the method's class
BOOL is_class_method; // if it is an obj-c method, type of method
const char *filename; // file that the method came from.
};

// Returns a string containing a nicely formatted stack trace.
//
// This function gets the stack trace for the current thread. It will
// be from the caller of GTMStackTrace upwards to the top the calling stack.
// Typically this function will be used along with some logging,
// as in the following:
//
// MyAppLogger(@"Should never get here:\n%@", GTMStackTrace());
//
// Here is a sample stack trace returned from this function:
//
// #0 0x00002d92 D () [/Users/me/./StackLog]
// #1 0x00002e45 C () [/Users/me/./StackLog]
// #2 0x00002e53 B () [/Users/me/./StackLog]
// #3 0x00002e61 A () [/Users/me/./StackLog]
// #4 0x00002e6f main () [/Users/me/./StackLog]
// #5 0x00002692 tart () [/Users/me/./StackLog]
// #6 0x000025b9 tart () [/Users/me/./StackLog]
//

NSString *GTMStackTrace(void);

#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
// Returns a string containing a nicely formatted stack trace from the
// exception. Only available on 10.5 or later, uses
// -[NSException callStackReturnAddresses].
//
NSString *GTMStackTraceFromException(NSException *e);
#endif

#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
// Returns an array of program counters from the current thread's stack.
// *** You should probably use GTMStackTrace() instead of this function ***
// However, if you actually want all the PCs in "void *" form, then this
// funtion is more convenient. This will include PCs of GTMStaceTrace and
// its inner utility functions that you may want to strip out.
//
// You can use +[NSThread callStackReturnAddresses] in 10.5 or later.
//
// Args:
// outPcs - an array of "void *" pointers to the program counters found on the
// current thread's stack.
// count - the number of entries in the outPcs array
//
// Returns:
// The number of program counters actually added to outPcs.
//
NSUInteger GTMGetStackProgramCounters(void *outPcs[], NSUInteger count);
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5

// Returns an array of GTMAddressDescriptors from the current thread's stack.
// *** You should probably use GTMStackTrace() instead of this function ***
// However, if you actually want all the PCs with symbols, this is the way
// to get them. There is no memory allocations done, so no clean up is required
// except for the caller to free outDescs if they allocated it themselves.
// This will include PCs of GTMStaceTrace and its inner utility functions that
// you may want to strip out.
//
// Args:
// outDescs - an array of "struct GTMAddressDescriptor" pointers corresponding
// to the program counters found on the current thread's stack.
// count - the number of entries in the outDescs array
//
// Returns:
// The number of program counters actually added to outPcs.
//
NSUInteger GTMGetStackAddressDescriptors(struct GTMAddressDescriptor outDescs[],
NSUInteger count);

#ifdef __cplusplus
}
#endif
Show details Hide details

Change log

r73 by thomasvl on Dec 12, 2008   Diff
- GTMStackTrace works on 10.5+ (and
iPhone) using NSThread to build the call
stack.

- Added GTM_EXTERN that makes it easier to
mix and match objc and objc++ code.

- Added GTMHotKeysTextField for display
and editing of hot key settings.

- Added GTMCarbonEvent for dealing with
Carbon Events and HotKeys in a ObjC like
...
Go to: 
Project members, sign in to write a code review

Older revisions

r66 by thomasvl on Nov 04, 2008   Diff
- Added has ability to check if a
script has an open handler to
GTMNSAppleScript+Handler.
- GTMStackTrace support for building a
trace from the call stack in an
...
r64 by thomasvl on Oct 22, 2008   Diff
- GTM_INLINE will make sure a function
gets inlined, and provides a
consistent
  way for all GTM code to do it.

...
r50 by thomasvl on Aug 12, 2008   Diff
- Added GTMNSMakeUncollectable for
forcing objects to survive in a GC
world.

- Added GTMCFAutorelease to make the
...
All revisions of this file

File info

Size: 4039 bytes, 105 lines