Apply local modifications to make Unwind Express BETA 10 buildable and

usable in the FreeBSD kernel.
This commit is contained in:
Marcel Moolenaar 2006-07-07 23:56:34 +00:00
parent 870376755a
commit b6352de96c
12 changed files with 92 additions and 20 deletions

View File

@ -25,8 +25,13 @@ OTHER DEALINGS IN THE SOFTWARE.
#ifndef __UWX_INCLUDED
#define __UWX_INCLUDED 1
#ifndef _KERNEL
#include <stdlib.h>
#include <inttypes.h>
#else
#include <sys/param.h>
#include <sys/systm.h>
#endif
#if defined(__cplusplus)
#define __EXTERN_C extern "C"

View File

@ -64,8 +64,6 @@ int uwx_get_byte(struct uwx_bstream *bstream)
int len;
int n;
int b;
uint32_t *wp;
uint64_t *dp;
if (bstream->peekc >= 0) {
b = bstream->peekc;
@ -131,6 +129,7 @@ int uwx_get_uleb128(struct uwx_bstream *bstream, uint64_t *valp)
return 0;
}
#if 0
int uwx_get_uleb128_alt(struct uwx_bstream *bstream, uint64_t *valp)
{
uint64_t val;
@ -179,3 +178,4 @@ int uwx_get_uleb128_alt(struct uwx_bstream *bstream, uint64_t *valp)
*valp = val;
return 0;
}
#endif

View File

@ -23,7 +23,6 @@ OTHER DEALINGS IN THE SOFTWARE.
*/
#include "uwx_env.h"
#include "uwx_context.h"
#include "uwx_scoreboard.h"
#include "uwx_step.h"
#include "uwx_trace.h"
@ -200,7 +199,6 @@ int uwx_get_spill_loc(struct uwx_env *env, int regid, uint64_t *dispp)
int sor;
int rrb_gr;
uint64_t bsp;
int n;
if (env == 0)
return UWX_ERR_NOENV;
@ -283,7 +281,6 @@ int uwx_set_reg(struct uwx_env *env, int regid, uint64_t val)
int uwx_set_fr(struct uwx_env *env, int regid, uint64_t *val)
{
int status;
if (regid >= UWX_REG_FR(2) && regid <= UWX_REG_FR(5))
regid -= UWX_REG_FR(2);
@ -349,6 +346,7 @@ uint64_t uwx_add_to_bsp(uint64_t bsp, int nslots)
return bsp + nslots * DWORDSZ;
}
#if 0
int uwx_selftest_bsp_arithmetic()
{
int i;
@ -407,3 +405,4 @@ int uwx_selftest_bsp_arithmetic()
return failed;
}
#endif

View File

@ -22,13 +22,21 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _KERNEL
#include <stdlib.h>
#endif
#include "uwx_env.h"
#include "uwx_scoreboard.h"
#include "uwx_str.h"
#include "uwx_trace.h"
#ifdef _KERNEL
static struct uwx_env uwx_env;
#define free(p) /* nullified */
#define malloc(sz) ((sz == sizeof(uwx_env)) ? &uwx_env : NULL)
#endif
alloc_cb uwx_allocate_cb = 0;
free_cb uwx_free_cb = 0;
@ -97,11 +105,11 @@ int uwx_init_env(struct uwx_env *env, size_t total_size)
if (uwx_allocate_cb != NULL)
env->allocate_cb = uwx_allocate_cb;
else
env->allocate_cb = malloc;
env->allocate_cb = NULL;
if (uwx_free_cb != NULL)
env->free_cb = uwx_free_cb;
else
env->free_cb = free;
env->free_cb = NULL;
env->free_scoreboards = 0;
env->used_scoreboards = 0;
env->labeled_scoreboards = 0;

View File

@ -22,12 +22,41 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _KERNEL
#include <stdlib.h>
#endif
#include "uwx_env.h"
#include "uwx_scoreboard.h"
#include "uwx_trace.h"
#ifdef _KERNEL
static unsigned short uwx_allocated;
static struct uwx_scoreboard uwx_scoreboard[sizeof(uwx_allocated) << 3];
static void
free(struct uwx_scoreboard *p)
{
int idx = p - uwx_scoreboard;
uwx_allocated &= ~(1 << idx);
}
static struct uwx_scoreboard *
malloc(size_t sz)
{
int idx;
if (sz != sizeof(struct uwx_scoreboard))
return (NULL);
for (idx = 0; idx < (sizeof(uwx_allocated) << 3); idx++) {
if ((uwx_allocated & (1 << idx)) == 0) {
uwx_allocated |= 1 << idx;
return (uwx_scoreboard + idx);
}
}
return (NULL);
}
#endif
void uwx_prealloc_scoreboard(struct uwx_env *env, struct uwx_scoreboard *sb)
{
@ -76,6 +105,7 @@ struct uwx_scoreboard *uwx_alloc_scoreboard(struct uwx_env *env)
return sb;
}
static
void uwx_reclaim_scoreboards(struct uwx_env *env)
{
struct uwx_scoreboard *sb;
@ -150,6 +180,7 @@ int uwx_label_scoreboard(
/* in the "nextstack" field. */
back = 0;
new = 0;
while (sb != 0) {
TRACE_B_LABEL_COPY(sb->id)
new = uwx_alloc_scoreboard(env);
@ -233,6 +264,7 @@ int uwx_copy_scoreboard(
/* Now copy its stack, storing reverse links in the nextstack field. */
back = sb;
new = 0;
for (next = lsb->nextstack; next != 0; next = next->nextstack) {
TRACE_B_COPY_COPY(next->id)
new = uwx_alloc_scoreboard(env);

View File

@ -23,7 +23,6 @@ OTHER DEALINGS IN THE SOFTWARE.
*/
#include "uwx_env.h"
#include "uwx_context.h"
#include "uwx_utable.h"
#include "uwx_uinfo.h"
#include "uwx_scoreboard.h"
@ -66,7 +65,7 @@ int uwx_lookupip_hook(int request, uint64_t ip, intptr_t tok, uint64_t **vecp,
/* uwx_get_frame_info: Gets unwind info for current frame */
static
int uwx_get_frame_info(struct uwx_env *env)
{
int i;
@ -77,7 +76,6 @@ int uwx_get_frame_info(struct uwx_env *env)
uint64_t *uvec;
uint64_t *rstate;
struct uwx_utable_entry uentry;
uint64_t uinfop;
uint64_t uvecout[UVECSIZE];
if (env->copyin == 0 || env->lookupip == 0)
@ -383,8 +381,6 @@ int uwx_get_funcstart(
uint64_t *funcstart)
{
int status;
uint64_t *uvec;
uint64_t uvecout[UVECSIZE];
if (env == 0)
return UWX_ERR_NOENV;

View File

@ -25,4 +25,6 @@ OTHER DEALINGS IN THE SOFTWARE.
#define UVECSIZE 20 /* Size of uvec supplied by unwind engine */
/* for callback's use. */
extern int uwx_lookupip_hook(int request, uint64_t ip, intptr_t tok,
uint64_t **vecp, size_t uvecsize);
extern int uwx_restore_markers(struct uwx_env *env);

View File

@ -22,11 +22,19 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _KERNEL
#include <string.h>
#endif
#include "uwx_env.h"
#include "uwx_str.h"
#ifdef _KERNEL
static struct uwx_str_pool uwx_str_pool;
#define free(p) /* nullified */
#define malloc(sz) ((sz == sizeof(uwx_str_pool)) ? &uwx_str_pool : NULL)
#endif
/*
* uwx_str.c
*

View File

@ -28,6 +28,8 @@ OTHER DEALINGS IN THE SOFTWARE.
#include "uwx_scoreboard.h"
#include "uwx_trace.h"
#ifdef UWX_TRACE_ENABLE
void uwx_trace_init(struct uwx_env *env)
{
char *tstr;
@ -35,7 +37,7 @@ void uwx_trace_init(struct uwx_env *env)
tstr = getenv("UWX_TRACE");
if (tstr != NULL) {
while (*tstr != '\0') {
switch (*tstr++) {
switch (*tstr) {
case 'i': env->trace |= UWX_TRACE_UINFO; break;
case 't': env->trace |= UWX_TRACE_UTABLE; break;
case 'b': env->trace |= UWX_TRACE_SB; break;
@ -45,6 +47,9 @@ void uwx_trace_init(struct uwx_env *env)
case 'C': env->trace |= UWX_TRACE_COPYIN; break;
case 'L': env->trace |= UWX_TRACE_LOOKUPIP; break;
case '?':
#ifdef _KERNEL
fprintf(stderr, "UWX_TRACE flag `%c' unknown.\n", *tstr);
#else
fprintf(stderr, "UWX_TRACE flags:\n");
fprintf(stderr, " i: unwind info\n");
fprintf(stderr, " t: unwind table searching\n");
@ -55,7 +60,9 @@ void uwx_trace_init(struct uwx_env *env)
fprintf(stderr, " C: copyin callback\n");
fprintf(stderr, " L: lookup ip callback\n");
exit(1);
#endif
}
tstr++;
}
}
}
@ -108,7 +115,7 @@ void uwx_dump_rstate(int regid, uint64_t rstate)
fprintf(stderr, " <reg %d>\n", reg);
break;
default:
fprintf(stderr, " <%08x>\n", rstate);
fprintf(stderr, " <%08lx>\n", (long)rstate);
break;
}
}
@ -149,9 +156,11 @@ void uwx_dump_uinfo_block(
while (ulen >= WORDSZ) {
fprintf(stderr, " %08lx: ", (unsigned long)uinfo);
for (i = 0; i < 4 * WORDSZ && ulen >= WORDSZ; i += WORDSZ) {
fprintf(stderr, " %08lx", *uinfo++);
fprintf(stderr, " %04x", *uinfo++);
ulen -= WORDSZ;
}
fprintf(stderr, "\n");
}
}
#endif /* UWX_TRACE_ENABLE */

View File

@ -33,8 +33,16 @@ OTHER DEALINGS IN THE SOFTWARE.
#ifdef UWX_TRACE_ENABLE
#ifdef _KERNEL
#define fprintf(f, ...) printf(__VA_ARGS__)
#endif
extern void uwx_trace_init(struct uwx_env *env);
struct uwx_utable_entry;
extern void uwx_dump_uinfo_block(struct uwx_utable_entry *, unsigned int);
extern void uwx_dump_rstate(int regid, uint64_t rstate);
struct uwx_rhdr;

View File

@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
#include "uwx_scoreboard.h"
#include "uwx_bstream.h"
#include "uwx_trace.h"
#include "uwx_swap.h"
int uwx_count_ones(unsigned int mask);

View File

@ -76,7 +76,10 @@ int uwx_search_utable(
/* Make sure all three required values are given. */
keys = 0;
text_base = 0;
unwind_flags = 0;
unwind_start = 0;
unwind_end = 0;
while (*uvec != 0) {
switch ((int)*uvec++) {
case UWX_KEY_TBASE:
@ -144,7 +147,6 @@ int uwx_search_utable32(
uint32_t unwind_end,
struct uwx_utable_entry *uentry)
{
int status;
int lb;
int ub;
int mid;
@ -165,11 +167,13 @@ int uwx_search_utable32(
lb = 0;
ub = (unwind_end - unwind_start) / (3 * WORDSZ);
mid = 0;
while (ub > lb) {
mid = (lb + ub) / 2;
len = COPYIN_UINFO_4((char *)&code_start, unwind_start+mid*3*WORDSZ);
len = COPYIN_UINFO_4((char *)&code_start,
(uintptr_t)(unwind_start+mid*3*WORDSZ));
len += COPYIN_UINFO_4((char *)&code_end,
unwind_start+mid*3*WORDSZ+WORDSZ);
(uintptr_t)(unwind_start+mid*3*WORDSZ+WORDSZ));
if (len != 2 * WORDSZ)
return UWX_ERR_COPYIN_UTBL;
if (env->byte_swap) {
@ -187,7 +191,7 @@ int uwx_search_utable32(
if (ub <= lb)
return UWX_ERR_NOUENTRY;
len = COPYIN_UINFO_4((char *)&unwind_info,
unwind_start+mid*3*WORDSZ+2*WORDSZ);
(uintptr_t)(unwind_start+mid*3*WORDSZ+2*WORDSZ));
if (len != WORDSZ)
return UWX_ERR_COPYIN_UTBL;
if (env->byte_swap)
@ -216,7 +220,6 @@ int uwx_search_utable64(
uint64_t unwind_end,
struct uwx_utable_entry *uentry)
{
int status;
int lb;
int ub;
int mid;
@ -235,6 +238,7 @@ int uwx_search_utable64(
lb = 0;
ub = (unwind_end - unwind_start) / (3 * DWORDSZ);
mid = 0;
while (ub > lb) {
mid = (lb + ub) / 2;
len = COPYIN_UINFO_8((char *)&code_start, unwind_start+mid*3*DWORDSZ);