How to determine if a function is using a system call

I am learning about system calls and starting to understand them. I understand that you shouldn't call them directly (as this makes your code less portable) and you should call the API instead. However, is there a way to determine if a particular function is using a system call? I read that not all functions require system calls (some library functions). For example fopen will end up using a system call. My questions:

  • Is cin (c ++) function required for system call

  • Is there a way to find out if a function is using a system call?

+3


source to share


1 answer


GDB has a "break on syscall" feature. See https://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html

So, the strategy, if you're new to debugging tools, is to set a catch point and step down the line that calls the function ("next" in gdb). If it breaks before it reaches the line after the function call, then a system call has occurred (or the program crashed, I suppose).



When you read the input using cin >> ...

, syscall may or may not be called. It depends on whether there is already enough data in the buffer. If there is not enough data in the buffer, a syscall must be performed to retrieve data from the main file or device.

The C ++ language does not provide an easy built-in way to statically determine whether a function can make a system call. In fact, a function foo

can call some function extern

bar

that will be compiled separately (in a different translation unit), which calls a system call; the fact that foo

can indirectly cause a system call cannot be known until reference time.

+3


source







All Articles