When working with strace for system call tracing, you might encounter output like this:
strace -e trace=write ls 2>&1 | tee output.log
The output strings are often truncated, making it difficult to analyze complete arguments passed to system calls. This is particularly problematic when debugging applications that handle long strings.
The solution lies in strace's -s (string size) parameter. By default, strace limits string output to 32 characters. You can increase this limit using:
strace -s 256 foo.exe | tee foo.log
This tells strace to display up to 256 characters for string arguments. For extremely long strings, you might want to set an even higher value:
strace -s 1024 ./your_program
Let's examine two scenarios:
1. Basic file operation tracing:
strace -s 512 -e trace=open,read,write cat /path/to/long_filename.txt
2. Network-related calls with full URLs:
strace -s 1024 -e trace=connect curl https://example.com/very/long/url/path
For comprehensive debugging, combine -s with other strace options:
strace -s 1024 -tt -T -o full_trace.log ./your_application
Where:
- -tt provides microsecond timestamps
- -T shows time spent in each call
- -o writes to a file
When dealing with non-string data, consider using -x for hex output:
strace -s 256 -x -e trace=read,write ./binary_processor
This combination gives you both string context and raw hexadecimal representation.
When using strace to debug programs, you might notice that string outputs get truncated:
strace -e trace=read ./myprogram | tee output.log
This typically shows something like:
read(3, "short string...", 1024) = 1024
The truncation occurs because strace has a default limit on how much string content it will display. This is meant to prevent extremely long strings from making the output unreadable.
To control the string length display, use the -s
parameter:
strace -s 512 ./myprogram # Shows first 512 characters of strings
strace -s 1024 ./myprogram # Shows first 1024 characters
strace -s 99999 ./myprogram # Shows (almost) complete strings
For comprehensive debugging, combine with other useful strace options:
strace -s 99999 -f -v -o debug.log ./myprogram
Where:
-f
follows child processes
-v
provides verbose output
-o
writes to a file
When debugging a web server reading configuration files:
strace -s 2048 -e trace=open,read -p $(pgrep nginx) 2>&1 | tee nginx_debug.log
This will show complete file paths and configuration file contents being read.
For frequent use, create an alias in your shell configuration:
alias fullstrace='strace -s 99999 -f -v'
Then simply use:
fullstrace ./myprogram
How to Increase String Output Width in strace for Better Debugging
2 views