/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <ctf_impl.h>
/*
* Compare the given input string and length against a table of known C storage
* qualifier keywords. We just ignore these in ctf_lookup_by_name, below. To
* do this quickly, we use a pre-computed Perfect Hash Function similar to the
* technique originally described in the classic paper:
*
* R.J. Cichelli, "Minimal Perfect Hash Functions Made Simple",
* Communications of the ACM, Volume 23, Issue 1, January 1980, pp. 17-19.
*
* For an input string S of length N, we use hash H = S[N - 1] + N - 105, which
* for the current set of qualifiers yields a unique H in the range [0 .. 20].
* The hash can be modified when the keyword set changes as necessary. We also
* store the length of each keyword and check it prior to the final strcmp().
*/
static int
{
static const struct qual {
const char *q_name;
} qhash[] = {
{ "static", 6 }, { "", 0 }, { "", 0 }, { "", 0 },
{ "volatile", 8 }, { "", 0 }, { "", 0 }, { "", 0 }, { "", 0 },
{ "", 0 }, { "auto", 4 }, { "extern", 6 }, { "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 }, { "const", 5 }, { "register", 8 },
{ "", 0 }, { "restrict", 8 }, { "_Restrict", 9 }
};
}
/*
* Attempt to convert the given C type name into the corresponding CTF type ID.
* It is not possible to do complete and proper conversion of type names
* without implementing a more full-fledged parser, which is necessary to
* handle things like types that are function pointers to functions that
* have arguments that are function pointers, and fun stuff like that.
* Instead, this function implements a very simple conversion algorithm that
* finds the things that we actually care about: structs, unions, enums,
* integers, floats, typedefs, and pointers to any of these named types.
*/
{
const char *p, *q, *end;
while (isspace(*p))
p++; /* skip leading ws */
if (p == end)
break;
q = end; /* compare until end */
if (*p == '*') {
/*
* Find a pointer to type by looking in fp->ctf_ptrtab.
* If we can't find a pointer to the given type, see if
* we can compute a pointer to the type resulting from
* resolving the type down to its base type and use
* that instead. This helps with cases where the CTF
* data includes "struct foo *" but not "foo_t *" and
* the user tries to access "foo_t *" in the debugger.
*/
if (ntype == 0) {
CTF_TYPE_TO_INDEX(ntype)]) == 0) {
goto err;
}
}
q = p + 1;
continue;
}
if (isqualifier(p, (size_t)(q - p)))
continue; /* skip qualifier keyword */
continue; /* skip prefix and next ws */
q = end; /* compare until end */
while (isspace(q[-1]))
q--; /* exclude trailing ws */
goto err;
}
break;
}
}
goto err;
}
}
if (*p != '\0' || type == 0)
return (type);
err:
return (ptype);
return (CTF_ERR);
}
/*
* Given a symbol table index, return the type of the data object described
* by the corresponding entry in the symbol table.
*/
{
} else {
}
if (type == 0)
return (type);
}
/*
* Return the pointer to the internal CTF type data corresponding to the
* given type ID. If the ID is invalid, the function returns NULL.
* This function is not exported outside of the library.
*/
const ctf_type_t *
{
return (NULL);
}
}
return (NULL);
}
/*
* Given a symbol table index, return the info for the function described
* by the corresponding entry in the symbol table.
*/
int
{
} else {
}
if (kind == CTF_K_UNKNOWN && n == 0)
if (kind != CTF_K_FUNCTION)
if (n != 0 && dp[n - 1] == 0) {
}
return (0);
}
/*
* Given a symbol table index, return the arguments for the function described
* by the corresponding entry in the symbol table.
*/
int
{
return (CTF_ERR); /* errno is set for us */
/*
* The argument data is two ushort_t's past the translation table
* offset: one for the function info, and one for the return type.
*/
return (0);
}