string drd_info_rep::get_child_name (tree t, int i) { tag_info ti= info[L(t)]; int index= ti->get_index (i, N(t)); if (is_func (t, EXTERN) && N(t)>0 && is_atomic (t[0])) { ti= info[make_tree_label ("extern:" * t[0]->label)]; index= ti->get_index (i-1, N(t)); } if ((index<0) || (index>=N(ti->ci))) return ""; return get_child_name (L(t), index); }
static int add_structmember_from_die(Dwarf_Debug dbg, Dwarf_Die parent_die, Dwarf_Die die) { int ret = DW_DLV_ERROR; Dwarf_Error err = 0; Dwarf_Half tag = 0; Dwarf_Off offset = 0; Dwarf_Unsigned tid = 0; Dwarf_Unsigned loc = 0; 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_member) return -1; ret = get_offset_tid(die, &offset, &tid); if (ret < 0) { derror("error in get_offset_tid()"); goto error; } t = get_or_add_type(offset); ret = get_child_name(dbg, die, t->name, 128); if (ret < 0) strncpy(t->name, "<unknown-structmbr>", 128); t->ohm_type = OHM_TYPE_ALIAS; ret = get_member_location(die, &loc); if (ret < 0) { derror("error in get_member_location()"); goto error; } // this is the struct member location and not the size; we will // fix it later in refresh_compound_sizes. t->size = loc; t2 = get_or_add_type(tid); t->nelem = 1; t->elems = malloc(sizeof(t)); t->elems[0] = t2; return 1; error: derror("error in add_structmember_from_die()"); return -1; }
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; }
bool drd_info_rep::heuristic_init_macro (string var, tree macro) { //cout << "init_macro " << var << " -> " << macro << "\n"; tree_label l = make_tree_label (var); tag_info old_ti= copy (info[l]); int i, n= N(macro)-1; set_arity (l, n, 0, ARITY_NORMAL, CHILD_DETAILED); set_type (l, get_type (macro[n])); set_with_like (l, heuristic_with_like (macro, "")); //if (heuristic_with_like (macro, "")) //cout << "With-like: " << var << LF; for (i=0; i<n; i++) { if (is_atomic (macro[i])) if (l >= START_EXTENSIONS || get_child_name (l, i) == "") set_child_name (l, i, macro[i]->label); int type= TYPE_UNKNOWN; tree arg (ARG, macro[i]); tree env= arg_access (macro[n], arg, tree (ATTR), type); //if (var == "section" || var == "section-title") //cout << var << " -> " << env << ", " << macro << "\n"; //if (var == "math") //cout << var << ", " << i << " -> " << type << ", " << env << ", " << macro << "\n"; set_type (l, i, type); if (env != "") { //if (var == "eqnarray*") //cout << var << " -> " << env << "\n"; //if (var == "session") //cout << var << " = " << macro << ", " << i << " -> " << env << "\n"; rewrite_symbolic_arguments (macro, env); set_accessible (l, i, ACCESSIBLE_ALWAYS); set_env (l, i, env); } } //if (old_ti != info[l]) //cout << var << ": " << old_ti << " -> " << info[l] << "\n"; return (old_ti != info[l]); }
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; }