1

Background and context: I am doing a small project on Chromium and I am working on a function that compiles the JS code which is received as a parameter.

I was able to take the type with the JS code and create from it a C++ string (or C char*) with the code.

The problem I am facing is creating something of the original type that had the JS code within it, I have searched in the Chromium files for a line that create this type and I didn't find one that takes code (as char* or string) and creates that type with the code - like the parameter that the function is receiving.

What I am looking for: In order to gain a better understanding as to how originally this function receives this parameter (so I will be able to create it myself) I am looking for a tool for C/C++ that can tell me for a given function, or a parameter for a given function, who passed this parameter, who passed it to the one that passed it to the function (and so forth) and finally who created it (preferably what line in the code)

Does anyone know such a tool ? any help is greatly appreciated!

Belgi
  • 14,542
  • 22
  • 58
  • 68
  • There are probably better tags than the ones I used (but I am unfamiliar with most tags). If someone believes there are better tags please feel free to edit accordingly – Belgi Mar 23 '13 at 09:33

5 Answers5

1

You can wrap your function with a macro that can help extracting the caller. E.g., if originally you have function signature void foo(int param1, int param2);, you can instead define:

#define foo(param1, param2) fooEx(param1, param2, __FUNCTION__)
void fooEx(int param1, int param2, const char* caller);

Now inside your original function you know the calling function, so you can do whatever you want with it, e.g. print. Your original interface remains unchanged so no changes are required from the calling party.

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85
0

At least one 'draft' idea is to use GNU debugger (gdb) with break points and stack trace. Probably with conditions check. Also ability to attach to running process should be useful in this case. Could you please explain more details if I did not understand your questions well?

Roman Nikitchenko
  • 12,800
  • 7
  • 74
  • 110
0

For more insight you can use valgrind (http://en.wikipedia.org/wiki/Valgrind). This will help you with debugging, memory-leak detection and profiling (which will tell you what called this function with what parameters) of your C/C++ code.

Prahlad Yeri
  • 3,567
  • 4
  • 25
  • 55
0

I'm not sure, if I understand the question correctly, but it seems that you need information about the call graph for the function, i.e. the information which function called your function, by which function this one was called and so on.

Here, you have basically two options: either use the debugger, set a breakpoint to your function and display the call graph dynamically (most debuggers have this functionality). Or you use a static code analysis tool (google will help you with this, I found this (closed) question for example).

Note that this will not always directly tell you, "where the parameter" came from: every function in the call graph can somehow manipulate the data, so you still have to look at every piece of code handling the data.

Community
  • 1
  • 1
MartinStettner
  • 28,719
  • 15
  • 79
  • 106
0

A competent IDE (I know Visual Studio does this, so others should be available as well) should be able to show you the statically known incoming calls to a function. Hopefully there aren't that many, and you can work your way backwards from there.

If that doesn't work out (ie you don't have an IDE which handles this, or there are prohibitably many callers) you're probably stuck with a debugger and breakpoints to examine the call stack.

carlpett
  • 12,203
  • 5
  • 48
  • 82