コード例 #1
0
ファイル: dbgstack.c プロジェクト: doniexun/OrangeC
void SetStackArea(HWND hwnd)
{
    int ebp = activeThread->regs.Ebp;
    int eip = activeThread->regs.Eip;
    SCOPE *stackbase = 0,  *stackptr,  *newStack;

    if (uState != atBreakpoint && uState != atException)
        return ;
    while (1)
    {
        eip = eipReal(eip);
        newStack = calloc(1,sizeof(SCOPE));
        if (!newStack)
            return ;
        newStack->next = 0;
        FindFunctionName(newStack->name, eip);
        GetBreakpointLine(eip, &newStack->fileName, &newStack->lineno, stackbase != NULL);
        newStack->address = eip;
        newStack->basePtr = ebp;
        if (stackbase)
            stackptr = stackptr->next = newStack;
        else
            stackbase = stackptr = newStack;
        eip = readStackedData(ebp, &ebp);
        if (!eip)
            break;
    }
    StackList = stackbase;
}
コード例 #2
0
ファイル: brkcode.c プロジェクト: bencz/OrangeC
void functionbp(void)
{
    char *name = (char *)DialogBox(hInstance, "FUNCTIONBPDIALOG", hwndFrame, (DLGPROC)
        FunctionBPProc);
    if (name)
    {
        char buf[2048];
        GetQualifiedName(buf, &name, FALSE, TRUE);
        // we aren't handling cast operators for now...
        if (*name)
        {
            name = NULL;
        }
        else
        {
            int count = 0;
            FUNCTIONLIST *list, *selected = NULL;
            DEBUG_INFO *dbg = findDebug(activeScope->address);
            list = GetFunctionList(dbg, activeScope, buf);
            if (list && list->next)
            {
                selected = (FUNCTIONLIST *)DialogBoxParam(hInstance, "FUNCTIONBPSELECTDIALOG", hwndFrame, (DLGPROC)
                    FunctionBPSelectProc, (LPARAM)list);
            }
            else
            {
                selected = list;
            }
            if (selected)
            {
                int line;
                char module[MAX_PATH];
                if (GetBreakpointLine(selected->address, module, &line, FALSE))
                {
                    Tag(TAG_BP, module, line, 0,0,0,0);
                }
                    
            }
            if (list)
            {
                while (list)
                {
                    FUNCTIONLIST *l = list;
                    list = list->next;
                    free(l);
               
                }
            }
        }
    }
}
コード例 #3
0
ファイル: dbgstack.c プロジェクト: doniexun/OrangeC
LRESULT CALLBACK StackProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    LV_ITEM item;
    LV_COLUMN lvC;    
    RECT r;
    LPNMHDR nmh;
    char module[256];
    SCOPE *sl;
    int i, lines;
    switch (iMessage)
    {
        case WM_CTLCOLORSTATIC:
            return (HBRUSH)(COLOR_WINDOW + 1);
        case WM_TIMER:
            KillTimer(hwnd, 100);
            ListView_SetItemState(hwndLV, curSel, 0, LVIS_SELECTED);
            break;
        case WM_NOTIFY:
            nmh = (LPNMHDR)lParam;
            if (nmh->code == NM_SETFOCUS)
            {
                PostMessage(hwndFrame, WM_REDRAWTOOLBAR, 0, 0);
                SendMessage(GetParent(hwnd), WM_ACTIVATEME, 0, 0);
            }
            else if (nmh->code == LVN_GETDISPINFO)
            {
                LV_DISPINFO *p = (LV_DISPINFO *)lParam;
                SCOPE *x = (SCOPE *)p->item.lParam;
                char addr[256];
                p->item.mask |= LVIF_TEXT | LVIF_DI_SETITEM;
                p->item.mask &= ~LVIF_STATE;
                if (p->item.iSubItem == 2)
                {
                    p->item.pszText = x->name;
                }
                else
                {
                    sprintf(addr,"%8X", x->address);
                    p->item.pszText = addr;
                }
            }
            else if (nmh->code == LVN_ITEMCHANGED)
            {
                LPNMLISTVIEW p = (LPNMHDR)lParam;
                if (p->uChanged & LVIF_STATE)
                {
                    if (p->uNewState & LVIS_SELECTED)
                    {
                        i = 0;
                        PostMessage(hwnd, WM_USER, p->iItem, 0);
                        SetTimer(hwnd, 100, 400, 0);
                    }
                }
            }
            else if (nmh->code == LVN_KEYDOWN)
            {
                switch (((LPNMLVKEYDOWN)lParam)->wVKey)
                {
                    case 'C':
                        if (GetKeyState(VK_CONTROL) &0x80000000)
                        {
                            CopyText(hwnd);
                        }
                        break;
                    case VK_UP:
                        if (curSel > 0)
                            SendMessage(hwnd, WM_USER, curSel-1, 0);
                        break;
                    case VK_DOWN:
                        if (curSel < ListView_GetItemCount(hwndLV) - 1)
                            SendMessage(hwnd, WM_USER, curSel + 1, 0);
                        break;
                }
            }
            break;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID_TBPROCEDURE:
                    if (HIWORD(wParam) == CBN_SELENDOK)
                    {
                        int i = SendMessage(hwndTbProcedure, CB_GETCURSEL, 0 , 0);
                        if (i != CB_ERR)
                        {
                            SendMessage(hwnd, WM_USER, i, 0);
                        }
                    }
                    break;
            }
            break;
        case WM_USER:
        {
            memset(&item, 0, sizeof(item));
            if (curSel != 0)
            {
                item.iItem = curSel;
                item.iSubItem = 0;
                item.mask = LVIF_IMAGE;
                item.iImage = IML_BLANK;
                ListView_SetItem(hwndLV, &item);
            }

            curSel = wParam;
            if (curSel != 0)
            {
                item.iItem = curSel;
                item.mask = LVIF_IMAGE;
                item.iImage = IML_CONTINUATION;
                ListView_SetItem(hwndLV, &item);
            }
            sl = StackList;
            lines = curSel;
            while (sl && lines)
            {
                sl = sl->next;
                lines--;
            }
            if (sl)
            {
                if (GetBreakpointLine(sl->address, module, &lines, curSel != 0))
                {
                    char *p;
                    static DWINFO x;
                    strcpy(x.dwName, sl->fileName);
                    p = strrchr(module, '\\');
                    if (p)
                        strcpy(x.dwTitle, p + 1);
                    else
                        strcpy(x.dwTitle, module);
                    x.dwLineNo = sl->lineno;
                    x.logMRU = FALSE;
                    x.newFile = FALSE;
                    SetScope(sl);
                    CreateDrawWindow(&x, TRUE);
                }
            }
        }
            break;
        case WM_CREATE:
            hwndStack = hwnd;
            GetClientRect(hwnd, &r);
            hwndLV = CreateWindowEx(0, WC_LISTVIEW, "", 
                           LVS_REPORT | LVS_SINGLESEL | WS_CHILD | WS_VISIBLE | WS_BORDER,
                           0,0,r.right-r.left, r.bottom - r.top, hwnd, 0, hInstance, 0);
            ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
            StackFont = CreateFontIndirect(&fontdata);
            SendMessage(hwndLV, WM_SETFONT, (WPARAM)StackFont, 0);
            lvC.mask = LVCF_WIDTH | LVCF_SUBITEM ;
            lvC.cx = 20;
            lvC.iSubItem = 0;
            ListView_InsertColumn(hwndLV, 0, &lvC);
            lvC.mask = LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT;
            lvC.cx = 80;
            lvC.iSubItem = 1;
            lvC.pszText = "Address";
            ListView_InsertColumn(hwndLV, 1, &lvC);
            lvC.mask = LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT;
            lvC.cx = 200;
            lvC.iSubItem = 2;
            lvC.pszText = "Location";
            ListView_InsertColumn(hwndLV, 2, &lvC);
            ListView_SetImageList(hwndLV, tagImageList, LVSIL_SMALL);
            break;
        case WM_SIZE:
            r.left = r.top = 0;
            r.right = LOWORD(lParam);
            r.bottom = HIWORD(lParam);
            MoveWindow(hwndLV, r.left, r.top, r.right - r.left,
                r.bottom - r.top, 1);
            break;
            // fall through
        case WM_RESTACK:
            SetScope(NULL);
            ClearStackArea(hwnd);
            EnableWindow(hwndLV, uState != notDebugging && wParam);
            EnableWindow(hwndTbProcedure, uState != notDebugging && wParam);
            if (uState != notDebugging && wParam)
            {
                int i = 0;
                char buf[256];
                SCOPE *list;
                SetStackArea(hwnd);
                
                list = StackList;
                ListView_DeleteAllItems(hwndLV);
                memset(&item, 0, sizeof(item));
                SendMessage(hwndTbProcedure, CB_RESETCONTENT, 0, 0);
                while (list)
                {

                    item.iItem = i;
                    item.iSubItem = 0;
                    item.mask = LVIF_IMAGE | LVIF_PARAM;
                    if (i == 0)
                    {
                        if (activeThread == stoppedThread)
                            item.iImage = IML_STOPBP;
                        else
                            item.iImage = IML_STOP;
                        if (i == curSel)
                            SetScope(list);
                            
                    }
                    else if (i == curSel)
                    {
                        item.iImage = IML_CONTINUATION;
                        SetScope(list);
                    }
                    else
                    {
                        item.iImage = IML_BLANK;
                    }
                    item.lParam = (LPARAM)list;
                    ListView_InsertItem(hwndLV, &item);
                    
                    item.iSubItem = 1;
                    item.mask = LVIF_PARAM | LVIF_TEXT;
                    item.lParam = (LPARAM)list;
                    item.pszText = "";
                    ListView_InsertItem(hwndLV, &item);
                    i++;
                    sprintf(buf, "%08x %s", list->address, list->name);
                    SendMessage(hwndTbProcedure, CB_ADDSTRING, 0, (LPARAM)buf);
                    list = list->next;
                }
                SendMessage(hwndTbProcedure, CB_SETCURSEL, curSel, 0);
            }
            break;
        case WM_DESTROY:
            ClearStackArea(hwnd);
            hwndStack = 0;
            DeleteObject(StackFont);
            break;
        case WM_SETFOCUS:
            SendMessage(GetParent(hwnd), WM_ACTIVATEME, 0, 0);
            break;
        case WM_KILLFOCUS:
            break;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}
コード例 #4
0
ファイル: brkcode.c プロジェクト: bencz/OrangeC
int dbgSetBreakPoint(char *name, int linenum, char *extra)
{
    BREAKPOINT **p = &activeProcess->breakpoints.next;
    if (uState == notDebugging)
        return 1;
    // will be checked when entering debugger
    if (!name)
    {
        // it was from the assembly window
        int addr = linenum;
        while (*p)
        {
            int *q;
            for (q = (*p)->addresses; q && *q !=0; ++q)
            {
                if (addr == *q)
                    return 1;
            }
            p = &(*p)->next;
        }
        *p = calloc(1,sizeof(BREAKPOINT));
        if (*p)
        {
            (*p)->addresses = calloc(2, sizeof(int ));
            (*p)->addresses[0] = addr;
            (*p)->extra = extra;
            GetBreakpointLine(addr, &(*p)->module[0], &(*p)->linenum, FALSE);
            if (hwndASM)
                InvalidateRect(hwndASM, 0, 0);
//            Tag(TAG_BP, (*p)->module, (*p)->linenum, 0, 0, 0, 0);
            if (uState == Running)
            {
                allocBreakPoint(activeProcess->hProcess,  *p);
            }
            else
            {
                char name[256];
                DWORD n = FindFunctionName(name, (*p)->addresses[0], NULL,NULL);
                if (n)
                    sprintf((*p)->name, "%s + 0x%x", name, (*p)->addresses[0]-n);
            }
        }
        SendDIDMessage(DID_BREAKWND, WM_RESTACK, 0, 0);
        return 1;
    }
    else
    {
        // it was from a source module
        int *addresses = GetBreakpointAddresses(name, &linenum);
        if (addresses)
        {
            int *t;
            for (t = addresses; *t !=0; ++t)
            {
                p = &activeProcess->breakpoints.next;
                while (*p)
                {
                    int *q;
                    for (q = (*p)->addresses; q && *q !=0; ++q)
                    {
                        if (*t == *q)
                            return 1;
                    }
                    p = &(*p)->next;
                }
            }
            *p = calloc(1,sizeof(BREAKPOINT));
            if (*p)
            {
                (*p)->addresses = addresses;
                (*p)->extra = extra;
                strcpy((*p)->module, name);
                (*p)->linenum = linenum;
                if (hwndASM)
                    InvalidateRect(hwndASM, 0, 0);
                if (uState == Running)
                {
                    allocBreakPoint(activeProcess->hProcess,  *p);
                }
                else
                {
                    char name[256];
                    DWORD n = FindFunctionName(name, (*p)->addresses[0], NULL, NULL);
                    if (n)
                        sprintf((*p)->name, "%s + 0x%x", name, (*p)->addresses[0]-n);
                }
            }
            else
            {
                free(addresses);
            }
            return 1;
        }
        else
            return 0;
        // couldn't locate line, invalid line...
    }
}