2021-11-21 23:59:44 +00:00
|
|
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
2022-11-02 00:05:16 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
2019-07-25 08:47:13 +01:00
|
|
|
|
|
|
|
#ifndef DRGN_SYMBOL_H
|
|
|
|
#define DRGN_SYMBOL_H
|
|
|
|
|
2021-08-19 22:12:44 +01:00
|
|
|
#include <gelf.h>
|
|
|
|
|
2024-03-02 00:46:53 +00:00
|
|
|
#include "cleanup.h"
|
2021-08-19 22:12:44 +01:00
|
|
|
#include "drgn.h"
|
2024-04-26 23:33:37 +01:00
|
|
|
#include "handler.h"
|
libdrgn: introduce Symbol Finder API
Symbol lookup is not yet modular, like type or object lookup. However,
making it modular would enable easier development and prototyping of
alternative Symbol providers, such as Linux kernel module symbol tables,
vmlinux kallsyms tables, and BPF function symbols. To begin with, create
a modular Symbol API within libdrgn, and refactor the ELF symbol search
to use it.
For now, we leave drgn_program_find_symbol_by_address_internal() alone.
Its conversion will require some surgery, since the new API can return
errors, whereas this function cannot.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2024-03-02 00:46:53 +00:00
|
|
|
#include "vector.h"
|
2019-07-25 08:47:13 +01:00
|
|
|
|
|
|
|
struct drgn_symbol {
|
|
|
|
const char *name;
|
|
|
|
uint64_t address;
|
|
|
|
uint64_t size;
|
2021-08-19 22:12:44 +01:00
|
|
|
enum drgn_symbol_binding binding;
|
|
|
|
enum drgn_symbol_kind kind;
|
python: Allow construction of Symbol objects
Previously, Symbol objects could not be constructed in Python. However,
in order to allow Python Symbol finders, this needs to be changed.
Unfortunately, Symbol name lifetimes are tricky to manage. We introduce
a lifetime enumeration to handle this. The lifetime may be "static",
i.e. longer than the life of the program; "external", i.e. longer than
the life of the symbol, but no guarantees beyond that; or "owned", i.e.
owned by the Symbol itself.
Symbol objects constructed in Python are "external". The Symbol struct
owns the pointer to the drgn_symbol, and it holds a reference to the
Python object keeping the name valid (either the program, or a PyUnicode
object).
The added complexity is justified by the fact that most symbols are from
the ELF file, and thus share a lifetime with the Program. It would be a
waste to constantly strdup() these strings, just to support a small
number of Symbols created by Python code.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2024-03-02 00:46:53 +00:00
|
|
|
enum drgn_lifetime name_lifetime;
|
2019-07-25 08:47:13 +01:00
|
|
|
};
|
|
|
|
|
libdrgn: introduce Symbol Finder API
Symbol lookup is not yet modular, like type or object lookup. However,
making it modular would enable easier development and prototyping of
alternative Symbol providers, such as Linux kernel module symbol tables,
vmlinux kallsyms tables, and BPF function symbols. To begin with, create
a modular Symbol API within libdrgn, and refactor the ELF symbol search
to use it.
For now, we leave drgn_program_find_symbol_by_address_internal() alone.
Its conversion will require some surgery, since the new API can return
errors, whereas this function cannot.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2024-03-02 00:46:53 +00:00
|
|
|
struct drgn_symbol_finder {
|
2024-04-26 23:33:37 +01:00
|
|
|
struct drgn_handler handler;
|
|
|
|
struct drgn_symbol_finder_ops ops;
|
libdrgn: introduce Symbol Finder API
Symbol lookup is not yet modular, like type or object lookup. However,
making it modular would enable easier development and prototyping of
alternative Symbol providers, such as Linux kernel module symbol tables,
vmlinux kallsyms tables, and BPF function symbols. To begin with, create
a modular Symbol API within libdrgn, and refactor the ELF symbol search
to use it.
For now, we leave drgn_program_find_symbol_by_address_internal() alone.
Its conversion will require some surgery, since the new API can return
errors, whereas this function cannot.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2024-03-02 00:46:53 +00:00
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_VECTOR_TYPE(symbolp_vector, struct drgn_symbol *);
|
|
|
|
|
|
|
|
struct drgn_symbol_result_builder {
|
|
|
|
bool one;
|
|
|
|
union {
|
|
|
|
struct symbolp_vector vector;
|
|
|
|
struct drgn_symbol *single;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-03-02 00:46:53 +00:00
|
|
|
#define _cleanup_symbol_ _cleanup_(drgn_symbol_cleanup)
|
|
|
|
static inline void drgn_symbol_cleanup(struct drgn_symbol **p)
|
|
|
|
{
|
|
|
|
drgn_symbol_destroy(*p);
|
|
|
|
}
|
|
|
|
|
2021-08-19 22:12:44 +01:00
|
|
|
/** Initialize a @ref drgn_symbol from an ELF symbol. */
|
|
|
|
void drgn_symbol_from_elf(const char *name, uint64_t address,
|
|
|
|
const GElf_Sym *elf_sym, struct drgn_symbol *ret);
|
|
|
|
|
libdrgn: introduce Symbol Finder API
Symbol lookup is not yet modular, like type or object lookup. However,
making it modular would enable easier development and prototyping of
alternative Symbol providers, such as Linux kernel module symbol tables,
vmlinux kallsyms tables, and BPF function symbols. To begin with, create
a modular Symbol API within libdrgn, and refactor the ELF symbol search
to use it.
For now, we leave drgn_program_find_symbol_by_address_internal() alone.
Its conversion will require some surgery, since the new API can return
errors, whereas this function cannot.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2024-03-02 00:46:53 +00:00
|
|
|
/** Destroy the contents of the result builder */
|
|
|
|
void drgn_symbol_result_builder_abort(struct drgn_symbol_result_builder *builder);
|
|
|
|
|
|
|
|
/** Initialize result builder */
|
|
|
|
void drgn_symbol_result_builder_init(struct drgn_symbol_result_builder *builder,
|
|
|
|
bool one);
|
|
|
|
|
|
|
|
/** Return single result */
|
|
|
|
struct drgn_symbol *
|
|
|
|
drgn_symbol_result_builder_single(struct drgn_symbol_result_builder *builder);
|
|
|
|
|
|
|
|
/** Return array result */
|
|
|
|
void drgn_symbol_result_builder_array(struct drgn_symbol_result_builder *builder,
|
|
|
|
struct drgn_symbol ***syms_ret, size_t *count_ret);
|
|
|
|
|
2024-03-02 00:46:53 +00:00
|
|
|
struct drgn_error *
|
|
|
|
drgn_symbol_copy(struct drgn_symbol *dst, struct drgn_symbol *src);
|
|
|
|
|
2019-07-25 08:47:13 +01:00
|
|
|
#endif /* DRGN_SYMBOL_H */
|