Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 349 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add print statements in every function in c files right programmatically?

#1
I am working on embedded code and for now totally reliant on prints from within functions to figure out the flow of execution (there is no stack trace functionality available).

It often happens that I put a bunch of print statements, build my code and run it only to realize I should've put prints in a dozen other places too. And then start the hour long process again.

Is there an easy way to take my 5 or 6 c files that I want to analyze and run some tool that will go in and add a print statement in each function? (this will obviously have to be after the variable declarations as this is in C)

Even better would be to have a print each time there is an if/ else or switch/ case ..basically any conditional statements.
Reply

#2
For only 5-6 files I would manually go in and add a PRINT("name of function") macro in each function and then define that to either output the string, or nothing

You could use ctags to analyse the files and build this automatically but unless you have 100s of files it would be quicker to just do it by hand
Reply

#3
You don't state the compiler you are using, but gcc has a very handy switch:

-finstrument-functions

which inserts a special call at each function entry and exit. You could compile only the relevant files with this tweak, no need to modify the source code.

The calls are made to two functions you should create:

void __cyg_profile_func_enter (void *this_fn,
void *call_site);
void __cyg_profile_func_exit (void *this_fn,
void *call_site);

Etrace is a tool designed for exploiting this to create call traces, see

[To see links please register here]

Reply

#4
If vim is your favourite editor you can install this plugin:

[To see links please register here]

and customize the related template. Can be useful for a lot of differents tasks. (It works for the new functions that you will define, that is not your case but might be useful for future use)
Reply

#5
I would recommend you using a debugger, like GBD. That way you can even run your program "step by step" and analyze such conditions. I don't see a reason to print something in every function.
Reply

#6
you can use macros like this

#define begin {printf(__func__##" Started");
#define end printf(__func__##" Ended");}

and then replace all your `{`,`}` with begin and end macros (\_\_func\_\_ is a macro which return function name and is defined in C99 there are also other equvalent macros for other compilers)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through