搜尋此網誌

2016年8月5日 星期五

How to use __FILE__, __DATE__, __TIME__, __LINE__, __FUNCTION__, __FILE__ to debug in C?

================================================
__FILE__        current file nume.
__FUNCTION__    current functionnume.
__LINE__        current line number.
__DATE__        built date.

__TIME__        built time.
================================================

#include
#include
void call_test_fun(void);


#define DBG_PRINT(msg, arg...) printf("%s:%s(%d): " msg, __FILE__, __FUNCTION__, __LINE__, ##arg)

int main(void)
{
    printf( "The file is: %s\n", __FILE__ );
  
  printf( "This function is: %s\n", __FUNCTION__ );
    printf( "This is line: %d\n", __LINE__ );
    printf( "The date is: %s\n", __DATE__ );
    printf( "The time is: %s\n", __TIME__ );
    call_test_fun();
    return 0;
}

void call_test_fun(void)
{
    printf( "This function is: %s\n", __func__ );
    printf( "The file is: %s\n", __FILE__ );
    printf( "This is line: %d\n", __LINE__ );

    printf( "STDC: %d \n", __STDC__);
    printf( "STDC_HOSTED: %d \n", __STDC_HOSTED__);
    printf( "VERSION: %s \n", __VERSION__);
    printf( "TIMESTAMP: %s \n", __TIMESTAMP__);
    DBG_PRINT("number = %d, str = %s\n", index, str);
}

Create a Pop Up box in Hii(Human Interface Infrstructure)

u16 i;
EFI_INPUT_KEY                   Key;
DEBUG_PRINT (("Key scan.........\n"));
do {
    CreatePopUp (
        EFI_LIGHTGRAY | EFI_BACKGROUND_RED,
        &Key,
        L"",
        L"Would you like to create this virtual disk?",
        L"         [Yes]               [No]         ",
        L"",
        NULL
    );
    DEBUG_PRINT (("Unicode=0x%x, ScanCode=0x%x <%c>\n", Key.UnicodeChar, Key.ScanCode, Key.UnicodeChar));
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));

Print Messages:
Unicode=0x79, ScanCode=0x0
Unicode=0x59, ScanCode=0x0
Unicode=0x6E, ScanCode=0x0
Unicode=0x4E, ScanCode=0x0

ScanCode=0x0(SCAN_NULL)

//
// EFI Console Colours
//
#define EFI_BLACK                 0x00
#define EFI_BLUE                  0x01
#define EFI_GREEN                 0x02
#define EFI_CYAN                  (EFI_BLUE | EFI_GREEN)
#define EFI_RED                   0x04
#define EFI_MAGENTA               (EFI_BLUE | EFI_RED)
#define EFI_BROWN                 (EFI_GREEN | EFI_RED)
#define EFI_LIGHTGRAY             (EFI_BLUE | EFI_GREEN | EFI_RED)
#define EFI_BRIGHT                0x08
#define EFI_DARKGRAY              (EFI_BRIGHT)
#define EFI_LIGHTBLUE             (EFI_BLUE | EFI_BRIGHT)
#define EFI_LIGHTGREEN            (EFI_GREEN | EFI_BRIGHT)
#define EFI_LIGHTCYAN             (EFI_CYAN | EFI_BRIGHT)
#define EFI_LIGHTRED              (EFI_RED | EFI_BRIGHT)
#define EFI_LIGHTMAGENTA          (EFI_MAGENTA | EFI_BRIGHT)
#define EFI_YELLOW                (EFI_BROWN | EFI_BRIGHT)
#define EFI_WHITE                 (EFI_BLUE | EFI_GREEN | EFI_RED | EFI_BRIGHT)

#define EFI_TEXT_ATTR(f, b)       ((f) | ((b) << 4))

#define EFI_BACKGROUND_BLACK      0x00
#define EFI_BACKGROUND_BLUE       0x10
#define EFI_BACKGROUND_GREEN      0x20
#define EFI_BACKGROUND_CYAN       (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN)
#define EFI_BACKGROUND_RED        0x40
#define EFI_BACKGROUND_MAGENTA    (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_RED)
#define EFI_BACKGROUND_BROWN      (EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)
#define EFI_BACKGROUND_LIGHTGRAY  (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)

//
// EFI Scan codes
//
#define SCAN_NULL       0x0000
#define SCAN_UP         0x0001
#define SCAN_DOWN       0x0002
#define SCAN_RIGHT      0x0003
#define SCAN_LEFT       0x0004
#define SCAN_HOME       0x0005
#define SCAN_END        0x0006
#define SCAN_INSERT     0x0007
#define SCAN_DELETE     0x0008
#define SCAN_PAGE_UP    0x0009
#define SCAN_PAGE_DOWN  0x000A
#define SCAN_F1         0x000B
#define SCAN_F2         0x000C
#define SCAN_F3         0x000D
#define SCAN_F4         0x000E
#define SCAN_F5         0x000F
#define SCAN_F6         0x0010
#define SCAN_F7         0x0011
#define SCAN_F8         0x0012
#define SCAN_F9         0x0013
#define SCAN_F10        0x0014
#define SCAN_F11        0x0015
#define SCAN_F12        0x0016

#define SCAN_ESC        0x0017