C/C++ Cross Reference Utilities - Recommendation 
Author Message
 C/C++ Cross Reference Utilities - Recommendation

I know MS Visual C does a good job of allow you to see where
vars and functions are defined.

There are times when you are reviewing code the old fashion way
via a printout, that it would be useful to have a list of :
- Who calls function X
- What functions function X calls

2 different approaches would be good.
Purely at a source level; and seperately at an .exe or .dll
level so that you can establish which library a function may be in
which is not in your source code.

[The background is trying to bug fix in lots of different
heritage code devices which i have never coded or seen before]

I have serached the public domain and can't see a lot of stuff out there.
Any recommendations ?

Thanks in advance

Greg Roberts (Ext: 7109)

Citect Senior Device Driver Developer
Ci Technologies Pty Ltd

Phone: +61 2 9855 1000
Fax: +61 2 9488 9164
Web: http://www.*-*-*.com/



Sun, 17 Nov 2002 03:00:00 GMT  
 C/C++ Cross Reference Utilities - Recommendation

Quote:

> I know MS Visual C does a good job of allow you to see where
> vars and functions are defined.

As much as I hate to admit it, I agree with you.  MSVC++'s debugging and
other utilities are quite good.

Quote:
> There are times when you are reviewing code the old fashion way
> via a printout, that it would be useful to have a list of :
> - Who calls function X
> - What functions function X calls

> 2 different approaches would be good.
> Purely at a source level; and seperately at an .exe or .dll
> level so that you can establish which library a function may be in
> which is not in your source code.

I have done the following once and it worked relatively well, although
is definitely *NOT* suitable for production code.  (I did it for fun
more than anything.)  Note that it won't work with code that is
precompiled (such as anything that you #include from the standard
headers.)

<warning: just a hack!!>
1) make a global var called spaces, initialize it to 0 and make it
available to all of your functions.
2) write 2 small functions like so:
void starting(char *func_name) {
  int i;

  for (i = 0; i < spaces; i++)
    putchar(' ');
    /* too lazy to look up how to do this in the printf (instead of the
       for loop), but it is quite easily done -- just can't remember my
       specifiers */
  printf("->%s\n", func_name);
  spaces++;
  return;

Quote:
}

and
void ending(char *func_name) {
  int i;

  for (i = 0; i < spaces; i++)
    putchar(' ');
  printf("<-%s\n", func_name);
  spaces--;
  return;

Quote:
}

Call starting() from the beginning of each function with the function
name as an argument.  Similarly, call ending() at the end of every
function.
This is a quick hack and annoying to implement, although it can be
automated quite easily.  (I did it by letting Perl read in the header
files' prototypes -- comments are fairly easily taken care of if not too
obfuscated -- and then searching for them within the .c files.
Inserting at the right spot wasn't particularly hard either, but
depended on my programming style always leaving a blank line between
variables' declarations and the beginning of the actual code or a blank
line between the function's opening brace and the code if no
decalarations were needed.  Also, contrary to the code I posted above, I
always use { and } for any type of loop or if clauses -- otherwise you
could have problems placing these just before your returns.  And this
brings me to my last point: if a functions returns nothing (i.e. void
foo() ), I still always have a return; from it.)

I have no clue how to do this for .exes or for .dlls.  I don't even
think that it is possible, but I may be wrong.

Quote:
> [The background is trying to bug fix in lots of different
> heritage code devices which i have never coded or seen before]

I'm happy that I'm not in your shoes!  :-)

Quote:
> I have serached the public domain and can't see a lot of stuff out
> there.  Any recommendations ?

My method works, although I'm sure that there are much more elegant ways
of implementing this.

Cheers,
Selim
--
"Although personally I am quite content with existing explosives, I feel
we must not stand in the way of improvement."
- Sir Winston Churchill, from "The Second World War" in reference to the
possibility of making a nuclear bomb



Sun, 17 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Cross Reference Utility for C Source?

2. Cross Reference Utility for C Source?

3. Need: ANSI cxref (cross-reference utility)

4. Newbie: separate big .cs file into small .cs files

5. Reference.cs Generated with Parameters Reversed

6. C/C++ cross reference tool

7. Cross reference tools for C/C++ under Unix

8. Need C++ text for non cs major course

9. C# Reference Book Recommendation?

10. Recommendations on compiling options references

11. Reference book recommendations?

12. Cross-referencing classes

 

 
Powered by phpBB® Forum Software