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.
118 lines
2.8 KiB
C
118 lines
2.8 KiB
C
// Copyright 2018-2019 - Omar Sandoval
|
|
// SPDX-License-Identifier: GPL-3.0+
|
|
|
|
/**
|
|
* @file
|
|
*
|
|
* Program internals.
|
|
*
|
|
* See @ref ProgramInternals.
|
|
*/
|
|
|
|
#ifndef DRGN_PROGRAM_H
|
|
#define DRGN_PROGRAM_H
|
|
|
|
#include <elfutils/libdwfl.h>
|
|
|
|
#include "memory_reader.h"
|
|
#include "symbol_index.h"
|
|
#include "type_index.h"
|
|
|
|
/**
|
|
* @ingroup Internals
|
|
*
|
|
* @defgroup ProgramInternals Programs
|
|
*
|
|
* Program internals.
|
|
*
|
|
* @{
|
|
*/
|
|
|
|
/** The important parts of the VMCOREINFO note of a Linux kernel core. */
|
|
struct vmcoreinfo {
|
|
/** <tt>uname -r</tt> */
|
|
char osrelease[128];
|
|
/** PAGE_SIZE of the kernel. */
|
|
uint64_t page_size;
|
|
/**
|
|
* The offset from the compiled address of the kernel image to its
|
|
* actual address in memory.
|
|
*
|
|
* This is non-zero if kernel address space layout randomization (KASLR)
|
|
* is enabled.
|
|
*/
|
|
uint64_t kaslr_offset;
|
|
};
|
|
|
|
struct drgn_dwarf_info_cache;
|
|
struct drgn_dwarf_index;
|
|
|
|
struct drgn_program {
|
|
/** @privatesection */
|
|
struct drgn_memory_reader reader;
|
|
struct drgn_type_index tindex;
|
|
struct drgn_symbol_index sindex;
|
|
struct drgn_memory_file_segment *file_segments;
|
|
size_t num_file_segments;
|
|
/*
|
|
* Valid iff <tt>flags & DRGN_PROGRAM_IS_LINUX_KERNEL</tt>.
|
|
*/
|
|
struct vmcoreinfo vmcoreinfo;
|
|
/*
|
|
* Valid iff
|
|
* <tt>(flags & (DRGN_PROGRAM_IS_LINUX_KERNEL | DRGN_PROGRAM_IS_LIVE)) ==
|
|
* DRGN_PROGRAM_IS_LIVE</tt>.
|
|
*/
|
|
pid_t pid;
|
|
Dwfl *_dwfl;
|
|
struct drgn_dwarf_info_cache *dicache;
|
|
int core_fd;
|
|
enum drgn_program_flags flags;
|
|
enum drgn_architecture_flags arch;
|
|
bool added_vmcoreinfo_symbol_finder;
|
|
};
|
|
|
|
/** Initialize a @ref drgn_program. */
|
|
void drgn_program_init(struct drgn_program *prog,
|
|
enum drgn_architecture_flags arch);
|
|
|
|
/** Deinitialize a @ref drgn_program. */
|
|
void drgn_program_deinit(struct drgn_program *prog);
|
|
|
|
/**
|
|
* Implement @ref drgn_program_from_core_dump() on an initialized @ref
|
|
* drgn_program.
|
|
*/
|
|
struct drgn_error *drgn_program_init_core_dump(struct drgn_program *prog,
|
|
const char *path);
|
|
|
|
/**
|
|
* Implement @ref drgn_program_from_kernel() on an initialized @ref
|
|
* drgn_program.
|
|
*/
|
|
struct drgn_error *drgn_program_init_kernel(struct drgn_program *prog);
|
|
|
|
/**
|
|
* Implement @ref drgn_program_from_pid() on an initialized @ref drgn_program.
|
|
*/
|
|
struct drgn_error *drgn_program_init_pid(struct drgn_program *prog, pid_t pid);
|
|
|
|
/** Return the maximum word value for a program. */
|
|
static inline uint64_t drgn_program_word_mask(struct drgn_program *prog)
|
|
{
|
|
return prog->arch & DRGN_ARCH_IS_64_BIT ? UINT64_MAX : UINT32_MAX;
|
|
}
|
|
|
|
/*
|
|
* Get the @c Dwfl handle and @ref drgn_dwarf_index for a @ref drgn_program.
|
|
*
|
|
* These are created the first time that this is called.
|
|
*/
|
|
struct drgn_error *drgn_program_get_dwarf(struct drgn_program *prog,
|
|
Dwfl **dwfl_ret,
|
|
struct drgn_dwarf_index **dindex_ret);
|
|
|
|
/** @} */
|
|
|
|
#endif /* DRGN_PROGRAM_H */
|