コード例 #1
0
static void
_dwarf_die_offset(Dwarf_Die die)
{
	Dwarf_Off rel_off, die_off, cu_off, cu_len;
	Dwarf_Error de;

	if (dwarf_die_CU_offset(die, &rel_off, &de) != DW_DLV_OK) {
		tet_printf("dwarf_die_CU_offset failed: %s\n",
		    dwarf_errmsg(de));
		result = TET_FAIL;
	}
	TS_CHECK_INT(rel_off);

	if (dwarf_die_CU_offset_range(die, &cu_off, &cu_len, &de) !=
	    DW_DLV_OK) {
		tet_printf("dwarf_die_CU_offset_range failed: %s\n",
		    dwarf_errmsg(de));
		result = TET_FAIL;
	}
	TS_CHECK_INT(cu_off);
	TS_CHECK_INT(cu_len);

	if (dwarf_dieoffset(die, &die_off, &de) != DW_DLV_OK) {
		tet_printf("dwarf_dieoffset failed: %s\n", dwarf_errmsg(de));
		result = TET_FAIL;
	}
	TS_CHECK_INT(die_off);
}
コード例 #2
0
ファイル: rdwarf.c プロジェクト: kubo/rdwarf
static VALUE rd_die_die_cu_offset(VALUE self)
{
    rd_die_t *die = GetDie(self);
    Dwarf_Off off;
    Dwarf_Error err;

    chkerr1(dwarf_die_CU_offset(die->die, &off, &err), &err, self);
    return LL2NUM(off);
}
コード例 #3
0
ファイル: dwarfclient.c プロジェクト: blucia0a/Legerdemain
static Dwarf_Off DC_get_CU_start_offset(Dwarf_Die v){
  Dwarf_Error error;
 
  Dwarf_Off dieOffset;
  dwarf_dieoffset(v,&dieOffset,&error);
  
  Dwarf_Off dieCUOffset;
  dwarf_die_CU_offset(v,&dieCUOffset,&error);

  Dwarf_Off CUStart = dieOffset - dieCUOffset;
  return CUStart;
}
コード例 #4
0
static void
tp_dwarf_die_offset_sanity(void)
{
	Dwarf_Debug dbg;
	Dwarf_Die die;
	Dwarf_Error de;
	Dwarf_Off rel_off, die_off, cu_off, cu_len;
	Dwarf_Unsigned cu_next_offset;
	int fd;

	result = TET_UNRESOLVED;

	TS_DWARF_INIT(dbg, fd, de);

	TS_DWARF_CU_FOREACH(dbg, cu_next_offset, de) {
		if (dwarf_siblingof(dbg, NULL, &die, &de) == DW_DLV_ERROR) {
			tet_printf("dwarf_siblingof failed: %s\n",
			    dwarf_errmsg(de));
			result = TET_FAIL;
			goto done;
		}
		if (dwarf_die_CU_offset(NULL, &rel_off, &de) != DW_DLV_ERROR) {
			tet_infoline("dwarf_die_CU_offset didn't return"
			    " DW_DLV_ERROR when called with NULL arguments");
			result = TET_FAIL;
			goto done;
		}
		if (dwarf_die_CU_offset_range(NULL, &cu_off, &cu_len, &de) !=
		    DW_DLV_ERROR) {
			tet_infoline("dwarf_die_CU_offset_range didn't return"
			    " DW_DLV_ERROR when called with NULL arguments");
			result = TET_FAIL;
			goto done;
		}
		if (dwarf_dieoffset(NULL, &die_off, &de) != DW_DLV_ERROR) {
			tet_infoline("dwarf_dieoffset didn't return DW_DLV_ERROR"
			    " when called with NULL arguments");
			result = TET_FAIL;
			goto done;
		}
	}

	if (result == TET_UNRESOLVED)
		result = TET_PASS;

done:
	TS_DWARF_FINISH(dbg, de);
	TS_RESULT(result);
}
コード例 #5
0
ファイル: types.c プロジェクト: adk9/ohm
int
add_basetype_from_die(Dwarf_Debug dbg, Dwarf_Die parent_die, Dwarf_Die die)
{
    int ret = DW_DLV_ERROR;
    Dwarf_Error err = 0;
    Dwarf_Off offset = 0;
    Dwarf_Unsigned bsz = 0;
    basetype_t *t;

    if (is_base_type(die) != 1)
        return -1;

    ret = dwarf_die_CU_offset(die, &offset, &err);
    if (ret != DW_DLV_OK) {
        derror("error in dwarf_die_CU_offset()");
        goto error;
    }

    ret = dwarf_bytesize(die, &bsz, &err);
    if (ret != DW_DLV_OK) {
        derror("error in dwarf_bytesize()");
        goto error;
    }

    /* We construct a table of base types here so that we can iœndex it
     * later to find the types of some of the probes on the stack. */

    t = get_or_add_type(offset);
    get_child_name(dbg, die, t->name, 128);
    t->ohm_type = get_type_ohmtype(t);
    t->size = bsz;
    t->nelem = 1;
    t->elems = NULL;
    return 1;

error:
    derror("error in add_basetype_from_die()");
    return -1;
}
コード例 #6
0
/* Unified pubnames style output.
   The error checking here against maxoff may be useless
   (in that libdwarf may return an error if the offset is bad
   and we will not get called here).
   But we leave it in nonetheless as it looks sensible.
   In at least one gigantic executable such offsets turned out wrong.
*/
void
print_pubname_style_entry(Dwarf_Debug dbg,
   char *line_title,
   char *name,
   Dwarf_Unsigned die_off,
   Dwarf_Unsigned cu_off,
   Dwarf_Unsigned global_cu_offset,
   Dwarf_Unsigned maxoff)
{
    Dwarf_Die die = NULL;
    Dwarf_Off die_CU_off = 0;
    int dres = 0;
    int ddres = 0;
    int cudres = 0;
    char tmp_buf[100];

    /* get die at die_off */
    dres = dwarf_offdie(dbg, die_off, &die, &err);
    if (dres != DW_DLV_OK) {
        struct esb_s details;
        esb_constructor(&details);
        esb_append(&details,line_title);
        esb_append(&details," dwarf_offdie : "
            "die offset does not reference valid DIE.  ");
        snprintf(tmp_buf,sizeof(tmp_buf),"0x%"  DW_PR_DUx, die_off);
        esb_append(&details,tmp_buf);
        esb_append(&details,".");
        print_error(dbg, esb_get_string(&details), dres, err);
        esb_destructor(&details);
    }

    /* get offset of die from its cu-header */
    ddres = dwarf_die_CU_offset(die, &die_CU_off, &err);
    if (ddres != DW_DLV_OK) {
        struct esb_s details;
        esb_constructor(&details);
        esb_append(&details,line_title);
        esb_append(&details," cannot get CU die offset");
        print_error(dbg, esb_get_string(&details), dres, err);
        esb_destructor(&details);
        die_CU_off = 0;
    }

    /* Get die at offset cu_off to check its existence. */
    {
        Dwarf_Die cu_die = NULL;
        cudres = dwarf_offdie(dbg, cu_off, &cu_die, &err);
        if (cudres != DW_DLV_OK) {
            struct esb_s details;
            esb_constructor(&details);
            esb_append(&details,line_title);
            esb_append(&details," dwarf_offdie: "
                "cu die offset  does not reference valid CU DIE.  ");
            snprintf(tmp_buf,sizeof(tmp_buf),"0x%"  DW_PR_DUx, cu_off);
            esb_append(&details,tmp_buf);
            esb_append(&details,".");
            print_error(dbg, esb_get_string(&details), dres, err);
            esb_destructor(&details);
        } else {
            /* It exists, all is well. */
            dwarf_dealloc(dbg, cu_die, DW_DLA_DIE);
        }
    }
    /* Display offsets */
    if (display_offsets) {
        /* Print 'name'at the end for better layout */
        printf("%s die-in-sect 0x%" DW_PR_XZEROS DW_PR_DUx
            ", cu-in-sect 0x%" DW_PR_XZEROS DW_PR_DUx ","
            " die-in-cu 0x%" DW_PR_XZEROS DW_PR_DUx
            ", cu-header-in-sect 0x%" DW_PR_XZEROS DW_PR_DUx ,
            line_title,
            die_off, cu_off,
            (Dwarf_Unsigned) die_CU_off,
            /*  Following is absolute offset of the ** beginning of the
                cu */
            (Dwarf_Signed) (die_off - die_CU_off));
    }

    if ((die_off - die_CU_off) != global_cu_offset) {
        printf(" error: real cuhdr 0x%" DW_PR_XZEROS DW_PR_DUx,
            global_cu_offset);
        exit(1);
    }

    /* Display offsets */
    if (display_offsets && verbose) {
        printf(" cuhdr 0x%" DW_PR_XZEROS DW_PR_DUx , global_cu_offset);
    }

    /* Print 'name'at the end for better layout */
    printf(" '%s'\n",name);

    dwarf_dealloc(dbg, die, DW_DLA_DIE);

    check_info_offset_sanity(line_title,
        "die offset", name, die_off, maxoff);
    check_info_offset_sanity(line_title,
        "die cu offset", name, die_CU_off, maxoff);
    check_info_offset_sanity(line_title,
        "cu offset", name,
        (die_off - die_CU_off), maxoff);

}
コード例 #7
0
ファイル: types.c プロジェクト: adk9/ohm
int
add_complextype_from_die(Dwarf_Debug dbg, Dwarf_Die parent_die, Dwarf_Die die)
{
    int ret = DW_DLV_ERROR, i, nsib;
    Dwarf_Error err = 0;
    Dwarf_Off offset = 0;
    Dwarf_Half tag = 0;
    Dwarf_Attribute attr;
    Dwarf_Unsigned bsz = 0, tid = 0;
    Dwarf_Die grandchild;
    basetype_t *t, *t2;

    ret = dwarf_tag(die, &tag, &err);
    if (ret != DW_DLV_OK) {
        derror("error in dwarf_tag()");
        goto error;
    }

    if ((tag != DW_TAG_array_type) && (tag != DW_TAG_structure_type) &&
        (tag != DW_TAG_typedef) && (tag != DW_TAG_pointer_type))
        return -1;

    switch (tag) {
        case DW_TAG_array_type:
            ret = get_offset_tid(die, &offset, &tid);
            if (ret < 0) {
                derror("error in get_offset_tid()");
                goto error;
            }

            // get the child
            dwarf_child(die, &grandchild, &err);
            ret = dwarf_attr(grandchild, DW_AT_upper_bound, &attr, &err);
            if (ret == DW_DLV_ERROR) {
                derror("error in dwarf_attr(DW_AT_upper_bound)");
                goto error;
            } else if (ret == DW_DLV_OK)
                get_number(attr, &bsz);
            else
                return 0;

            t = get_or_add_type(offset);
            snprintf(t->name, 128, "arr%u[]", (unsigned int)offset);
            t->ohm_type = OHM_TYPE_ARRAY;
            t->nelem = bsz+1;
            t2 = get_or_add_type(tid);
            t->size = t->nelem * get_type_size(t2);
            t->elems = malloc(sizeof(t));
            t->elems[0] = t2;
            break;

        case DW_TAG_structure_type:
            ret = dwarf_die_CU_offset(die, &offset, &err);
            if (ret != DW_DLV_OK) {
                derror("error in dwarf_die_CU_offset()");
                goto error;
            }

            t = get_or_add_type(offset);
            strncpy(t->name, "struct ", 7);
            ret = get_child_name(dbg, die, t->name+7, 128);
            if (ret < 0)
                strncpy(t->name, "<unknown-struct>", 128);
            t->ohm_type = OHM_TYPE_STRUCT;
            ret = dwarf_bytesize(die, &bsz, &err);
            t->size = ((ret == DW_DLV_OK) ? bsz : 0);

            // ensure that struct members get added to the table
            nsib = traverse_die(&add_structmember_from_die, dbg, parent_die, die);
            if (nsib < 0)
                goto error;
            t->nelem = nsib;
            t->elems = malloc((t->nelem)*sizeof(t));
            for (i = 0; i < t->nelem; i++)
                t->elems[i] = &types_table[types_table_size-t->nelem-1+i];
            break;

        case DW_TAG_typedef:
            ret = get_offset_tid(die, &offset, &tid);
            if (ret < 0) {
                derror("error in get_offset_tid()");
                goto error;
            }

            t = get_or_add_type(offset);
            t->ohm_type = OHM_TYPE_ALIAS;
            t->size = 0;
            t->nelem = 1;
            t2 = get_or_add_type(tid);
            t->elems = malloc(sizeof(t));
            t->elems[0] = t2;
            ret = get_child_name(dbg, die, t->name, 128);
            if (ret < 0)
                strncpy(t->name, "<unknown-typedef>", 128);
            break;

        case DW_TAG_pointer_type:
            ret = get_offset_tid(die, &offset, &tid);
            if (ret < 0) {
                derror("error in get_offset_tid()");
                goto error;
            }

            t = get_or_add_type(offset);
            strncpy(t->name, "ptr", 128);
            t->ohm_type = OHM_TYPE_PTR;
            t->nelem = 1;
            t->size = sizeof(void*);
            t2 = get_type(tid);
            t->size = get_type_size(t2);
            t->elems = malloc(sizeof(t));
            t->elems[0] = t2;
            break;
            
        default:
            break;
    }

    return 1;

error:
    derror("error in add_complextype_from_die()");
    return -1;
}
コード例 #8
0
ファイル: dwarfclient.c プロジェクト: blucia0a/Legerdemain
static void show_all_attrs(Dwarf_Die die, unsigned long level, void *ndata){
  Dwarf_Error error;
  Dwarf_Half tag; 
  dwarf_tag(die,&tag,&error);

  const char *stag;
  dwarf_get_TAG_name(tag,&stag); 

  Dwarf_Off off = 0x0;
  dwarf_die_CU_offset(die,&off,&error);
  fprintf(stderr,"[%u]<%x>%s\n",level,off,stag);
  
  char **sourceFiles;
  Dwarf_Signed num;
  int res;
  if( (res = dwarf_srcfiles(die,&sourceFiles,&num,&error)) == DW_DLV_OK){
    fprintf(stderr,"Source Files Referenced:\n");
    int i;
    for(i = 0; i < num; i++){
      fprintf(stderr,"%s\n",sourceFiles[i]);
      dwarf_dealloc(d, sourceFiles[i],DW_DLA_STRING);
    } 
    dwarf_dealloc(d, sourceFiles,DW_DLA_LIST);
  }

  Dwarf_Unsigned atcnt;
  Dwarf_Attribute *atlist;
  int errv;
  if((errv = dwarf_attrlist(die, &atlist, &atcnt, &error)) == DW_DLV_OK){
    int i;
    for(i = 0; i < atcnt; i++){
      Dwarf_Half attr;
      if(dwarf_whatattr(atlist[i],&attr,&error) == DW_DLV_OK){
        const char *sattr;
        dwarf_get_AT_name(attr,&sattr); 
        fprintf(stderr,"\t%s => ",sattr);
      }else{
        fprintf(stderr,"\tCouldn't Get Attr Type!\n"); 
        continue;
      }
      Dwarf_Half form;
      if(dwarf_whatform(atlist[i],&form,&error) == DW_DLV_OK){
        //const char *formname;
        //dwarf_get_FORM_name(form,&formname);
        //fprintf(stderr,"[%s] ",formname);
        switch(form){
          case DW_FORM_ref1:
          case DW_FORM_ref2:
          case DW_FORM_ref4:
          case DW_FORM_ref8:
          case DW_FORM_ref_udata:
            {Dwarf_Off offset;
            dwarf_formref(atlist[i],&offset,&error); 
            fprintf(stderr,"%x\n",offset);}
            break;
          case DW_FORM_ref_addr:
            {Dwarf_Off offset;
            dwarf_global_formref(atlist[i],&offset,&error); 
            fprintf(stderr,"%x\n",offset);}
            break;
          case DW_FORM_addr:
            {Dwarf_Addr addr;
            dwarf_formaddr(atlist[i],&addr,&error); 
            fprintf(stderr,"%x\n",addr);}
            break;
          case DW_FORM_flag:
            {Dwarf_Bool flag;
            dwarf_formflag(atlist[i],&flag,&error); 
            fprintf(stderr,"%s\n",flag ? "True" : "False");}
            break;
          case DW_FORM_udata:
          case DW_FORM_data1:
          case DW_FORM_data2:
          case DW_FORM_data4:
          case DW_FORM_data8:
            {Dwarf_Unsigned val;
            dwarf_formudata(atlist[i],&val,&error); 
            fprintf(stderr,"%u\n",val);}
            break;
          case DW_FORM_sdata:
            {Dwarf_Signed val;
            dwarf_formsdata(atlist[i],&val,&error); 
            fprintf(stderr,"%d\n",val);}
            break;
          case DW_FORM_block:
          case DW_FORM_block1:
            if(attr == DW_AT_location ||
               attr == DW_AT_data_member_location ||
               attr == DW_AT_vtable_elem_location ||
               attr == DW_AT_string_length ||
               attr == DW_AT_use_location ||
               attr == DW_AT_return_addr){
              /* 
              Dwarf_Locdesc *locationList;
              Dwarf_Signed listLength;
              int ret = dwarf_loclist( atlist[i], &locationList, &listLength, &error );
              int frameRel = 0;
              long offset = 0;
              decode_location(locationList,listLength,&offset,NULL,&frameRel);
              int i;
              for( i = 0; i < listLength; ++i){
                dwarf_dealloc(d,locationList[i].ld_s,DW_DLA_LOC_BLOCK);               
              }
              dwarf_dealloc(d,locationList,DW_DLA_LOCDESC);               
              */
              DC_location dcl;
              DC_get_location_attr_value(atlist[i],&dcl); 
              fprintf(stderr," %s:",dcl.isFrameOffset ? "FP Offset" : "Address");
              fprintf(stderr," %ld\n",dcl.offset);

            }else{
              fprintf(stderr,"UNSUPPORTED ATTRIBUTE TYPE\n");
            }
            break;
          case DW_FORM_string:
            {char *val;
            dwarf_formstring(atlist[i],&val,&error); 
            fprintf(stderr,"%s\n",val);}
            break;
          
          case DW_FORM_strp:
            {char *str;
            if( (dwarf_formstring(atlist[i],&str,&error) == DW_DLV_OK) ){
              fprintf(stderr,"%s\n",str);
            } }
            break;
          
          default:
            fprintf(stderr,"Unhandled Attribute Form!\n");
            break;
            
        };
      }
      dwarf_dealloc(d, atlist[i], DW_DLA_ATTR);
    }
    dwarf_dealloc(d, atlist, DW_DLA_LIST);
  } 

}