0

Debug Help Library allows to load symbols from external storages. You just call SymSetSearchPath, specifying symbol servers, and then SymLoadModuleExW loads symbols from the specified locations.

Downloading symbols may take some time and I am currently looking for a way to cancel downloading symbols. But suddenly I couldn't find any API for that.

Is there a way to cancel downloading symbols?

Artem Razin
  • 1,234
  • 8
  • 22
  • 2
    I doubt there is. The best you can do is offload symbol loading onto a sacrificial thread of execution that you're willing to give up on. Since [*"All DbgHelp functions, such as this one, are single threaded"*](https://learn.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symloadmoduleexw#remarks) I cannot envision how cancellation of an operation could possibly be implemented or exposed in the API. – IInspectable Sep 26 '22 at 14:40
  • @IInspectable, I've expected it, but still hoped that I have a chance. I am currently using a separate process that downloads symbols and just terminate it when the downloading has cancelled. But I don't like this solution and it looks a bit dirty. – Artem Razin Sep 26 '22 at 14:48
  • 1
    Terminating a [sacrificial process](https://devblogs.microsoft.com/oldnewthing/20090212-00/?p=19173) is far less dirty than [terminating a thread](https://devblogs.microsoft.com/oldnewthing/20150814-00/?p=91811). Sometimes you're going to have to make compromises in aesthetics, when you're dealing with a design that wasn't actually designed. – IInspectable Sep 26 '22 at 15:00
  • You cannot cancel loading modules, nor can VisualStudio. – YangXiaoPo-MSFT Sep 27 '22 at 02:44

1 Answers1

1

You can althrough only at a specific times you have no control over.

To cancel the download you:

  1. Register for the callback funcation with SymRegisterCallback64 or SymRegisterCallbackW64 funcation.
  2. In the callback handle the CBA_DEFERRED_SYMBOL_LOAD_CANCEL message.

e.g.

    SymRegisterCallbackW64(process, sym_register_callback_proc64, nullptr);

    BOOL CALLBACK sym_register_callback_proc64(__in HANDLE h_process, __in ULONG const action_code, __in_opt ULONG64 const callback_data, __in_opt ULONG64 const user_context)
    {
        switch (action_code)
        {
...
        case CBA_DEFERRED_SYMBOL_LOAD_CANCEL:
            if(<test for cancel now?>)
            {
                return TRUE;
            }
            break;
...
        }

        // Return false to any ActionCode we don't handle
        // or we could generate some undesirable behavior.
        return FALSE;
    }
Shane Powell
  • 13,698
  • 2
  • 49
  • 61
  • I see. It is so sad that they didn't add a way to notify about progress where an application could also cancel downloading symbols. – Artem Razin Sep 29 '22 at 08:58
  • 1
    If you look at the CBA_XML_LOG callback event, it gives you a XML blob that you can break down to get the what is downloading and the percent progress of the download. – Shane Powell Sep 29 '22 at 17:17
  • wow, I've never heard about CBA_XML_LOG! Really, thank you so much. I need to update progress bar while symbols are loading. So CBA_XML_LOG is what I need. – Artem Razin Sep 30 '22 at 13:12