2012-09-17 16:38:38 +00:00
|
|
|
/* internal.h -- Internal header file for stack backtrace library.
|
2024-01-03 11:19:35 +00:00
|
|
|
Copyright (C) 2012-2024 Free Software Foundation, Inc.
|
2012-09-17 16:38:38 +00:00
|
|
|
Written by Ian Lance Taylor, Google.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
(1) Redistributions of source code must retain the above copyright
|
2016-09-11 13:44:07 +00:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2012-09-17 16:38:38 +00:00
|
|
|
|
|
|
|
(2) Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the
|
2016-09-11 13:44:07 +00:00
|
|
|
distribution.
|
|
|
|
|
2012-09-17 16:38:38 +00:00
|
|
|
(3) The name of the author may not be used to
|
|
|
|
endorse or promote products derived from this software without
|
|
|
|
specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE. */
|
|
|
|
|
|
|
|
#ifndef BACKTRACE_INTERNAL_H
|
|
|
|
#define BACKTRACE_INTERNAL_H
|
|
|
|
|
|
|
|
/* We assume that <sys/types.h> and "backtrace.h" have already been
|
|
|
|
included. */
|
|
|
|
|
|
|
|
#ifndef GCC_VERSION
|
|
|
|
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (GCC_VERSION < 2007)
|
|
|
|
# define __attribute__(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ATTRIBUTE_UNUSED
|
|
|
|
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ATTRIBUTE_MALLOC
|
|
|
|
# if (GCC_VERSION >= 2096)
|
|
|
|
# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
|
|
|
|
# else
|
|
|
|
# define ATTRIBUTE_MALLOC
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2024-07-18 18:34:09 +00:00
|
|
|
#ifdef __has_attribute
|
|
|
|
# if __has_attribute(fallthrough)
|
|
|
|
# define ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough))
|
|
|
|
# endif
|
|
|
|
#endif
|
2020-10-20 18:47:35 +00:00
|
|
|
#ifndef ATTRIBUTE_FALLTHROUGH
|
|
|
|
# if (GCC_VERSION >= 7000)
|
|
|
|
# define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
|
|
|
|
# else
|
|
|
|
# define ATTRIBUTE_FALLTHROUGH
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2012-09-17 16:38:38 +00:00
|
|
|
#ifndef HAVE_SYNC_FUNCTIONS
|
|
|
|
|
|
|
|
/* Define out the sync functions. These should never be called if
|
|
|
|
they are not available. */
|
|
|
|
|
|
|
|
#define __sync_bool_compare_and_swap(A, B, C) (abort(), 1)
|
|
|
|
#define __sync_lock_test_and_set(A, B) (abort(), 0)
|
|
|
|
#define __sync_lock_release(A) abort()
|
|
|
|
|
2013-11-19 01:09:47 +00:00
|
|
|
#endif /* !defined (HAVE_SYNC_FUNCTIONS) */
|
|
|
|
|
|
|
|
#ifdef HAVE_ATOMIC_FUNCTIONS
|
|
|
|
|
|
|
|
/* We have the atomic builtin functions. */
|
|
|
|
|
|
|
|
#define backtrace_atomic_load_pointer(p) \
|
|
|
|
__atomic_load_n ((p), __ATOMIC_ACQUIRE)
|
|
|
|
#define backtrace_atomic_load_int(p) \
|
|
|
|
__atomic_load_n ((p), __ATOMIC_ACQUIRE)
|
|
|
|
#define backtrace_atomic_store_pointer(p, v) \
|
|
|
|
__atomic_store_n ((p), (v), __ATOMIC_RELEASE)
|
|
|
|
#define backtrace_atomic_store_size_t(p, v) \
|
|
|
|
__atomic_store_n ((p), (v), __ATOMIC_RELEASE)
|
|
|
|
#define backtrace_atomic_store_int(p, v) \
|
|
|
|
__atomic_store_n ((p), (v), __ATOMIC_RELEASE)
|
|
|
|
|
|
|
|
#else /* !defined (HAVE_ATOMIC_FUNCTIONS) */
|
|
|
|
#ifdef HAVE_SYNC_FUNCTIONS
|
|
|
|
|
|
|
|
/* We have the sync functions but not the atomic functions. Define
|
|
|
|
the atomic ones in terms of the sync ones. */
|
|
|
|
|
|
|
|
extern void *backtrace_atomic_load_pointer (void *);
|
|
|
|
extern int backtrace_atomic_load_int (int *);
|
|
|
|
extern void backtrace_atomic_store_pointer (void *, void *);
|
|
|
|
extern void backtrace_atomic_store_size_t (size_t *, size_t);
|
|
|
|
extern void backtrace_atomic_store_int (int *, int);
|
|
|
|
|
|
|
|
#else /* !defined (HAVE_SYNC_FUNCTIONS) */
|
|
|
|
|
|
|
|
/* We have neither the sync nor the atomic functions. These will
|
|
|
|
never be called. */
|
|
|
|
|
2014-10-23 22:40:37 +00:00
|
|
|
#define backtrace_atomic_load_pointer(p) (abort(), (void *) NULL)
|
2013-11-19 01:09:47 +00:00
|
|
|
#define backtrace_atomic_load_int(p) (abort(), 0)
|
|
|
|
#define backtrace_atomic_store_pointer(p, v) abort()
|
|
|
|
#define backtrace_atomic_store_size_t(p, v) abort()
|
|
|
|
#define backtrace_atomic_store_int(p, v) abort()
|
|
|
|
|
|
|
|
#endif /* !defined (HAVE_SYNC_FUNCTIONS) */
|
|
|
|
#endif /* !defined (HAVE_ATOMIC_FUNCTIONS) */
|
2012-09-17 16:38:38 +00:00
|
|
|
|
|
|
|
/* The type of the function that collects file/line information. This
|
|
|
|
is like backtrace_pcinfo. */
|
|
|
|
|
|
|
|
typedef int (*fileline) (struct backtrace_state *state, uintptr_t pc,
|
|
|
|
backtrace_full_callback callback,
|
|
|
|
backtrace_error_callback error_callback, void *data);
|
|
|
|
|
|
|
|
/* The type of the function that collects symbol information. This is
|
|
|
|
like backtrace_syminfo. */
|
|
|
|
|
|
|
|
typedef void (*syminfo) (struct backtrace_state *state, uintptr_t pc,
|
|
|
|
backtrace_syminfo_callback callback,
|
|
|
|
backtrace_error_callback error_callback, void *data);
|
|
|
|
|
|
|
|
/* What the backtrace state pointer points to. */
|
|
|
|
|
|
|
|
struct backtrace_state
|
|
|
|
{
|
|
|
|
/* The name of the executable. */
|
|
|
|
const char *filename;
|
|
|
|
/* Non-zero if threaded. */
|
|
|
|
int threaded;
|
|
|
|
/* The master lock for fileline_fn, fileline_data, syminfo_fn,
|
|
|
|
syminfo_data, fileline_initialization_failed and everything the
|
|
|
|
data pointers point to. */
|
|
|
|
void *lock;
|
|
|
|
/* The function that returns file/line information. */
|
|
|
|
fileline fileline_fn;
|
|
|
|
/* The data to pass to FILELINE_FN. */
|
|
|
|
void *fileline_data;
|
|
|
|
/* The function that returns symbol information. */
|
|
|
|
syminfo syminfo_fn;
|
|
|
|
/* The data to pass to SYMINFO_FN. */
|
|
|
|
void *syminfo_data;
|
|
|
|
/* Whether initializing the file/line information failed. */
|
|
|
|
int fileline_initialization_failed;
|
|
|
|
/* The lock for the freelist. */
|
|
|
|
int lock_alloc;
|
|
|
|
/* The freelist when using mmap. */
|
|
|
|
struct backtrace_freelist_struct *freelist;
|
|
|
|
};
|
|
|
|
|
2012-10-26 20:08:29 +00:00
|
|
|
/* Open a file for reading. Returns -1 on error. If DOES_NOT_EXIST
|
|
|
|
is not NULL, *DOES_NOT_EXIST will be set to 0 normally and set to 1
|
|
|
|
if the file does not exist. If the file does not exist and
|
|
|
|
DOES_NOT_EXIST is not NULL, the function will return -1 and will
|
|
|
|
not call ERROR_CALLBACK. On other errors, or if DOES_NOT_EXIST is
|
|
|
|
NULL, the function will call ERROR_CALLBACK before returning. */
|
2012-09-17 16:38:38 +00:00
|
|
|
extern int backtrace_open (const char *filename,
|
|
|
|
backtrace_error_callback error_callback,
|
2012-10-26 20:08:29 +00:00
|
|
|
void *data,
|
|
|
|
int *does_not_exist);
|
2012-09-17 16:38:38 +00:00
|
|
|
|
|
|
|
/* A view of the contents of a file. This supports mmap when
|
|
|
|
available. A view will remain in memory even after backtrace_close
|
|
|
|
is called on the file descriptor from which the view was
|
|
|
|
obtained. */
|
|
|
|
|
|
|
|
struct backtrace_view
|
|
|
|
{
|
|
|
|
/* The data that the caller requested. */
|
|
|
|
const void *data;
|
|
|
|
/* The base of the view. */
|
|
|
|
void *base;
|
|
|
|
/* The total length of the view. */
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Create a view of SIZE bytes from DESCRIPTOR at OFFSET. Store the
|
|
|
|
result in *VIEW. Returns 1 on success, 0 on error. */
|
|
|
|
extern int backtrace_get_view (struct backtrace_state *state, int descriptor,
|
2019-01-18 17:13:59 +00:00
|
|
|
off_t offset, uint64_t size,
|
2012-09-17 16:38:38 +00:00
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data, struct backtrace_view *view);
|
|
|
|
|
|
|
|
/* Release a view created by backtrace_get_view. */
|
|
|
|
extern void backtrace_release_view (struct backtrace_state *state,
|
|
|
|
struct backtrace_view *view,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data);
|
|
|
|
|
|
|
|
/* Close a file opened by backtrace_open. Returns 1 on success, 0 on
|
|
|
|
error. */
|
|
|
|
|
|
|
|
extern int backtrace_close (int descriptor,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data);
|
|
|
|
|
2014-03-07 05:07:56 +00:00
|
|
|
/* Sort without using memory. */
|
|
|
|
|
|
|
|
extern void backtrace_qsort (void *base, size_t count, size_t size,
|
|
|
|
int (*compar) (const void *, const void *));
|
|
|
|
|
2015-09-08 16:46:16 +00:00
|
|
|
/* Allocate memory. This is like malloc. If ERROR_CALLBACK is NULL,
|
|
|
|
this does not report an error, it just returns NULL. */
|
2012-09-17 16:38:38 +00:00
|
|
|
|
|
|
|
extern void *backtrace_alloc (struct backtrace_state *state, size_t size,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data) ATTRIBUTE_MALLOC;
|
|
|
|
|
2015-09-08 16:46:16 +00:00
|
|
|
/* Free memory allocated by backtrace_alloc. If ERROR_CALLBACK is
|
|
|
|
NULL, this does not report an error. */
|
2012-09-17 16:38:38 +00:00
|
|
|
|
|
|
|
extern void backtrace_free (struct backtrace_state *state, void *mem,
|
|
|
|
size_t size,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data);
|
|
|
|
|
|
|
|
/* A growable vector of some struct. This is used for more efficient
|
|
|
|
allocation when we don't know the final size of some group of data
|
|
|
|
that we want to represent as an array. */
|
|
|
|
|
|
|
|
struct backtrace_vector
|
|
|
|
{
|
|
|
|
/* The base of the vector. */
|
|
|
|
void *base;
|
|
|
|
/* The number of bytes in the vector. */
|
|
|
|
size_t size;
|
|
|
|
/* The number of bytes available at the current allocation. */
|
|
|
|
size_t alc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Grow VEC by SIZE bytes. Return a pointer to the newly allocated
|
|
|
|
bytes. Note that this may move the entire vector to a new memory
|
|
|
|
location. Returns NULL on failure. */
|
|
|
|
|
|
|
|
extern void *backtrace_vector_grow (struct backtrace_state *state, size_t size,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data,
|
|
|
|
struct backtrace_vector *vec);
|
|
|
|
|
|
|
|
/* Finish the current allocation on VEC. Prepare to start a new
|
2013-12-05 18:32:02 +00:00
|
|
|
allocation. The finished allocation will never be freed. Returns
|
|
|
|
a pointer to the base of the finished entries, or NULL on
|
|
|
|
failure. */
|
2012-09-17 16:38:38 +00:00
|
|
|
|
2013-12-05 18:32:02 +00:00
|
|
|
extern void* backtrace_vector_finish (struct backtrace_state *state,
|
|
|
|
struct backtrace_vector *vec,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data);
|
2012-09-17 16:38:38 +00:00
|
|
|
|
2013-12-05 18:32:02 +00:00
|
|
|
/* Release any extra space allocated for VEC. This may change
|
|
|
|
VEC->base. Returns 1 on success, 0 on failure. */
|
2012-09-17 16:38:38 +00:00
|
|
|
|
|
|
|
extern int backtrace_vector_release (struct backtrace_state *state,
|
|
|
|
struct backtrace_vector *vec,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data);
|
|
|
|
|
2018-11-30 08:43:50 +00:00
|
|
|
/* Free the space managed by VEC. This will reset VEC. */
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
backtrace_vector_free (struct backtrace_state *state,
|
|
|
|
struct backtrace_vector *vec,
|
|
|
|
backtrace_error_callback error_callback, void *data)
|
|
|
|
{
|
|
|
|
vec->alc += vec->size;
|
|
|
|
vec->size = 0;
|
|
|
|
backtrace_vector_release (state, vec, error_callback, data);
|
|
|
|
}
|
|
|
|
|
2012-09-17 16:38:38 +00:00
|
|
|
/* Read initial debug data from a descriptor, and set the
|
|
|
|
fileline_data, syminfo_fn, and syminfo_data fields of STATE.
|
|
|
|
Return the fileln_fn field in *FILELN_FN--this is done this way so
|
|
|
|
that the synchronization code is only implemented once. This is
|
|
|
|
called after the descriptor has first been opened. It will close
|
|
|
|
the descriptor if it is no longer needed. Returns 1 on success, 0
|
|
|
|
on error. There will be multiple implementations of this function,
|
|
|
|
for different file formats. Each system will compile the
|
|
|
|
appropriate one. */
|
|
|
|
|
|
|
|
extern int backtrace_initialize (struct backtrace_state *state,
|
2017-09-20 21:09:37 +00:00
|
|
|
const char *filename,
|
2012-09-17 16:38:38 +00:00
|
|
|
int descriptor,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data,
|
|
|
|
fileline *fileline_fn);
|
|
|
|
|
2019-12-05 02:20:11 +00:00
|
|
|
/* An enum for the DWARF sections we care about. */
|
|
|
|
|
|
|
|
enum dwarf_section
|
|
|
|
{
|
|
|
|
DEBUG_INFO,
|
|
|
|
DEBUG_LINE,
|
|
|
|
DEBUG_ABBREV,
|
|
|
|
DEBUG_RANGES,
|
|
|
|
DEBUG_STR,
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 20:04:47 +00:00
|
|
|
DEBUG_ADDR,
|
|
|
|
DEBUG_STR_OFFSETS,
|
|
|
|
DEBUG_LINE_STR,
|
|
|
|
DEBUG_RNGLISTS,
|
2019-12-05 02:20:11 +00:00
|
|
|
|
|
|
|
DEBUG_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Data for the DWARF sections we care about. */
|
|
|
|
|
|
|
|
struct dwarf_sections
|
|
|
|
{
|
|
|
|
const unsigned char *data[DEBUG_MAX];
|
|
|
|
size_t size[DEBUG_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* DWARF data read from a file, used for .gnu_debugaltlink. */
|
|
|
|
|
2019-01-17 00:07:32 +00:00
|
|
|
struct dwarf_data;
|
|
|
|
|
2024-07-16 00:27:18 +00:00
|
|
|
/* The load address mapping. */
|
|
|
|
|
|
|
|
#if defined(__FDPIC__) && defined(HAVE_DL_ITERATE_PHDR) && (defined(HAVE_LINK_H) || defined(HAVE_SYS_LINK_H))
|
|
|
|
|
|
|
|
#ifdef HAVE_LINK_H
|
|
|
|
#include <link.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_LINK_H
|
|
|
|
#include <sys/link.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define libbacktrace_using_fdpic() (1)
|
|
|
|
|
|
|
|
struct libbacktrace_base_address
|
|
|
|
{
|
|
|
|
struct elf32_fdpic_loadaddr m;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define libbacktrace_add_base(pc, base) \
|
|
|
|
((uintptr_t) (__RELOC_POINTER ((pc), (base).m)))
|
|
|
|
|
|
|
|
#else /* not _FDPIC__ */
|
|
|
|
|
|
|
|
#define libbacktrace_using_fdpic() (0)
|
|
|
|
|
|
|
|
struct libbacktrace_base_address
|
|
|
|
{
|
|
|
|
uintptr_t m;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define libbacktrace_add_base(pc, base) ((pc) + (base).m)
|
|
|
|
|
|
|
|
#endif /* not _FDPIC__ */
|
|
|
|
|
2012-10-09 18:20:45 +00:00
|
|
|
/* Add file/line information for a DWARF module. */
|
|
|
|
|
|
|
|
extern int backtrace_dwarf_add (struct backtrace_state *state,
|
2024-07-16 00:27:18 +00:00
|
|
|
struct libbacktrace_base_address base_address,
|
2019-12-05 02:20:11 +00:00
|
|
|
const struct dwarf_sections *dwarf_sections,
|
2012-10-09 18:20:45 +00:00
|
|
|
int is_bigendian,
|
2019-01-17 00:07:43 +00:00
|
|
|
struct dwarf_data *fileline_altlink,
|
2012-10-09 18:20:45 +00:00
|
|
|
backtrace_error_callback error_callback,
|
2019-01-17 00:07:32 +00:00
|
|
|
void *data, fileline *fileline_fn,
|
|
|
|
struct dwarf_data **fileline_entry);
|
2012-09-17 16:38:38 +00:00
|
|
|
|
2020-09-17 00:03:52 +00:00
|
|
|
/* A data structure to pass to backtrace_syminfo_to_full. */
|
|
|
|
|
|
|
|
struct backtrace_call_full
|
|
|
|
{
|
|
|
|
backtrace_full_callback full_callback;
|
|
|
|
backtrace_error_callback full_error_callback;
|
|
|
|
void *full_data;
|
|
|
|
int ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A backtrace_syminfo_callback that can call into a
|
|
|
|
backtrace_full_callback, used when we have a symbol table but no
|
|
|
|
debug info. */
|
|
|
|
|
|
|
|
extern void backtrace_syminfo_to_full_callback (void *data, uintptr_t pc,
|
|
|
|
const char *symname,
|
|
|
|
uintptr_t symval,
|
|
|
|
uintptr_t symsize);
|
|
|
|
|
|
|
|
/* An error callback that corresponds to
|
|
|
|
backtrace_syminfo_to_full_callback. */
|
|
|
|
|
|
|
|
extern void backtrace_syminfo_to_full_error_callback (void *, const char *,
|
|
|
|
int);
|
|
|
|
|
re PR other/67165 (please enable libbacktrace to work with compressed debug sections)
PR other/67165
* elf.c (__builtin_prefetch): Define if not __GNUC__.
(unlikely): Define.
(SHF_UNCOMPRESSED, ELFCOMPRESS_ZLIB): Define.
(b_elf_chdr): Define type.
(enum debug_section): Add ZDEBUG_xxx values.
(debug_section_names): Add names for new sections.
(struct debug_section_info): Add compressed field.
(elf_zlib_failed, elf_zlib_fetch): New static functions.
(HUFFMAN_TABLE_SIZE, HUFFMAN_VALUE_MASK): Define.
(HUFFMAN_BITS_SHIFT, HUFFMAN_BITS_MASK): Define.
(HUFFMAN_SECONDARY_SHIFT): Define.
(ZDEBUG_TABLE_SIZE): Define.
(ZDEBUG_TABLE_CODELEN_OFFSET, ZDEBUG_TABLE_WORK_OFFSET): Define.
(final_next_secondary): New static variable if
BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE.
(elf_zlib_inflate_table): New static function.
(BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE): If define, define main
function to produce fixed Huffman table.
(elf_zlib_default_table): New static variable.
(elf_zlib_inflate): New static function.
(elf_zlib_verify_checksum): Likewise.
(elf_zlib_inflate_and_verify): Likewise.
(elf_uncompress_zdebug): Likewise.
(elf_uncompress_chdr): Likewise.
(backtrace_uncompress_zdebug): New extern function.
(elf_add): Look for .zdebug sections and SHF_COMPRESSED debug
sections, and uncompress them.
* internal.h (backtrace_compress_zdebug): Declare.
* ztest.c: New file.
* configure.ac: Check for -lz and check whether the linker
supports --compress-debug-sections.
* Makefile.am (ztest_SOURCES): New variable.
(ztest_CFLAGS, ztest_LDADD): New variables.
(check_PROGRAMS): Add ztest.
(ctestg_SOURCES): New variable.
(ctestg_CFLAGS, ctestg_LDFLAGS, ctestg_LDADD): New variables.
(ctesta_SOURCES): New variable.
(ctesta_CFLAGS, ctesta_LDFLAGS, ctesta_LDADD): New variables.
(check_PROGRAMS): Add ctestg and ctesta.
* configure, config.h.in, Makefile.in: Rebuild.
From-SVN: r253275
2017-09-29 00:30:35 +00:00
|
|
|
/* A test-only hook for elf_uncompress_zdebug. */
|
|
|
|
|
|
|
|
extern int backtrace_uncompress_zdebug (struct backtrace_state *,
|
|
|
|
const unsigned char *compressed,
|
|
|
|
size_t compressed_size,
|
|
|
|
backtrace_error_callback, void *data,
|
|
|
|
unsigned char **uncompressed,
|
|
|
|
size_t *uncompressed_size);
|
|
|
|
|
libbacktrace: support zstd decompression
Support decompressing --compress-debug-sections=zstd.
* configure.ac: Check for zstd library and
--compress-debug-sections=zstd linker option.
* Makefile.am (zstdtest_*): New targets.
(zstdtest_alloc_*, ctestzstd_*): New targets.
(BUILDTESTS): Add zstdtest, zstdtest_alloc, ctestzstd as
appropriate.
* elf.c (ELFCOMPRESS_ZSTD): Define.
(elf_fetch_bits): Rename from elf_zlib_fetch. Update uses.
(elf_fetch_bits_backward): New static function.
(ZLIB_HUFFMAN_*): Rename from HUFFMAN_*. Update uses.
(ZLIB_TABLE_*): Rename from ZDEBUG_TABLE_*. Update uses.
(ZSTD_TABLE_*): Define.
(struct elf_zstd_fse_entry): Define.
(elf_zstd_read_fse): New static function.
(elf_zstd_build_fse): Likewise.
(lit): Define if BACKTRACE_GENERATE_ZSTD_FSE_TABLES.
(match, offset, next, print_table, main): Likewise.
(elf_zstd_lit_table): New static const array.
(elf_zstd_match_table, elf_zstd_offset_table): Likewise.
(elf_zstd_read_huff): New static function.
(struct elf_zstd_seq_decode): Define.
(elf_zstd_unpack_seq_decode): New static function.
(ZSTD_LIT_*): Define.
(struct elf_zstd_literals): Define.
(elf_zstd_literal_output): New static function.
(ZSTD_LITERAL_LENGTH_BASELINE_OFFSET): Define.
(elf_zstd_literal_length_baseline): New static const array.
(elf_zstd_literal_length_bits): Likewise.
(ZSTD_MATCH_LENGTH_BASELINE_OFFSET): Define.
(elf_zstd_match_length_baseline): New static const array.
(elf_zstd_match_length_bits): Likewise.
(elf_zstd_decompress): New static function.
(ZDEBUG_TABLE_SIZE): New definition.
(elf_uncompress_chdr): Support ELF_COMPRESS_ZSTD.
(backtrace_uncompress_zstd): New function.
(elf_add): Use ZLIB_TABLE_SIZE for zlib-gnu sections.
* internal.h (backtrace_uncompress_zstd): Declare.
* zstdtest.c: New file.
* configure, config.h.in, Makefile.in: Regenerate.
2022-12-08 00:21:26 +00:00
|
|
|
/* A test-only hook for elf_zstd_decompress. */
|
|
|
|
|
|
|
|
extern int backtrace_uncompress_zstd (struct backtrace_state *,
|
|
|
|
const unsigned char *compressed,
|
|
|
|
size_t compressed_size,
|
|
|
|
backtrace_error_callback, void *data,
|
|
|
|
unsigned char *uncompressed,
|
|
|
|
size_t uncompressed_size);
|
|
|
|
|
libbacktrace: support MiniDebugInfo
libbacktrace/ChangeLog:
PR libbacktrace/93608
Add support for MiniDebugInfo.
* elf.c (struct elf_view): Define. Replace most uses of
backtrace_view with elf_view.
(elf_get_view): New static functions. Replace most calls of
backtrace_get_view with elf_get_view.
(elf_release_view): New static functions. Replace most calls of
backtrace_release_view with elf_release_view.
(elf_uncompress_failed): Rename from elf_zlib_failed. Change all
callers.
(LZMA_STATES, LZMA_POS_STATES, LZMA_DIST_STATES): Define.
(LZMA_DIST_SLOTS, LZMA_DIST_MODEL_START): Define.
(LZMA_DIST_MODEL_END, LZMA_FULL_DISTANCES): Define.
(LZMA_ALIGN_SIZE, LZMA_LEN_LOW_SYMBOLS): Define.
(LZMA_LEN_MID_SYMBOLS, LZMA_LEN_HIGH_SYMBOLS): Define.
(LZMA_LITERAL_CODERS_MAX, LZMA_LITERAL_CODER_SIZE): Define.
(LZMA_PROB_IS_MATCH_LEN, LZMA_PROB_IS_REP_LEN): Define.
(LZMA_PROB_IS_REP0_LEN, LZMA_PROB_IS_REP1_LEN): Define.
(LZMA_PROB_IS_REP2_LEN, LZMA_PROB_IS_REP0_LONG_LEN): Define.
(LZMA_PROB_DIST_SLOT_LEN, LZMA_PROB_DIST_SPECIAL_LEN): Define.
(LZMA_PROB_DIST_ALIGN_LEN): Define.
(LZMA_PROB_MATCH_LEN_CHOICE_LEN): Define.
(LZMA_PROB_MATCH_LEN_CHOICE2_LEN): Define.
(LZMA_PROB_MATCH_LEN_LOW_LEN): Define.
(LZMA_PROB_MATCH_LEN_MID_LEN): Define.
(LZMA_PROB_MATCH_LEN_HIGH_LEN): Define.
(LZMA_PROB_REP_LEN_CHOICE_LEN): Define.
(LZMA_PROB_REP_LEN_CHOICE2_LEN): Define.
(LZMA_PROB_REP_LEN_LOW_LEN): Define.
(LZMA_PROB_REP_LEN_MID_LEN): Define.
(LZMA_PROB_REP_LEN_HIGH_LEN): Define.
(LZMA_PROB_LITERAL_LEN): Define.
(LZMA_PROB_IS_MATCH_OFFSET, LZMA_PROB_IS_REP_OFFSET): Define.
(LZMA_PROB_IS_REP0_OFFSET, LZMA_PROB_IS_REP1_OFFSET): Define.
(LZMA_PROB_IS_REP2_OFFSET): Define.
(LZMA_PROB_IS_REP0_LONG_OFFSET): Define.
(LZMA_PROB_DIST_SLOT_OFFSET): Define.
(LZMA_PROB_DIST_SPECIAL_OFFSET): Define.
(LZMA_PROB_DIST_ALIGN_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_CHOICE_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_CHOICE2_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_LOW_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_MID_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_HIGH_OFFSET): Define.
(LZMA_PROB_REP_LEN_CHOICE_OFFSET): Define.
(LZMA_PROB_REP_LEN_CHOICE2_OFFSET): Define.
(LZMA_PROB_REP_LEN_LOW_OFFSET): Define.
(LZMA_PROB_REP_LEN_MID_OFFSET): Define.
(LZMA_PROB_REP_LEN_HIGH_OFFSET): Define.
(LZMA_PROB_LITERAL_OFFSET): Define.
(LZMA_PROB_TOTAL_COUNT): Define.
(LZMA_IS_MATCH, LZMA_IS_REP, LZMA_IS_REP0): Define.
(LZMA_IS_REP1, LZMA_IS_REP2, LZMA_IS_REP0_LONG): Define.
(LZMA_DIST_SLOT, LZMA_DIST_SPECIAL, LZMA_DIST_ALIGN): Define.
(LZMA_MATCH_LEN_CHOICE, LZMA_MATCH_LEN_CHOICE2): Define.
(LZMA_MATCH_LEN_LOW, LZMA_MATCH_LEN_MID): Define.
(LZMA_MATCH_LEN_HIGH, LZMA_REP_LEN_CHOICE): Define.
(LZMA_REP_LEN_CHOICE2, LZMA_REP_LEN_LOW): Define.
(LZMA_REP_LEN_MID, LZMA_REP_LEN_HIGH, LZMA_LITERAL): Define.
(elf_lzma_varint): New static function.
(elf_lzma_range_normalize): New static function.
(elf_lzma_bit, elf_lzma_integer): New static functions.
(elf_lzma_reverse_integer): New static function.
(elf_lzma_len, elf_uncompress_lzma_block): New static functions.
(elf_uncompress_lzma): New static function.
(backtrace_uncompress_lzma): New function.
(elf_add): Add memory and memory_size parameters. Change all
callers. Look for .gnu_debugdata section, and, if found,
decompress it and use it for symbols and debug info. Permit the
descriptor parameter to be -1.
* internal.h (backtrace_uncompress_lzma): Declare.
* mtest.c: New file.
* xztest.c: New file.
* configure.ac: Check for nm, xz, and comm programs. Check for
liblzma library.
(HAVE_MINIDEBUG): Define.
* Makefile.am (mtest_SOURCES): Define.
(mtest_CFLAGS, mtest_LDADD): Define.
(TESTS): Add mtest_minidebug if HAVE_MINIDEBUG.
(%_minidebug): New pattern rule, if HAVE_MINIDEBUG.
(xztest_SOURCES, xztest_CFLAGS, xztest_LDADD): Define.
(xztest_alloc_SOURCES, xztest_alloc_CFLAGS): Define
(xztest_alloc_LDADD): Define.
(BUILDTESTS): Add mtest, xztest, xztest_alloc.
(CLEANFILES): Add files created by minidebug pattern.
(btest.lo): Correct INCDIR reference.
(mtest.lo, xztest.lo, ztest.lo): New targets.
* configure: Regenerate.
* config.h.in: Regenerate.
* Makefile.in: Regenerate.
2020-09-14 21:01:56 +00:00
|
|
|
/* A test-only hook for elf_uncompress_lzma. */
|
|
|
|
|
|
|
|
extern int backtrace_uncompress_lzma (struct backtrace_state *,
|
|
|
|
const unsigned char *compressed,
|
|
|
|
size_t compressed_size,
|
|
|
|
backtrace_error_callback, void *data,
|
|
|
|
unsigned char **uncompressed,
|
|
|
|
size_t *uncompressed_size);
|
|
|
|
|
2012-09-17 16:38:38 +00:00
|
|
|
#endif
|