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
|
Issuetracker : #i56946#
CWS : N/A
Author : <maho@openoffice.org> (JCA)
Description : FreeBSD porting : An implementation of backtrace at sal/osl/unx
To pass the compilation, we had been preparing dummy function at sal.
We implemented this.
--- sal/osl/unx/backtrace.c Thu Sep 8 23:52:44 2005
+++ sal/osl/unx/backtrace.c Sun Oct 23 09:19:04 2005
@@ -129,6 +129,7 @@
#include <pthread.h>
#include <setjmp.h>
#include <stdio.h>
+#include <stddef.h>
#include "backtrace.h"
#define FRAME_PTR_OFFSET 1
@@ -136,11 +137,55 @@
int backtrace( void **buffer, int max_frames )
{
- return 1;
+ struct frame *fp;
+ jmp_buf ctx;
+ int i;
+ /* get stack- and framepointer */
+ setjmp(ctx);
+ fp = (struct frame*)(((size_t*)(ctx))[FRAME_PTR_OFFSET]);
+ for ( i=0; (i<FRAME_OFFSET) && (fp!=0); i++)
+ fp = fp->fr_savfp;
+ /* iterate through backtrace */
+ for (i=0; fp && fp->fr_savpc && i<max_frames; i++)
+ {
+ /* store frame */
+ *(buffer++) = (void *)fp->fr_savpc;
+ /* next frame */
+ fp=fp->fr_savfp;
+ }
+ return i;
}
void backtrace_symbols_fd( void **buffer, int size, int fd )
{
+ FILE *fp = fdopen( fd, "w" );
+
+ if ( fp )
+ {
+ void **pFramePtr;
+ for ( pFramePtr = buffer; size > 0 && pFramePtr && *pFramePtr; pFramePtr++, size-- )
+ {
+ Dl_info dli;
+ ptrdiff_t offset;
+
+ if ( 0 != dladdr( *pFramePtr, &dli ) )
+ {
+ if ( dli.dli_fname && dli.dli_fbase )
+ {
+ offset = (ptrdiff_t)*pFramePtr - (ptrdiff_t)dli.dli_fbase;
+ fprintf( fp, "%s+0x%x", dli.dli_fname, offset );
+ }
+ if ( dli.dli_sname && dli.dli_saddr )
+ {
+ offset = (ptrdiff_t)*pFramePtr - (ptrdiff_t)dli.dli_saddr;
+ fprintf( fp, "(%s+0x%x)", dli.dli_sname, offset );
+ }
+ }
+ fprintf( fp, "[0x%x]\n", *pFramePtr );
+ }
+ fflush( fp );
+ fclose( fp );
+ }
}
#endif /* defined FREEBSD */
--- sal/osl/unx/backtrace.h Thu Sep 8 23:52:59 2005
+++ sal/osl/unx/backtrace.h Sun Oct 23 09:19:40 2005
@@ -46,6 +46,16 @@
void backtrace_symbols_fd( void **buffer, int size, int fd );
+/* no frame.h on FreeBSD */
+#if defined FREEBSD
+struct frame {
+ long arg0[8];
+ long arg1[6];
+ struct frame *fr_savfp;
+ long fr_savpc;
+};
+#endif
+
#ifdef __cplusplus
} /* extern "C" */
#endif
|