@@ -43,6 +43,10 @@ POSSIBILITY OF SUCH DAMAGE. */
43
43
#include <sys/sysctl.h>
44
44
#endif
45
45
46
+ #ifdef HAVE_MACH_O_DYLD_H
47
+ #include <mach-o/dyld.h>
48
+ #endif
49
+
46
50
#include "backtrace.h"
47
51
#include "internal.h"
48
52
@@ -122,6 +126,35 @@ sysctl_exec_name2 (struct backtrace_state *state,
122
126
123
127
#endif /* defined (HAVE_KERN_PROC_ARGS) || |defined (HAVE_KERN_PROC) */
124
128
129
+ #ifdef HAVE_MACH_O_DYLD_H
130
+
131
+ static char *
132
+ macho_get_executable_path (struct backtrace_state * state ,
133
+ backtrace_error_callback error_callback , void * data )
134
+ {
135
+ uint32_t len ;
136
+ char * name ;
137
+
138
+ len = 0 ;
139
+ if (_NSGetExecutablePath (NULL , & len ) == 0 )
140
+ return NULL ;
141
+ name = (char * ) backtrace_alloc (state , len , error_callback , data );
142
+ if (name == NULL )
143
+ return NULL ;
144
+ if (_NSGetExecutablePath (name , & len ) != 0 )
145
+ {
146
+ backtrace_free (state , name , len , error_callback , data );
147
+ return NULL ;
148
+ }
149
+ return name ;
150
+ }
151
+
152
+ #else /* !defined (HAVE_MACH_O_DYLD_H) */
153
+
154
+ #define macho_get_executable_path (state , error_callback , data ) NULL
155
+
156
+ #endif /* !defined (HAVE_MACH_O_DYLD_H) */
157
+
125
158
/* Initialize the fileline information from the executable. Returns 1
126
159
on success, 0 on failure. */
127
160
@@ -159,7 +192,7 @@ fileline_initialize (struct backtrace_state *state,
159
192
160
193
descriptor = -1 ;
161
194
called_error_callback = 0 ;
162
- for (pass = 0 ; pass < 7 ; ++ pass )
195
+ for (pass = 0 ; pass < 8 ; ++ pass )
163
196
{
164
197
int does_not_exist ;
165
198
@@ -188,6 +221,9 @@ fileline_initialize (struct backtrace_state *state,
188
221
case 6 :
189
222
filename = sysctl_exec_name2 (state , error_callback , data );
190
223
break ;
224
+ case 7 :
225
+ filename = macho_get_executable_path (state , error_callback , data );
226
+ break ;
191
227
default :
192
228
abort ();
193
229
}
0 commit comments