mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 09:43:06 +00:00
0c5df56fba
struct drgn_symbol doesn't really represent a symbol; it's just an
object which hasn't been fully initialized (see c2be52dff0
("libdrgn:
rename object index to symbol index"), it used to be called a "partial
object"). For stack traces, we're going to have a notion of a symbol
that more closely represents an ELF symbol, so let's get rid of the
temporary struct drgn_symbol representation and just return an object
directly.
94 lines
2.0 KiB
C
94 lines
2.0 KiB
C
// Copyright 2018-2019 - Omar Sandoval
|
|
// SPDX-License-Identifier: GPL-3.0+
|
|
|
|
#include <string.h>
|
|
|
|
#include "internal.h"
|
|
#include "object_index.h"
|
|
#include "type.h"
|
|
|
|
void drgn_object_index_init(struct drgn_object_index *oindex)
|
|
{
|
|
oindex->finders = NULL;
|
|
}
|
|
|
|
void drgn_object_index_deinit(struct drgn_object_index *oindex)
|
|
{
|
|
struct drgn_object_finder *finder;
|
|
|
|
finder = oindex->finders;
|
|
while (finder) {
|
|
struct drgn_object_finder *next = finder->next;
|
|
|
|
free(finder);
|
|
finder = next;
|
|
}
|
|
}
|
|
|
|
struct drgn_error *
|
|
drgn_object_index_add_finder(struct drgn_object_index *oindex,
|
|
drgn_object_find_fn fn, void *arg)
|
|
{
|
|
struct drgn_object_finder *finder;
|
|
|
|
finder = malloc(sizeof(*finder));
|
|
if (!finder)
|
|
return &drgn_enomem;
|
|
finder->fn = fn;
|
|
finder->arg = arg;
|
|
finder->next = oindex->finders;
|
|
oindex->finders = finder;
|
|
return NULL;
|
|
}
|
|
|
|
struct drgn_error *drgn_object_index_find(struct drgn_object_index *oindex,
|
|
const char *name,
|
|
const char *filename,
|
|
enum drgn_find_object_flags flags,
|
|
struct drgn_object *ret)
|
|
{
|
|
struct drgn_error *err;
|
|
size_t name_len;
|
|
struct drgn_object_finder *finder;
|
|
const char *kind_str;
|
|
|
|
if ((flags & ~DRGN_FIND_OBJECT_ANY) || !flags) {
|
|
return drgn_error_create(DRGN_ERROR_INVALID_ARGUMENT,
|
|
"invalid find object flags");
|
|
}
|
|
|
|
name_len = strlen(name);
|
|
finder = oindex->finders;
|
|
while (finder) {
|
|
err = finder->fn(name, name_len, filename, flags, finder->arg,
|
|
ret);
|
|
if (err != &drgn_not_found)
|
|
return err;
|
|
finder = finder->next;
|
|
}
|
|
|
|
switch (flags) {
|
|
case DRGN_FIND_OBJECT_CONSTANT:
|
|
kind_str = "constant ";
|
|
break;
|
|
case DRGN_FIND_OBJECT_FUNCTION:
|
|
kind_str = "function ";
|
|
break;
|
|
case DRGN_FIND_OBJECT_VARIABLE:
|
|
kind_str = "variable ";
|
|
break;
|
|
default:
|
|
kind_str = "";
|
|
break;
|
|
}
|
|
if (filename) {
|
|
return drgn_error_format(DRGN_ERROR_LOOKUP,
|
|
"could not find %s'%s' in '%s'",
|
|
kind_str, name, filename);
|
|
} else {
|
|
return drgn_error_format(DRGN_ERROR_LOOKUP,
|
|
"could not find %s'%s'", kind_str,
|
|
name);
|
|
}
|
|
}
|