On Nov 21, 5:41 pm, Benjamin Smedberg <[EMAIL PROTECTED]> wrote:
> Tarmik wrote:
> > 1. dehydra port for cygwin (windows) environment -
> > currently stuck, since I did not receive any reply on another thread.
>
> Can you explain *why* you want to do this. As we discussed in the other
> thread, getting GCC plugins to work in a Windows host environment could be
> very difficult because the Windows PE executable format doesn't support a
> DLL importing functions from the primary executable without special export
> libraries. This magic is very hard.

If I need only dehydra for code analysis - I would switch to linux.
I have linux expirience and played around with ddd.
But steps 3 & 4 dicatates to me that I will need to have decent
debugger, since I
will need to develop infra structure similar to gcc trees.
Step 2 is only intermediate step for 3 & 4.

But weak linking is not a showstopper - there is a possibility to
extract interface
which dehydra wants from gcc, and try to cleanly rewrite/specify it.
It's also in dehydra intrest - who can guarantee you that in gcc
4.8.9
internal_error, host_integerp, warning or error function calls ?

I have already code like this in gcc:
....
plugin_set_param(21,
    #ifdef ENABLE_CHECKING
        (void*) &vec_assert_fail,
    #else
        NULL,
    #endif
    sizeof(void*) );
plugin_set_param(22,(void*) &warning , sizeof(void*) );
plugin_set_param(23,(void*) &warning0 , sizeof(void*) );
plugin_set_param(24,(void*) &error , sizeof(void*) );

....
and defines similar to this on DLL side:

....
typedef void (*pPointerToFunction_vec_assert_fail) (const char* op,
const char* struct_name, const char* file, unsigned int line, const
char* function);

#define   vec_assert_fail   \
    JUMP_VIA(pPointerToFunction_vec_assert_fail,21,vec_assert_fail)

typedef void (*pPointerToFunction_warning) (int a, const char*
b, ... );

#define   warning   \
    JUMP_VIA(pPointerToFunction_warning,22,warning)

typedef void (*pPointerToFunction_warning0) (const char* a, ... );

#define   warning0   \
    JUMP_VIA(pPointerToFunction_warning0,23,warning0)

typedef void (*pPointerToFunction_error) (const char* fmt, ... );

#define   error   \
    JUMP_VIA(pPointerToFunction_error,24,error)

....
where macros expand further to:

#define JUMP_VIA(func_def,ordinal, function_name) \
    ((func_def) pdebug_jump(#function_name,
ordinal,__LOC__,__FUNCTION__))

#define DATA_REF_VIA(data_type,ordinal, variable_name) \
    ((data_type) pdebug_dataref(#variable_name,
ordinal,__LOC__,__FUNCTION__))

void* pdebug_jump(const char* pszFunctioName, int iOridinal, const
char* pszPos, const char* pszCalleeFunction);
void* pdebug_dataref(const char* pszVariableName, int iOridinal, const
char* pszPos, const char* pszCalleeFunction);

void* pdebug_jump(const char* pszFunctioName, int iOridinal, const
char* pszPos, const char* pszCalleeFunction)
{
    //printf("(From: %s, func '%s')-> %s (%d) at 0x%X\n", pszPos,
pszCalleeFunction, pszFunctioName,iOridinal ,(int)
g_jumpTable_gcc_externals[iOridinal]);
    return g_jumpTable_gcc_externals[iOridinal];
} //pdebug_jump


void* pdebug_dataref(const char* pszVariableName, int iOridinal, const
char* pszPos, const char* pszCalleeFunction)
{
    //printf("(From: %s, func '%s')-> %s (%d) at 0x%X\n", pszPos,
pszCalleeFunction, pszVariableName,iOridinal ,(int)
g_jumpTable_gcc_externals[iOridinal]);
    return g_jumpTable_gcc_externals[iOridinal];
} //pdebug_dataref

void* g_jumpTable_gcc_externals[MAX_JUMP_ENTRIES];

and originals set up function:

DLL_EXPORTED_FUNCTION void gcc_plugin_set_param(
    int iArg,                   //[in] Argument index
    void* pParamValue,          //[in] pointer to argument
    int iDataSize               //[in] size of argument.
)
{
    //Unbuffer stdout. This makes sure that any printf command
executed will
    //display text right away
    setvbuf(stdout,NULL,_IONBF,0);
    setvbuf(stderr,NULL,_IONBF,0);

    printf("-> gcc_plugin_set_param (%d, 0x%X, size=%d)\n", iArg,
(unsigned int)pParamValue,iDataSize);

    if(!pParamValue)
    {
        printf("pParamValue is NULL, return\n");
        printf("<- gcc_plugin_set_param");
        return;
    } //if

    // Arguments specified by value.
    switch(iArg)
    {
        case 1:
            memcpy((void*) tree_contains_struct,pParamValue,sizeof
(tree_contains_struct));
            printf("<- gcc_plugin_set_param");
            return;
        case 2:
            printf("->memset");
            memset((void*) tree_code_type,0,1000);
            printf("<-memset");

            memcpy((void*) tree_code_type,pParamValue,iDataSize);
            printf("<- gcc_plugin_set_param");
            return;
        case 3:
            memcpy((void*) tree_code_length,pParamValue,iDataSize);
            printf("<- gcc_plugin_set_param");
            return;
        case 14:
            global_namespace=(tree) pParamValue;
            printf("<- gcc_plugin_set_param");
            return;
        default: break;
    } //if

    g_jumpTable_gcc_externals[iArg]=pParamValue;
    printf("<- gcc_plugin_set_param");
} //gcc_plugin_set_param


Btw - currently dehydra is bound to c++ frontend, merely because you
cannot modify const tables -
like tree_code_type. If you would like to switch front end - e.g. to c
or to java - then best approach would be able
to modify those const tables. (tree_code_type, tree_code_length,
tree_contains_struct)

> I strongly recommend that you do this hacking on Linux instead of Windows.

Hmm... Intrested idea btw...  I just don't have native linux os
installed on my pc computers,
but may be I could install that one.

I need anyway to learn how dehydra works, so it's irrelevant whether
I'm learning it on linux or on windows.

Related to Run-Time Check Failure of expand_location.

I wrote on gcc side following code:

void expand_location_2(source_location a, expanded_location* pOut)
{
    *pOut=expand_location(a);
}

and routed pointer to .DLL:
    plugin_set_param(48,(void*) &expand_location_2, sizeof(void*) );

On .DLL side I have made a wrapper:

typedef void (*pPointerToFunction_expand_location) (source_location
a,expanded_location* pOut);

expanded_location expand_location(source_location a)
{
    expanded_location exl;
    JUMP_VIA(pPointerToFunction_expand_location,48,expanded_location)
(a,&exl);
    return exl;
}

After this expand_location seems to be working correctly with
microsoft compiler.

This means that:
expanded_location expand_location (source_location a);

this function prototype causes some calling convention problem between
$m compiler and gcc compiler
but function:
void expand_location (source_location a,expanded_location* pOut);

works fine. I suspect that pointers are allocated in same manner on
stack, but not structures.

One step further, now I can see all locations where particular code
resides.

Now I will analyze statement_walker bit deeper.
_______________________________________________
dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis

Reply via email to