1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 // This file is #include from backtrace.c
26 #include <sys/frame.h>
32 #define FRAME_PTR_OFFSET 1
33 #define FRAME_OFFSET 0
34 #define STACK_BIAS 0x7ff
38 #define FRAME_PTR_OFFSET 1
39 #define FRAME_OFFSET 0
44 #elif defined( INTEL )
46 #define FRAME_PTR_OFFSET 3
47 #define FRAME_OFFSET 0
52 #error Unknown Solaris target platform.
54 #endif /* defined SPARC or INTEL */
56 int backtrace( void **buffer
, int max_frames
)
63 /* flush register windows */
68 /* get stack- and framepointer */
71 fpval
= ((long*)(ctx
))[FRAME_PTR_OFFSET
];
72 fp
= (struct frame
*)((char*)(fpval
) + STACK_BIAS
);
74 for (i
= 0; (i
< FRAME_OFFSET
) && (fp
!= 0); i
++)
75 fp
= (struct frame
*)((char*)(fp
->fr_savfp
) + STACK_BIAS
);
77 /* iterate through backtrace */
78 for (i
= 0; (fp
!= 0) && (fp
->fr_savpc
!= 0) && (i
< max_frames
); i
++)
80 /* saved (prev) frame */
81 struct frame
* prev
= (struct frame
*)((char*)(fp
->fr_savfp
) + STACK_BIAS
);
84 *(buffer
++) = (void*)(fp
->fr_savpc
);
86 /* prev frame (w/ stack growing top down) */
87 fp
= (prev
> fp
) ? prev
: 0;
90 /* return number of frames stored */
94 char ** backtrace_symbols(void * const * buffer
, int size
)
96 (void)buffer
; (void)size
;
100 void backtrace_symbols_fd( void **buffer
, int size
, int fd
)
102 FILE *fp
= fdopen( fd
, "w" );
108 for ( pFramePtr
= buffer
; size
> 0 && pFramePtr
&& *pFramePtr
; pFramePtr
++, size
-- )
113 if ( 0 != dladdr( *pFramePtr
, &dli
) )
115 if ( dli
.dli_fname
&& dli
.dli_fbase
)
117 offset
= (ptrdiff_t)*pFramePtr
- (ptrdiff_t)dli
.dli_fbase
;
118 fprintf( fp
, "%s+0x%" SAL_PRI_PTRDIFFT
"x", dli
.dli_fname
, offset
);
120 if ( dli
.dli_sname
&& dli
.dli_saddr
)
122 offset
= (ptrdiff_t)*pFramePtr
- (ptrdiff_t)dli
.dli_saddr
;
123 fprintf( fp
, "(%s+0x%" SAL_PRI_PTRDIFFT
"x)", dli
.dli_sname
, offset
);
126 fprintf( fp
, "[%p]\n", *pFramePtr
);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */