Sign in to follow this  
Verg

debugging invalid page faults and other nasties (assembler)

Recommended Posts

I'm not real, real familiar with Pentium-based assembler code (last assembly language I used was for the Commodore 64 [grin])... but this thought occurred today... Paranoia exists that as soon as we release a beta version of our app, there will be page faults a-plenty. Am I right to assume that: With a dump of the registers and a couple dozen opcodes, surrounding the "fault" point, you could actually find the corresponding "opcodes" in the same build... and (in that way) trace down where in the high-level code things break? IOW... with that info, you should be able to find the spot in the original code where things broke? --------------- If THAT assumption is correct... then... How might someone 1) log such unforseen calamities as page faults? (attach a separate process? If so, how does that process get signalled that a page fault happened in the main process?) ------------ Seems like this would simplify the debugging process, after beginning beta testing. Thank you for any replies Chad Greetings! [Edited by - Verg on July 10, 2005 6:59:34 PM]

Share this post


Link to post
Share on other sites
Why are page faults calamitous? Are you talking about segmentation faults?

If it's a segmentation fault you're worried about then as long as you run it through a good debugger you'll find the source of the fault easily enough.

Lots of logging can't hurt either, although you might want to use a logging library with variable levels of logging so you can tone it down for the sake of performance (one of the Apache log4* libraries could do the trick.)

What language are you programming in?

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
Page faults aren't bugs, they're a normal part of virtual memory.

What on earth are you on about?!
While they normally aren't bugs they're often still a serious problem and analyzing them can be a useful profiling technique when optimizing your application's data structures.
You might for example decide to load certain data manually (and fall back to something else while waiting for it to become available) instead of halting the entire application while the drive is catching up.

Share this post


Link to post
Share on other sites
just as a by side node you can create a seperate heap for storing your data and you can request the page size with posix so you could layout your data to fit into your pages



i have heard there there are memory management implementations that assign a page to each allocated chunk and at runtime try to find wholes in your address space and copy the allocated chunks/pages into those holes

Share this post


Link to post
Share on other sites
Quote:
Original post by lucky_monkey
Why are page faults calamitous? Are you talking about segmentation faults?

If it's a segmentation fault you're worried about then as long as you run it through a good debugger you'll find the source of the fault easily enough.


This isn't about debugging on a host computer. It's about capturing the information from a user's computer when an invalid page fault happens

Thanks.

[Edited by - Verg on July 10, 2005 7:24:14 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
Page faults aren't bugs, they're a normal part of virtual memory.

What on earth are you on about?!


How about "how to dump the two dozen opcodes surrounding a fault point to a file"?

Does that make more sense to you?

When an abnormal exit occurs, I want to capture the relevant information from the BETA USER's page fault, and find the corresponding opcodes in the .exe on MY OWN MACHINE.

Thanks again.


Chad

Share this post


Link to post
Share on other sites
Quote:
Original post by Verg
When an abnormal exit occurs, I want to capture the relevant information from the BETA USER's page fault, and find the corresponding opcodes in the .exe on MY OWN MACHINE.


taskmgr.exe popped up no less than 295 page faults during the frame (about 1 second in length) it showed after loading, for itself. Page faults occur quite often, whenever the program tries to access memory which has been swapped out to the hard drive. Page faults occur during normal operation. Information about these faults are normally gleaned through profiler tools, on the developers machine(s), not on the client, and are a point for optimization, not debugging.

If you're talking about "invalid page faults", otherwise known as "segmentation faults" (segfault) or "access violations", which occur when the program tries to access memory that it shouldn't, that's a different story.

Considering you're talking about abnormal exits, it's now clear you're probably talking about the later, before it wasn't so clear, which had people confused.

Then again, I'm not positive, because you state:

Quote:
Please re-read the original post.

This isn't about debugging per se. It's about capturing the information when a page fault happens

Thanks.


Trying to locate errors in the program, wheither through information gleaned from process information when the program crashes on a client's computer, or reproducing the problem locally, is debugging, period.

Unfortunately, I havn't any experience with this method of debugging.

Share this post


Link to post
Share on other sites
Ok... my fault... invalid page fault is what I'm talking about. Thanks for the clarification.

....

The "invalid page fault" dialog that pops up on abnormal exits.... does that come from the operating system, or from something built into the .exe file itself? If so, seems it would be possible to place some code before that to trap all the relevant information.

....

Again for clarity's sake (I'm not the best at putting thoughts across on the internet)...

Looking for a way to: dump machine codes (opcodes) surrounding the invalid page fault, as well as the registers, to a file.

Thank you.


Chad

Share this post


Link to post
Share on other sites
Quote:
Original post by Verg
The "invalid page fault" dialog that pops up on abnormal exits.... does that come from the operating system, or from something built into the .exe file itself?


Depends :). I know the OS can and does generate dialogs on this, but I also know it's possible to generate one's own dialog.

On linux, one can set a signal handler for SIGSEGV, which is sent to the application upon a segfault, and have your own cleanup there. I've even reproduced the effect on windows, I believe through the POSIX subsystem. SDL does this to display it's "parachute deployed" message and to clean up DirectX (or X11) resources and the like.

It's possible to get register/memory information, as I've seen programs do so before. How to do it is what I unfortunately don't know. Searching the MSDN seems to turn up bazillions of pages of programs displaying these symptoms, rather than explaining how to debug them. I might look at Mozilla's "Talkback" mechanism, I'm not sure if it deals with invalid page faults, but I know it's used to report errors in the Firefox browser back to the Mozilla servers, automatically.

Share this post


Link to post
Share on other sites
john robbins posted some code taht does what you want. YOu have to set the exception handler. When an unhandled exception happens, your exception handler is called. If you link with his library and set up his stack collection calls then it will create a dump file for you with the stack trace and register contents at the time of the crash.

It works well for us. We even wrote anotehr program that ftp's it to us and allows the user to add notes about what they were doing at the time of the crash.

Cheers
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by chollida1
john robbins posted some code taht does what you want. YOu have to set the exception handler. When an unhandled exception happens, your exception handler is called. If you link with his library and set up his stack collection calls then it will create a dump file for you with the stack trace and register contents at the time of the crash.

It works well for us. We even wrote anotehr program that ftp's it to us and allows the user to add notes about what they were doing at the time of the crash.

Cheers
Chris


Cheers, Chris.

Google has turned up a plethora of information on John Robbins and
SetUnhandledExceptionFilter...

Thanks a million.


Chad

Share this post


Link to post
Share on other sites
If I'd known that you were simply talking about access violations then I would have told you how to set an unhandled exception filter.

You do see where I'm coming from though eh? Try to be more specific when possible.

Just do make sure that you put more effort into preventing and detecting bugs than you do to simply log them if they happen on the users machine. Asserts are your best friend, and UHE filters can be merely the ambulance at the bottom of the cliff.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this