1

I'm reading Apache httpd source code, I would like to know when a request come, which function get called first, followed by which function, and so on, is there some easy way to do so?

Something like

Waiting client connection...  # a client send a HTTP request
client.c:accept_request() is called
client.c:handle_request() is called
asdf.c:func1() is called
fdsa.c:func2() is called
response.c:send_response() is called
Waiting client connection...
6
  • ehh? Isn't is C code? (you tagged so), and AFAIK, C is process oriented... Commented Aug 1, 2017 at 8:14
  • Please clarify: Do you want to print the call stack at runtime? This isn't possible in standard C. Commented Aug 1, 2017 at 8:15
  • For Linux, there is backtrace() .. compile with debugging symbols for meaningful output. Commented Aug 1, 2017 at 8:22
  • 1
    Possible duplicate of How can one grab a stack trace in C? Commented Aug 1, 2017 at 8:22
  • Can you give an example of the output you want to see? This can probably be done using systemtap. Commented Aug 1, 2017 at 15:00

2 Answers 2

1

Put a printf statement at the beginning of each function

printf("Called function: %s\n", __func__);

This will print the name of the function when that function is called and this way you will able to know the function call sequence.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the only hard way.
1

Not an easy way no, but there are multiple possibilities:

  • if you can run the code then going through it with a debugger or a profiler can help you see what is going on
  • again if you can run the code you can add traces to understand the flow of functions
printf(">>> entering %s\n", __func__);
printf("<<< leaving %s\n", __func__);
  • if you cannot run the code then maybe tools like ctags or cscope can help your see which functions are called when (or an IDE like eclipse or intellij)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.