EKI
EKI

Reputation: 866

How can I investigate the source of an Access Violation that occurs on launching the app?

I´m new to C++ programing. I am compiling a Windows Application which compiles ok with just a few warnings, but when I launch it, it doesn´t even seem to start and returns an Access Violation 3 seconds into the run. When I try to debug it doesn´t even seem to get into the code, so I don´t know where to start looking for the problem.

Here is the info I have been able to retrieve from the debugger:

Building to ensure sources are up-to-date
Build succeeded
Selecting target: 
Debug
Adding source dir: C:\Documents and Settings\Christian Ekiza\Mis documentos\My Dropbox\Private Files\coding\juego_pruebas_01\juego_pruebas_01\
Adding source dir: C:\Documents and Settings\Christian Ekiza\Mis documentos\My Dropbox\Private Files\coding\juego_pruebas_01\juego_pruebas_01\
Adding file: bin\Debug\juego_pruebas_01.exe
Starting debugger: 
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 6.8
Child process PID: 3328
Program received signal SIGSEGV, Segmentation fault.
In ?? () ()

and this is from the Call Stack

#0 00000000 0x000154e4 in ??() (??:??)
#1 00409198 __cmshared_create_or_grab() (../../../../gcc-4.4.1/libgcc/../gcc/config/i386/cygming-shared-data.c:140)
#2 00000000 0x0040131b in __gcc_register_frame() (??:??)
#3 00000000 0x0040a09b in register_frame_ctor() (??:??)
#4 00000000 0x00408f42 in __do_global_ctors() (??:??)
#5 00000000 0x00401095 in __mingw_CRTStartup() (??:??)
#6 00000000 0x00401148 in mainCRTStartup() (??:??)

And the CPU Registers end with a

'gs' register with a hex value '0x0'

I don't really know where to start looking for the problem. Anyone can help me out or point me in the right direction?

Note: I am using Code::Blocks

Upvotes: 3

Views: 1301

Answers (5)

Mark B
Mark B

Reputation: 96311

Did you you compile with debug mode (-g) enabled?

Also seriously consider actually fixing the warnings. Most of the time they are actual problems in the code that should be resolved.

You should also try to see if this happens with a nearly empty main (comment out most/all of your code in main).

Upvotes: 0

Morten Fjeldstad
Morten Fjeldstad

Reputation: 913

Sounds to me like one of your DLL dependencies can't be loaded or instantiated correctly.

Upvotes: 0

ttt
ttt

Reputation: 184

Try the following free MS tools - both are great for debugging this kind of problem.

Upvotes: 0

Chubsdad
Chubsdad

Reputation: 25537

As you say it is a Windows application. Then, any issues with startup, I have found ADPlus very useful.

EDIT 2:

You may also check User Mode Process Dumper if ADPlus does not apply

Upvotes: 1

Fazi
Fazi

Reputation: 11

See, if you have some global instance(s) of class with constructor - if error is raised in constructor and class is declared globally (bad thing to do btw) - you'll get sigsegv even before main(). If you have such classes - try to refactor your code to have them inside main (or other function) - it will be easier to debug.

Upvotes: 0

Related Questions