dwarves: Expose and maintain active debug info loader operations
Maintain a pointer to debug_fmt_ops corresponding to currently used debug info format loader (DWARF, BTF, or CTF), to allow various parts of libdwarves to do things like resolve string offset to actual string pointer in a format-agnostic format. This allows to, say, load DWARF debug info, and use it for BTF generation, without either of them making assumptions about how strings are actually stored internally. This is going to be used in the next patch to allow BTF loader and encoder to use a very different way of storing strings (not a global shared gobuffer). Committer notes: Since it is available in multiple object files, add a dwarves__ prefix namespace and add an extern for it in dwarves.h. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Cc: bpf@vger.kernel.org Cc: dwarves@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
7bc2dd07d5
commit
0a9b89910e
|
@ -1901,6 +1901,8 @@ static struct debug_fmt_ops *debug_fmt_table[] = {
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct debug_fmt_ops *dwarves__active_loader;
|
||||||
|
|
||||||
static int debugging_formats__loader(const char *name)
|
static int debugging_formats__loader(const char *name)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -1938,6 +1940,7 @@ int cus__load_file(struct cus *cus, struct conf_load *conf,
|
||||||
conf->conf_fprintf->has_alignment_info = debug_fmt_table[loader]->has_alignment_info;
|
conf->conf_fprintf->has_alignment_info = debug_fmt_table[loader]->has_alignment_info;
|
||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
|
dwarves__active_loader = debug_fmt_table[loader];
|
||||||
if (debug_fmt_table[loader]->load_file(cus, conf,
|
if (debug_fmt_table[loader]->load_file(cus, conf,
|
||||||
filename) == 0)
|
filename) == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -1949,17 +1952,20 @@ int cus__load_file(struct cus *cus, struct conf_load *conf,
|
||||||
fp = sep + 1;
|
fp = sep + 1;
|
||||||
}
|
}
|
||||||
free(fpath);
|
free(fpath);
|
||||||
|
dwarves__active_loader = NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (debug_fmt_table[i] != NULL) {
|
while (debug_fmt_table[i] != NULL) {
|
||||||
if (conf && conf->conf_fprintf)
|
if (conf && conf->conf_fprintf)
|
||||||
conf->conf_fprintf->has_alignment_info = debug_fmt_table[i]->has_alignment_info;
|
conf->conf_fprintf->has_alignment_info = debug_fmt_table[i]->has_alignment_info;
|
||||||
|
dwarves__active_loader = debug_fmt_table[i];
|
||||||
if (debug_fmt_table[i]->load_file(cus, conf, filename) == 0)
|
if (debug_fmt_table[i]->load_file(cus, conf, filename) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dwarves__active_loader = NULL;
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2283,8 +2289,10 @@ static int cus__load_running_kernel(struct cus *cus, struct conf_load *conf)
|
||||||
if (conf && conf->conf_fprintf)
|
if (conf && conf->conf_fprintf)
|
||||||
conf->conf_fprintf->has_alignment_info = debug_fmt_table[loader]->has_alignment_info;
|
conf->conf_fprintf->has_alignment_info = debug_fmt_table[loader]->has_alignment_info;
|
||||||
|
|
||||||
|
dwarves__active_loader = debug_fmt_table[loader];
|
||||||
if (debug_fmt_table[loader]->load_file(cus, conf, "/sys/kernel/btf/vmlinux") == 0)
|
if (debug_fmt_table[loader]->load_file(cus, conf, "/sys/kernel/btf/vmlinux") == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
dwarves__active_loader = NULL;
|
||||||
}
|
}
|
||||||
try_elf:
|
try_elf:
|
||||||
elf_version(EV_CURRENT);
|
elf_version(EV_CURRENT);
|
||||||
|
|
Loading…
Reference in New Issue