1 /* Symbol, variable and name lookup.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
4 This file is part of libctf.
6 libctf is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not see
18 <http://www.gnu.org/licenses/>. */
25 /* Grow the pptrtab so that it is at least NEW_LEN long. */
27 grow_pptrtab (ctf_dict_t
*fp
, size_t new_len
)
29 uint32_t *new_pptrtab
;
31 if ((new_pptrtab
= realloc (fp
->ctf_pptrtab
, sizeof (uint32_t)
33 return (ctf_set_errno (fp
, ENOMEM
));
35 fp
->ctf_pptrtab
= new_pptrtab
;
37 memset (fp
->ctf_pptrtab
+ fp
->ctf_pptrtab_len
, 0,
38 sizeof (uint32_t) * (new_len
- fp
->ctf_pptrtab_len
));
40 fp
->ctf_pptrtab_len
= new_len
;
44 /* Update entries in the pptrtab that relate to types newly added in the
47 refresh_pptrtab (ctf_dict_t
*fp
, ctf_dict_t
*pfp
)
50 for (i
= fp
->ctf_pptrtab_typemax
; i
<= fp
->ctf_typemax
; i
++)
52 ctf_id_t type
= LCTF_INDEX_TO_TYPE (fp
, i
, 1);
55 if (ctf_type_kind (fp
, type
) != CTF_K_POINTER
)
58 reffed_type
= ctf_type_reference (fp
, type
);
60 if (LCTF_TYPE_ISPARENT (fp
, reffed_type
))
62 uint32_t idx
= LCTF_TYPE_TO_INDEX (fp
, reffed_type
);
64 /* Guard against references to invalid types. No need to consider
65 the CTF dict corrupt in this case: this pointer just can't be a
66 pointer to any type we know about. */
67 if (idx
<= pfp
->ctf_typemax
)
69 if (idx
>= fp
->ctf_pptrtab_len
70 && grow_pptrtab (fp
, pfp
->ctf_ptrtab_len
) < 0)
71 return -1; /* errno is set for us. */
73 fp
->ctf_pptrtab
[idx
] = i
;
78 fp
->ctf_pptrtab_typemax
= fp
->ctf_typemax
;
83 /* Compare the given input string and length against a table of known C storage
84 qualifier keywords. We just ignore these in ctf_lookup_by_name, below. To
85 do this quickly, we use a pre-computed Perfect Hash Function similar to the
86 technique originally described in the classic paper:
88 R.J. Cichelli, "Minimal Perfect Hash Functions Made Simple",
89 Communications of the ACM, Volume 23, Issue 1, January 1980, pp. 17-19.
91 For an input string S of length N, we use hash H = S[N - 1] + N - 105, which
92 for the current set of qualifiers yields a unique H in the range [0 .. 20].
93 The hash can be modified when the keyword set changes as necessary. We also
94 store the length of each keyword and check it prior to the final strcmp().
96 TODO: just use gperf. */
99 isqualifier (const char *s
, size_t len
)
101 static const struct qual
106 {"static", 6}, {"", 0}, {"", 0}, {"", 0},
107 {"volatile", 8}, {"", 0}, {"", 0}, {"", 0}, {"", 0},
108 {"", 0}, {"auto", 4}, {"extern", 6}, {"", 0}, {"", 0},
109 {"", 0}, {"", 0}, {"const", 5}, {"register", 8},
110 {"", 0}, {"restrict", 8}, {"_Restrict", 9}
113 int h
= s
[len
- 1] + (int) len
- 105;
114 const struct qual
*qp
= &qhash
[h
];
116 return (h
>= 0 && (size_t) h
< sizeof (qhash
) / sizeof (qhash
[0])
117 && (size_t) len
== qp
->q_len
&&
118 strncmp (qp
->q_name
, s
, qp
->q_len
) == 0);
121 /* Attempt to convert the given C type name into the corresponding CTF type ID.
122 It is not possible to do complete and proper conversion of type names
123 without implementing a more full-fledged parser, which is necessary to
124 handle things like types that are function pointers to functions that
125 have arguments that are function pointers, and fun stuff like that.
126 Instead, this function implements a very simple conversion algorithm that
127 finds the things that we actually care about: structs, unions, enums,
128 integers, floats, typedefs, and pointers to any of these named types. */
131 ctf_lookup_by_name_internal (ctf_dict_t
*fp
, ctf_dict_t
*child
,
134 static const char delimiters
[] = " \t\n\r\v\f*";
136 const ctf_lookup_t
*lp
;
137 const char *p
, *q
, *end
;
139 ctf_id_t ntype
, ptype
;
142 return (ctf_set_errno (fp
, EINVAL
));
144 for (p
= name
, end
= name
+ strlen (name
); *p
!= '\0'; p
= q
)
146 while (isspace ((int) *p
))
147 p
++; /* Skip leading whitespace. */
152 if ((q
= strpbrk (p
+ 1, delimiters
)) == NULL
)
153 q
= end
; /* Compare until end. */
157 /* Find a pointer to type by looking in child->ctf_pptrtab (if child
158 is set) and fp->ctf_ptrtab. If we can't find a pointer to the
159 given type, see if we can compute a pointer to the type resulting
160 from resolving the type down to its base type and use that instead.
161 This helps with cases where the CTF data includes "struct foo *"
162 but not "foo_t *" and the user tries to access "foo_t *" in the
165 There is extra complexity here because uninitialized elements in
166 the pptrtab and ptrtab are set to zero, but zero (as the type ID
167 meaning the unimplemented type) is a valid return type from
168 ctf_lookup_by_name. (Pointers to types are never of type 0, so
169 this is unambiguous, just fiddly to deal with.) */
171 uint32_t idx
= LCTF_TYPE_TO_INDEX (fp
, type
);
175 if (child
&& idx
<= child
->ctf_pptrtab_len
)
177 ntype
= child
->ctf_pptrtab
[idx
];
184 if (ntype
== CTF_ERR
)
186 ntype
= fp
->ctf_ptrtab
[idx
];
191 /* Try resolving to its base type and check again. */
192 if (ntype
== CTF_ERR
)
195 ntype
= ctf_type_resolve_unsliced (child
, type
);
197 ntype
= ctf_type_resolve_unsliced (fp
, type
);
199 if (ntype
== CTF_ERR
)
202 idx
= LCTF_TYPE_TO_INDEX (fp
, ntype
);
205 if (child
&& idx
<= child
->ctf_pptrtab_len
)
207 ntype
= child
->ctf_pptrtab
[idx
];
214 if (ntype
== CTF_ERR
)
216 ntype
= fp
->ctf_ptrtab
[idx
];
220 if (ntype
== CTF_ERR
)
224 type
= LCTF_INDEX_TO_TYPE (fp
, ntype
, (fp
->ctf_flags
& LCTF_CHILD
)
227 /* We are looking up a type in the parent, but the pointed-to type is
228 in the child. Switch to looking in the child: if we need to go
229 back into the parent, we can recurse again. */
240 if (isqualifier (p
, (size_t) (q
- p
)))
241 continue; /* Skip qualifier keyword. */
243 for (lp
= fp
->ctf_lookups
; lp
->ctl_prefix
!= NULL
; lp
++)
245 /* TODO: This is not MT-safe. */
246 if ((lp
->ctl_prefix
[0] == '\0' ||
247 strncmp (p
, lp
->ctl_prefix
, (size_t) (q
- p
)) == 0) &&
248 (size_t) (q
- p
) >= lp
->ctl_len
)
250 for (p
+= lp
->ctl_len
; isspace ((int) *p
); p
++)
251 continue; /* Skip prefix and next whitespace. */
253 if ((q
= strchr (p
, '*')) == NULL
)
254 q
= end
; /* Compare until end. */
256 while (isspace ((int) q
[-1]))
257 q
--; /* Exclude trailing whitespace. */
259 /* Expand and/or allocate storage for a slice of the name, then
262 if (fp
->ctf_tmp_typeslicelen
>= (size_t) (q
- p
) + 1)
264 memcpy (fp
->ctf_tmp_typeslice
, p
, (size_t) (q
- p
));
265 fp
->ctf_tmp_typeslice
[(size_t) (q
- p
)] = '\0';
269 free (fp
->ctf_tmp_typeslice
);
270 fp
->ctf_tmp_typeslice
= xstrndup (p
, (size_t) (q
- p
));
271 if (fp
->ctf_tmp_typeslice
== NULL
)
273 ctf_set_errno (fp
, ENOMEM
);
278 if ((type
= ctf_lookup_by_rawhash (fp
, lp
->ctl_hash
,
279 fp
->ctf_tmp_typeslice
)) == 0)
286 if (lp
->ctl_prefix
== NULL
)
290 if (*p
!= '\0' || type
== 0)
291 return (ctf_set_errno (fp
, ECTF_SYNTAX
));
296 ctf_set_errno (fp
, ECTF_NOTYPE
);
297 if (fp
->ctf_parent
!= NULL
)
299 /* Need to look up in the parent, from the child's perspective.
300 Make sure the pptrtab is up to date. */
302 if (fp
->ctf_pptrtab_typemax
< fp
->ctf_typemax
)
304 if (refresh_pptrtab (fp
, fp
->ctf_parent
) < 0)
305 return -1; /* errno is set for us. */
308 if ((ptype
= ctf_lookup_by_name_internal (fp
->ctf_parent
, fp
,
311 return (ctf_set_errno (fp
, ctf_errno (fp
->ctf_parent
)));
318 ctf_lookup_by_name (ctf_dict_t
*fp
, const char *name
)
320 return ctf_lookup_by_name_internal (fp
, NULL
, name
);
323 /* Return the pointer to the internal CTF type data corresponding to the
324 given type ID. If the ID is invalid, the function returns NULL.
325 This function is not exported outside of the library. */
328 ctf_lookup_by_id (ctf_dict_t
**fpp
, ctf_id_t type
)
330 ctf_dict_t
*fp
= *fpp
; /* Caller passes in starting CTF dict. */
333 if ((fp
= ctf_get_dict (fp
, type
)) == NULL
)
335 (void) ctf_set_errno (*fpp
, ECTF_NOPARENT
);
339 /* If this dict is writable, check for a dynamic type. */
341 if (fp
->ctf_flags
& LCTF_RDWR
)
345 if ((dtd
= ctf_dynamic_type (fp
, type
)) != NULL
)
348 return &dtd
->dtd_data
;
350 (void) ctf_set_errno (*fpp
, ECTF_BADID
);
354 /* Check for a type in the static portion. */
356 idx
= LCTF_TYPE_TO_INDEX (fp
, type
);
357 if (idx
> 0 && (unsigned long) idx
<= fp
->ctf_typemax
)
359 *fpp
= fp
; /* Function returns ending CTF dict. */
360 return (LCTF_INDEX_TO_TYPEPTR (fp
, idx
));
363 (void) ctf_set_errno (*fpp
, ECTF_BADID
);
367 typedef struct ctf_lookup_idx_key
370 const char *clik_name
;
371 uint32_t *clik_names
;
372 } ctf_lookup_idx_key_t
;
374 /* A bsearch function for variable names. */
377 ctf_lookup_var (const void *key_
, const void *lookup_
)
379 const ctf_lookup_idx_key_t
*key
= key_
;
380 const ctf_varent_t
*lookup
= lookup_
;
382 return (strcmp (key
->clik_name
, ctf_strptr (key
->clik_fp
, lookup
->ctv_name
)));
385 /* Given a variable name, return the type of the variable with that name. */
388 ctf_lookup_variable (ctf_dict_t
*fp
, const char *name
)
391 ctf_lookup_idx_key_t key
= { fp
, name
, NULL
};
393 /* This array is sorted, so we can bsearch for it. */
395 ent
= bsearch (&key
, fp
->ctf_vars
, fp
->ctf_nvars
, sizeof (ctf_varent_t
),
400 if (fp
->ctf_parent
!= NULL
)
401 return ctf_lookup_variable (fp
->ctf_parent
, name
);
403 return (ctf_set_errno (fp
, ECTF_NOTYPEDAT
));
406 return ent
->ctv_type
;
409 typedef struct ctf_symidx_sort_arg_cb
413 } ctf_symidx_sort_arg_cb_t
;
416 sort_symidx_by_name (const void *one_
, const void *two_
, void *arg_
)
418 const uint32_t *one
= one_
;
419 const uint32_t *two
= two_
;
420 ctf_symidx_sort_arg_cb_t
*arg
= arg_
;
422 return (strcmp (ctf_strptr (arg
->fp
, arg
->names
[*one
]),
423 ctf_strptr (arg
->fp
, arg
->names
[*two
])));
426 /* Sort a symbol index section by name. Takes a 1:1 mapping of names to the
427 corresponding symbol table. Returns a lexicographically sorted array of idx
428 indexes (and thus, of indexes into the corresponding func info / data object
432 ctf_symidx_sort (ctf_dict_t
*fp
, uint32_t *idx
, size_t *nidx
,
438 if ((sorted
= malloc (len
)) == NULL
)
440 ctf_set_errno (fp
, ENOMEM
);
444 *nidx
= len
/ sizeof (uint32_t);
445 for (i
= 0; i
< *nidx
; i
++)
448 if (!(fp
->ctf_header
->cth_flags
& CTF_F_IDXSORTED
))
450 ctf_symidx_sort_arg_cb_t arg
= { fp
, idx
};
451 ctf_dprintf ("Index section unsorted: sorting.");
452 ctf_qsort_r (sorted
, *nidx
, sizeof (uint32_t), sort_symidx_by_name
, &arg
);
453 fp
->ctf_header
->cth_flags
|= CTF_F_IDXSORTED
;
459 /* Given a symbol index, return the name of that symbol from the table provided
460 by ctf_link_shuffle_syms, or failing that from the secondary string table, or
463 ctf_lookup_symbol_name (ctf_dict_t
*fp
, unsigned long symidx
)
465 const ctf_sect_t
*sp
= &fp
->ctf_symtab
;
469 if (fp
->ctf_dynsymidx
)
472 if (symidx
> fp
->ctf_dynsymmax
)
475 ctf_link_sym_t
*symp
= fp
->ctf_dynsymidx
[symidx
];
480 return symp
->st_name
;
484 if (sp
->cts_data
== NULL
)
487 if (symidx
>= fp
->ctf_nsyms
)
490 switch (sp
->cts_entsize
)
492 case sizeof (Elf64_Sym
):
494 const Elf64_Sym
*symp
= (Elf64_Sym
*) sp
->cts_data
+ symidx
;
495 ctf_elf64_to_link_sym (fp
, &sym
, symp
, symidx
);
498 case sizeof (Elf32_Sym
):
500 const Elf32_Sym
*symp
= (Elf32_Sym
*) sp
->cts_data
+ symidx
;
501 ctf_elf32_to_link_sym (fp
, &sym
, symp
, symidx
);
505 ctf_set_errno (fp
, ECTF_SYMTAB
);
509 assert (!sym
.st_nameidx_set
);
515 return ctf_lookup_symbol_name (fp
->ctf_parent
, symidx
);
518 ctf_set_errno (fp
, err
);
523 /* Iterate over all symbols with types: if FUNC, function symbols, otherwise,
524 data symbols. The name argument is not optional. The return order is
525 arbitrary, though is likely to be in symbol index or name order. You can
526 change the value of 'functions' in the middle of iteration over non-dynamic
527 dicts, but doing so on dynamic dicts will fail. (This is probably not very
528 useful, but there is no reason to prohibit it.) */
531 ctf_symbol_next (ctf_dict_t
*fp
, ctf_next_t
**it
, const char **name
,
540 if ((i
= ctf_next_create ()) == NULL
)
541 return ctf_set_errno (fp
, ENOMEM
);
544 i
->ctn_iter_fun
= (void (*) (void)) ctf_symbol_next
;
549 if ((void (*) (void)) ctf_symbol_next
!= i
->ctn_iter_fun
)
550 return (ctf_set_errno (fp
, ECTF_NEXT_WRONGFUN
));
552 if (fp
!= i
->cu
.ctn_fp
)
553 return (ctf_set_errno (fp
, ECTF_NEXT_WRONGFP
));
555 /* We intentionally use raw access, not ctf_lookup_by_symbol, to avoid
556 incurring additional sorting cost for unsorted symtypetabs coming from the
557 compiler, to allow ctf_symbol_next to work in the absence of a symtab, and
558 finally because it's easier to work out what the name of each symbol is if
561 if (fp
->ctf_flags
& LCTF_RDWR
)
563 ctf_dynhash_t
*dynh
= functions
? fp
->ctf_funchash
: fp
->ctf_objthash
;
564 void *dyn_name
= NULL
, *dyn_value
= NULL
;
568 ctf_next_destroy (i
);
569 return (ctf_set_errno (fp
, ECTF_NEXT_END
));
572 err
= ctf_dynhash_next (dynh
, &i
->ctn_next
, &dyn_name
, &dyn_value
);
573 /* This covers errors and also end-of-iteration. */
576 ctf_next_destroy (i
);
578 return ctf_set_errno (fp
, err
);
582 sym
= (ctf_id_t
) (uintptr_t) dyn_value
;
584 else if ((!functions
&& fp
->ctf_objtidx_names
) ||
585 (functions
&& fp
->ctf_funcidx_names
))
587 ctf_header_t
*hp
= fp
->ctf_header
;
588 uint32_t *idx
= functions
? fp
->ctf_funcidx_names
: fp
->ctf_objtidx_names
;
594 len
= (hp
->cth_varoff
- hp
->cth_funcidxoff
) / sizeof (uint32_t);
595 tab
= (uint32_t *) (fp
->ctf_buf
+ hp
->cth_funcoff
);
599 len
= (hp
->cth_funcidxoff
- hp
->cth_objtidxoff
) / sizeof (uint32_t);
600 tab
= (uint32_t *) (fp
->ctf_buf
+ hp
->cth_objtoff
);
608 *name
= ctf_strptr (fp
, idx
[i
->ctn_n
]);
609 sym
= tab
[i
->ctn_n
++];
610 } while (sym
== -1u || sym
== 0);
614 /* Skip over pads in ctf_xslate, padding for typeless symbols in the
615 symtypetab itself, and symbols in the wrong table. */
616 for (; i
->ctn_n
< fp
->ctf_nsyms
; i
->ctn_n
++)
618 ctf_header_t
*hp
= fp
->ctf_header
;
620 if (fp
->ctf_sxlate
[i
->ctn_n
] == -1u)
623 sym
= *(uint32_t *) ((uintptr_t) fp
->ctf_buf
+ fp
->ctf_sxlate
[i
->ctn_n
]);
630 if (fp
->ctf_sxlate
[i
->ctn_n
] >= hp
->cth_funcoff
631 && fp
->ctf_sxlate
[i
->ctn_n
] < hp
->cth_objtidxoff
)
636 if (fp
->ctf_sxlate
[i
->ctn_n
] >= hp
->cth_objtoff
637 && fp
->ctf_sxlate
[i
->ctn_n
] < hp
->cth_funcoff
)
642 if (i
->ctn_n
>= fp
->ctf_nsyms
)
645 *name
= ctf_lookup_symbol_name (fp
, i
->ctn_n
++);
651 ctf_next_destroy (i
);
653 return (ctf_set_errno (fp
, ECTF_NEXT_END
));
656 /* A bsearch function for function and object index names. */
659 ctf_lookup_idx_name (const void *key_
, const void *idx_
)
661 const ctf_lookup_idx_key_t
*key
= key_
;
662 const uint32_t *idx
= idx_
;
664 return (strcmp (key
->clik_name
, ctf_strptr (key
->clik_fp
, key
->clik_names
[*idx
])));
667 /* Given a symbol number, look up that symbol in the function or object
668 index table (which must exist). Return 0 if not found there (or pad). */
671 ctf_try_lookup_indexed (ctf_dict_t
*fp
, unsigned long symidx
, int is_function
)
673 const char *symname
= ctf_lookup_symbol_name (fp
, symidx
);
674 struct ctf_header
*hp
= fp
->ctf_header
;
675 uint32_t *symtypetab
;
680 ctf_dprintf ("Looking up type of object with symtab idx %lx (%s) in "
681 "indexed symtypetab\n", symidx
, symname
);
683 if (symname
[0] == '\0')
684 return -1; /* errno is set for us. */
688 if (!fp
->ctf_funcidx_sxlate
)
690 if ((fp
->ctf_funcidx_sxlate
691 = ctf_symidx_sort (fp
, (uint32_t *)
692 (fp
->ctf_buf
+ hp
->cth_funcidxoff
),
694 hp
->cth_varoff
- hp
->cth_funcidxoff
))
697 ctf_err_warn (fp
, 0, 0, _("cannot sort function symidx"));
698 return -1; /* errno is set for us. */
701 symtypetab
= (uint32_t *) (fp
->ctf_buf
+ hp
->cth_funcoff
);
702 sxlate
= fp
->ctf_funcidx_sxlate
;
703 names
= fp
->ctf_funcidx_names
;
704 nidx
= fp
->ctf_nfuncidx
;
708 if (!fp
->ctf_objtidx_sxlate
)
710 if ((fp
->ctf_objtidx_sxlate
711 = ctf_symidx_sort (fp
, (uint32_t *)
712 (fp
->ctf_buf
+ hp
->cth_objtidxoff
),
714 hp
->cth_funcidxoff
- hp
->cth_objtidxoff
))
717 ctf_err_warn (fp
, 0, 0, _("cannot sort object symidx"));
718 return -1; /* errno is set for us. */
722 symtypetab
= (uint32_t *) (fp
->ctf_buf
+ hp
->cth_objtoff
);
723 sxlate
= fp
->ctf_objtidx_sxlate
;
724 names
= fp
->ctf_objtidx_names
;
725 nidx
= fp
->ctf_nobjtidx
;
728 ctf_lookup_idx_key_t key
= { fp
, symname
, names
};
731 idx
= bsearch (&key
, sxlate
, nidx
, sizeof (uint32_t), ctf_lookup_idx_name
);
735 ctf_dprintf ("%s not found in idx\n", symname
);
739 /* Should be impossible, but be paranoid. */
740 if ((idx
- sxlate
) > (ptrdiff_t) nidx
)
741 return (ctf_set_errno (fp
, ECTF_CORRUPT
));
743 ctf_dprintf ("Symbol %lx (%s) is of type %x\n", symidx
, symname
,
745 return symtypetab
[*idx
];
748 /* Given a symbol table index, return the type of the function or data object
749 described by the corresponding entry in the symbol table. We can only return
750 symbols in read-only dicts and in dicts for which ctf_link_shuffle_syms has
751 been called to assign symbol indexes to symbol names. */
754 ctf_lookup_by_symbol (ctf_dict_t
*fp
, unsigned long symidx
)
756 const ctf_sect_t
*sp
= &fp
->ctf_symtab
;
760 /* Shuffled dynsymidx present? Use that. */
761 if (fp
->ctf_dynsymidx
)
763 const ctf_link_sym_t
*sym
;
765 ctf_dprintf ("Looking up type of object with symtab idx %lx in "
766 "writable dict symtypetab\n", symidx
);
768 /* The dict must be dynamic. */
769 if (!ctf_assert (fp
, fp
->ctf_flags
& LCTF_RDWR
))
773 if (symidx
> fp
->ctf_dynsymmax
)
776 sym
= fp
->ctf_dynsymidx
[symidx
];
777 err
= ECTF_NOTYPEDAT
;
778 if (!sym
|| (sym
->st_shndx
!= STT_OBJECT
&& sym
->st_shndx
!= STT_FUNC
))
781 if (!ctf_assert (fp
, !sym
->st_nameidx_set
))
784 if (fp
->ctf_objthash
== NULL
785 || ((type
= (ctf_id_t
) (uintptr_t)
786 ctf_dynhash_lookup (fp
->ctf_objthash
, sym
->st_name
)) == 0))
788 if (fp
->ctf_funchash
== NULL
789 || ((type
= (ctf_id_t
) (uintptr_t)
790 ctf_dynhash_lookup (fp
->ctf_funchash
, sym
->st_name
)) == 0))
798 if (sp
->cts_data
== NULL
)
801 /* This covers both out-of-range lookups and a dynamic dict which hasn't been
804 if (symidx
>= fp
->ctf_nsyms
)
807 if (fp
->ctf_objtidx_names
)
809 if ((type
= ctf_try_lookup_indexed (fp
, symidx
, 0)) == CTF_ERR
)
810 return CTF_ERR
; /* errno is set for us. */
812 if (type
== 0 && fp
->ctf_funcidx_names
)
814 if ((type
= ctf_try_lookup_indexed (fp
, symidx
, 1)) == CTF_ERR
)
815 return CTF_ERR
; /* errno is set for us. */
820 err
= ECTF_NOTYPEDAT
;
821 if (fp
->ctf_objtidx_names
&& fp
->ctf_funcidx_names
)
824 /* Table must be nonindexed. */
826 ctf_dprintf ("Looking up object type %lx in 1:1 dict symtypetab\n", symidx
);
828 if (fp
->ctf_sxlate
[symidx
] == -1u)
831 type
= *(uint32_t *) ((uintptr_t) fp
->ctf_buf
+ fp
->ctf_sxlate
[symidx
]);
839 return ctf_lookup_by_symbol (fp
->ctf_parent
, symidx
);
841 return (ctf_set_errno (fp
, err
));
844 /* Given a symbol table index, return the info for the function described
845 by the corresponding entry in the symbol table, which may be a function
846 symbol or may be a data symbol that happens to be a function pointer. */
849 ctf_func_info (ctf_dict_t
*fp
, unsigned long symidx
, ctf_funcinfo_t
*fip
)
853 if ((type
= ctf_lookup_by_symbol (fp
, symidx
)) == CTF_ERR
)
854 return -1; /* errno is set for us. */
856 if (ctf_type_kind (fp
, type
) != CTF_K_FUNCTION
)
857 return (ctf_set_errno (fp
, ECTF_NOTFUNC
));
859 return ctf_func_type_info (fp
, type
, fip
);
862 /* Given a symbol table index, return the arguments for the function described
863 by the corresponding entry in the symbol table. */
866 ctf_func_args (ctf_dict_t
*fp
, unsigned long symidx
, uint32_t argc
,
871 if ((type
= ctf_lookup_by_symbol (fp
, symidx
)) == CTF_ERR
)
872 return -1; /* errno is set for us. */
874 if (ctf_type_kind (fp
, type
) != CTF_K_FUNCTION
)
875 return (ctf_set_errno (fp
, ECTF_NOTFUNC
));
877 return ctf_func_type_args (fp
, type
, argc
, argv
);