Skip to main content

winedbg --command 'info wnd': increase column size

·302 words·2 mins
Dev Wine
ALT
Author
ALT

If you’ve ever tried to get a specific window’s title using wine winedbg --command 'info wnd', you may have noticed the Text column is truncated after a few characters (14 to be precise).

This annoyed me greatly while I was working on the Blacklight: Revive Docker image I mentionned recently, so I ventured onto IRC for the first time in more than 5 years, to Libera’s #winehq.

A very nice person going by Krock instantly pointed me to winedbg’s packet_query_monitor_wnd_helper in programs/winedbg/gdbproxy.c and info_window in programs/winedbg/info.c functions, which are hardcoded to return only 14 characters.

As such, the easiest way to increase the text column’s size is to change the buffer size to a higher value in packet_query_monitor_wnd_helper and change %.14 to something bigger in both functions, like so (valid for Wine 7.0):

static void packet_query_monitor_wnd_helper(struct gdb_context* gdbctx, HWND hWnd, int indent)
{
    char        buffer[256];
    char    clsName[128];
    char    wndName[128];
    HWND    child;

    do {
       if (!GetClassNameA(hWnd, clsName, sizeof(clsName)))
      strcpy(clsName, "-- Unknown --");
       if (!GetWindowTextA(hWnd, wndName, sizeof(wndName)))
      strcpy(wndName, "-- Empty --");

       packet_reply_open(gdbctx);
       packet_reply_add(gdbctx, "O");
       snprintf(buffer, sizeof(buffer),
                "%*s%04Ix%*s%-17.17s %08x %0*Ix %.80s\n",
                indent, "", (ULONG_PTR)hWnd, 13 - indent, "",
                clsName, GetWindowLongW(hWnd, GWL_STYLE),
                addr_width(gdbctx), (ULONG_PTR)GetWindowLongPtrW(hWnd, GWLP_WNDPROC),
                wndName);
       packet_reply_hex_to_str(gdbctx, buffer);
       packet_reply_close(gdbctx);

       if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
      packet_query_monitor_wnd_helper(gdbctx, child, indent + 1);
    } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
}
static void info_window(HWND hWnd, int indent)
{
    char    clsName[128];
    char    wndName[128];
    HWND    child;

    do
    {
        if (!GetClassNameA(hWnd, clsName, sizeof(clsName)))
            strcpy(clsName, "-- Unknown --");
        if (!GetWindowTextA(hWnd, wndName, sizeof(wndName)))
            strcpy(wndName, "-- Empty --");

        dbg_printf("%*s%08Ix%*s %-17.17s %08x %0*Ix %08x %.80s\n",
                   indent, "", (DWORD_PTR)hWnd, 12 - indent, "",
                   clsName, GetWindowLongW(hWnd, GWL_STYLE),
                   ADDRWIDTH, (ULONG_PTR)GetWindowLongPtrW(hWnd, GWLP_WNDPROC),
                   GetWindowThreadProcessId(hWnd, NULL), wndName);

        if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
            info_window(child, indent + 1);
    } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
}

This patch file precisely does that.

Once edited, build and run it again!