Debugging a problem that doesn't show up on any machine with Visual Studio installed?

I'm having a problem with my browser plugin in firefox.  It runs fine, but when it exits, the plugin crashes and Firefox traps the error so that the browser doesn't crash.  The problem is the crash only happens on machines which don't have Visual studio installed on so I can't exactly trace through the code.  How would I go about debugging this?

The best I can come up with is I'm including something to do with debugging in a release build, but I have no idea how I can track it down.

If you want to see it in action the plugin can be installed from http://www.buildingtogo.com/yecho/torque/dual.html

It also only happens in Firefox.  It doesn't IE doesn't crash (Or at least it never reports it).
LVL 5
GENTPAsked:
Who is Participating?
 
jkrCommented:
>>The problem is the crash only happens on machines which don't have Visual studio installed on so I can't
>>exactly trace through the code.

Run the Dependency Walker (www.dependencywalker.com) in "Profile" mode, the logfile that is created will already reveal a lot of issues. Apart from that install an exception filter in your plugin and check what's going on. If you have the faulting address (RVA) and a map file (generated when linking your plugin), you can find the faulting function using the following method:

Consider

#include <windows.h>
#include <stddef.h>
#include <stdio.h>

LONG
WINAPI
ExceptionHandler(LPEXCEPTION_POINTERS pe) {

    char acModule[MAX_PATH];

    MEMORY_BASIC_INFORMATION mbi;
    HMODULE hMod;

    VirtualQuery (pe->ExceptionRecord->ExceptionAddress,&mbi,sizeof(mbi));

    ptrdiff_t RVA = (char*)pe->ExceptionRecord->ExceptionAddress - (char*)mbi.AllocationBase;

    hMod = (HMODULE) mbi.AllocationBase;

    GetModuleFileName(hMod,acModule,sizeof (acModule));

    printf( "Detected Exception in %s at RVA 0x%08X\n", acModule, RVA);

    return EXCEPTION_EXECUTE_HANDLER;
}

void FaultingFunction () {

    LONG* p = NULL;
    *p = 42;
}

void main(){

    SetUnhandledExceptionFilter (ExceptionHandler);
    FaultingFunction ();
}

(compiled with "cl rvaxcept.cpp /link /map")

which prints

Detected Exception in C:\tmp\cc\rvaxcept.exe at RVA 0x00001088

The map file is

rvaxcept

Timestamp is 44660958 (Sat May 13 18:29:12 2006)

Preferred load address is 00400000

Start         Length     Name                   Class
0001:00000000 00004938H .text                   CODE
[...]

 Address         Publics by Value              Rva+Base     Lib:Object

0001:00000000       _ExceptionHandler@4        00401000 f   rvaxcept.obj
0001:0000007a       _FaultingFunction          0040107a f   rvaxcept.obj
0001:00000092       _main                      00401092 f   rvaxcept.obj
0001:000000a7       _printf                    004010a7 f   LIBC:printf.obj
0001:000000d8       _mainCRTStartup            004010d8 f   LIBC:crt0.obj
0001:000001b7       __amsg_exit                004011b7 f   LIBC:crt0.obj
[...]

You can see the 'Rva+Base' column, base is given as 'Preferred load address is 00400000'

Add that to the faulting module RVA of 0x00001088 and you get 0x00401088, then look that up in the above (i.e. the 'nearest symbol' and you can see that it is 'FaultingFunction'

0001:0000007a       _FaultingFunction          0040107a f   rvaxcept.obj
0001:00000092       _main                      00401092 f   rvaxcept.obj

The address is between main and FaultingFunction, which starts before 0x00401088, the next function is main and starts later.
0
 
mrwad99Commented:
>> The problem is the crash only happens on machines which don't have Visual studio installed on so I can't exactly trace through the code

That means that your plugin has some dependency that is only resolved when VS is installed, like MSVC71.dll for example.  I suggest you check out the dependencies with depends (check out depends.exe, it ships with VS) of your plugin, and see where that leads you to.

HTH
0
 
GENTPAuthor Commented:
is depends.exe included in 2003.net or is it just in 2005?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
GENTPAuthor Commented:
I can't seem to run the profiler because the plugin is a dll and not an executable.  I've got it up but I don't understand the program well enough to figure out whats going on.  The only thing that really showed up was msjava.dll which in their faq says happens and it doesn't matter.  I also exported the data on the machine that crashes and the machine that works and only 2 dates on dll's are different.  Everything else is the same.

As for adding this faulting function code I'm not really understanding it.  Do I actually create the faultingfunction or is that just an example that causes a crash of some sort?

I'm also having a problem compiling it.  Probably because the initialization functions of the plugin are in a class not like an executables main function. At least I THINK thats the problem.  Maybe you can tell me otherwise:
 
C:\Projects\tge14\TGE14Plugin\engine\np3DPlugin\plugin.cpp(159): error C2664: 'SetUnhandledExceptionFilter' : cannot convert parameter 1 from 'LONG (LPEXCEPTION_POINTERS)' to 'LPTOP_LEVEL_EXCEPTION_FILTER'
        None of the functions with this name in scope match the target type

The plugin starts off in this class:
class nsPluginInstance : public nsPluginInstanceBase
{
public:
   nsPluginInstance(NPP aInstance);
   ~nsPluginInstance();

   NPBool init(NPWindow* aWindow);

I tried to put that one line in init().
0
 
GENTPAuthor Commented:
Nevermind the compile problem.  I got it to work.
0
 
jkrCommented:
>>I can't seem to run the profiler because the plugin is a dll and not an executable.

Err, you should profile Firefox ;o)

BTW, the exception filter cannot be a class method unless it is static. Just copy&paste it from the above.
0
 
GENTPAuthor Commented:
Okay I ran Dependency walker on the plugin and put the results up here http://www.buildingtogo.com/yecho/exit.zip
The txt file in the zip is everything in the shutdown code.  It crashes somewhere in there, but I don't see anything.  the .dwi is the Dep. walker file for the process.  I'm not sure if that has any useful information in it though.


As for the code, I have it compiling but I can't find the option in visual studio which enables the /link command.  I found the /map commands and I think I set that part up properly.  I'm just fuzzy as to what else I need to do to get a result out of the function.

Generate Debug Info: No

Generate Map File: Yes (/MAP)
Map File Name: mappitymap.map
Map Exports: Yes (/MAPINFO:EXPORTS)
Map Lines: Yes (/MAPINFO:LINES)

What else do I have to set if anything?
0
 
jkrCommented:
The link settings seem OK. What you should do is output the results accordingly (FF has no console, so the 'printf()' won't help, e.g.

LONG
WINAPI
ExceptionHandler(LPEXCEPTION_POINTERS pe) {

    char acModule[MAX_PATH];

    MEMORY_BASIC_INFORMATION mbi;
    HMODULE hMod;

    VirtualQuery (pe->ExceptionRecord->ExceptionAddress,&mbi,sizeof(mbi));

    ptrdiff_t RVA = (char*)pe->ExceptionRecord->ExceptionAddress - (char*)mbi.AllocationBase;

    hMod = (HMODULE) mbi.AllocationBase;

    GetModuleFileName(hMod,acModule,sizeof (acModule));

    char buf[1024];

    wsprintf( buf,"Detected Exception 0x%8.8x in %s at RVA 0x%08X\n", pe->ExceptionRecord.ExceptionCode,acModule, RVA);

    OutputDebugString(buf);

    return EXCEPTION_EXECUTE_HANDLER;
}

and check the results using e.g. DebugView (http://www.sysinternals.com/Utilities/DebugView.html)

The other log file does not even indicate that there was a crash.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.