Elf_Data *debug_frame,
void **debug_frame_hdr,
size_t *debug_frame_hdr_len,
+ Dwarf_Addr *debug_frame_off,
systemtap_session& session,
- const string& modname)
+ Dwfl_Module *mod)
{
*debug_frame_hdr = NULL;
*debug_frame_hdr_len = 0;
{
// Warn, but continue, backtracing will be slow...
if (session.verbose > 2 && ! session.suppress_warnings)
- session.print_warning ("Problem creating debug frame hdr for "
- + modname + ", " + dwarf_errmsg (-1));
+ {
+ const char *modname = dwfl_module_info (mod, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ session.print_warning("Problem creating debug frame hdr for "
+ + lex_cast_qstring(modname)
+ + ", " + dwarf_errmsg (-1));
+ }
return;
}
off = next_off;
}
+ if (fdes.size() > 0)
+ {
+ it = fdes.begin();
+ Dwarf_Addr first_addr = (*it).first;
+ int res = dwfl_module_relocate_address (mod, &first_addr);
+ dwfl_assert ("create_debug_frame_hdr, dwfl_module_relocate_address",
+ res >= 0);
+ *debug_frame_off = (*it).first - first_addr;
+ }
+
size_t total_size = 4 + (2 * size) + (2 * size * fdes.size());
uint8_t *hdr = (uint8_t *) malloc(total_size);
*debug_frame_hdr = hdr;
void **eh_frame_hdr, size_t *eh_frame_hdr_len,
void **debug_frame_hdr,
size_t *debug_frame_hdr_len,
+ Dwarf_Addr *debug_frame_off,
Dwarf_Addr *eh_frame_hdr_addr,
systemtap_session& session,
- const string& modname)
+ Dwfl_Module *mod)
{
Dwarf_Addr start, bias = 0;
GElf_Ehdr *ehdr, ehdr_mem;
if (*debug_frame != NULL && *debug_len > 0)
create_debug_frame_hdr (ehdr->e_ident, data,
debug_frame_hdr, debug_frame_hdr_len,
- session, modname);
+ debug_frame_off, session, mod);
}
static int
size_t debug_len = 0;
void *debug_frame_hdr = NULL;
size_t debug_frame_hdr_len = 0;
+ Dwarf_Addr debug_frame_off = 0;
void *eh_frame = NULL;
void *eh_frame_hdr = NULL;
size_t eh_len = 0;
Dwarf_Addr eh_frame_hdr_addr = 0;
get_unwind_data (m, &debug_frame, &eh_frame, &debug_len, &eh_len, &eh_addr,
&eh_frame_hdr, &eh_frame_hdr_len, &debug_frame_hdr,
- &debug_frame_hdr_len, &eh_frame_hdr_addr,
- c->session, modname);
+ &debug_frame_hdr_len, &debug_frame_off, &eh_frame_hdr_addr,
+ c->session, m);
if (debug_frame != NULL && debug_len > 0)
{
c->output << "#if defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)\n";
c->output << "#endif /* STP_USE_DWARF_UNWINDER && STP_NEED_UNWIND_DATA */\n";
}
- if (debug_frame_hdr != NULL && debug_frame_hdr_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
- << "_debug_frame_hdr[] = \n";
- c->output << " {";
- if (debug_frame_hdr_len > MAX_UNWIND_TABLE_SIZE)
- {
- if (! c->session.suppress_warnings)
- c->session.print_warning ("skipping module " + modname + " debug_frame_hdr table (too big: " +
- lex_cast(debug_frame_hdr_len) + " > " + lex_cast(MAX_UNWIND_TABLE_SIZE) + ")");
- }
- else
- for (size_t i = 0; i < debug_frame_hdr_len; i++)
- {
- int h = ((uint8_t *)debug_frame_hdr)[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 (eh_frame != NULL && eh_len > 0)
{
c->output << "#if defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)\n";
c->output << "#endif /* STP_NEED_SYMBOL_DATA */\n";
c->output << "};\n";
+
+ /* For now output debug_frame index only in "magic" sections. */
+ string secname = seclist[secidx].first;
+ if (secname == ".dynamic" || secname == ".absolute"
+ || secname == ".text" || secname == "_stext")
+ {
+ if (debug_frame_hdr != NULL && debug_frame_hdr_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
+ << "_debug_frame_hdr_" << secidx << "[] = \n";
+ c->output << " {";
+ if (debug_frame_hdr_len > MAX_UNWIND_TABLE_SIZE)
+ {
+ if (! c->session.suppress_warnings)
+ c->session.print_warning ("skipping module "
+ + modname
+ + ", section" + secname
+ + " debug_frame_hdr table"
+ + " (too big: "
+ + lex_cast(debug_frame_hdr_len)
+ + " > "
+ + lex_cast(MAX_UNWIND_TABLE_SIZE)
+ + ")");
+ }
+ else
+ for (size_t i = 0; i < debug_frame_hdr_len; i++)
+ {
+ int h = ((uint8_t *)debug_frame_hdr)[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";
+ }
+ }
}
c->output << "static struct _stp_section _stp_module_" << stpmod_idx<< "_sections[] = {\n";
<< ".name = " << lex_cast_qstring(seclist[secidx].first) << ",\n"
<< ".size = 0x" << hex << seclist[secidx].second << dec << ",\n"
<< ".symbols = _stp_module_" << stpmod_idx << "_symbols_" << secidx << ",\n"
- << ".num_symbols = " << addrmap[secidx].size() << "\n"
- << "},\n";
+ << ".num_symbols = " << addrmap[secidx].size() << ",\n";
+
+ /* For now output debug_frame index only in "magic" sections. */
+ string secname = seclist[secidx].first;
+ if (debug_frame_hdr && (secname == ".dynamic" || secname == ".absolute"
+ || secname == ".text" || secname == "_stext"))
+ {
+ c->output << "#if defined(STP_USE_DWARF_UNWINDER)"
+ << " && defined(STP_NEED_UNWIND_DATA)\n";
+
+ c->output << ".debug_hdr = "
+ << "_stp_module_" << stpmod_idx
+ << "_debug_frame_hdr_" << secidx << ",\n";
+ c->output << ".debug_hdr_len = " << debug_frame_hdr_len << ", \n";
+
+ Dwarf_Addr dwbias = 0;
+ dwfl_module_getdwarf (m, &dwbias);
+ c->output << ".sec_load_offset = 0x"
+ << hex << debug_frame_off - dwbias << dec << "\n";
+
+ c->output << "#else\n";
+ c->output << ".debug_hdr = NULL,\n";
+ c->output << ".debug_hdr_len = 0,\n";
+ c->output << ".sec_load_offset = 0\n";
+ c->output << "#endif /* STP_USE_DWARF_UNWINDER"
+ << " && STP_NEED_UNWIND_DATA */\n";
+
+ }
+ else
+ {
+ c->output << ".debug_hdr = NULL,\n";
+ c->output << ".debug_hdr_len = 0,\n";
+ c->output << ".sec_load_offset = 0\n";
+ }
+
+ c->output << "},\n";
}
c->output << "};\n";
c->output << "static struct _stp_module _stp_module_" << stpmod_idx << " = {\n";
c->output << ".name = " << lex_cast_qstring (mainname) << ", \n";
c->output << ".path = " << lex_cast_qstring (mainpath) << ",\n";
- Dwarf_Addr dwbias = 0;
- dwfl_module_getdwarf (m, &dwbias);
- c->output << ".dwarf_module_base = 0x" << hex << (base - dwbias) << ", \n";
- c->output << ".eh_frame_addr = 0x" << eh_addr << ", \n";
- c->output << ".unwind_hdr_addr = 0x" << eh_frame_hdr_addr << dec << ", \n";
+ c->output << ".eh_frame_addr = 0x" << hex << eh_addr << dec << ", \n";
+ c->output << ".unwind_hdr_addr = 0x" << hex << eh_frame_hdr_addr
+ << dec << ", \n";
if (debug_frame != NULL)
{
c->output << ".debug_frame = "
<< "_stp_module_" << stpmod_idx << "_debug_frame, \n";
c->output << ".debug_frame_len = " << debug_len << ", \n";
- if (debug_frame_hdr)
- {
- c->output << ".debug_hdr = "
- << "_stp_module_" << stpmod_idx << "_debug_frame_hdr, \n";
- c->output << ".debug_hdr_len = " << debug_frame_hdr_len << ", \n";
- }
- else
- {
- c->output << ".debug_hdr = NULL,\n";
- c->output << ".debug_hdr_len = 0,\n";
- }
c->output << "#else\n";
}