Solved

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

Posted on 2006-07-20
8
514 Views
Last Modified: 2013-12-14
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).
0
Comment
Question by:GENTP
  • 4
  • 3
8 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 17148999
>> 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
 
LVL 5

Author Comment

by:GENTP
ID: 17149041
is depends.exe included in 2003.net or is it just in 2005?
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 17149045
>>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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

by:GENTP
ID: 17154072
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
 
LVL 5

Author Comment

by:GENTP
ID: 17154205
Nevermind the compile problem.  I got it to work.
0
 
LVL 86

Expert Comment

by:jkr
ID: 17154241
>>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
 
LVL 5

Author Comment

by:GENTP
ID: 17155679
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
 
LVL 86

Expert Comment

by:jkr
ID: 17156617
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to split this in C++ 4 106
Best book to learn C++ 4 84
How to increment counter variables in ANSI  C (Not C# or C++). 9 18
learn programming 8 34
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question