31
votes
Accepted
Any way to have a "verbose mode" or "debug mode" with sed?
As fra-san mentioned, GNU sed introduced a --debug option which does pretty much what you’re looking for, in version 4.6; so e.g if you run:
printf '%s\n' one two | sed --debug 'H;1h;$x;$s/\n/_/g'
...
29
votes
How to passively capture from Unix domain sockets (AF_UNIX socket monitoring)?
I wrote a tool to capture and dump unix domain socket traffic. It uses bpf/kprobe to probe kernel function unix_stream_sendmsg and dump traffic to user space.
The tool depends on bcc, so you need to ...
23
votes
How can I make cron run a job right now (for testing/debugging), without changing the schedule?
CronitorCLI has a command cronitor select that lets you select and run any cron job from the command line. You do not need to create a Cronitor account to use it.
https://cronitor.io/docs/using-...
23
votes
Accepted
set -eux instead set -x in Bash profile for global debugging
This is a matter of opinion, but I think set -eu is a bad idea for interactive use. Here’s what each one does:
set -e causes the shell to exit whenever a pipeline, list, or compound command exits with ...
22
votes
Accepted
function's calling context in zsh: equivalent of bash `caller`
I don't think there's a builtin command equivalent, but some combination of these four variables from the zsh/Parameter module can be used:
funcfiletrace
This array contains the absolute line ...
21
votes
How to compile without optimizations -O0 using CMake
At invocation time, normally all that you need to make a debug build with CMake is:
cmake -DCMAKE_BUILD_TYPE=Debug ..
Doing that adds the -g flag as can be confirmed with:
make VERBOSE=1
which shows ...
18
votes
debugging zsh completion method
Press ^X? (Ctrl+X ?) instead of Tab to run _complete_debug. This places a trace of the completion code into a file which you can view by pressing Up Enter.
Alternatively, if you want to generate a ...
16
votes
Accepted
What is `bash -x`
-x is the same as setting xtrace with the -o option to bash. From my copy of the bash manpage:
After expanding each simple command, for command, case command, select command, or arithmetic for ...
16
votes
Change format of syscall event trace output to ftrace
Unfortunately, there is currently not a way to do this. But perhaps in the future I may add it, if I can figure out a sane interface and implementation to do such a thing. Maybe I will add a trigger ...
15
votes
Accepted
How to know the code flow of a driver module?
When I want to do this, I use the ftrace framework. Start by mounting the special file system:
mount -t tracefs nodev /sys/kernel/tracing
(as root; you should become root for all this, you’ll be ...
15
votes
Temporarily unset bash option -x
You can achieve this in Bash by not using set -x and instead trapping DEBUG and doing your own tracing:
#!/bin/bash
set -T
trap '! [[ "$BASH_COMMAND" =~ ^(echo|printf) ]] &&
...
13
votes
Accepted
ACPI BIOS Error / AE_NOT_FOUND
Your hardware is too new sort of speak.
The bugs you are seeing are harmless and may persist for some time.
You could try upgrading your BIOS, that is utmost priority.
Then, you could try ...
13
votes
Accepted
Is there a command line program to check IP location (for VPN)?
You can use ipinfo.io or ipstack.com services through curl:
curl --silent "https://ipinfo.io/ip"
similarly change ip to country to get your geographical location.
11
votes
How can I get glibc/libstdc++ sources and set them up for gdb to find?
The simplest way is to extract the package source code somewhere: go to an appropriate directory, then run
apt source glibc
In gdb, add the corresponding directory to the source path by using the ...
10
votes
How to change the console_loglevel in linux?
Moved comment to answer.
You must leave a space between a number and > or the shell will redirect that file descriptor. Use
echo 5 >/proc/sys/kernel/printk
Or
dmesg -n 5
Community wiki
10
votes
Accepted
Temporarily unset bash option -x
This is a horrible kluge, and I feel dirty for suggesting it, but... you could do this with a magic alias. The key to this trick is that aliases are expanded as part of the parsing phase of command ...
9
votes
How to step-into, step-over and step-out with GDB?
Use command 'finish'; this sometimes does the same thing as 'step-out'. It'll finish what the stack is doing (a function, usually), and go to the next line after that. Look up the command for more ...
9
votes
How to know where a program is stuck in linux?
You want eu-stack from elfutils. For example,
$ sudo eu-stack -id -p $$
PID 9189 - process
TID 9189:
#0 0x00007fd36c69e687 __GI___waitpid
#1 0x000055ba004c0c19
#2 0x000055ba004c234b wait_for
#3 ...
9
votes
Accepted
Kernel: BUG: unable to handle page fault for address
[79648.067306] BUG: unable to handle page fault for address: 0000000004000034
[79648.067315] #PF: supervisor read access in kernel mode
[79648.067318] #PF: error_code(0x0000) - not-present page
These ...
9
votes
Accepted
Tool to detect errors in application's execution logic
forgot to call free() on address returned by malloc()
Well, malloc and free aren't kernel calls! What malloc() (which is a libc library function, normal user process code!) does
look up in the ...
8
votes
Accepted
How did `git pull` eat my homework?
Yes, git ate my homework. All of it.
I made a dd image of this disk after the incident and messed around with it later. Reconstructing the series of events from system logs, I deduce what happened ...
8
votes
Debugging boot performance issues in grub / before kernel logging starts
This is certainly not a full answer to my own question but might be useful for others landing here while investigating similar issues.
The GRUB manual suggests to use the debug environment variable, ...
7
votes
How can I make cron run a job right now (for testing/debugging), without changing the schedule?
After having the need myself to debug cron jobs,
I wrote the following script.
It tries hard to simulate the exact same conditions as cron
before running a command (that includes a modified ...
7
votes
Accepted
Why some libraries and other parts get repeated in the linux virtual memory with gdb?
There’s one important piece of information missing from gdb’s output: the pages’ permissions. (They’re shown on Solaris and FreeBSD, but not on Linux.) You can see those by looking at /proc/<pid>...
7
votes
Accepted
Who is eating data? Xargs?
To see whether xargs makes a difference, run the command lines that it runs. Here are a couple of ways to see exactly what it runs, while not risking changing what it runs:
Write a script called php ...
7
votes
How to debug/trace bash function?
Just add these line before section you want to debug.
set -v -x -e
and to disable it.
set +v +x +e
7
votes
Accepted
alias using `$1` and fallback default value prints both the param and the fallback value
aliases are just text replacement before another round of shell syntax interpretation, they don't take arguments, so after:
foo 69
The foo text is replaced with NUM=${1:-42}; echo $NUM and then the ...
7
votes
PS4: debug bash script with $LINENO: execute vs source
From man bash (emphasis mine):
PS4 The value of this parameter is expanded as with PS1 and the
value is printed before each command bash displays during an
execution trace. The first ...
7
votes
Accepted
How to read and debug SSH verbose-mode?
SSH is defined in IETF RFCs like
RFC4253 - The Secure Shell (SSH) Transport Layer Protocol (note
that there's errata and several updates)
RFC4250 - The Secure Shell (SSH) Protocol Assigned Numbers
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
debugging × 469linux × 94
bash × 49
linux-kernel × 41
gdb × 41
kernel × 39
shell-script × 31
debian × 25
process × 23
logs × 20
shell × 17
kernel-modules × 15
ubuntu × 14
networking × 12
strace × 12
arch-linux × 11
zsh × 11
monitoring × 11
crash × 11
trace × 11
fedora × 10
centos × 9
core-dump × 9
systemd × 8
signals × 8