Dudebbing windows externs in MSVC

martinrobinson's icon

Hello,

Could anyone give me a quick outline of how to debug a extern for Max on Windows using MS VC++ Express?

I should probably outline how I get this working on the Mac in case it bears no resemblance to the process on Windows.

I'm familiar with doing this in Xcode by setting the custom executable environment as the MaxMSPRuntime which GDB then attaches to when doing build->debug. Then I usually drag and drop the external I want to debug onto the MaxMSPRuntime. This loads the external and I get any debug messages (in the console output back in Xcode) that I generate in main() using printf() or similar. Finally I load a pre-built patch that tests the extern and again I get any debug messages.

In MSVC I have tried launching MaxMSPRntime then attaching MSVC's debugger using Debug->Attach.... Then, as on the Mac, I drag and drop the extern and load the pre-built patch. This gives me post() messages in Max but I don't get any printf() debug messages in the debugger output back in MSVC. I can only assume it's not attaching correctly.

Any hints?

thezer0ist@gmail.com's icon

i've used msvc to debug externals when they cause a crash... there's that "kill program or debug" message box that pops up, which brings you to another one that allows you to attach an instance of msvc. i'm not sure how to get it to debug without a crash though.
my guess is that stuff like printf wouldn't really work there anyway... i'm not sure that the debugger connects to the max standard i/o streams, which it would need to do for that stuff to work.
in a worst case scenario, you could just use a log file...

martinrobinson's icon

...I just noticed my rather interesting spelling of debugging in the original post... anyway:

Thanks, thezer0ist I guess I'll need to use a log file unless someone knows how to get similar behaviour to Xcode. I don't want to use post() since the problem I'm having is in inside some C++ class where I don't want to include the MaxAPI, ext.h etc.

thezer0ist@gmail.com's icon

my approach to that kind of thing has always been a combination of wrapper functions and variadic macros, which allow me to switch the debug output from one method to another simply by changing a single #define statement...

something like...

void _dbg_print_log(const char *fmt, ...)
{
print message to log file
}

void _dbg_print_max(const char *fmt, ...)
{
print message using post()
}

#ifdef DEBUG_OUT_MAX
#define dbg_print(fmt, ...) _dbg_print_max(fmt, __VAR_ARGS)
#else
#define dbg_print(fmt, ...) _dbg_print_log(fmt, __VAR_ARGS)
#endif

i'm not sure about the syntax of the macros... i generally end up spending a few minutes looking at reference materials for stuff like __VAR_ARGS (which i'm sure is supposed to be something else)