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
28 /* no frame.h on FreeBSD */
30 struct frame
*fr_savfp
;
34 #if defined(POWERPC) || defined(POWERPC64)
36 #define FRAME_PTR_OFFSET 1
37 #define FRAME_OFFSET 0
41 #define FRAME_PTR_OFFSET 3
42 #define FRAME_OFFSET 0
46 int backtrace( void **buffer
, int max_frames
)
51 /* get stack- and framepointer */
53 fp
= (struct frame
*)(((size_t*)(ctx
))[FRAME_PTR_OFFSET
]);
54 for ( i
=0; (i
<FRAME_OFFSET
) && (fp
!=0); i
++)
56 /* iterate through backtrace */
57 for (i
=0; fp
&& fp
->fr_savpc
&& i
<max_frames
; i
++)
60 *(buffer
++) = (void *)fp
->fr_savpc
;
67 char ** backtrace_symbols(void * const * buffer
, int size
)
69 (void)buffer
; (void)size
;
73 void backtrace_symbols_fd( void **buffer
, int size
, int fd
)
75 FILE *fp
= fdopen( fd
, "w" );
80 for ( pFramePtr
= buffer
; size
> 0 && pFramePtr
&& *pFramePtr
; pFramePtr
++, size
-- )
85 if ( 0 != dladdr( *pFramePtr
, &dli
) )
87 if ( dli
.dli_fname
&& dli
.dli_fbase
)
89 offset
= (ptrdiff_t)*pFramePtr
- (ptrdiff_t)dli
.dli_fbase
;
90 fprintf( fp
, "%s+0x%" SAL_PRI_PTRDIFFT
"x", dli
.dli_fname
, offset
);
92 if ( dli
.dli_sname
&& dli
.dli_saddr
)
94 offset
= (ptrdiff_t)*pFramePtr
- (ptrdiff_t)dli
.dli_saddr
;
95 fprintf( fp
, "(%s+0x%" SAL_PRI_PTRDIFFT
"x)", dli
.dli_sname
, offset
);
98 fprintf( fp
, "[%p]\n", *pFramePtr
);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */