diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2008-04-13 14:59:36 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2008-04-13 14:59:36 -0400 |
commit | 1ec6761a6b893c2c755753617bebac79b3040fca (patch) | |
tree | bd252bb1d5253e1a10ff24b1790e6e0e1b7cec02 /runtime/staprun/unwind_data.c | |
parent | bf50bb491c5bfcf3035de45ac58acf11ed02af06 (diff) | |
parent | 1c86aa2adc1165906057cdde4cc7484468726fc4 (diff) | |
download | systemtap-steved-1ec6761a6b893c2c755753617bebac79b3040fca.tar.gz systemtap-steved-1ec6761a6b893c2c755753617bebac79b3040fca.tar.xz systemtap-steved-1ec6761a6b893c2c755753617bebac79b3040fca.zip |
Merge commit 'origin/unwind'
* commit 'origin/unwind':
Fixes for 2.6.25 pt_regs changes.
Include string.h
Change stap to get kernel symbols from debuginfo and
reincarnate vim/ directory in this branch to match master
Add new define STP_USE_DWARF_UNWINDER which is set based on which archs
Remove misleading error message.
Support for kernels built with CONFIG_FRAME_POINTER
Fix regression.
dded _stp_read_address() and changed code to use it.
kretprobe trampoline fixes
i386 fixes.
control.c (_stp_ctl_write_dbug): Insert missing break.
32-bit fixes
Cleanup.
2008-03-23 Frank Ch. Eigler <fche@elastic.org>
2008-03-23 Frank Ch. Eigler <fche@elastic.org>
2008-03-21 Eugene Teo <eugeneteo@kernel.sg>
add (back) runtime/unwind files
* clarify utility of epilogue-type probe aliases in documentation
rebased unwind_branch on top of current master
Diffstat (limited to 'runtime/staprun/unwind_data.c')
-rw-r--r-- | runtime/staprun/unwind_data.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/runtime/staprun/unwind_data.c b/runtime/staprun/unwind_data.c new file mode 100644 index 00000000..ed27cc20 --- /dev/null +++ b/runtime/staprun/unwind_data.c @@ -0,0 +1,97 @@ +/* -*- linux-c -*- + * Unwind data functions for staprun. + * + * Copyright (C) 2008 Red Hat Inc. + * + * This file is part of systemtap, and is free software. You can + * redistribute it and/or modify it under the terms of the GNU General + * Public License (GPL); either version 2, or (at your option) any + * later version. + */ + +#include "staprun.h" +#include <elfutils/libdwfl.h> +#include <dwarf.h> + +static char debuginfo_path_arr[] = "-:.debug:/usr/lib/debug"; +static char *debuginfo_path = debuginfo_path_arr; +static const Dwfl_Callbacks kernel_callbacks = { + .find_debuginfo = dwfl_standard_find_debuginfo, + .debuginfo_path = &debuginfo_path, + .find_elf = dwfl_linux_kernel_find_elf, + .section_address = dwfl_linux_kernel_module_section_address, +}; + +void *get_module_unwind_data(Dwfl * dwfl, const char *name, int *len) +{ + Dwarf_Addr bias = 0; + Dwarf *dw; + GElf_Ehdr *ehdr, ehdr_mem; + GElf_Shdr *shdr, shdr_mem; + Elf_Scn *scn = NULL; + Elf_Data *data = NULL; + + Dwfl_Module *mod = dwfl_report_module(dwfl, name, 0, 0); + dwfl_report_end(dwfl, NULL, NULL); + dw = dwfl_module_getdwarf(mod, &bias); + Elf *elf = dwarf_getelf(dw); + ehdr = gelf_getehdr(elf, &ehdr_mem); + while ((scn = elf_nextscn(elf, scn))) { + shdr = gelf_getshdr(scn, &shdr_mem); + if (strcmp(elf_strptr(elf, ehdr->e_shstrndx, shdr->sh_name), ".debug_frame") == 0) { + data = elf_rawdata(scn, NULL); + break; + } + } + + if (data == NULL) { + *len = 0; + dbug(2, "module %s returns NULL\n", name); + return NULL; + } + dbug(2, "module %s returns %d\n", name, (int)data->d_size); + *len = data->d_size; + return data->d_buf; +} + +void send_unwind_data(const char *name) +{ + struct _stp_msg_unwind *un; + int unwind_data_len = 0; + void *unwind_data = NULL; + char *buf; + + dbug(2, "module %s\n", name); + if (strcmp(name, "*")) { + Dwfl *dwfl = dwfl_begin(&kernel_callbacks); + + if (name[0] == 0) + unwind_data = get_module_unwind_data(dwfl, "kernel", &unwind_data_len); + else + unwind_data = get_module_unwind_data(dwfl, name, &unwind_data_len); + + /* yuck */ + buf = (char *)malloc(unwind_data_len + sizeof(*un) + sizeof(uint32_t)); + if (!buf) { + err("malloc failed\n"); + return; + } + memcpy(buf + sizeof(*un) + sizeof(uint32_t), unwind_data, unwind_data_len); + dwfl_end(dwfl); + } else { + buf = (char *)malloc(sizeof(*un) + sizeof(uint32_t)); + if (!buf) { + err("malloc failed\n"); + return; + } + } + + un = (struct _stp_msg_unwind *)(buf + sizeof(uint32_t)); + strncpy(un->name, name, sizeof(un->name)); + un->unwind_len = unwind_data_len; + *(uint32_t *) buf = STP_UNWIND; + + /* send unwind data */ + if (write(control_channel, buf, unwind_data_len + sizeof(*un) + sizeof(uint32_t)) <= 0) + err("write failed\n"); +} |