How to read DWARF2 and later from memory.
*/
#include <config.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libdwarf_private.h"
0x01, 0x11, 0x01, 0x25, 0x0e, 0x13, 0x0b, 0x03, 0x08, 0x1b,
0x0e, 0x11, 0x01, 0x12, 0x01, 0x10, 0x06, 0x00, 0x00, 0x02,
0x2e, 0x01, 0x3f, 0x0c, 0x03, 0x08, 0x3a, 0x0b, 0x3b, 0x0b,
0x39, 0x0b, 0x27, 0x0c, 0x11, 0x01, 0x12, 0x01, 0x40, 0x06,
0x97, 0x42, 0x0c, 0x01, 0x13, 0x00, 0x00, 0x03, 0x34, 0x00,
0x03, 0x08, 0x3a, 0x0b, 0x3b, 0x0b, 0x39, 0x0b, 0x49, 0x13,
0x02, 0x0a, 0x00, 0x00, 0x04, 0x24, 0x00, 0x0b, 0x0b, 0x3e,
0x0b, 0x03, 0x08, 0x00, 0x00, 0x00, };
0x60, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x74, 0x2e, 0x63,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x66, 0x00, 0x01,
0x02, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x5c, 0x00, 0x00, 0x00, 0x03, 0x69,
0x00, 0x01, 0x03, 0x08, 0x5c, 0x00, 0x00, 0x00, 0x02, 0x91,
0x6c, 0x00, 0x04, 0x04, 0x05, 0x69, 0x6e, 0x74, 0x00, 0x00, };
0x47, 0x4e, 0x55, 0x20, 0x43, 0x31, 0x37, 0x20, 0x39, 0x2e,
0x33, 0x2e, 0x30, 0x20, 0x2d, 0x6d, 0x74, 0x75, 0x6e, 0x65,
0x3d, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x20, 0x2d,
0x6d, 0x61, 0x72, 0x63, 0x68, 0x3d, 0x78, 0x38, 0x36, 0x2d,
0x36, 0x34, 0x20, 0x2d, 0x67, 0x64, 0x77, 0x61, 0x72, 0x66,
0x2d, 0x32, 0x20, 0x2d, 0x4f, 0x30, 0x20, 0x2d, 0x66, 0x61,
0x73, 0x79, 0x6e, 0x63, 0x68, 0x72, 0x6f, 0x6e, 0x6f, 0x75,
0x73, 0x2d, 0x75, 0x6e, 0x77, 0x69, 0x6e, 0x64, 0x2d, 0x74,
0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x2d, 0x66, 0x73, 0x74,
0x61, 0x63, 0x6b, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63,
0x74, 0x6f, 0x72, 0x2d, 0x73, 0x74, 0x72, 0x6f, 0x6e, 0x67,
0x20, 0x2d, 0x66, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, 0x63,
0x6c, 0x61, 0x73, 0x68, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x65,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x2d, 0x66, 0x63, 0x66,
0x2d, 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6f,
0x6e, 0x00, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x74, 0x6d, 0x70,
0x2f, 0x74, 0x69, 0x6e, 0x79, 0x64, 0x77, 0x61, 0x72, 0x66,
0x00, };
#define SECCOUNT 4
struct sectiondata_s {
unsigned int sd_addr;
unsigned int sd_objoffsetlen;
unsigned int sd_objpointersize;
const char * sd_secname;
};
static struct sectiondata_s sectiondata[SECCOUNT] = {
{0,0,0,0,"",0},
{0,32,32,sizeof(abbrevbytes),".debug_abbrev",abbrevbytes},
{0,32,32,sizeof(infobytes),".debug_info",infobytes},
{0,32,32,sizeof(strbytes),".debug_str",strbytes}
};
typedef struct special_filedata_s {
int f_is_64bit;
unsigned f_pointersize;
unsigned f_offsetsize;
struct sectiondata_s * f_sectarray;
} special_filedata_internals_t;
static special_filedata_internals_t base_internals =
{ FALSE,DW_END_little,32,32,200,SECCOUNT, sectiondata };
static
int gsinfo(void* obj,
int* error )
{
special_filedata_internals_t *internals =
(special_filedata_internals_t *)(obj);
struct sectiondata_s *finfo = 0;
*error = 0;
if (section_index >= SECCOUNT) {
return DW_DLV_NO_ENTRY;
}
finfo = internals->f_sectarray + section_index;
return_section->as_name = finfo->sd_secname;
return_section->as_type = 0;
return_section->as_flags = 0;
return_section->as_addr = finfo->sd_addr;
return_section->as_offset = 0;
return_section->as_size = finfo->sd_sectionsize;
return_section->as_link = 0;
return_section->as_info = 0;
return_section->as_addralign = 0;
return_section->as_entrysize = 1;
return DW_DLV_OK;
}
gborder(void * obj)
{
special_filedata_internals_t *internals =
(special_filedata_internals_t *)(obj);
return internals->f_object_endian;
}
static
{
special_filedata_internals_t *internals =
(special_filedata_internals_t *)(obj);
return internals->f_offsetsize/8;
}
static
{
special_filedata_internals_t *internals =
(special_filedata_internals_t *)(obj);
return internals->f_pointersize/8;
}
static
{
special_filedata_internals_t *internals =
(special_filedata_internals_t *)(obj);
return internals->f_filesize;
}
static
{
special_filedata_internals_t *internals =
(special_filedata_internals_t *)(obj);
return internals->f_sectioncount;
}
static
int gloadsec(void * obj,
int *error)
{
special_filedata_internals_t *internals =
(special_filedata_internals_t *)(obj);
struct sectiondata_s *secp = 0;
*error = 0;
if (secindex >= internals->f_sectioncount) {
return DW_DLV_NO_ENTRY;
}
secp = secindex +internals->f_sectarray;
*rdata = secp->sd_content;
return DW_DLV_OK;
}
gsinfo,
gborder,
glensize,
gptrsize,
gfilesize,
gseccount,
gloadsec,
0
};
{ &base_internals,&methods };
static int
{
switch(form) {
case DW_FORM_string: return TRUE;
case DW_FORM_GNU_strp_alt: return TRUE;
case DW_FORM_GNU_str_index: return TRUE;
case DW_FORM_strx: return TRUE;
case DW_FORM_strx1: return TRUE;
case DW_FORM_strx2: return TRUE;
case DW_FORM_strx3: return TRUE;
case DW_FORM_strx4: return TRUE;
case DW_FORM_strp: return TRUE;
default: break;
};
return FALSE;
}
static int
{
int res = 0;
char *str = 0;
const char *attrname = 0;
const char *formname = 0;
if (res != DW_DLV_OK) {
printf("dwarf_whatform failed! res %d\n",res);
return res;
}
if (res != DW_DLV_OK) {
printf("dwarf_whatattr failed! res %d\n",res);
return res;
}
if (res == DW_DLV_NO_ENTRY) {
printf("Bogus attrnum 0x%x\n",attrnum);
attrname = "<internal error ?>";
}
if (res == DW_DLV_NO_ENTRY) {
printf("Bogus form 0x%x\n",attrnum);
attrname = "<internal error ?>";
}
if (!isformstring(form)) {
printf(" [%2d] Attr: %-15s Form: %-15s\n",
(int)anumber,attrname,formname);
return DW_DLV_OK;
}
if (res != DW_DLV_OK) {
printf("dwarf_formstring failed! res %d\n",res);
return res;
}
printf(" [%2d] Attr: %-15s Form: %-15s %s\n",
(int)anumber,attrname,formname,str);
return DW_DLV_OK;
}
static void
{
for ( ; i < attrcount; ++i) {
}
}
static int
{
const char * tagname = 0;
int res = 0;
if (res != DW_DLV_OK) {
printf("dwarf_tag failed! res %d\n",res);
return res;
}
if (res != DW_DLV_OK) {
tagname = "<bogus tag>";
}
printf("%3d: Die: %s\n",level,tagname);
if (res != DW_DLV_OK) {
printf("dwarf_attrlist failed! res %d\n",res);
return res;
}
for (i = 0; i <attrcount;++i) {
res =print_attr(attrbuf[i],i,error);
if (res != DW_DLV_OK) {
dealloc_list(dbg,attrbuf,attrcount,0);
printf("dwarf_attr print failed! res %d\n",res);
return res;
}
}
dealloc_list(dbg,attrbuf,attrcount,0);
return DW_DLV_OK;
}
static int
{
int res = 0;
int level = 0;
type_signature = zerosignature;
is_info,
&cu_header_length,
&version_stamp,
&abbrev_offset,
&address_size,
&length_size,
&extension_size,
&type_signature,
&typeoffset,
&next_cu_header_offset,
&header_cu_type,
error);
if (res != DW_DLV_OK) {
printf("Next cu header result %d. "
"Something is wrong FAIL, line %d\n",res,__LINE__);
if (res == DW_DLV_ERROR) {
}
exit(EXIT_FAILURE);
}
printf("CU header length..........0x%lx\n",
(unsigned long)cu_header_length);
printf("Version stamp.............%d\n",version_stamp);
printf("Address size .............%d\n",address_size);
printf("Offset size...............%d\n",length_size);
printf("Next cu header offset.....0x%lx\n",
(unsigned long)next_cu_header_offset);
if (res != DW_DLV_OK) {
if (res == DW_DLV_ERROR) {
printf("ERROR: dwarf_siblingof_b failed, no CU die\n");
return res;
} else {
printf("ERROR: dwarf_siblingof_b got NO_ENTRY, "
"no CU die\n");
return res;
}
}
res = print_one_die(dbg,cu_die,level,error);
if (res != DW_DLV_OK) {
printf("print_one_die failed! %d\n",res);
return res;
}
return DW_DLV_OK;
}
int main(int argc, char **argv)
{
int res = 0;
int fail = FALSE;
int i = 1;
if (i >= argc) {
} else {
if (!strcmp(argv[i],"--suppress-de-alloc-tree")) {
++i;
}
}
0,0,DW_GROUPNUMBER_ANY,&dbg,
&error);
if (res == DW_DLV_NO_ENTRY) {
printf("FAIL Cannot dwarf_object_init_b() NO ENTRY. \n");
exit(EXIT_FAILURE);
} else if (res == DW_DLV_ERROR){
printf("FAIL Cannot dwarf_object_init_b(). \n");
exit(EXIT_FAILURE);
}
res = print_object_info(dbg,&error);
if (res != DW_DLV_OK) {
if (res == DW_DLV_ERROR) {
}
printf("FAIL printing, res %d line %d\n",res,__LINE__);
exit(EXIT_FAILURE);
}
if (fail) {
printf("FAIL objectaccess.c\n");
exit(EXIT_FAILURE);
}
return 0;
}
int dwarf_get_FORM_name(unsigned int dw_val_in, const char **dw_s_out)
dwarf_get_FORM_name
int dwarf_get_TAG_name(unsigned int dw_val_in, const char **dw_s_out)
dwarf_get_TAG_name
int dwarf_get_AT_name(unsigned int dw_val_in, const char **dw_s_out)
dwarf_get_AT_name
struct Dwarf_Debug_s * Dwarf_Debug
Definition: libdwarf.h:603
struct Dwarf_Die_s * Dwarf_Die
Definition: libdwarf.h:608
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:597
struct Dwarf_Attribute_s * Dwarf_Attribute
Definition: libdwarf.h:658
unsigned char Dwarf_Small
Definition: libdwarf.h:204
signed long long Dwarf_Signed
Definition: libdwarf.h:197
unsigned short Dwarf_Half
Definition: libdwarf.h:203
unsigned long long Dwarf_Unsigned
Definition: libdwarf.h:196
int Dwarf_Bool
Definition: libdwarf.h:202
unsigned long long Dwarf_Off
Definition: libdwarf.h:198
int dwarf_next_cu_header_d(Dwarf_Debug dw_dbg, Dwarf_Bool dw_is_info, Dwarf_Unsigned *dw_cu_header_length, Dwarf_Half *dw_version_stamp, Dwarf_Off *dw_abbrev_offset, Dwarf_Half *dw_address_size, Dwarf_Half *dw_length_size, Dwarf_Half *dw_extension_size, Dwarf_Sig8 *dw_type_signature, Dwarf_Unsigned *dw_typeoffset, Dwarf_Unsigned *dw_next_cu_header_offset, Dwarf_Half *dw_header_cu_type, Dwarf_Error *dw_error)
Return information on the next CU header(d)
void dwarf_dealloc_die(Dwarf_Die dw_die)
Deallocate (free) a DIE.
int dwarf_siblingof_b(Dwarf_Debug dw_dbg, Dwarf_Die dw_die, Dwarf_Bool dw_is_info, Dwarf_Die *dw_return_siblingdie, Dwarf_Error *dw_error)
Return the first DIE or the next sibling DIE.
int dwarf_tag(Dwarf_Die dw_die, Dwarf_Half *dw_return_tag, Dwarf_Error *dw_error)
Get TAG value of DIE.
void dwarf_dealloc(Dwarf_Debug dw_dbg, void *dw_space, Dwarf_Unsigned dw_type)
The generic dealloc (free) function. It requires you know the correct DW_DLA value to pass in,...
void dwarf_dealloc_error(Dwarf_Debug dw_dbg, Dwarf_Error dw_error)
Free (dealloc) an Dwarf_Error something created.
char * dwarf_errmsg(Dwarf_Error dw_error)
What message string is in the error?
int dwarf_object_init_b(Dwarf_Obj_Access_Interface_a *dw_obj, Dwarf_Handler dw_errhand, Dwarf_Ptr dw_errarg, unsigned int dw_groupnumber, Dwarf_Debug *dw_dbg, Dwarf_Error *dw_error)
Used to access DWARF information in memory or in an object format unknown to libdwarf.
int dwarf_object_finish(Dwarf_Debug dw_dbg)
Used to close the object_init dw_dbg.
Definition: libdwarf.h:815
Definition: libdwarf.h:796
Definition: libdwarf.h:778
Definition: libdwarf.h:313