XS-libdwarf
view release on metacpan or search on metacpan
libdwarf-code-0.11.1/src/lib/libdwarf/dwarf_form.c view on Meta::CPAN
}
errcode = DW_DLE_STRING_OFFSET_BAD;
errname = "DW_DLE_STRING_OFFSET_BAD";
secsize = dbg->de_debug_str.dss_size;
secbegin = dbg->de_debug_str.dss_data;
strbegin= dbg->de_debug_str.dss_data + offset;
secend = dbg->de_debug_str.dss_data + secsize;
}
if (offset >= secsize) {
dwarfstring m;
const char *name = "<unknownform>";
dwarf_get_FORM_name(attrform,&name);
dwarfstring_constructor(&m);
dwarfstring_append(&m,(char *)errname);
dwarfstring_append_printf_s(&m,
" Form %s ",(char *)name);
dwarfstring_append_printf_u(&m,
"string offset of 0x%" DW_PR_DUx " ",
offset);
dwarfstring_append_printf_u(&m,
"is larger than the string section "
"size of 0x%" DW_PR_DUx,
secsize);
_dwarf_error_string(dbg, error, errcode,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
/* Badly damaged DWARF here. */
return DW_DLV_ERROR;
}
res= _dwarf_check_string_valid(dbg,secbegin,strbegin, secend,
errcode,error);
if (res != DW_DLV_OK) {
return res;
}
*return_str = (char *)strbegin;
return DW_DLV_OK;
}
generate_form_error(dbg,error,attrform,
DW_DLE_ATTR_FORM_BAD,
"DW_DLE_ATTR_FORM_BAD",
"extract debug_str string");
return DW_DLV_ERROR;
}
/* Contrary to pre-2005 documentation,
The string pointer returned thru return_str must
never have dwarf_dealloc() applied to it.
Documentation fixed July 2005.
*/
int
dwarf_formstring(Dwarf_Attribute attr,
char **return_str, Dwarf_Error * error)
{
Dwarf_CU_Context cu_context = 0;
Dwarf_Debug dbg = 0;
Dwarf_Unsigned offset = 0;
int res = DW_DLV_ERROR;
Dwarf_Small *secdataptr = 0;
Dwarf_Small *secend = 0;
Dwarf_Unsigned secdatalen = 0;
Dwarf_Small *infoptr = attr->ar_debug_ptr;
Dwarf_Small *contextend = 0;
res = get_attr_dbg(&dbg,&cu_context,attr,error);
if (res != DW_DLV_OK) {
return res;
}
if (cu_context->cc_is_info) {
secdataptr = (Dwarf_Small *)dbg->de_debug_info.dss_data;
secdatalen = dbg->de_debug_info.dss_size;
} else {
secdataptr = (Dwarf_Small *)dbg->de_debug_types.dss_data;
secdatalen = dbg->de_debug_types.dss_size;
}
contextend = secdataptr +
cu_context->cc_debug_offset +
cu_context->cc_length +
cu_context->cc_length_size +
cu_context->cc_extension_size;
secend = secdataptr + secdatalen;
if (contextend < secend) {
secend = contextend;
}
switch(attr->ar_attribute_form) {
case DW_FORM_string: {
Dwarf_Small *begin = attr->ar_debug_ptr;
res= _dwarf_check_string_valid(dbg,secdataptr,begin, secend,
DW_DLE_FORM_STRING_BAD_STRING,error);
if (res != DW_DLV_OK) {
return res;
}
*return_str = (char *) (begin);
return DW_DLV_OK;
}
case DW_FORM_GNU_strp_alt:
case DW_FORM_strp_sup: {
Dwarf_Error alterr = 0;
Dwarf_Bool is_info = TRUE;
/* See dwarfstd.org issue 120604.1
This is the offset in the .debug_str section
of another object file.
The 'tied' file notion should apply.
It is not clear whether both a supplementary
and a split object might be needed at the same time
(hence two 'tied' files simultaneously). */
Dwarf_Off soffset = 0;
res = dwarf_global_formref_b(attr, &soffset,
&is_info,error);
if (res != DW_DLV_OK) {
return res;
}
res = _dwarf_get_string_from_tied(dbg, soffset,
return_str, &alterr);
if (res == DW_DLV_ERROR) {
if (dwarf_errno(alterr) ==
DW_DLE_NO_TIED_FILE_AVAILABLE) {
dwarf_dealloc_error(dbg,alterr);
if ( attr->ar_attribute_form ==
DW_FORM_GNU_strp_alt) {
*return_str =
(char *)"<DW_FORM_GNU_strp_alt-no-tied-file>";
} else {
*return_str =
(char *)"<DW_FORM_strp_sup-no-tied-file>";
}
return DW_DLV_OK;
}
if (error) {
*error = alterr;
} else {
dwarf_dealloc_error(dbg,alterr);
alterr = 0;
}
return res;
}
if (res == DW_DLV_NO_ENTRY) {
if ( attr->ar_attribute_form == DW_FORM_GNU_strp_alt) {
*return_str =
(char *)"<DW_FORM_GNU_strp_alt-no-tied-file>";
}else {
*return_str =
(char *)"<DW_FORM_strp_sup-no-tied-file>";
}
}
return res;
( run in 0.801 second using v1.01-cache-2.11-cpan-39bf76dae61 )