⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symtab.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 4 页
字号:
                return 4;
            case CV_REG_EDI:
                *(int*)val = regs->Edi;
                return 4;
            case CV_REG_ST0:
                // not supported
            case CV_REG_ST1:
            case CV_REG_ST2:
            case CV_REG_ST3:
            case CV_REG_ST4:
            case CV_REG_ST5:
            case CV_REG_ST6:
            case CV_REG_ST7:
                return 0;
        }
    }
    else
    {
        ReadProcessMemory(DebugProcess.hProcess, (LPVOID)address, (LPVOID)val,
            size, &len);
        return len;
    }
    return 0;
}

//-------------------------------------------------------------------------

int HintBasicType(VARINFO *info, int *signedtype, char *data)
{
    if (CV_TYP_IS_REAL(info->type) || CV_TYP_IS_IMAGINARY(info->type))
    {
        switch (info->type)
        {
            case T_REAL32:
            case T_IMAGINARY32:
                ReadValue(info->address, data, 4, &info->thread->regs);
                break;
            case T_REAL64:
            case T_IMAGINARY64:
                ReadValue(info->address, data, 8, &info->thread->regs);
                break;
            case T_REAL80:
            case T_IMAGINARY80:
                ReadValue(info->address, data, 10, &info->thread->regs);
                break;
            default:
                return 0;
        }
        return info->type;
    }
    else if (CV_TYP_IS_COMPLEX(info->type)) 
    {
        switch (info->type)
        {
            case T_CPLX32:
                ReadValue(info->address, data, 8, &info->thread->regs);
                break;
            case T_CPLX64:
                ReadValue(info->address, data, 16, &info->thread->regs);
                break;
            case T_CPLX80:
                ReadValue(info->address, data, 20, &info->thread->regs);
                break;
            default:
                return 0;
        }
        return info->type;
    } else
    {
        int size = 4;
        *(int*)data = 0;
        if (CV_TYP_IS_SIGNED(info->type))
            *signedtype = TRUE;
        else
            *signedtype = FALSE;
        switch (CV_TYPE(info->type))
        {
            case CV_INT:
                size = 1 << (CV_SUBT(info->type) / 2);
                break;
            case CV_SIGNED:
            case CV_UNSIGNED:
                size = 1 << CV_SUBT(info->type);
                break;
            case CV_BOOLEAN:
                ReadValue(info->address, data, 1, info->inreg ? &info->thread
                    ->regs: 0);
                return info->type;
        }
        ReadValue(info->address, data, size, info->inreg ? &info->thread->regs:
            0);
        if (*signedtype)
        {
            switch (size)
            {
                case 1:
                    if (*data &0x80)
                        *(int*)data |= 0xffffff00;
                    break;
                case 2:
                    if (*(short*)data &0x8000)
                        *(int*)data |= 0xffff0000;
                    break;
                case 4:
                    #ifndef BORLANDC
                        if (*(int*)data &0x80000000)
                            *(LLONG_TYPE*)data |= 0xffffffff00000000;
                    #endif 
                    break;
                case 8:
                    return T_INT8;
                default:
                    return 0;
            }
        }
        else if (size == 8)
            return T_INT8;
        return T_INT4;
    }
}

//-------------------------------------------------------------------------

void HintEnum(char *typetab, VARINFO *info, char *buf, int toenum, int onevalue)
{
    int signedtype;
    LLONG_TYPE v = 0;
    short *typeptr = info->typetab;
    HintBasicType(info, &signedtype, &v);
    while (*(typeptr + 1) == LF_FIELDLIST)
    {
        int done = FALSE;
        int len;
        len =  *typeptr - 2;
        typeptr += 2;
        while (len > 0 && !done)
        {
            int xlen;
            char *nmptr;
            switch (*typeptr)
            {
                case LF_ENUMERATE:
                    xlen = sizeof(lfEnumerate) - 1;
                    if (v < LF_NUMERIC)
                        xlen += 2;
                    else
                        xlen += 6;
                    nmptr = ((char*)typeptr) + xlen;
                    if (GetNumericLeaf(&((lfEnumerate*)typeptr)->value) == v)
                    {
                        char buf1[256];
                        memset(buf1, 0, 256);
                        strncpy(buf1, nmptr + 1,  *nmptr);
                        if (toenum)
                            sprintf(buf, "ENUM: %s(%u)", buf1, v);
                        else if (onevalue)
                            sprintf(buf, "%s", buf1);
                        else
                            sprintf(buf, "%s(%u)", buf1, v);
                        return ;
                    }
                    xlen +=  *nmptr + 1;
                    if ((*((char*)typeptr + xlen) &0xf0) == 0xf0)
                        xlen += *((char*)typeptr + xlen) &15;
                    (char*)typeptr += xlen;
                    len -= xlen;
                    break;
                case LF_INDEX:
                    typeptr = LookupType(typetab, ((lfIndex*)typeptr)->index);
                    done = TRUE;
                    break;
                default:
                    sprintf(buf, "ENUM: (UNKNOWN)(%u)", v);
                    return ;
            }
        }
    }
    sprintf(buf, "ENUM: (UNKNOWN)(%u)", v);
}

//-------------------------------------------------------------------------

int HintBf(VARINFO *info, int *signedtype)
{
    char data[20];
    int v;
    HintBasicType(info, signedtype, &data);
    v = *(int*)data;
    if (*signedtype)
    {
        v <<= 32-info->bitstart - info->bitlength;
        v >>= 32-info->bitlength;
    }
    else
    {
        v >>= info->bitstart;
        v &= bitmask[info->bitlength - 1];
    }
    return v;
}

//-------------------------------------------------------------------------

void GetStringValue(VARINFO *info, char *buf, int len, int address)
{
    int i;
    char buf2[256],  *p;
    if (info->type == T_CHAR && ReadValue(address, buf2, len, 0))
    {
        int j;
        buf += strlen(buf);
        *buf++ = '\"';
        p = buf2;
        for (i = 0; i < len &&  *p; i++)
            if (isprint(*p))
                *buf++ =  *p++;
            else
        {
            char temp[5];
            int l;
            *buf++ = '\\';
            itoa((unsigned char) *p++, temp, 8);
            l = strlen(temp);
            for (j = 0; j < (3-l); j++)
                    *buf++ = '0';
            for (j = 0; j < l; j++)
                *buf++ = temp[j];
        }
        *buf++ = '"';
        *buf++ = 0;
    }
}

//-------------------------------------------------------------------------

void HintValue(char *typetab, VARINFO *info, char *buf)
{
    int i;
    if (info->outofscope || info->outofscopereg)
        strcpy(buf, "out of scope");
    else if (info->constant)
    {
        if (CV_TYP_IS_REAL(info->type) || CV_TYP_IS_IMAGINARY(info->type))
            sprintf(buf, "%f", (double)info->fval);
        else if (CV_TYP_IS_COMPLEX(info->type))
            sprintf(buf, "%f + %f * I", (double)info->fval,(double)info->fvali) ;
        else
            sprintf(buf, "%lld(%llx)", info->ival);
    }
    else if (info->structure)
    {
        sprintf(buf, "STRUCTURE: %p", info->address);
    }
    else if (info->unionx)
    {
        sprintf(buf, "UNION: %p", info->address);
    }
    else if (info->pointer)
    {
        int val;
        char buf2[256],  *p;
        if (ReadValue(info->address, &val, 4, info->inreg ? &info->thread->regs
            : 0))
        {
            sprintf(buf, "POINTER: %p ", val);
            GetStringValue(info, buf + strlen(buf), 32, val);
        }
        else
            sprintf(buf, "POINTER: <UNKNOWN>");
    }
    else if (info->enumx)
        HintEnum(typetab, info, buf, TRUE, FALSE);
    else if (info->bitfield)
    {
        int signedtype;
        int v = HintBf(info, &signedtype);
        if (signedtype)
            sprintf(buf, "%d(%x)", v, v);
        else
            sprintf(buf, "%u(%x)", v, v);
    }
    else if (info->array)
    {
        sprintf(buf, "ARRAY: %p ", info->address);
        GetStringValue(info, buf + strlen(buf), 32, info->address);
    }
    else
    {
        int signedtype;
        char buf1[20];
        LLONG_TYPE v;
        switch (HintBasicType(info, &signedtype, buf1))
        {
            case T_INT8:
                #ifndef BORLANDC
                    v = *(LLONG_TYPE*)buf1;
                    if (signedtype)
                        sprintf(buf, "%lld(0x%llx)", v, v);
                    else
                        sprintf(buf, "%llu(0x%llx)", v, v);
                    break;
                #endif 
            default:
                sprintf(buf, "unknown type");
                break;
            case T_INT4:
                v = *(int*)buf1;
                if (signedtype)
                    sprintf(buf, "%d(0x%x)", (int)v, (int)v);
                else
                    sprintf(buf, "%u(0x%x)", (int)v, (int)v);
                break;
            case T_BOOL08:
                if (buf1[0])
                    sprintf(buf, "True");
                else
                    sprintf(buf, "False");
                break;
            case T_REAL32:
            case T_IMAGINARY32:
                sprintf(buf, "%f", (double)*(float*)buf1);
                break;
            case T_REAL80:
            case T_IMAGINARY80:
                *(double*)buf1 = *(long double*)buf1;
            case T_REAL64:
            case T_IMAGINARY64:
                sprintf(buf, "%f", *(double*)buf1);
                break;
            case T_CPLX32:
                sprintf(buf, "%f + %f * I", (double)*(float *)buf1, (double) *(float *)(buf1+4));
                break;
            case T_CPLX64:
                sprintf(buf, "%f + %f * I", *(double*)buf1, *(double *)(buf1+8));
                break;
            case T_CPLX80:
                sprintf(buf, "%f + %f * I", (double)*(long double*)buf1, (double)*(long double *)(buf1+10));
                break;
        }
    }
}

//-------------------------------------------------------------------------

void SimpleTypeName(char *buf, int type)
{
    char *p = buf;
    if (CV_TYP_IS_REAL(type) || CV_TYP_IS_IMAGINARY(type))
    {
        switch (type)
        {
            case T_REAL32:
                sprintf(buf, "float ");
                break;
            case T_REAL64:
                sprintf(buf, "double ");
                break;
            case T_REAL80:
                sprintf(buf, "long double ");
                break;
            case T_IMAGINARY32:
                sprintf(buf, "float imaginary ");
                break;
            case T_IMAGINARY64:
                sprintf(buf, "double imaginary ");
                break;
            case T_IMAGINARY80:
                sprintf(buf, "long double imaginary ");
                break;
            default:
                sprintf(buf, "unknown");
                break;
        }
    }
    else if (CV_TYP_IS_COMPLEX(type))
    {
        switch(type)
        {
            case T_CPLX32:
                sprintf(buf, "float complex ");
                break;
            case T_CPLX64:
                sprintf(buf, "double complex ");
                break;
            case T_CPLX80:
                sprintf(buf, "long double complex ");
                break;
        }
    }
    else
    {
        int size;
        if (!CV_TYP_IS_SIGNED(type))
        {
            sprintf(p, "unsigned ");
            p += strlen(p);
        }
        switch (CV_TYPE(type))
        {
            case CV_INT:
                size = 1 << (CV_SUBT(type) / 2);
                break;
            case CV_SIGNED:
            case CV_UNSIGNED:
                size = 1 << CV_SUBT(type);
                break;
            case CV_BOOLEAN:
                size =  - 1;
                break;
        }
        switch (size)
        {
            case  - 1: sprintf(p, "bool ");
            break;
            case 1:
                sprintf(p, "char ");
                break;
            case 2:
                sprintf(p, "short ");
                break;
            case 4:
                sprintf(p, "int ");
                break;
            case 8:
                sprintf(p, "long long ");
                break;
            default:
                break;
        }
        p += strlen(p);
    }

    return ;
}

//-------------------------------------------------------------------------

char *SymTypeName(char *buf, char *typetab, VARINFO *v)
{
    short *typeptr;
    char *p = buf;
    p[0] = 0;
    if (!v)
        return buf;
    if (v->constant)
    {
        strcpy(buf, "constant ");
        return buf;
    }
    else if (v->pointer)
    {
        if (CV_IS_PRIMITIVE(v->type))
            SimpleTypeName(buf, v->type &~CV_MMASK);
        else
        {
            int replace = !v->subtype;
            if (!v->subtype)
                GetPointerInfo(typetab, v);
            SymTypeName(buf + strlen(buf), typetab, v->subtype);
            strcat(buf, "* ");
            if (replace)
            {
                FreeVarInfo(v->subtype);
                v->subtype = 0;
            }
        }
    }
    else if (CV_IS_PRIMITIVE(v->type))
    {
        SimpleTypeName(buf, v->type &~CV_MMASK);
        if (CV_TYP_IS_PTR(v->type))
            strcat(buf, "* ");
    }
    else if (v->unionx)
    {
        sprintf(buf, "union ");
        p = buf + strlen(buf);
        sprintf(p, "%s", v->structtag);
    }
    else if (v->structure)
    {
        sprintf(buf, "struct ");
        p = buf + strlen(buf);
        sprintf(p, "%s", v->structtag);
    }
    else if (v->enumx)
    {
        sprintf(buf, "enum ");
        p = buf + strlen(buf);
        sprintf(p, "%s", v->structtag);
    }
    if (v->array)
    {
        strcat(buf, "[] ");
    }
    if (v->bitfield)
    {
        p = buf + strlen(buf);
        sprintf(p, ":%d", v->bitlength);
    }
    return buf;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -