R.M.
R.M.

Reputation: 3652

Why am I getting a spurious error message from SymInitialize?

In writing a C++ Windows application, I'm using the SymInitializeW to initialize the symbols for getting a backtrace. As the documentation mentions, I'm checking the return code, and then using GetLastError and FormatMessage when SymInitializeW returns false (like in the example).

However, I'm getting an error message of "The data area passed to a system call is too small" when I do so. I'm not sure what that's referring to, as there really isn't a "data area" being passed - just the process handle, the PCWSTR for the search path, and the bool. -- It's doubly confusing as it seems like the symbol loading works. (e.g. if I skip the error handling, things seem to work properly.)

Does this message point to something I'm actually doing wrong, or is it spurious? If spurious, why is SymInitializeW returning false?

Upvotes: 0

Views: 2202

Answers (1)

R.M.
R.M.

Reputation: 3652

The SymInitialize functions should only be called once on a given process handle. If there's any code path in which a SymInitialize function can be called multiple times, you may get odd errors like "The data area passed to a system call is too small" (ERROR_INSUFFICIENT_BUFFER, 122 (0x7A)) or "The parameter is incorrect" (ERROR_INVALID_PARAMETER 87 (0x57)) and potentially others from GetLastError, despite the fact that you're using all the correct parameters according to the documentation. (There isn't necessarily a specific "Don't call SymInitialize twice" error.)

Best practice is to make sure the control flow through your symbol-handling functions is clear, and that you call SymInitialize once and only once at the top, and then call SymCleanup on the process handle prior to exiting the functions that are doing symbol handling. If you've properly called SymCleanup, subsequent calls to SymInitialize should succeed.

Upvotes: 0

Related Questions