summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2009-05-20 15:24:02 +0200
committerMark Wielaard <mjw@redhat.com>2009-05-20 15:24:02 +0200
commit4285dc9a58fbdae1516c4117a3f9297b822f27ff (patch)
treedad37f2df6e827565ceb80aadb98426d5b22e817
parent78c9d72e18da2d5c930fb39460c236ea24fee423 (diff)
downloadsystemtap-steved-4285dc9a58fbdae1516c4117a3f9297b822f27ff.tar.gz
systemtap-steved-4285dc9a58fbdae1516c4117a3f9297b822f27ff.tar.xz
systemtap-steved-4285dc9a58fbdae1516c4117a3f9297b822f27ff.zip
Fetch and store both debug_frame and eh_frame tables.
* runtime/sym.h (_stp_module): Remove unwind_data, unwind_data_len and unwind_is_ehframe fields. Add debug_frame, eh_frame, debug_frame_len, eh_frame_len and eh_frame_addr fields. * runtime/unwind.c: Use debug_frame and debug_frame_len instead of unwind_data and unwind_data_len throughout. (cie_for_fde): Take unwind_data and is_ehframe as direct arguments. * runtime/unwind/unwind.h (cie_for_fde): New function declaration. * translate.cxx (get_unwind_data): Fetch and return both debug_frame and eh_frame tables. (dump_unwindsyms): Dump both debug_frame and eh_frame tables.
-rw-r--r--runtime/sym.h8
-rw-r--r--runtime/unwind.c29
-rw-r--r--runtime/unwind/unwind.h4
-rw-r--r--translate.cxx130
4 files changed, 113 insertions, 58 deletions
diff --git a/runtime/sym.h b/runtime/sym.h
index 80c334fb..7e28ebe6 100644
--- a/runtime/sym.h
+++ b/runtime/sym.h
@@ -42,11 +42,13 @@ struct _stp_module {
unsigned long dwarf_module_base;
/* the stack unwind data for this module */
- void *unwind_data;
+ void *debug_frame;
+ void *eh_frame;
void *unwind_hdr;
- uint32_t unwind_data_len;
+ uint32_t debug_frame_len;
+ uint32_t eh_frame_len;
uint32_t unwind_hdr_len;
- uint32_t unwind_is_ehframe; /* unwind data comes from .eh_frame */
+ unsigned long eh_frame_addr; /* Orig load address (offset) .eh_frame */
/* build-id information */
unsigned char *build_id_bits;
unsigned long build_id_offset;
diff --git a/runtime/unwind.c b/runtime/unwind.c
index f03534bd..8ba3cf76 100644
--- a/runtime/unwind.c
+++ b/runtime/unwind.c
@@ -87,7 +87,8 @@ static sleb128_t get_sleb128(const u8 **pcur, const u8 *end)
}
/* given an FDE, find its CIE */
-static const u32 *cie_for_fde(const u32 *fde, const struct _stp_module *m)
+static const u32 *cie_for_fde(const u32 *fde, void *unwind_data,
+ int is_ehframe)
{
const u32 *cie;
@@ -96,7 +97,7 @@ static const u32 *cie_for_fde(const u32 *fde, const struct _stp_module *m)
return &bad_cie;
/* CIE id for eh_frame is 0, otherwise 0xffffffff */
- if (m->unwind_is_ehframe && fde[1] == 0)
+ if (is_ehframe && fde[1] == 0)
return &not_fde;
else if (fde[1] == 0xffffffff)
return &not_fde;
@@ -104,18 +105,18 @@ static const u32 *cie_for_fde(const u32 *fde, const struct _stp_module *m)
/* OK, must be an FDE. Now find its CIE. */
/* CIE_pointer must be a proper offset */
- if ((fde[1] & (sizeof(*fde) - 1)) || fde[1] > (unsigned long)(fde + 1) - (unsigned long)m->unwind_data) {
+ if ((fde[1] & (sizeof(*fde) - 1)) || fde[1] > (unsigned long)(fde + 1) - (unsigned long)unwind_data) {
dbug_unwind(1, "fde[1]=%lx fde+1=%lx, unwind_data=%lx %lx\n",
(unsigned long)fde[1], (unsigned long)(fde + 1),
- (unsigned long)m->unwind_data, (unsigned long)(fde + 1) - (unsigned long)m->unwind_data);
+ (unsigned long)unwind_data, (unsigned long)(fde + 1) - (unsigned long)unwind_data);
return NULL; /* this is not a valid FDE */
}
/* cie pointer field is different in eh_frame vs debug_frame */
- if (m->unwind_is_ehframe)
+ if (is_ehframe)
cie = fde + 1 - fde[1] / sizeof(*fde);
else
- cie = m->unwind_data + fde[1];
+ cie = unwind_data + fde[1];
if (*cie <= sizeof(*cie) + 4 || *cie >= fde[1] - sizeof(*fde)
|| (*cie & (sizeof(*cie) - 1))
@@ -488,7 +489,7 @@ static u32 *_stp_search_unwind_hdr(unsigned long pc,
ptr = hdr + 4;
end = hdr + m->unwind_hdr_len;
- if (read_pointer(&ptr, end, hdr[1]) != (unsigned long)m->unwind_data) {
+ if (read_pointer(&ptr, end, hdr[1]) != (unsigned long)m->debug_frame) {
dbug_unwind(1, "eh_frame_ptr not valid");
return NULL;
}
@@ -592,8 +593,8 @@ static int unwind(struct unwind_frame_info *frame, struct task_struct *tsk)
return -EINVAL;
}
- if (unlikely(m->unwind_data_len == 0 || m->unwind_data_len & (sizeof(*fde) - 1))) {
- dbug_unwind(1, "Module %s: unwind_data_len=%d", m->name, m->unwind_data_len);
+ if (unlikely(m->debug_frame_len == 0 || m->debug_frame_len & (sizeof(*fde) - 1))) {
+ dbug_unwind(1, "Module %s: unwind_data_len=%d", m->name, m->debug_fram_len);
goto err;
}
@@ -602,7 +603,7 @@ static int unwind(struct unwind_frame_info *frame, struct task_struct *tsk)
/* found the fde, now set startLoc and endLoc */
if (fde != NULL) {
- cie = cie_for_fde(fde, m);
+ cie = cie_for_fde(fde, m->debug_frame, false);
if (likely(cie != NULL && cie != &bad_cie && cie != &not_fde)) {
ptr = (const u8 *)(fde + 2);
ptrType = fde_pointer_type(cie);
@@ -625,10 +626,10 @@ static int unwind(struct unwind_frame_info *frame, struct task_struct *tsk)
/* did not a good fde find with binary search, so do slow linear search */
if (fde == NULL) {
- for (fde = m->unwind_data, tableSize = m->unwind_data_len; cie = NULL, tableSize > sizeof(*fde)
- && tableSize - sizeof(*fde) >= *fde; tableSize -= sizeof(*fde) + *fde, fde += 1 + *fde / sizeof(*fde)) {
+ for (fde = m->debug_frame, tableSize = m->debug_frame_len; cie = NULL, tableSize > sizeof(*fde)
+ && tableSize - sizeof(*fde) >= *fde; tableSize -= sizeof(*fde) + *fde, fde += 1 + *fde / sizeof(*fde)) {
dbug_unwind(3, "fde=%lx tableSize=%d\n", (long)*fde, (int)tableSize);
- cie = cie_for_fde(fde, m);
+ cie = cie_for_fde(fde, m->debug_frame, false);
if (cie == &bad_cie) {
cie = NULL;
break;
@@ -651,7 +652,7 @@ static int unwind(struct unwind_frame_info *frame, struct task_struct *tsk)
}
}
- dbug_unwind(1, "cie=%lx fde=%lx startLoc=%lx endLoc=%lx\n", cie, fde, startLoc, endLoc);
+ dbug_unwind(1, "cie=%lx fde=%lx startLoc=%lx endLoc=%lx, pc=%lx\n", cie, fde, startLoc, endLoc, pc);
if (cie == NULL || fde == NULL)
goto err;
diff --git a/runtime/unwind/unwind.h b/runtime/unwind/unwind.h
index 3b6d0de0..285a3a34 100644
--- a/runtime/unwind/unwind.h
+++ b/runtime/unwind/unwind.h
@@ -1,7 +1,7 @@
/* -*- linux-c -*-
*
* dwarf unwinder header file
- * Copyright (C) 2008 Red Hat Inc.
+ * Copyright (C) 2008, 2009 Red Hat Inc.
* Copyright (C) 2002-2006 Novell, Inc.
*
* This file is part of systemtap, and is free software. You can
@@ -143,7 +143,7 @@ static unsigned long read_pointer(const u8 **pLoc,
const void *end,
signed ptrType);
static const u32 bad_cie, not_fde;
-static const u32 *cie_for_fde(const u32 *fde, const struct _stp_module *);
+static const u32 *cie_for_fde(const u32 *fde, void *table, int is_ehframe);
static signed fde_pointer_type(const u32 *cie);
diff --git a/translate.cxx b/translate.cxx
index 87811e9f..eaa2e942 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -4413,41 +4413,56 @@ struct unwindsym_dump_context
};
-// Get the .debug_frame section for the given module.
-// l will be set to the length of the size of the unwind data if found.
-static void *get_unwind_data (Dwfl_Module *m, size_t *l)
+// Get the .debug_frame end .eh_frame sections for the given module.
+// Also returns the lenght of both sections when found, plus the section
+// address of the eh_frame data.
+static void get_unwind_data (Dwfl_Module *m,
+ void **debug_frame, void **eh_frame,
+ size_t *debug_len, size_t *eh_len,
+ Dwarf_Addr *eh_addr)
{
Dwarf_Addr bias = 0;
- Dwarf *dw;
GElf_Ehdr *ehdr, ehdr_mem;
GElf_Shdr *shdr, shdr_mem;
- Elf_Scn *scn = NULL;
- Elf_Data *data = NULL;
-
- dw = dwfl_module_getdwarf(m, &bias);
- if (dw != NULL)
+ Elf_Scn *scn;
+ Elf_Data *data;
+ Elf *elf;
+
+ // fetch .eh_frame info preferably from main elf file.
+ elf = dwfl_module_getelf(m, &bias);
+ ehdr = gelf_getehdr(elf, &ehdr_mem);
+ scn = NULL;
+ while ((scn = elf_nextscn(elf, scn)))
{
- 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),
+ ".eh_frame") == 0)
{
- 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;
- }
+ data = elf_rawdata(scn, NULL);
+ *eh_frame = data->d_buf;
+ *eh_len = data->d_size;
+ *eh_addr = shdr->sh_addr;
+ break;
}
}
- if (data != NULL)
+ // fetch .debug_frame info preferably from dwarf debuginfo file.
+ elf = (dwarf_getelf (dwfl_module_getdwarf (m, &bias))
+ ?: dwfl_module_getelf (m, &bias));
+ ehdr = gelf_getehdr(elf, &ehdr_mem);
+ scn = NULL;
+ while ((scn = elf_nextscn(elf, scn)))
{
- *l = data->d_size;
- return data->d_buf;
+ 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);
+ *debug_frame = data->d_buf;
+ *debug_len = data->d_size;
+ break;
+ }
}
-
- return NULL;
}
static int
@@ -4680,17 +4695,21 @@ dump_unwindsyms (Dwfl_Module *m,
}
// Add unwind data to be included if it exists for this module.
- size_t len = 0;
- void *unwind = get_unwind_data (m, &len);
- if (unwind != NULL)
+ void *debug_frame = NULL;
+ size_t debug_len = 0;
+ void *eh_frame = NULL;
+ size_t eh_len = 0;
+ Dwarf_Addr eh_addr = NULL;
+ get_unwind_data (m, &debug_frame, &eh_frame, &debug_len, &eh_len, &eh_addr);
+ if (debug_frame != NULL && debug_len > 0)
{
c->output << "#if defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)\n";
c->output << "static uint8_t _stp_module_" << stpmod_idx
- << "_unwind_data[] = \n";
+ << "_debug_frame[] = \n";
c->output << " {";
- for (size_t i = 0; i < len; i++)
+ for (size_t i = 0; i < debug_len; i++)
{
- int h = ((uint8_t *)unwind)[i];
+ int h = ((uint8_t *)debug_frame)[i];
c->output << "0x" << hex << h << dec << ",";
if ((i + 1) % 16 == 0)
c->output << "\n" << " ";
@@ -4698,7 +4717,25 @@ dump_unwindsyms (Dwfl_Module *m,
c->output << "};\n";
c->output << "#endif /* STP_USE_DWARF_UNWINDER && STP_NEED_UNWIND_DATA */\n";
}
- else
+
+ if (eh_frame != NULL && eh_len > 0)
+ {
+ c->output << "#if defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)\n";
+ c->output << "static uint8_t _stp_module_" << stpmod_idx
+ << "_eh_frame[] = \n";
+ c->output << " {";
+ for (size_t i = 0; i < debug_len; i++)
+ {
+ int h = ((uint8_t *)debug_frame)[i];
+ c->output << "0x" << hex << h << dec << ",";
+ if ((i + 1) % 16 == 0)
+ c->output << "\n" << " ";
+ }
+ c->output << "};\n";
+ c->output << "#endif /* STP_USE_DWARF_UNWINDER && STP_NEED_UNWIND_DATA */\n";
+ }
+
+ if (debug_frame == NULL && eh_frame == NULL)
{
// There would be only a small benefit to warning. A user
// likely can't do anything about this; backtraces for the
@@ -4755,25 +4792,40 @@ dump_unwindsyms (Dwfl_Module *m,
c->output << ".path = " << lex_cast_qstring (mainfile) << ",\n";
c->output << ".dwarf_module_base = 0x" << hex << base << dec << ", \n";
+ c->output << ".eh_frame_addr = 0x" << hex << eh_addr << dec << ", \n";
+
+ if (debug_frame != NULL)
+ {
+ c->output << "#if defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)\n";
+ c->output << ".debug_frame = "
+ << "_stp_module_" << stpmod_idx << "_debug_frame, \n";
+ c->output << ".debug_frame_len = " << debug_len << ", \n";
+ c->output << "#else\n";
+ }
+
+ c->output << ".debug_frame = NULL,\n";
+ c->output << ".debug_frame_len = 0,\n";
+
+ if (debug_frame != NULL)
+ c->output << "#endif /* STP_USE_DWARF_UNWINDER && STP_NEED_UNWIND_DATA*/\n";
- if (unwind != NULL)
+ if (eh_frame != NULL)
{
c->output << "#if defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)\n";
- c->output << ".unwind_data = "
- << "_stp_module_" << stpmod_idx << "_unwind_data, \n";
- c->output << ".unwind_data_len = " << len << ", \n";
+ c->output << ".eh_frame = "
+ << "_stp_module_" << stpmod_idx << "_eh_frame, \n";
+ c->output << ".eh_frame_len = " << eh_len << ", \n";
c->output << "#else\n";
}
- c->output << ".unwind_data = NULL,\n";
- c->output << ".unwind_data_len = 0,\n";
+ c->output << ".eh_frame = NULL,\n";
+ c->output << ".eh_frame_len = 0,\n";
- if (unwind != NULL)
+ if (eh_frame != NULL)
c->output << "#endif /* STP_USE_DWARF_UNWINDER && STP_NEED_UNWIND_DATA*/\n";
c->output << ".unwind_hdr = NULL,\n";
c->output << ".unwind_hdr_len = 0,\n";
- c->output << ".unwind_is_ehframe = 0,\n";
c->output << ".sections = _stp_module_" << stpmod_idx << "_sections" << ",\n";
c->output << ".num_sections = sizeof(_stp_module_" << stpmod_idx << "_sections)/"