On Sat, 2008-01-26 at 01:50 +0000, peternilsson42 wrote:
> "Paul Herring" <[EMAIL PROTECTED]> wrote:
> > Christopher Carver <[EMAIL PROTECTED]> wrote:
> > > I have an application where I want to generate unique error
> > > codes depending on the path the code takes (call stack).
>
> Why?
Mainly for problem isolation and dynamic solution resolutions. I run in
an extremely large production environment and in many cases the best
that can be produced is a simple error code that could have been
generated more than a dozen ways, depending on the path the code takes.
How many times do you hear development ask "can you reproduce the
problem?"
If I can get very specific codes I can write the code to take the codes
and then repair or take the appropriate action to handle the cause of
the error.
>
> >
> > [snip]
> >
> > Sounds like what a lot of other tools out there do during
> > development work. Sounds like you want something for
> > production however. Not something I'd advocate. However...
> >
> > Have a global variable, and (re-)hash it every time at the
> > start of a function call (or wherever in your code you want
> > a path to be noted) with either a fixed number or the
> > current line number in that file. The eventual hash should
> > give you some sort of indication of the path taken.
> >
> > static hash_val;
> > void rehash(long l_val){
> > // your hash function here to change hash_val with l_val)
> > }
> >
> > int foo(...){
> > rehash(__LINE__);
> > // body of foo();
> > }
> >
> > float bar(...){
> > rehash(__LINE__);
> > // body of bar();
> > }
> >
> > ... etc.
> >
> > Generating the lookup table will not be fun however.
>
> If you simply want the call stack, then implement a call
> stack. Hash the result when you need it.
>
> Uniquely enumerating traversal paths can produce some
> very large numbers quite quickly, especially if heavy
> recursion is involved. Do you actually need an error
> code (number), or do you simply need to show where the
> code is up to?
>
Very rarely will the code have any recursion. I fixed infinite loop
recursion, because the code checks the calling path and arguments taken.
Once it sees it duplicates itself in the code stack the code bails out
in a safe manner regardless of the depth the code takes. This slows the
code down a bit, but it's worth it not to get stuck in this.
And you are right it can get very large, like I mentioned already. Hence
I'm looking for a mathematical solution, not a C data structure
solution.
> --
> Peter
>
>
>
>
>