Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplest way to print function called with the arguments that were passed #27

Closed
vadi2 opened this issue May 10, 2022 · 6 comments
Closed

Comments

@vadi2
Copy link

vadi2 commented May 10, 2022

What is the simplest way to print function called with the arguments that were passed? I'm debugging an interface implementation, so I don't have so much control over who is calling me methods; rather I am on the receiving end of them being called.

I can add IC() at the beginning of a function to see its name and arguments, but the argument values themselves aren't printed.

@renatoGarcia
Copy link
Owner

If I understand your question correctly, in a code like:

// ------------ Your code
void my_function(int a, float b)
{
    IC(a, b);
}

// ------------ External code calling your function
int foo = 7;
my_function(foo, 3.14)

You will print the arguments of my_function with IC(a, b). That will print something like:

ic| a: 7, b: 3.14

Unfortunately the variable names used at calling site (foo and 3.14) are not accessible inside of my_function.

@vadi2
Copy link
Author

vadi2 commented May 10, 2022

That does work, but it then doesn't say which function was called unlike IC() by itself. I see that there's a config toggle for prefixing the function called to all output - perhaps that is the best way?

@renatoGarcia
Copy link
Owner

Oh, sure. So you are right. You will need call

icecream::ic.include_context(true);

With that all calls to IC* macros all around the code will print the source name, line number, and function signature.

You gave me a new idea. Maybe a way to print the context along with the values would be nice. Let's say something at the lines of

IC(IC_CTX, foo, bar)
IC_CTX(foo, bar)

Food for thought.

@vadi2
Copy link
Author

vadi2 commented May 10, 2022

Yep, that would be perfect 👍

@vadi2
Copy link
Author

vadi2 commented Jun 19, 2022

Did this end up making it in?

@renatoGarcia
Copy link
Owner

Hi @vadi2. Not yet, but it is on my roadmap. I just need find some free time to put the work on.
I will go with the IC_CTX(...) option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants