winedbg --gdb does nothing

Questions about Wine on Linux
Post Reply
algiel
Newbie
Newbie
Posts: 2
Joined: Thu Oct 08, 2020 6:17 am

winedbg --gdb does nothing

Post by algiel » Thu Oct 08, 2020 7:19 am

Hi,

I recetly wanted to run winedbg with --gdb option to remote debug with radare2, but when I use the --gdb option, winegdb exit with no error :

Code: Select all

$ winedbg --gdb test.exe
0088:0089: create process ''/0x1131c0 @0x4012d0 (33792<558>)
0088:0089: create thread I @0x4012d0
$
So I red the source code to find why the option does not work, and I found this (programs/winedbg/winedbg.c):

Code: Select all

static BOOL CALLBACK mod_loader_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
{
    struct mod_loader_info*     mli = ctx;

    if (!strcmp(mod_name, "<wine-loader>"))
    {
        if (SymGetModuleInfo64(mli->handle, base, mli->imh_mod))
            return FALSE; /* stop enum */
    }
    return TRUE;
}

BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE64* imh_mod)
{
    struct mod_loader_info  mli;
    BOOL                    opt;

    /* this will resynchronize builtin dbghelp's internal ELF module list */
    SymLoadModule(hProcess, 0, 0, 0, 0, 0);
    mli.handle  = hProcess;
    mli.imh_mod = imh_mod;
    imh_mod->SizeOfStruct = sizeof(*imh_mod);
    imh_mod->BaseOfImage = 0;
    /* this is a wine specific options to return also ELF modules in the
     * enumeration
     */
    opt = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
    SymEnumerateModules64(hProcess, mod_loader_cb, &mli);
    SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);

    return imh_mod->BaseOfImage != 0;
}
This piece of code try to find a module named "<wine-loader>" but in my case there are only those following modules loaded :

Code: Select all

kernelbase
kernel32
ntdll
test
so the function dbg_get_debuggee_info return FALSE and the program exit.
I went deeper in the code and found that the purpose of this function is to get the full path of the program being debugged to give it to gdb.
In my case the the full path is something like /full/path/test.exe and the module name associated is "test", so the code above must be searching for "test" and not "<wine-loader>".
To verify my assumptions I replaced it directly in the code, and it worked. Then I tried to find why winedbg is searching for "<wine-loader>", but there is no occurrence of this string in the code and there is no module named "<wine-loader>", there is nowhere in the code where the name of the currently debugged module is overwrite with "<wine-loader>" , so it cannot work !
If someone can help me understand from where the "<wine-loader>" module comes from, then I could fix this bug.

algiel
Newbie
Newbie
Posts: 2
Joined: Thu Oct 08, 2020 6:17 am

Re: winedbg --gdb does nothing

Post by algiel » Fri Oct 09, 2020 7:32 am

I forget to say that I was using the latest stable version of wine : 5.0.1, and I found that in an earlier version my problem was solved by removing the call of dbg_get_debuggee_info.
Now winedbg didn't try to find the path of the current debugged program by searching in loaded modules, so the functions "dbg_get_debuggee_info" and "mod_loader_cb" are now dead code.
I cannot answer the question about the mysterious "<wine-loader>" module because I think this piece of code had no sens in the 5.0.1 version of the code.
Now it's unused code (probably removed soon I hope) and I can finally debug windows programs with radare2 and that's all that matters :D

Post Reply