Log in

View Full Version : Identify an address in the source code


aureliuh
April 27th, 2007, 04:39
Hello to everyone. For a long time I have a problem with debuging my application. Sometimes I get Access Violation and an address. Could anyone tells me if there is any chance to find out the name of the function which generate the access violation or any usefull information to debug my source code?

Thank you very much

Silver
April 27th, 2007, 05:43
If it's your own code, try Numega Devpartner/Boundschecker.

Alternatively, please wait while we reboot JMI...

aureliuh
April 27th, 2007, 06:07
The problem is that the source code are written in borland c++ 6. So I don't think it could help me. Thank you very much anyway. I taught that there is any possibility to include in exe my comments from the source code so I could find the function.

naides
April 27th, 2007, 07:30
Ummhh. . .
You are describing the vane of the debugging world.
Question 1: Is the access violation address always the same? or at least within a narrow range?

Step A: in that case disassemble your app with IDA, search for the address and you may get near the code that generates the exception. IDA will tell you the name of the function.

If the reported address varies wildly with each crash, chances are the code generating the address is located in the heap ie, it belongs to an object that is created on the fly, at runtime.
Those bugs are much more challenging.
What I would do is assign Olly as the "just in time" debugger and when the exception hits, accept the choice of running Olly. Look at the code pattern that generated the error . Then try to locate that code pattern in the disassembly, by going to step A

squidge
April 27th, 2007, 07:52
Surely if it's your own code, then all you need to do is enable debug output, and you'll be able to get an address for each line of source.

In either case, running it in Ollydbg should tell you exactly what it threw an exception, and point to the offending code.

aureliuh
April 27th, 2007, 07:57
Hmmm.. It sounds very good I will try that. But I have another question..maybe very stupid. How do I link the ollydbg to the source codes? Or just see the address where it crashes and then search for it in debugoutput?

Thank you

blabberer
April 27th, 2007, 10:32
Code:


\aureliah>type aureliah.c
#include <stdio.h>

int main (void)

{
long access=0;
printf("hello aureliah\n";
printf("wanna violate access\n";
printf("%x\n",*(long *)access);
printf("the above code violates your access\t Didnt it?\n";
return 0;
}
\aureliah>aureliah


hello aureliah
wanna violate access

\aureliah>



i dont think you could expect anything more than this
yeah im using bcc v6 is clickety click bpl bloat im using free commandline v 5.5

aureliuh
April 27th, 2007, 10:45
Thank you very much for all! It really helped me! You are great! Thanks again

blurcode
April 27th, 2007, 10:56
What you need is http://www.madshi.net/madExceptDescription.htm

LLXX
April 28th, 2007, 01:21
Look at the code around the address, and see if you can figure out what it's doing (find anything distinctive, like some constants you recognise, etc.) API calls are usually a good place to correlate between the source and the Asm. If all else fails embed variable assignments with unique values like this:
Code:
a = 0xdeadbeef;
...
a = 0xcafebabe;
...and look for those in the Asm.

Also, compilers tend to generate code in the order the source file describes. If the exception occurs at an address near the end of the program, then look at the end of the source, and vice versa.

squidge
April 28th, 2007, 04:08
for stuff like that, I normally ask the compiler to embed assembler and use some distinctive opcodes, such as "or al, al; nop; or al, al". These can be easily searched for by a debugger. The usual reason for this is when I'm trying to figure out and optimise the assembler output of the compiler (and the built in one is usually complete crap compared to the likes of Ollydbg)

omega_red
April 28th, 2007, 09:09
Options - linker - generate MAP file