tags:

views:

80

answers:

1

Hi all,

i've successfully get the GCC instrument functions functional with MSYS/MinGW. When i use instrument functions I only have the pointer as reference of the module, which has invoked the instrument function...

Now I try to get more detailed information of the module. Using Linux OS i could use the dladdr function to grab the name of the module. But this method is part of the dlfcn header which is not included in MSYS/MinGW.

By this reason I've tried to implement a win32 wrapper using win32 API methods (GetModuleFileNameA), but i fail. I only got the path to the execution file as module name instead of the method. Following the specification of the win32 API this only should happend if the module handle is invalid (NULL), but it is valid ...

void dladdrWrapper(void *addr){
     printf("Enter testprint!\n");

     MEMORY_BASIC_INFORMATION mbi;
     HMODULE hMod;

     if (!VirtualQuery (addr, &mbi, sizeof (mbi)))
     {
        printf("VirtualQuery call failed!");
        exit(1);
     }

     hMod = (HMODULE) mbi.AllocationBase;
     char module_name[MAX_PATH];


     printf("HMODULE: %p\n", hMod);

     if (!GetModuleFileNameA (hMod, module_name, sizeof (module_name)))
     {
        printf("GetModuleFileNameA call failed!");
        exit(1);
     }

     printf("Identfied module name: %s\n", module_name);
     printf("Exit testprint\n");
  }

Has anyone successfully request the module name of the instruction function caller using a dladdr win32 API call wrapper or get the dladdr runable with MSYS/MinGW ?

Thanks for any hint. Best regards, Christian

A: 

I've figured out that the bfd mechanism maybe a solution to grep the method name using instrument functions. But i couldn't get the bfd library runable. I allways get undefined reference failures, when i use the lbfd library include on compilation.

$ g++ iftest.cpp -o iftest -lbfd -finstrument-functions 
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0x2f9): undefined reference to `lbasename'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0x411): undefined reference to `lbasename'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0x681): undefined reference to `lrealpath'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0x9c3): undefined reference to `_objalloc_alloc'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0xa3f): undefined reference to `_objalloc_alloc'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0xc69): undefined reference to `objalloc_free'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0xcd9): undefined reference to `objalloc_free'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0xe3d): undefined reference to `objalloc_create'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(opncls.o):opncls.c:(.text+0x944): undefined reference to `objalloc_free_block'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(archures.o):archures.c:(.text+0x3cb): undefined reference to `_sch_istable'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(archures.o):archures.c:(.text+0x3e9): undefined reference to `_sch_istable'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(libbfd.o):libbfd.c:(.text+0x6ee): undefined reference to `libintl_dgettext'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(libbfd.o):libbfd.c:(.text+0x740): undefined reference to `libintl_dgettext'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(libbfd.o):libbfd.c:(.text+0x79b): undefined reference to `libintl_dgettext'
c:/Programme/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libbfd.a(libbfd.o):libbfd.c:(.text+0x7d0): undefined reference to `libintl_dgettext'

I've installed (unzipped) all gettext and libiconf packages from sourceforge to my MinGW application. But no effect, the linker problems still exists.

Any suggestions?

Hellhound