mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 17:53:07 +00:00
e5874ad18a
libdwfl is the elfutils "DWARF frontend library". It has high-level functionality for looking up symbols, walking stack traces, etc. In order to use this functionality, we need to report our debugging information through libdwfl. For userspace programs, libdwfl has a much better implementation than drgn for automatically finding debug information from a core dump or PID. However, for the kernel, libdwfl has a few issues: - It only supports finding debug information for the running kernel, not vmcores. - It determines the vmlinux address range by reading /proc/kallsyms, which is slow (~70ms on my machine). - If separate debug information isn't available for a kernel module, it finds it by walking /lib/modules/$(uname -r)/kernel; this is repeated for every module. - It doesn't find kernel modules with names containing both dashes and underscores (e.g., aes-x86_64). Luckily, drgn already solved all of these problems, and with some effort, we can keep doing it ourselves and report it to libdwfl. The conversion replaces a bunch of code for dealing with userspace core dump notes, /proc/$pid/maps, and relocations.
123 lines
3.0 KiB
C
123 lines
3.0 KiB
C
// Copyright 2018-2019 - Omar Sandoval
|
|
// SPDX-License-Identifier: GPL-3.0+
|
|
|
|
/**
|
|
* @file
|
|
*
|
|
* Error helpers.
|
|
*
|
|
* See @ref Errors.
|
|
*/
|
|
|
|
#ifndef DRGN_ERROR_H
|
|
#define DRGN_ERROR_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "drgn.h"
|
|
|
|
/**
|
|
* @ingroup Internals
|
|
*
|
|
* @defgroup Errors Errors
|
|
*
|
|
* Common errors.
|
|
*
|
|
* @{
|
|
*/
|
|
|
|
#define DRGN_UNREACHABLE() abort()
|
|
|
|
struct drgn_object_type;
|
|
|
|
/**
|
|
* Global stop iteration error.
|
|
*
|
|
* This is also used as a special sentinel return in various places internally.
|
|
*/
|
|
extern struct drgn_error drgn_stop;
|
|
|
|
struct string_builder;
|
|
|
|
/**
|
|
* Create a @ref drgn_error with a message from a @ref string_builder.
|
|
*
|
|
* This finalizes the string builder.
|
|
*/
|
|
struct drgn_error *drgn_error_from_string_builder(enum drgn_error_code code,
|
|
struct string_builder *sb);
|
|
|
|
/**
|
|
* Append a formatted @ref drgn_error to a @ref string_builder.
|
|
*
|
|
* @return @c true on success, @c false on error (if we couldn't allocate
|
|
* memory).
|
|
*/
|
|
bool string_builder_append_error(struct string_builder *sb,
|
|
struct drgn_error *err);
|
|
|
|
/** Create a @ref drgn_error from the libelf error indicator. */
|
|
struct drgn_error *drgn_error_libelf(void)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/** Create a @ref drgn_error from the libdw error indicator. */
|
|
struct drgn_error *drgn_error_libdw(void)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/** Create a @ref drgn_error from the libdwfl error indicator. */
|
|
struct drgn_error *drgn_error_libdwfl(void)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/**
|
|
* Create a @ref drgn_error with a type name.
|
|
*
|
|
* The error code will be @ref DRGN_ERROR_TYPE.
|
|
*
|
|
* @param[in] format Format string for the type error. Must contain %s, which
|
|
* will be replaced with the type name, and no other conversion specifications.
|
|
*/
|
|
struct drgn_error *drgn_type_error(const char *format, struct drgn_type *type)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/**
|
|
* Create a @ref drgn_error with a qualified type name.
|
|
*
|
|
* @sa drgn_type_error().
|
|
*/
|
|
struct drgn_error *
|
|
drgn_qualified_type_error(const char *format,
|
|
struct drgn_qualified_type qualified_type)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/**
|
|
* Create a @ref drgn_error for an incomplete type.
|
|
*
|
|
* @sa drgn_type_error().
|
|
*/
|
|
struct drgn_error *drgn_error_incomplete_type(const char *format,
|
|
struct drgn_type *type);
|
|
|
|
/**
|
|
* Create a @ref drgn_error for a type which does not have a given member.
|
|
*
|
|
* The error code will be @ref DRGN_ERROR_LOOKUP.
|
|
*/
|
|
struct drgn_error *drgn_error_member_not_found(struct drgn_type *type,
|
|
const char *member_name)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/** Create a @ref drgn_error for invalid types to a binary operator. */
|
|
struct drgn_error *drgn_error_binary_op(const char *op_name,
|
|
struct drgn_object_type *type1,
|
|
struct drgn_object_type *type2)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/** Create a @ref drgn_error for an invalid type to a unary operator. */
|
|
struct drgn_error *drgn_error_unary_op(const char *op_name,
|
|
struct drgn_object_type *type)
|
|
__attribute__((returns_nonnull));
|
|
|
|
/** @} */
|
|
|
|
#endif /* DRGN_ERROR_H */
|