debugger tracer [anti-crash system]

Hi all,

Well, I dont know if it is the best place to talk about this... but...

I am developing one program that process texts, with a plugin system, and I need to make some type of anti-crash system in the plugin system...
Well, this anti-crash system for what I researched, is a type of automatic debugger/tracer [I am not sure]. The goal of it is keep the information of the last processed text line [and also many other useful information] in a case of a bug happen and crash the plugin it will write in a log the last line processed and any other useful information [that supposedly will help me to find and fix the bug in the plugin] and later it will just simple close the plugin [it means that it will clean the space on memory that the plugin and the text was loaded] and/or re-start it without crash the whole environment [IDE]...

The problem is that I dont have the lesser idea on how I can do this type of task, and I dont found any program that can do something similar, or even opensource programs... so... any one have any idea?

Ahh, someone said to me to use SEH, but for my researches, it cant help me much with all types of bugs that can happen, or, the SEH documentations I saw is not reliable...

Any extra information will help me, for example:
*anything that can help me create my anti-crash system [I mean, docs, pdf's, or any other form of documentation, books];
*information about any type of debugger/tracer that can do this type of task, if possible, need to be opensource to me integrate in my system;
*anything about a plugin system and/or with some type of anti-crash system or some type of anti-crash protection;
*any one that have some codes related with a plugin system, or anti-crash system, or debugger/tracer and want share it to me, are all welcome;
*any other alternative that can solve my problem is also welcome.

Thanks.
Best regards.

Last edited on
I think your goal is poorly defined.
What kind of errors are you trying to prevent? Syntax errors? Internal errors caused by malfunctioning code (e.g. something equivalent to *((int*)0)=1)?
This type of detection will depend heavily on your design, but usually syntax errors are caught at a higher level, and they're not necessarily fatal. While prevention of serious errors -- the kind that can crash the entire program, rather than just the plugin -- are detected much deeper. For example, you wouldn't be able to know whether a call to a user-level API function will fail because a file can't be found until your code has made the call to std::fstream::open(), which will most likely happen at the highest point of the call stack.
Well, sure, I forgot to define better the goal.

My project is mixed, I am building the IDE with Visual C++ and some interface builders to speed up the IDE development, to make the whole task more easy. By the way, I am doing all the things to enable the plugins to be done in any type of language [delphi, c, c++, asm, etc...].

So, the goal here is only to catch fatal errors that can happen only inside the plugins, since that is not that easy to prevent the IDE crash without some kind of low level API anti-crash system that will need to "watch" the program all the time [just a thought :-)].

So, the basic idea is, I will keep a snapshot of the text, and will send the text to the plugin, and here at this point I will need to have some type of system to prevent any crash in case of a fatal error, and it will take any information that can be useful to fix the bug, so, will be done a snapshot of data in registers, the used buffers, last line processed in text, or anything that can be useful [I dont have any idea about what more can be useful], if possible it need to try to identify what type of bug happened [wild pointer, null pointer or any other...], those data will be written in a log, the "anti-crash system" will clean the memory space used by the plugin, there will be an option to re-start the plugin with the "last" good snapshot of the text, or shut it down and jump to the next plugin [if there is any].

It is just some ideas I have to this system, but, I am open to new ideas and better opinions to implement this. I dont care to modify the design of my IDE/Project to implement this. I want to implement the anti-crash system at any cost.

Well, to specify better my project, the IDE is just the interface alone, to process the texts will be used external modules [plugins], and is supposed that these plugins will dont use many functions from windows API, but, in some special cases that will be used any API from windows, the anti-crash system will try to use the function GetLastError to try catch any information about the crash from Windows. Also, there will be any other plugins that will not be related to processing texts, so, in such cases, I will dont need to know the last processed line in the text [:-)]. It depends about the purpose of the plugin, but my main problem is with plugins to process texts.
Last edited on
If your loading plugins at runtime. Then your best bet is to encapsulate all calls that would goto a plugin with exception handling.
Hi,

Yes, good.
I am loading the plugins at runtime using LoadLibrary API.
Well, I thought in this possibility you said Zaita, but.... it would work? Since I need to take the "last" state of registers before crash, I am not sure if it would work, because I need to take many internal info about the crash [last text line processed, state of registers, type of error that happened, etc...]. Just using SEH encapsulating the calls seems not good enough... Also, is SEH compatible with LoadLibrary [I mean, this API will dont destruct important infos about the errors, etc]? There is nothing better to do?
Last edited on
What your asking is an extremely difficult task. I'd suggest looking at profiling applications that are open source and emulating them. I think one is called Vanguard. I've only used commercial ones.
Vanguard
*Valgrind
Thanks very much,
I know that it is complex, but if you saw my first post, I said...
...Any extra information will help me, for example:....


Well, Valgrind seems to be really good, I found that many other systems uses it to catch bugs.... and also, to watch what happen in the program... The technique used in it is the same used in VMs, the binary translation.
By the way, have some disadvantages:
-Excessive processing, lost is performance, uses a lot more memory;
-The whole thing is about 5Mb[compressed];
-And, it is just for linux, so, not good for me since my project is just for windows.

I saw that there is one project that is based on Valgrind see it... http://groups.csail.mit.edu/pag/daikon/
Dynamic invariant detection runs a program, observes the values that the program computes, and then reports properties that were true over the observed executions.


By the way, for what I know, the right term for this program is a type of debugger called: tracer, watcher or logger.
Maybe there is some other name that I dont know for this type of tool.

One other problem is that Daikon is 30Mb sized [compressed]. It is java based, so , to run it will need the JVM [more few MB...]. And, to "test" programs is necessary to have one front-end for each language used [more few MB...], and the front-end for C/C++ for windows uses the IBM Rational Purify [so, I will need a license for it, and it is some more MB. :-(]. And it also have few support for windows.

At the moment, no one seems to be good to use in my project, it is sad. :-(
Last edited on
To be perfectly honest with you, that's not the sort of application development someone would normally do as a project. Unless it was being funded by a commercial venture and you had a huge amount of capital to hire developers to focus full-time effort on then it's unlikely your going to find alot of useful assistance.

There are many commercial applications that already do what your trying to do (I for example use AQTime for Windows). These come with a hefty price tag, but in comparison to writing your own it's a bargain. These applications also do alot more, such as monitor memory allocation and de-allocation to find leaks, do static analysis to inform you of platform compatibility etc and do performance profiles of the runtime.

A basic rundown of how you can do it:
http://www.cpptalk.net/how-does-sampling-profiler-work-vt43931.html

You should check out some open source debuggers as a first step:
http://www.ollydbg.de/
http://osdir.com/ml/hardware.microcontrollers.hc12/2006-03/msg00115.html
GDB (Works on both Windows and Linux)
http://www.gnu.org/software/ddd/


Thanks very much again,
But my project is opensource.... I am developing it with some few guys, and the complete plugin system [including the anti-crash system] is what I need to do... most of it alone... :-(
My project does not have a public release yet, and will not be released until the first functional stable version.
Last edited on
The problem with the method your trying to do is that using the LoadLibrary function your forcing the library to conform to a function interface of your own. In that case, it's really upto the developer of the plugin to ensure it's stable. You can try to use exception handling, but it'd be worth testing if this would propagate from a library back to your code @ runtime.
Hummm, right...

I am only using LoadLibrary because some types of plugins [depending what language was used to create the plugin] dont load directly, I dont know why, but they load fine with LoadLibrary. But I think I can create one way that will only use LoadLibrary only in cases that the plugin cant load directly...

If I leave the LoadLibrary, what do you recommend?

I will do some tests with SEH with and without using the LoadLibrary. But my doubts about SEH was exactly what you said, about the propagation from the lib to my code....
...but it'd be worth testing if this would propagate from a library back to your code @ runtime

But I think SEH only can be used to recover from a crash... I will need to implement something more to find the infos I need...
...snapshot of data in registers, the used buffers, last line processed in text, or anything that can be useful [I dont have any idea about what more can be useful], if possible it need to try to identify what type of bug happened [wild pointer, null pointer or any other...]...


Thanks...
Best regards...
Then using load library isn't your best bet. You need to develop a debugger or a virtual machine to run the code in.
Topic archived. No new replies allowed.