From 0c31b8e434d634c81479bf396c752d1baaff7603 Mon Sep 17 00:00:00 2001 From: johannst Date: Fri, 23 Sep 2022 18:47:33 +0000 Subject: deploy: 47218d271f20b39610d5f63b3bc7dfc86642bdba --- print.html | 4 ++++ searchindex.js | 2 +- searchindex.json | 2 +- tools/awk.html | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/print.html b/print.html index bec2e28..6466334 100644 --- a/print.html +++ b/print.html @@ -1132,6 +1132,10 @@ but this is a function and return value can be assigned to a variable.

The pattern NR%2 == 0 matches every second record and the action { print $0 } prints the whole record.

+

Negative patterns

+
awk '!/^#/ { print $1 }' <file>
+
+

Matches records not starting with #.

Access last fields in records

echo 'a b c d e f' | awk '{ print $NF $(NF-1) }'
 
diff --git a/searchindex.js b/searchindex.js index 99f3688..d68ced1 100644 --- a/searchindex.js +++ b/searchindex.js @@ -1 +1 @@ -Object.assign(window.search, {"doc_urls":["intro.html#notes","tools/index.html#tools","tools/zsh.html#zsh1","tools/zsh.html#keybindings","tools/zsh.html#parameter","tools/zsh.html#variables","tools/zsh.html#expansion-flags","tools/zsh.html#argument-parsing-with-zparseopts","tools/zsh.html#example","tools/zsh.html#regular-expressions","tools/zsh.html#completion","tools/zsh.html#installation","tools/zsh.html#completion-variables","tools/zsh.html#completion-functions","tools/zsh.html#example-1","tools/bash.html#bash1","tools/bash.html#expansion","tools/bash.html#generator","tools/bash.html#parameter","tools/bash.html#pathname","tools/bash.html#io-redirection","tools/bash.html#explanation","tools/bash.html#argument-parsing-with-getopts","tools/bash.html#example","tools/bash.html#regular-expressions","tools/bash.html#completion","tools/bash.html#example-1","tools/fish.html#fish1","tools/fish.html#quick-info","tools/fish.html#variables","tools/fish.html#setunset-variables","tools/fish.html#lists","tools/fish.html#special-variables-lists","tools/fish.html#command-handling","tools/fish.html#io-redirection","tools/fish.html#control-flow","tools/fish.html#if--else","tools/fish.html#switch","tools/fish.html#while-loop","tools/fish.html#for-loop","tools/fish.html#functions","tools/fish.html#autoloading","tools/fish.html#helper","tools/fish.html#prompt","tools/fish.html#useful-builtins","tools/fish.html#keymaps","tools/fish.html#debug","tools/tmux.html#tmux1","tools/tmux.html#tmux-cli","tools/tmux.html#scripting","tools/tmux.html#bindings","tools/tmux.html#command-mode","tools/git.html#git1","tools/git.html#working-areas","tools/git.html#staging","tools/git.html#remote","tools/git.html#branching","tools/git.html#tags","tools/git.html#log--commit-history","tools/git.html#diff--commit-info","tools/git.html#patching","tools/git.html#resetting","tools/git.html#submodules","tools/git.html#inspection","tools/git.html#revision-specifier","tools/awk.html#awk1","tools/awk.html#input-processing","tools/awk.html#program","tools/awk.html#special-pattern","tools/awk.html#special-variables","tools/awk.html#special-statements--functions","tools/awk.html#examples","tools/awk.html#filter-records","tools/awk.html#access-last-fields-in-records","tools/awk.html#capture-in-variables","tools/awk.html#capture-in-array","tools/awk.html#run-shell-command-and-capture-output","tools/emacs.html#emacs1","tools/emacs.html#help","tools/emacs.html#package-manager","tools/emacs.html#window","tools/emacs.html#buffer","tools/emacs.html#ibuffer","tools/emacs.html#isearch","tools/emacs.html#occur","tools/emacs.html#grep","tools/emacs.html#yankpaste","tools/emacs.html#register","tools/emacs.html#blockrect","tools/emacs.html#mass-edit","tools/emacs.html#narrow","tools/emacs.html#org","tools/emacs.html#org-source","tools/emacs.html#comapny","tools/emacs.html#tags","tools/emacs.html#lisp","tools/emacs.html#ido","tools/emacs.html#evil","tools/emacs.html#dired","tools/gpg.html#gpg1","tools/gpg.html#generate-new-keypair","tools/gpg.html#list-keys","tools/gpg.html#edit-keys","tools/gpg.html#export--import-keys","tools/gpg.html#search--send-keys","tools/gpg.html#encrypt-passphrase","tools/gpg.html#encrypt-public-key","tools/gpg.html#signing","tools/gpg.html#signing-detached","tools/gpg.html#abbreviations","tools/gpg.html#keyservers","tools/gdb.html#gdb1","tools/gdb.html#cli","tools/gdb.html#interactive-usage","tools/gdb.html#misc","tools/gdb.html#breakpoints","tools/gdb.html#watchpoints","tools/gdb.html#inspection","tools/gdb.html#signal-handling","tools/gdb.html#source-file-locations","tools/gdb.html#configuration","tools/gdb.html#user-commands-macros","tools/gdb.html#hooks","tools/gdb.html#examples","tools/gdb.html#automatically-print-next-instr","tools/gdb.html#conditional-breakpoints","tools/gdb.html#catch-sigsegv-and-execute-commands","tools/gdb.html#run-backtrace-on-thread-1-batch-mode","tools/gdb.html#script-gdb-for-automating-debugging-sessions","tools/gdb.html#know-bugs","tools/gdb.html#workaround-command--finish-bug","tools/gdbserver.html#gdbserver1","tools/gdbserver.html#cli","tools/gdbserver.html#example","tools/radare2.html#radare21","tools/radare2.html#print","tools/radare2.html#flags","tools/radare2.html#help","tools/radare2.html#relocation","tools/radare2.html#examples","tools/radare2.html#patch-file-alter-bytes","tools/radare2.html#assemble--disassmble-rasm2","tools/qemu.html#qemu1","tools/qemu.html#keybindings","tools/qemu.html#vm-config-snippet","tools/qemu.html#cpu--ram","tools/qemu.html#graphic--display","tools/qemu.html#boot-menu","tools/qemu.html#block-devices","tools/qemu.html#usb","tools/qemu.html#debugging","tools/qemu.html#io-redirection","tools/qemu.html#network","tools/qemu.html#shared-drives","tools/qemu.html#debug-logging","tools/qemu.html#tracing","tools/qemu.html#vm-snapshots","tools/qemu.html#vm-migration","tools/qemu.html#appendix-direct-kernel-boot","tools/qemu.html#references","tools/pacman.html#pacman1","tools/pacman.html#remote-package-repositories","tools/pacman.html#remove-packages","tools/pacman.html#local-package-database","tools/pacman.html#local-file-database","tools/pacman.html#hacks","tools/dot.html#dot1","tools/dot.html#example-dot-file-to-copy--paste-from","tools/dot.html#references","monitor/index.html#resource-analysis--monitor","monitor/lsof.html#lsof8","monitor/lsof.html#examples","monitor/lsof.html#file-flags","monitor/lsof.html#open-tcp-connections","monitor/lsof.html#open-connection-to-specific-host","monitor/lsof.html#open-connection-to-specific-port","monitor/lsof.html#ipv4-tcp-connections-in-established-state","monitor/ss.html#ss8","monitor/ss.html#examples","monitor/pidstat.html#pidstat1","monitor/pidstat.html#page-fault-and-memory-utilization","monitor/pidstat.html#io-statistics","monitor/pgrep.html#pgrep1","monitor/pgrep.html#debug-newest-process","monitor/pmap.html#pmap1","monitor/pstack.html#pstack1","trace_profile/index.html#trace-and-profile","trace_profile/strace.html#strace1","trace_profile/strace.html#examples","trace_profile/ltrace.html#ltrace1","trace_profile/ltrace.html#example","trace_profile/perf.html#perf1","trace_profile/perf.html#flamegraph","trace_profile/perf.html#flamegraph-with-single-event-trace","trace_profile/perf.html#flamegraph-with-multiple-event-traces","trace_profile/oprofile.html#oprofile","trace_profile/time.html#usrbintime1","binary/index.html#binary","binary/od.html#od1","binary/od.html#ascii-to-hex-string","binary/od.html#extract-parts-of-file","binary/xxd.html#xxd1","binary/xxd.html#ascii-to-hex-stream","binary/xxd.html#hex-to-binary-stream","binary/xxd.html#ascii-to-binary","binary/xxd.html#ascii-to-c-array-hex-encoded","binary/readelf.html#readelf1","binary/objdump.html#objdump1","binary/objdump.html#disassemble-section","binary/nm.html#nm1","development/index.html#development","development/c++filt.html#cfilt1","development/c++filt.html#demangle-symbol","development/c++filt.html#demangle-stream","development/c++.html#c","development/c++.html#type-deduction","development/c++.html#variadic-templates--parameter-pack-","development/c++.html#example-any_of-template-meta-function","development/c++.html#example--sfinae---enable_if-","development/glibc.html#glibc","development/glibc.html#malloc-tracer--mtrace3","development/glibc.html#malloc-check--mallopt3","development/gcc.html#gcc1","development/gcc.html#cli","development/gcc.html#preprocessing","development/gcc.html#target-options","development/gcc.html#builtins","development/gcc.html#__builtin_expectexpr-cond","development/gcc.html#abi-linux","development/make.html#make1","development/make.html#anatomy-of-make-rules","development/make.html#pattern-rules--automatic-variables","development/make.html#pattern-rules","development/make.html#automatic-variables","development/make.html#useful-functions","development/make.html#substitution-references","development/make.html#filter","development/make.html#filter-out","development/make.html#abspath","development/ld.so.html#ldso8","development/ld.so.html#environment-variables","development/ld.so.html#ld_preload-initialization-order-and-link-map","development/ld.so.html#dynamic-linking-x86_64","development/symbolver.html#elf-symbol-versioning","development/symbolver.html#example-version-script","development/symbolver.html#references","development/python.html#python","development/python.html#decorator--run-","development/python.html#walrus-operator--run-","development/python.html#unittest---run-","development/python.html#doctest---run-","development/python.html#timeit","linux/index.html#linux","linux/systemd.html#systemd","linux/systemd.html#systemctl","linux/systemd.html#example-trivial-user-unit","linux/systemd.html#journalctl","linux/systemd.html#references","linux/coredump.html#core5","linux/coredump.html#naming-of-coredump-files","linux/coredump.html#control-which-segments-are-dumped","linux/coredump.html#some-examples-out-there","linux/coredump.html#coredumpctl-systemd","linux/coredump.html#apport-ubuntu","linux/ptrace_scope.html#ptrace_scope","linux/cryptsetup.html#cryptsetup8","linux/cryptsetup.html#example-create-luks-encrypted-disk","linux/cryptsetup.html#example-using-an-existing-luks-device","linux/swap.html#swap","linux/swap.html#list-active-swap-areas","linux/swap.html#manual-swapfile-setup","linux/swap.html#using-dphys-swapfile-service","network/index.html#network","network/tcpdump.html#tcpdump1","network/tcpdump.html#cli","network/tcpdump.html#examples","network/tcpdump.html#capture-packets-from-remote-host","web/index.html#web","web/html.html#html","web/html.html#collapsible-element","web/html.html#minimal-2-column-layout","arch/index.html#arch","arch/x86_64.html#x86_64","arch/x86_64.html#registers","arch/x86_64.html#general-purpose-register","arch/x86_64.html#special-register","arch/x86_64.html#flags-register","arch/x86_64.html#model-specific-register-msr","arch/x86_64.html#size-directives","arch/x86_64.html#addressing","arch/x86_64.html#string-instructions","arch/x86_64.html#example-simple-memset","arch/x86_64.html#sysv-x86_64-abi","arch/x86_64.html#passing-arguments-to-functions","arch/x86_64.html#return-values-from-functions","arch/x86_64.html#caller-saved-registers","arch/x86_64.html#callee-saved-registers","arch/x86_64.html#stack","arch/x86_64.html#function-prologue--epilogue","arch/x86_64.html#asm-skeleton","arch/x86_64.html#references","arch/arm64.html#arm64","arch/arm64.html#registers","arch/arm64.html#general-purpose-registers","arch/arm64.html#special-registers-per-el","arch/arm64.html#instructions-cheatsheet","arch/arm64.html#accessing-system-registers","arch/arm64.html#control-flow","arch/arm64.html#addressing","arch/arm64.html#offset","arch/arm64.html#index","arch/arm64.html#pair-access","arch/arm64.html#procedure-call-standard-arm64--aapcs64-","arch/arm64.html#passing-arguments-to-functions","arch/arm64.html#return-values-from-functions","arch/arm64.html#callee-saved-registers","arch/arm64.html#stack","arch/arm64.html#frame-chain","arch/arm64.html#function-prologue--epilogue","arch/arm64.html#asm-skeleton","arch/arm64.html#references","arch/armv7.html#armv7a","arch/armv7.html#registers","arch/armv7.html#general-purpose-registers","arch/armv7.html#special-registers","arch/armv7.html#cpsr-register","arch/armv7.html#instructions-cheatsheet","arch/armv7.html#accessing-system-registers","arch/armv7.html#control-flow","arch/armv7.html#loadstore","arch/armv7.html#procedure-call-standard-arm--aapcs32-","arch/armv7.html#passing-arguments-to-functions","arch/armv7.html#return-values-from-functions","arch/armv7.html#callee-saved-registers","arch/armv7.html#stack","arch/armv7.html#frame-chain","arch/armv7.html#function-prologue--epilogue","arch/armv7.html#asm-skeleton","arch/armv7.html#references","arch/riscv.html#riscv","arch/riscv.html#registers","arch/riscv.html#general-purpose-registers","arch/riscv.html#asm-skeleton","arch/riscv.html#references"],"index":{"documentStore":{"docInfo":{"0":{"body":8,"breadcrumbs":2,"title":1},"1":{"body":14,"breadcrumbs":2,"title":1},"10":{"body":0,"breadcrumbs":3,"title":1},"100":{"body":4,"breadcrumbs":5,"title":3},"101":{"body":13,"breadcrumbs":4,"title":2},"102":{"body":55,"breadcrumbs":4,"title":2},"103":{"body":19,"breadcrumbs":5,"title":3},"104":{"body":14,"breadcrumbs":5,"title":3},"105":{"body":19,"breadcrumbs":4,"title":2},"106":{"body":26,"breadcrumbs":5,"title":3},"107":{"body":55,"breadcrumbs":3,"title":1},"108":{"body":32,"breadcrumbs":4,"title":2},"109":{"body":12,"breadcrumbs":3,"title":1},"11":{"body":36,"breadcrumbs":3,"title":1},"110":{"body":3,"breadcrumbs":3,"title":1},"111":{"body":0,"breadcrumbs":3,"title":1},"112":{"body":42,"breadcrumbs":3,"title":1},"113":{"body":0,"breadcrumbs":4,"title":2},"114":{"body":66,"breadcrumbs":3,"title":1},"115":{"body":103,"breadcrumbs":3,"title":1},"116":{"body":37,"breadcrumbs":3,"title":1},"117":{"body":22,"breadcrumbs":3,"title":1},"118":{"body":42,"breadcrumbs":4,"title":2},"119":{"body":33,"breadcrumbs":5,"title":3},"12":{"body":25,"breadcrumbs":4,"title":2},"120":{"body":72,"breadcrumbs":3,"title":1},"121":{"body":25,"breadcrumbs":5,"title":3},"122":{"body":24,"breadcrumbs":3,"title":1},"123":{"body":0,"breadcrumbs":3,"title":1},"124":{"body":24,"breadcrumbs":6,"title":4},"125":{"body":25,"breadcrumbs":4,"title":2},"126":{"body":13,"breadcrumbs":6,"title":4},"127":{"body":9,"breadcrumbs":8,"title":6},"128":{"body":36,"breadcrumbs":7,"title":5},"129":{"body":0,"breadcrumbs":4,"title":2},"13":{"body":89,"breadcrumbs":4,"title":2},"130":{"body":27,"breadcrumbs":6,"title":4},"131":{"body":0,"breadcrumbs":3,"title":1},"132":{"body":13,"breadcrumbs":3,"title":1},"133":{"body":12,"breadcrumbs":3,"title":1},"134":{"body":0,"breadcrumbs":3,"title":1},"135":{"body":11,"breadcrumbs":3,"title":1},"136":{"body":16,"breadcrumbs":3,"title":1},"137":{"body":9,"breadcrumbs":3,"title":1},"138":{"body":15,"breadcrumbs":3,"title":1},"139":{"body":0,"breadcrumbs":3,"title":1},"14":{"body":77,"breadcrumbs":3,"title":1},"140":{"body":19,"breadcrumbs":6,"title":4},"141":{"body":18,"breadcrumbs":5,"title":3},"142":{"body":11,"breadcrumbs":3,"title":1},"143":{"body":31,"breadcrumbs":3,"title":1},"144":{"body":37,"breadcrumbs":5,"title":3},"145":{"body":40,"breadcrumbs":4,"title":2},"146":{"body":30,"breadcrumbs":4,"title":2},"147":{"body":10,"breadcrumbs":4,"title":2},"148":{"body":105,"breadcrumbs":4,"title":2},"149":{"body":41,"breadcrumbs":3,"title":1},"15":{"body":0,"breadcrumbs":3,"title":1},"150":{"body":18,"breadcrumbs":3,"title":1},"151":{"body":48,"breadcrumbs":4,"title":2},"152":{"body":11,"breadcrumbs":3,"title":1},"153":{"body":22,"breadcrumbs":4,"title":2},"154":{"body":20,"breadcrumbs":4,"title":2},"155":{"body":32,"breadcrumbs":3,"title":1},"156":{"body":38,"breadcrumbs":4,"title":2},"157":{"body":89,"breadcrumbs":4,"title":2},"158":{"body":30,"breadcrumbs":6,"title":4},"159":{"body":22,"breadcrumbs":3,"title":1},"16":{"body":0,"breadcrumbs":3,"title":1},"160":{"body":0,"breadcrumbs":3,"title":1},"161":{"body":33,"breadcrumbs":5,"title":3},"162":{"body":9,"breadcrumbs":4,"title":2},"163":{"body":37,"breadcrumbs":5,"title":3},"164":{"body":31,"breadcrumbs":5,"title":3},"165":{"body":39,"breadcrumbs":3,"title":1},"166":{"body":2,"breadcrumbs":3,"title":1},"167":{"body":91,"breadcrumbs":7,"title":5},"168":{"body":8,"breadcrumbs":3,"title":1},"169":{"body":6,"breadcrumbs":6,"title":3},"17":{"body":16,"breadcrumbs":3,"title":1},"170":{"body":102,"breadcrumbs":5,"title":1},"171":{"body":0,"breadcrumbs":5,"title":1},"172":{"body":10,"breadcrumbs":6,"title":2},"173":{"body":21,"breadcrumbs":7,"title":3},"174":{"body":9,"breadcrumbs":8,"title":4},"175":{"body":10,"breadcrumbs":8,"title":4},"176":{"body":4,"breadcrumbs":9,"title":5},"177":{"body":52,"breadcrumbs":5,"title":1},"178":{"body":28,"breadcrumbs":5,"title":1},"179":{"body":26,"breadcrumbs":5,"title":1},"18":{"body":69,"breadcrumbs":3,"title":1},"180":{"body":50,"breadcrumbs":8,"title":4},"181":{"body":6,"breadcrumbs":6,"title":2},"182":{"body":22,"breadcrumbs":5,"title":1},"183":{"body":14,"breadcrumbs":7,"title":3},"184":{"body":12,"breadcrumbs":5,"title":1},"185":{"body":6,"breadcrumbs":5,"title":1},"186":{"body":5,"breadcrumbs":4,"title":2},"187":{"body":89,"breadcrumbs":4,"title":1},"188":{"body":26,"breadcrumbs":4,"title":1},"189":{"body":27,"breadcrumbs":4,"title":1},"19":{"body":92,"breadcrumbs":3,"title":1},"190":{"body":11,"breadcrumbs":4,"title":1},"191":{"body":128,"breadcrumbs":4,"title":1},"192":{"body":0,"breadcrumbs":4,"title":1},"193":{"body":15,"breadcrumbs":7,"title":4},"194":{"body":17,"breadcrumbs":7,"title":4},"195":{"body":43,"breadcrumbs":4,"title":1},"196":{"body":6,"breadcrumbs":4,"title":1},"197":{"body":5,"breadcrumbs":2,"title":1},"198":{"body":45,"breadcrumbs":3,"title":1},"199":{"body":34,"breadcrumbs":5,"title":3},"2":{"body":0,"breadcrumbs":3,"title":1},"20":{"body":38,"breadcrumbs":4,"title":2},"200":{"body":76,"breadcrumbs":5,"title":3},"201":{"body":19,"breadcrumbs":3,"title":1},"202":{"body":6,"breadcrumbs":5,"title":3},"203":{"body":7,"breadcrumbs":5,"title":3},"204":{"body":11,"breadcrumbs":4,"title":2},"205":{"body":15,"breadcrumbs":7,"title":5},"206":{"body":55,"breadcrumbs":3,"title":1},"207":{"body":36,"breadcrumbs":3,"title":1},"208":{"body":8,"breadcrumbs":4,"title":2},"209":{"body":7,"breadcrumbs":3,"title":1},"21":{"body":26,"breadcrumbs":3,"title":1},"210":{"body":9,"breadcrumbs":2,"title":1},"211":{"body":0,"breadcrumbs":3,"title":1},"212":{"body":3,"breadcrumbs":4,"title":2},"213":{"body":10,"breadcrumbs":4,"title":2},"214":{"body":0,"breadcrumbs":3,"title":1},"215":{"body":14,"breadcrumbs":4,"title":2},"216":{"body":93,"breadcrumbs":6,"title":4},"217":{"body":69,"breadcrumbs":7,"title":5},"218":{"body":248,"breadcrumbs":5,"title":3},"219":{"body":0,"breadcrumbs":3,"title":1},"22":{"body":64,"breadcrumbs":5,"title":3},"220":{"body":62,"breadcrumbs":5,"title":3},"221":{"body":34,"breadcrumbs":5,"title":3},"222":{"body":0,"breadcrumbs":3,"title":1},"223":{"body":0,"breadcrumbs":3,"title":1},"224":{"body":28,"breadcrumbs":3,"title":1},"225":{"body":18,"breadcrumbs":4,"title":2},"226":{"body":0,"breadcrumbs":3,"title":1},"227":{"body":104,"breadcrumbs":4,"title":2},"228":{"body":9,"breadcrumbs":4,"title":2},"229":{"body":0,"breadcrumbs":3,"title":1},"23":{"body":35,"breadcrumbs":3,"title":1},"230":{"body":27,"breadcrumbs":5,"title":3},"231":{"body":0,"breadcrumbs":6,"title":4},"232":{"body":36,"breadcrumbs":4,"title":2},"233":{"body":81,"breadcrumbs":4,"title":2},"234":{"body":0,"breadcrumbs":4,"title":2},"235":{"body":14,"breadcrumbs":4,"title":2},"236":{"body":16,"breadcrumbs":3,"title":1},"237":{"body":17,"breadcrumbs":4,"title":2},"238":{"body":23,"breadcrumbs":3,"title":1},"239":{"body":0,"breadcrumbs":3,"title":1},"24":{"body":58,"breadcrumbs":4,"title":2},"240":{"body":38,"breadcrumbs":4,"title":2},"241":{"body":128,"breadcrumbs":7,"title":5},"242":{"body":246,"breadcrumbs":5,"title":3},"243":{"body":422,"breadcrumbs":6,"title":3},"244":{"body":278,"breadcrumbs":6,"title":3},"245":{"body":13,"breadcrumbs":4,"title":1},"246":{"body":0,"breadcrumbs":3,"title":1},"247":{"body":59,"breadcrumbs":4,"title":2},"248":{"body":45,"breadcrumbs":5,"title":3},"249":{"body":43,"breadcrumbs":4,"title":2},"25":{"body":123,"breadcrumbs":3,"title":1},"250":{"body":28,"breadcrumbs":4,"title":2},"251":{"body":8,"breadcrumbs":3,"title":1},"252":{"body":5,"breadcrumbs":2,"title":1},"253":{"body":0,"breadcrumbs":3,"title":1},"254":{"body":55,"breadcrumbs":3,"title":1},"255":{"body":31,"breadcrumbs":6,"title":4},"256":{"body":46,"breadcrumbs":3,"title":1},"257":{"body":4,"breadcrumbs":3,"title":1},"258":{"body":27,"breadcrumbs":3,"title":1},"259":{"body":77,"breadcrumbs":5,"title":3},"26":{"body":66,"breadcrumbs":3,"title":1},"260":{"body":87,"breadcrumbs":5,"title":3},"261":{"body":0,"breadcrumbs":4,"title":2},"262":{"body":48,"breadcrumbs":4,"title":2},"263":{"body":18,"breadcrumbs":4,"title":2},"264":{"body":43,"breadcrumbs":3,"title":1},"265":{"body":64,"breadcrumbs":3,"title":1},"266":{"body":154,"breadcrumbs":7,"title":5},"267":{"body":36,"breadcrumbs":7,"title":5},"268":{"body":0,"breadcrumbs":3,"title":1},"269":{"body":7,"breadcrumbs":6,"title":4},"27":{"body":0,"breadcrumbs":3,"title":1},"270":{"body":59,"breadcrumbs":5,"title":3},"271":{"body":42,"breadcrumbs":6,"title":4},"272":{"body":1,"breadcrumbs":2,"title":1},"273":{"body":0,"breadcrumbs":3,"title":1},"274":{"body":59,"breadcrumbs":3,"title":1},"275":{"body":0,"breadcrumbs":3,"title":1},"276":{"body":11,"breadcrumbs":6,"title":4},"277":{"body":1,"breadcrumbs":2,"title":1},"278":{"body":0,"breadcrumbs":3,"title":1},"279":{"body":19,"breadcrumbs":4,"title":2},"28":{"body":19,"breadcrumbs":4,"title":2},"280":{"body":55,"breadcrumbs":6,"title":4},"281":{"body":4,"breadcrumbs":2,"title":1},"282":{"body":21,"breadcrumbs":3,"title":1},"283":{"body":0,"breadcrumbs":3,"title":1},"284":{"body":62,"breadcrumbs":5,"title":3},"285":{"body":15,"breadcrumbs":4,"title":2},"286":{"body":102,"breadcrumbs":4,"title":2},"287":{"body":14,"breadcrumbs":6,"title":4},"288":{"body":40,"breadcrumbs":4,"title":2},"289":{"body":40,"breadcrumbs":3,"title":1},"29":{"body":19,"breadcrumbs":3,"title":1},"290":{"body":116,"breadcrumbs":4,"title":2},"291":{"body":17,"breadcrumbs":5,"title":3},"292":{"body":0,"breadcrumbs":5,"title":3},"293":{"body":40,"breadcrumbs":5,"title":3},"294":{"body":23,"breadcrumbs":5,"title":3},"295":{"body":14,"breadcrumbs":5,"title":3},"296":{"body":15,"breadcrumbs":5,"title":3},"297":{"body":29,"breadcrumbs":3,"title":1},"298":{"body":31,"breadcrumbs":5,"title":3},"299":{"body":94,"breadcrumbs":4,"title":2},"3":{"body":96,"breadcrumbs":3,"title":1},"30":{"body":25,"breadcrumbs":4,"title":2},"300":{"body":47,"breadcrumbs":3,"title":1},"301":{"body":14,"breadcrumbs":3,"title":1},"302":{"body":0,"breadcrumbs":3,"title":1},"303":{"body":40,"breadcrumbs":5,"title":3},"304":{"body":52,"breadcrumbs":6,"title":4},"305":{"body":0,"breadcrumbs":4,"title":2},"306":{"body":18,"breadcrumbs":5,"title":3},"307":{"body":38,"breadcrumbs":4,"title":2},"308":{"body":0,"breadcrumbs":3,"title":1},"309":{"body":47,"breadcrumbs":3,"title":1},"31":{"body":51,"breadcrumbs":3,"title":1},"310":{"body":18,"breadcrumbs":3,"title":1},"311":{"body":18,"breadcrumbs":4,"title":2},"312":{"body":0,"breadcrumbs":7,"title":5},"313":{"body":35,"breadcrumbs":5,"title":3},"314":{"body":8,"breadcrumbs":5,"title":3},"315":{"body":3,"breadcrumbs":5,"title":3},"316":{"body":27,"breadcrumbs":3,"title":1},"317":{"body":52,"breadcrumbs":4,"title":2},"318":{"body":36,"breadcrumbs":5,"title":3},"319":{"body":141,"breadcrumbs":4,"title":2},"32":{"body":39,"breadcrumbs":5,"title":3},"320":{"body":27,"breadcrumbs":3,"title":1},"321":{"body":10,"breadcrumbs":3,"title":1},"322":{"body":0,"breadcrumbs":3,"title":1},"323":{"body":23,"breadcrumbs":5,"title":3},"324":{"body":8,"breadcrumbs":4,"title":2},"325":{"body":55,"breadcrumbs":4,"title":2},"326":{"body":0,"breadcrumbs":4,"title":2},"327":{"body":18,"breadcrumbs":5,"title":3},"328":{"body":50,"breadcrumbs":4,"title":2},"329":{"body":96,"breadcrumbs":3,"title":1},"33":{"body":8,"breadcrumbs":4,"title":2},"330":{"body":0,"breadcrumbs":7,"title":5},"331":{"body":44,"breadcrumbs":5,"title":3},"332":{"body":11,"breadcrumbs":5,"title":3},"333":{"body":3,"breadcrumbs":5,"title":3},"334":{"body":26,"breadcrumbs":3,"title":1},"335":{"body":65,"breadcrumbs":4,"title":2},"336":{"body":19,"breadcrumbs":5,"title":3},"337":{"body":165,"breadcrumbs":4,"title":2},"338":{"body":21,"breadcrumbs":3,"title":1},"339":{"body":9,"breadcrumbs":3,"title":1},"34":{"body":8,"breadcrumbs":4,"title":2},"340":{"body":4,"breadcrumbs":3,"title":1},"341":{"body":55,"breadcrumbs":5,"title":3},"342":{"body":143,"breadcrumbs":4,"title":2},"343":{"body":5,"breadcrumbs":3,"title":1},"35":{"body":0,"breadcrumbs":4,"title":2},"36":{"body":10,"breadcrumbs":2,"title":0},"37":{"body":14,"breadcrumbs":3,"title":1},"38":{"body":4,"breadcrumbs":3,"title":1},"39":{"body":5,"breadcrumbs":3,"title":1},"4":{"body":88,"breadcrumbs":3,"title":1},"40":{"body":11,"breadcrumbs":3,"title":1},"41":{"body":24,"breadcrumbs":3,"title":1},"42":{"body":24,"breadcrumbs":3,"title":1},"43":{"body":19,"breadcrumbs":3,"title":1},"44":{"body":24,"breadcrumbs":4,"title":2},"45":{"body":28,"breadcrumbs":3,"title":1},"46":{"body":19,"breadcrumbs":3,"title":1},"47":{"body":19,"breadcrumbs":3,"title":1},"48":{"body":86,"breadcrumbs":4,"title":2},"49":{"body":119,"breadcrumbs":3,"title":1},"5":{"body":79,"breadcrumbs":3,"title":1},"50":{"body":128,"breadcrumbs":3,"title":1},"51":{"body":24,"breadcrumbs":4,"title":2},"52":{"body":0,"breadcrumbs":3,"title":1},"53":{"body":23,"breadcrumbs":4,"title":2},"54":{"body":7,"breadcrumbs":3,"title":1},"55":{"body":21,"breadcrumbs":3,"title":1},"56":{"body":77,"breadcrumbs":3,"title":1},"57":{"body":45,"breadcrumbs":3,"title":1},"58":{"body":46,"breadcrumbs":5,"title":3},"59":{"body":58,"breadcrumbs":5,"title":3},"6":{"body":79,"breadcrumbs":4,"title":2},"60":{"body":109,"breadcrumbs":3,"title":1},"61":{"body":50,"breadcrumbs":3,"title":1},"62":{"body":64,"breadcrumbs":3,"title":1},"63":{"body":27,"breadcrumbs":3,"title":1},"64":{"body":28,"breadcrumbs":4,"title":2},"65":{"body":18,"breadcrumbs":3,"title":1},"66":{"body":45,"breadcrumbs":4,"title":2},"67":{"body":37,"breadcrumbs":3,"title":1},"68":{"body":29,"breadcrumbs":4,"title":2},"69":{"body":29,"breadcrumbs":4,"title":2},"7":{"body":48,"breadcrumbs":5,"title":3},"70":{"body":86,"breadcrumbs":5,"title":3},"71":{"body":0,"breadcrumbs":3,"title":1},"72":{"body":18,"breadcrumbs":4,"title":2},"73":{"body":19,"breadcrumbs":6,"title":4},"74":{"body":39,"breadcrumbs":4,"title":2},"75":{"body":34,"breadcrumbs":4,"title":2},"76":{"body":25,"breadcrumbs":7,"title":5},"77":{"body":0,"breadcrumbs":3,"title":1},"78":{"body":74,"breadcrumbs":3,"title":1},"79":{"body":21,"breadcrumbs":4,"title":2},"8":{"body":40,"breadcrumbs":3,"title":1},"80":{"body":40,"breadcrumbs":3,"title":1},"81":{"body":50,"breadcrumbs":3,"title":1},"82":{"body":77,"breadcrumbs":3,"title":1},"83":{"body":57,"breadcrumbs":3,"title":1},"84":{"body":51,"breadcrumbs":3,"title":1},"85":{"body":24,"breadcrumbs":3,"title":1},"86":{"body":43,"breadcrumbs":3,"title":1},"87":{"body":24,"breadcrumbs":3,"title":1},"88":{"body":19,"breadcrumbs":3,"title":1},"89":{"body":32,"breadcrumbs":4,"title":2},"9":{"body":46,"breadcrumbs":4,"title":2},"90":{"body":22,"breadcrumbs":3,"title":1},"91":{"body":39,"breadcrumbs":3,"title":1},"92":{"body":23,"breadcrumbs":4,"title":2},"93":{"body":26,"breadcrumbs":3,"title":1},"94":{"body":38,"breadcrumbs":3,"title":1},"95":{"body":49,"breadcrumbs":3,"title":1},"96":{"body":24,"breadcrumbs":3,"title":1},"97":{"body":28,"breadcrumbs":3,"title":1},"98":{"body":16,"breadcrumbs":3,"title":1},"99":{"body":21,"breadcrumbs":3,"title":1}},"docs":{"0":{"body":"A personal collection of notes and cheatsheets. Source code is located at johannst/notes .","breadcrumbs":"Introduction » Notes","id":"0","title":"Notes"},"1":{"body":"zsh bash fish tmux git awk emacs gpg gdb gdbserver radare2 qemu pacman dot","breadcrumbs":"Tools » Tools","id":"1","title":"Tools"},"10":{"body":"","breadcrumbs":"Tools » zsh » Completion","id":"10","title":"Completion"},"100":{"body":"gpg --full-generate-key","breadcrumbs":"Tools » gpg » Generate new keypair","id":"100","title":"Generate new keypair"},"101":{"body":"gpg -k / --list-key # public keys\ngpg -K / --list-secret-keys # secret keys","breadcrumbs":"Tools » gpg » List keys","id":"101","title":"List keys"},"102":{"body":"gpg --edit-key Gives prompt to modify KEY ID, common commands: help show help\nsave save & quit list list keys and user IDs\nkey select subkey \nuid select user ID expire change expiration of selected key adduid add user ID\ndeluid delete selected user ID addkey add subkey\ndelkey delete selected subkey","breadcrumbs":"Tools » gpg » Edit keys","id":"102","title":"Edit keys"},"103":{"body":"gpg --export --armor --output \ngpg --export-secret-key --armor --output \ngpg --import ","breadcrumbs":"Tools » gpg » Export & Import Keys","id":"103","title":"Export & Import Keys"},"104":{"body":"gpg --keyserver --send-keys \ngpg --keyserver --search-keys ","breadcrumbs":"Tools » gpg » Search & Send keys","id":"104","title":"Search & Send keys"},"105":{"body":"Encrypt file using passphrase and write encrypted data to .gpg. gpg --symmetric # Decrypt using passphrase\ngpg -o --decrypt .gpg","breadcrumbs":"Tools » gpg » Encrypt (passphrase)","id":"105","title":"Encrypt (passphrase)"},"106":{"body":"Encrypt file with public key of specified recipient and write encrypted data to .gpg. gpg --encrypt -r foo@bar.de # Decrypt at foos side (private key required)\ngpg -o --decrypt .gpg","breadcrumbs":"Tools » gpg » Encrypt (public key)","id":"106","title":"Encrypt (public key)"},"107":{"body":"Generate a signed file and write to .gpg. # Sign with private key of foo@bar.de\ngpg --sign -u foor@bar.de # Verify with public key of foo@bar.de\ngpg --verify # Extract content from signed file\ngpg -o --decrypt .gpg Without -u use first private key in list gpg -K for signing. Files can also be signed and encrypted at once, gpg will first sign the file and then encrypt it. gpg --sign --encrypt -r ","breadcrumbs":"Tools » gpg » Signing","id":"107","title":"Signing"},"108":{"body":"Generate a detached signature and write to .asc. Send .asc along with when distributing. gpg --detach-sign --armor -u foor@bar.de # Verify\ngpg --verify .asc Without -u use first private key in list gpg -K for signing.","breadcrumbs":"Tools » gpg » Signing (detached)","id":"108","title":"Signing (detached)"},"109":{"body":"sec secret key ssb secret subkey pub public key sub public subkey","breadcrumbs":"Tools » gpg » Abbreviations","id":"109","title":"Abbreviations"},"11":{"body":"Completion functions are provided via files and need to be placed in a location covered by $fpath. By convention the completion files are names as _. A completion skeleton for the command foo, stored in _foo #compdef _foo foo function _foo() { ...\n} Alternatively one can install a completion function explicitly by calling compdef .","breadcrumbs":"Tools » zsh » Installation","id":"11","title":"Installation"},"110":{"body":"http://pgp.mit.edu http://keyserver.ubuntu.com hkps://pgp.mailbox.org","breadcrumbs":"Tools » gpg » Keyservers","id":"110","title":"Keyservers"},"111":{"body":"","breadcrumbs":"Tools » gdb » gdb(1)","id":"111","title":"gdb(1)"},"112":{"body":"gdb [opts] [prg [-c coredump | -p pid]] gdb [opts] --args prg opts: -p attach to pid -c use -x execute script before prompt -ex execute command before prompt --tty set I/O tty for debugee","breadcrumbs":"Tools » gdb » CLI","id":"112","title":"CLI"},"113":{"body":"","breadcrumbs":"Tools » gdb » Interactive usage","id":"113","title":"Interactive usage"},"114":{"body":"tty Set as tty for debugee. Make sure nobody reads from target tty, easiest is to spawn a shell and run following in target tty: > while true; do sleep 1024; done sharedlibrary [] Load symbols of shared libs loaded by debugee. Optionally use to filter libs for symbol loading. display [/FMT] Print every time debugee stops. Eg print next instr, see examples below. undisplay [] Delete display expressions either all or one referenced by . info display List display expressions.","breadcrumbs":"Tools » gdb » Misc","id":"114","title":"Misc"},"115":{"body":"break [-qualified] thread Set a breakpoint only for a specific thread. -qualified: Treat as fully qualified symbol (quiet handy to set breakpoints on C symbols in C++ contexts) break if Set conditional breakpoint (see examples below). delete [] Delete breakpoint either all or one referenced by . info break List breakpoints. cond Make existing breakpoint conditional with . tbreak Set temporary breakpoint, will be deleted when hit. Same syntax as `break`. rbreak Set breakpoints matching , where matching internally is done on: .*.* command [] Define commands to run after breakpoint hit. If is not specified attach command to last created breakpoint. Command block terminated with 'end' token. : Space separates list, eg 'command 2 5-8' to run command for breakpoints: 2,5,6,7,8.","breadcrumbs":"Tools » gdb » Breakpoints","id":"115","title":"Breakpoints"},"116":{"body":"watch [-location|-l] [thread ] Create a watchpoint for , will break if is written to. Watchpoints respect scope of variables, -l can be used to watch the memory location instead. rwatch ... Sets a read watchpoint, will break if is read from. awatch ... Sets an access watchpoint, will break if is written to or read from.","breadcrumbs":"Tools » gdb » Watchpoints","id":"116","title":"Watchpoints"},"117":{"body":"info functions [] List functions matching . List all functions if no provided. info variables [] List variables matching . List all variables if no provided.","breadcrumbs":"Tools » gdb » Inspection","id":"117","title":"Inspection"},"118":{"body":"info handle [] Print how to handle . If no specified print for all signals. handle Configure how gdb handles sent to debugee. : stop/nostop Catch signal in gdb and break. print/noprint Print message when gdb catches signal. pass/nopass Pass signal down to debugee. catch signal Create a catchpoint for .","breadcrumbs":"Tools » gdb » Signal handling","id":"118","title":"Signal handling"},"119":{"body":"dir Add to the beginning of the searh path for source files. show dir Show current search path. set substitute-path Add substitution rule checked during source file lookup. show substitute-path Show current substitution rules.","breadcrumbs":"Tools » gdb » Source file locations","id":"119","title":"Source file locations"},"12":{"body":"Following variables are available in Completion functions: $words # array with command line in words\n$#words # number words\n$CURRENT # index into $words for cursor position\n$words[CURRENT-1] # previous word (relative to cursor position)","breadcrumbs":"Tools » zsh » Completion Variables","id":"12","title":"Completion Variables"},"120":{"body":"set follow-fork-mode Specify which process to follow when debuggee makes a fork(2) syscall. set pagination Turn on/off gdb's pagination. set breakpoint pending on: always set pending breakpoints. off: error when trying to set pending breakpoints. auto: interatively query user to set breakpoint. set print pretty Turn on/off pertty printing of structures. set logging Enable output logging to file (default gdb.txt). set logging file Change output log file to set logging redirect on: only log to file. off: log to file and tty.","breadcrumbs":"Tools » gdb » Configuration","id":"120","title":"Configuration"},"121":{"body":"Gdb allows to create & document user commands as follows: define # cmds end document # docu end To get all user commands or documentations one can use: help user-defined help ","breadcrumbs":"Tools » gdb » User commands (macros)","id":"121","title":"User commands (macros)"},"122":{"body":"Gdb allows to create two types of command hooks hook- will be run before hookpost- will be run after define hook- # cmds end define hookpost- # cmds end","breadcrumbs":"Tools » gdb » Hooks","id":"122","title":"Hooks"},"123":{"body":"","breadcrumbs":"Tools » gdb » Examples","id":"123","title":"Examples"},"124":{"body":"When ever the debugee stops automatically print the memory at the current instruction pointer ($rip x86) and format as instruction /i. # rip - x86 display /i $rip # step instruction, after the step the next instruction is automatically printed si","breadcrumbs":"Tools » gdb » Automatically print next instr","id":"124","title":"Automatically print next instr"},"125":{"body":"Create conditional breakpoints for a function void foo(int i) in the debugee. # Create conditional breakpoint b foo if i == 42 b foo # would create bp 2 # Make existing breakpoint conditional cond 2 if i == 7","breadcrumbs":"Tools » gdb » Conditional breakpoints","id":"125","title":"Conditional breakpoints"},"126":{"body":"This creates a catchpoint for the SIGSEGV signal and attached the command to it. catch signal SIGSEGV command bt c end","breadcrumbs":"Tools » gdb » Catch SIGSEGV and execute commands","id":"126","title":"Catch SIGSEGV and execute commands"},"127":{"body":"gdb --batch -ex 'thread 1' -ex 'bt' -p ","breadcrumbs":"Tools » gdb » Run backtrace on thread 1 (batch mode)","id":"127","title":"Run backtrace on thread 1 (batch mode)"},"128":{"body":"To script gdb add commands into a file and pass it to gdb via -x. For example create run.gdb: set pagination off break mmap command info reg rdi rsi rdx bt c end #initial drop c This script can be used as: gdb --batch -x ./run.gdb -p ","breadcrumbs":"Tools » gdb » Script gdb for automating debugging sessions","id":"128","title":"Script gdb for automating debugging sessions"},"129":{"body":"","breadcrumbs":"Tools » gdb » Know Bugs","id":"129","title":"Know Bugs"},"13":{"body":"_describe simple completion, just words + description _arguments sophisticated completion, allow to specify actions Completion with _describe _describe MSG COMP MSG simple string with header message COMP array of completions where each entry is \"opt:description\" function _foo() { local -a opts opts=('bla:desc for bla' 'blu:desc for blu') _describe 'foo-msg' opts\n}\ncompdef _foo foo foo -- foo-msg --\nbla -- desc for bla\nblu -- desc for blu Completion with _arguments _arguments SPEC [SPEC...] where SPEC can have one of the following forms: OPT[DESC]:MSG:ACTION N:MSG:ACTION Available actions (op1 op2) list possible matches\n->VAL set $state=VAL and continue, `$state` can be checked later in switch case\nFUNC call func to generate matches\n{STR} evaluate `STR` to generate matches","breadcrumbs":"Tools » zsh » Completion Functions","id":"13","title":"Completion Functions"},"130":{"body":"When using finish inside a command block, commands after finish are not executed. To workaround that bug one can create a wrapper function which calls finish. define handler bt finish info reg rax end command handler end","breadcrumbs":"Tools » gdb » Workaround command + finish bug","id":"130","title":"Workaround command + finish bug"},"131":{"body":"","breadcrumbs":"Tools » gdbserver » gdbserver(1)","id":"131","title":"gdbserver(1)"},"132":{"body":"gdbserver [opts] comm prog [args] opts: --disable-randomization --no-disable-randomization comm: host:port tty","breadcrumbs":"Tools » gdbserver » CLI","id":"132","title":"CLI"},"133":{"body":"# Start gdbserver.\ngdbserver localhost:1234 /bin/ls # Attach gdb.\ngdb -ex 'target remote localhost:1234'","breadcrumbs":"Tools » gdbserver » Example","id":"133","title":"Example"},"134":{"body":"","breadcrumbs":"Tools » radare2 » radare2(1)","id":"134","title":"radare2(1)"},"135":{"body":"pd [@ ] # print disassembly for instructions # with optional temporary seek to ","breadcrumbs":"Tools » radare2 » print","id":"135","title":"print"},"136":{"body":"fs # list flag-spaces fs # select flag-space f # print flags of selected flag-space","breadcrumbs":"Tools » radare2 » flags","id":"136","title":"flags"},"137":{"body":"?*~ # '?*' list all commands and '~' grep for ?*~... # '..' less mode /'...' interactive search","breadcrumbs":"Tools » radare2 » help","id":"137","title":"help"},"138":{"body":"> r2 -B # open mapped to addr oob # reopen current file at ","breadcrumbs":"Tools » radare2 » relocation","id":"138","title":"relocation"},"139":{"body":"","breadcrumbs":"Tools » radare2 » Examples","id":"139","title":"Examples"},"14":{"body":"Skeleton to copy/paste for writing simple completions. Assume a program foo with the following interface: foo -c green|red|blue -s low|high -f -d -h The completion handler could be implemented as follows in a file called _foo: #compdef _foo foo function _foo_color() { local colors=() colors+=('green:green color') colors+=('red:red color') colors+=('blue:blue color') _describe \"color\" colors\n} function _foo() { _arguments \\ \"-c[define color]:color:->s_color\" \\ \"-s[select sound]:sound:(low high)\" \\ \"-f[select file]:file:_files\" \\ \"-d[select dir]:dir:_files -/\" \\ \"-h[help]\" case $state in s_color) _foo_color;; esac\n} _files is a zsh builtin utility function to complete files/dirs see zsh completion functions zsh completion utility functions","breadcrumbs":"Tools » zsh » Example","id":"14","title":"Example"},"140":{"body":"> r2 [-w] oo+ # re-open for write if -w was not passed s # seek to position wv # write 4 byte (dword)","breadcrumbs":"Tools » radare2 » Patch file (alter bytes)","id":"140","title":"Patch file (alter bytes)"},"141":{"body":"rasm2 -L # list supported archs > rasm2 -a x86 'mov eax, 0xdeadbeef' b8efbeadde > rasm2 -a x86 -d \"b8efbeadde\" mov eax, 0xdeadbeef","breadcrumbs":"Tools » radare2 » Assemble / Disassmble (rasm2)","id":"141","title":"Assemble / Disassmble (rasm2)"},"142":{"body":"All the examples & notes use qemu-system-x86_64 but in most cases this can be swapped with the system emulator for other architectures.","breadcrumbs":"Tools » qemu » qemu(1)","id":"142","title":"qemu(1)"},"143":{"body":"Graphic mode: Ctrl+Alt+g release mouse capture from VM Ctrl+Alt+1 switch to display of VM\nCtrl+Alt+2 switch to qemu monitor No graphic mode: Ctrl+a h print help\nCtrl+a x exit emulator\nCtrl+a c switch between monitor and console","breadcrumbs":"Tools » qemu » Keybindings","id":"143","title":"Keybindings"},"144":{"body":"Following command-line gives a good starting point to assemble a VM: qemu-system-x86_64 \\ -cpu host -enable-kvm -smp 4 \\ -m 8G \\ -vga virtio -display sdl,gl=on \\ -boot menu=on \\ -cdrom \\ -hda \\ -device qemu-xhci,id=xhci \\ -device usb-host,bus=xhci.0,vendorid=0x05e1,productid=0x0408,id=capture-card","breadcrumbs":"Tools » qemu » VM config snippet","id":"144","title":"VM config snippet"},"145":{"body":"# Emulate host CPU in guest VM, enabling all supported host featured (requires KVM).\n# List available CPUs `qemu-system-x86_64 -cpu help`.\n-cpu host # Enable KVM instead software emulation.\n-enable-kvm # Configure number of guest CPUs.\n-smp # Configure size of guest RAM.\n-m 8G","breadcrumbs":"Tools » qemu » CPU & RAM","id":"145","title":"CPU & RAM"},"146":{"body":"# Use sdl window as display and enable openGL context.\n-display sdl,gl=on # Use vnc server as display (eg on display `:42` here).\n-display vnc=localhost:42 # Confifure virtio as 3D video graphic accelerator (requires virgl in guest).\n-vga virtio","breadcrumbs":"Tools » qemu » Graphic & Display","id":"146","title":"Graphic & Display"},"147":{"body":"# Enables boot menu to select boot device (enter with `ESC`).\n-boot menu=on","breadcrumbs":"Tools » qemu » Boot Menu","id":"147","title":"Boot Menu"},"148":{"body":"# Attach cdrom drive with iso to a VM.\n-cdrom # Attach disk drive to a VM.\n-hda # Generic way to configure & attach a drive to a VM.\n-drive file=,format=qcow2 Create a disk with qemu-img To create a qcow2 disk (qemu copy-on-write) of size 10G: qemu-img create -f qcow2 disk.qcow2 10G The disk does not contain any partitions or a partition table. We can format the disk from within the guest as following example: # Create `gpt` partition table.\nsudo parted /dev/sda mktable gpt # Create two equally sized primary partitions.\nsudo parted /dev/sda mkpart primary 0% 50%\nsudo parted /dev/sda mkpart primary 50% 100% # Create filesystem on each partition.\nsudo mkfs.ext3 /dev/sda1\nsudo mkfs.ext4 /dev/sda2 lsblk -f /dev/sda NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT sda ├─sda1 ext3 .... └─sda2 ext4 ....","breadcrumbs":"Tools » qemu » Block devices","id":"148","title":"Block devices"},"149":{"body":"Host Controller # Add XHCI USB controller to the VM (supports USB 3.0, 2.0, 1.1).\n# `id=xhci` creates a usb bus named `xhci`.\n-device qemu-xhci,id=xhci USB Device # Pass-through USB device from host identified by vendorid & productid and\n# attach to usb bus `xhci.0` (defined with controller `id`).\n-device usb-host,bus=xhci.0,vendorid=0x05e1,productid=0x0408","breadcrumbs":"Tools » qemu » USB","id":"149","title":"USB"},"15":{"body":"","breadcrumbs":"Tools » bash » bash(1)","id":"15","title":"bash(1)"},"150":{"body":"# Open gdbstub on tcp `` (`-s` shorthand for `-gdb tcp::1234`).\n-gdb tcp:: # Freeze guest CPU at startup and wait for debugger connection.\n-S","breadcrumbs":"Tools » qemu » Debugging","id":"150","title":"Debugging"},"151":{"body":"# Create raw tcp server for `serial IO` and wait until a client connects\n# before executing the guest.\n-serial tcp:localhost:12345,server,wait # Create telnet server for `serial IO` and wait until a client connects\n# before executing the guest.\n-serial telnet:localhost:12345,server,wait # Configure redirection for the QEMU `mointor`, arguments similar to `-serial`\n# above.\n-monitor ... In server mode use nowait to execute guest without waiting for a client connection.","breadcrumbs":"Tools » qemu » IO redirection","id":"151","title":"IO redirection"},"152":{"body":"# Redirect host tcp port `1234` to guest port `4321`.\n-nic user,hostfwd=tcp:localhost:1234-:4321","breadcrumbs":"Tools » qemu » Network","id":"152","title":"Network"},"153":{"body":"# Attach a `virtio-9p-pci` device to the VM.\n# The guest requires 9p support and can mount the shared drive as:\n# mount -t 9p -o trans=virtio someName /mnt\n-virtfs local,id=someName,path=,mount_tag=someName,security_model=none","breadcrumbs":"Tools » qemu » Shared drives","id":"153","title":"Shared drives"},"154":{"body":"# List debug items.\n-d help # Write debug log to file instead stderr.\n-D # Examples\n-d in_asm Log executed guest instructions.","breadcrumbs":"Tools » qemu » Debug logging","id":"154","title":"Debug logging"},"155":{"body":"# List name of all trace points.\n-trace help # Enable trace points matching pattern and optionally write trace to file.\n-trace [,file=] # Enable trace points for all events listed in the file.\n# File must contain one event/pattern per line.\n-trace events=","breadcrumbs":"Tools » qemu » Tracing","id":"155","title":"Tracing"},"156":{"body":"VM snapshots require that there is at least on qcow2 disk attached to the VM ( VM Snapshots ). Commands for qemu Monitor or QMP : # List available snapshots.\ninfo snapshots # Create/Load/Delete snapshot with name .\nsavevm \nloadvm \ndelvm The snapshot can also be directly specified when invoking qemu as: qemu-system-x86_64 \\ -loadvm \\ ...","breadcrumbs":"Tools » qemu » VM snapshots","id":"156","title":"VM snapshots"},"157":{"body":"Online migration example: # Start machine 1 on host ABC.\nqemu-system-x86_64 -monitor stdio -cdrom # Prepare machine 2 on host DEF as migration target.\n# Listen for any connection on port 12345.\nqemu-system-x86_64 -monitor stdio -incoming tcp:0.0.0.0:12345 # Start migration from the machine 1 monitor console.\n(qemu) migrate tcp:DEF:12345 Save to external file example: ```bash\n# Start machine 1.\nqemu-system-x86_64 -monitor stdio -cdrom # Save VM state to file.\n(qemu) migrate \"exec:gzip -c > vm.gz\" # Load VM from file.\nqemu-system-x86_64 -monitor stdio -incoming \"exec: gzip -d -c vm.gz\" The migration source machine and the migration target machine should be launched with the same parameters.","breadcrumbs":"Tools » qemu » VM Migration","id":"157","title":"VM Migration"},"158":{"body":"Example command line to directly boot a Kernel with an initrd ramdisk. qemu-system-x86_64 \\ -cpu host \\ -enable-kvm \\ -kernel /arch/x86/boot/bzImage \\ -append \"earlyprintk=ttyS0 console=ttyS0 nokaslr init=/init debug\" \\ -initrd /initramfs.cpio.gz \\ ... Instructions to build a minimal Kernel and initrd .","breadcrumbs":"Tools » qemu » Appendix: Direct Kernel boot","id":"158","title":"Appendix: Direct Kernel boot"},"159":{"body":"QEMU USB QEMU IMG QEMU Tools QEMU System QEMU Invocation (command line args) QEMU Monitor QEMU machine protocol (QMP) QEMU VM Snapshots","breadcrumbs":"Tools » qemu » References","id":"159","title":"References"},"16":{"body":"","breadcrumbs":"Tools » bash » Expansion","id":"16","title":"Expansion"},"160":{"body":"","breadcrumbs":"Tools » pacman » pacman(1)","id":"160","title":"pacman(1)"},"161":{"body":"pacman -Sy refresh package database\npacman -S install pkg\npacman -Ss search remote package database\npacman -Si get info for pkg\npacman -Su upgrade installed packages\npacman -Sc clean local package cache","breadcrumbs":"Tools » pacman » Remote package repositories","id":"161","title":"Remote package repositories"},"162":{"body":"pacman -Rsn uninstall package and unneeded deps + config files","breadcrumbs":"Tools » pacman » Remove packages","id":"162","title":"Remove packages"},"163":{"body":"Local package database of installed packages. pacman -Q list all installed packages\npacman -Qs search local package database\npacman -Ql list files installed by pkg\npacman -Qo query package that owns file\npacman -Qe only list explicitly installed packages","breadcrumbs":"Tools » pacman » Local package database","id":"163","title":"Local package database"},"164":{"body":"Local file database which allows to search packages owning certain files. Also searches non installed packages, but database must be synced. pacman -Fy refresh file database\npacman -Fl list files in pkg (must not be installed)\npacman -Fx search","breadcrumbs":"Tools » pacman » Local file database","id":"164","title":"Local file database"},"165":{"body":"Uninstall all orphaned packages (including config files) that were installed as dependencies. pacman -Rsn $(pacman -Qqtq) List explicitly installed packages that are not required as dependency by any package and sort by size. pacman -Qetq | xargs pacman -Qi | awk '/Name/ { name=$3 } /Installed Size/ { printf \"%8.2f%s %s\\n\", $4, $5, name }' | sort -h","breadcrumbs":"Tools » pacman » Hacks","id":"165","title":"Hacks"},"166":{"body":"Online playground","breadcrumbs":"Tools » dot » dot(1)","id":"166","title":"dot(1)"},"167":{"body":"Can be rendered to svg with the following command. dot -T svg -o g.svg g.dot Example dot file. // file: g.dot\ndigraph { // Render ranks from left to right. rankdir=LR // Make background transparent. bgcolor=transparent // Global node attributes. node [shape=box] // Global edge attributes. edge [style=dotted,color=red] // Add nodes & edge. stage1 -> stage2 // Add multiple edges at once. stage2 -> { stage3_1, stage3_2 } // Add edge with custom attributes. stage3_2 -> stage4 [label=\"some text\"] // Set custom attributes for specific node. stage4 [color=green,fillcolor=lightgray,style=\"filled,dashed\",label=\"s4\"] // Create a subgraph. This can be used to group nodes/edges or as scope for // global node/edge attributes. // If the name starts with 'cluster' a border is drawn. subgraph cluster_1 { stage5_1 stage5_2 } // Add some edges to subgraph nodes. stage3_1 -> { stage5_1, stage5_2 }\n} Rendered svg file. g.svg","breadcrumbs":"Tools » dot » Example dot file to copy & paste from.","id":"167","title":"Example dot file to copy & paste from."},"168":{"body":"DOT language Attributes Node shapes Colors User manual","breadcrumbs":"Tools » dot » References","id":"168","title":"References"},"169":{"body":"lsof ss pidstat pgrep pmap pstack","breadcrumbs":"Resource analysis & monitor » Resource analysis & monitor","id":"169","title":"Resource analysis & monitor"},"17":{"body":"# generate sequence from n to m\n{n..m}\n# generate sequence from n to m step by s\n{n..m..s} # expand cartesian product\n{a,b}{c,d}","breadcrumbs":"Tools » bash » Generator","id":"17","title":"Generator"},"170":{"body":"lsof -r ..... repeatedly execute command ervery seconds -a ......... AND slection filters instead ORing (OR: default) -p ... filter by +fg ........ show file flags for file descripros -n ......... don't convert network addr to hostnames -P ......... don't convert network port to service names -i <@h[:p]>. show connections to h (hostname|ip addr) with optional port p -s ... in conjunction with '-i' filter for protocol

in state -U ......... show unix domain sockets ('@' indicates abstract sock name, see unix(7)) file flags: R/W/RW ..... read/write/read-write CR ......... create AP ......... append TR ......... truncate -s protocols TCP, UDP -s states (TCP) CLOSED, IDLE, BOUND, LISTEN, ESTABLISHED, SYN_SENT, SYN_RCDV, ESTABLISHED, CLOSE_WAIT, FIN_WAIT1, CLOSING, LAST_ACK, FIN_WAIT_2, TIME_WAIT -s states (UDP) Unbound, Idle","breadcrumbs":"Resource analysis & monitor » lsof » lsof(8)","id":"170","title":"lsof(8)"},"171":{"body":"","breadcrumbs":"Resource analysis & monitor » lsof » Examples","id":"171","title":"Examples"},"172":{"body":"Show open files with file flags for process: lsof +fg -p ","breadcrumbs":"Resource analysis & monitor » lsof » File flags","id":"172","title":"File flags"},"173":{"body":"Show open tcp connections for $USER: lsof -a -u $USER -i TCP Note : -a ands the results. If -a is not given all open files matching $USER and all tcp connections are listed ( ored ).","breadcrumbs":"Resource analysis & monitor » lsof » Open TCP connections","id":"173","title":"Open TCP connections"},"174":{"body":"Show open connections to localhost for $USER: lsof -a -u $USER -i @localhost","breadcrumbs":"Resource analysis & monitor » lsof » Open connection to specific host","id":"174","title":"Open connection to specific host"},"175":{"body":"Show open connections to port :1234 for $USER: lsof -a -u $USER -i :1234","breadcrumbs":"Resource analysis & monitor » lsof » Open connection to specific port","id":"175","title":"Open connection to specific port"},"176":{"body":"lsof -i 4TCP -s TCP:ESTABLISHED","breadcrumbs":"Resource analysis & monitor » lsof » IPv4 TCP connections in ESTABLISHED state","id":"176","title":"IPv4 TCP connections in ESTABLISHED state"},"177":{"body":"ss [option] [filter] [option] -p ..... Show process using socket -l ..... Show sockets in listening state -4/-6 .. Show IPv4/6 sockets -x ..... Show unix sockets -n ..... Show numeric ports (no resolve) -O ..... Oneline output per socket [filter] dport/sport PORT .... Filter for destination/source port dst/src ADDR ........ Filter for destination/source address and/or .............. Logic operator ==/!= ............... Comparison operator (EXPR) .............. Group exprs","breadcrumbs":"Resource analysis & monitor » ss » ss(8)","id":"177","title":"ss(8)"},"178":{"body":"Show all tcp IPv4 sockets connecting to port 443: ss -4 'dport 443' Show all tcp IPv4 sockets that don't connect to port 443 or connect to address 1.2.3.4. ss -4 'dport != 443 or dst 1.2.3.4'","breadcrumbs":"Resource analysis & monitor » ss » Examples","id":"178","title":"Examples"},"179":{"body":"pidstat [opt] [interval] [cont] -U [user] show username instead UID, optionally only show for user -r memory statistics -d I/O statistics -h single line per process and no lines with average","breadcrumbs":"Resource analysis & monitor » pidstat » pidstat(1)","id":"179","title":"pidstat(1)"},"18":{"body":"# default value\nbar=${foo:-some_val} # if $foo set, then bar=$foo else bar=some_val # alternate value\nbar=${foo:+bla $foo} # if $foo set, then bar=\"bla $foo\" else bar=\"\" # check param set\nbar=${foo:?msg} # if $foo set, then bar=$foo else exit and print msg # indirect\nFOO=foo\nBAR=FOO\nbar=${!BAR} # deref value of BAR -> bar=$FOO # prefix\n${foo#prefix} # remove prefix when expanding $foo\n# suffix\n${foo%suffix} # remove suffix when expanding $foo # substitute\n${foo/pattern/string} # replace pattern with string when expanding foo\n# pattern starts with\n# '/' replace all occurences of pattern\n# '#' pattern match at beginning\n# '%' pattern match at end Note: prefix/suffix/pattern are expanded as pathnames .","breadcrumbs":"Tools » bash » Parameter","id":"18","title":"Parameter"},"180":{"body":"pidstat -r -p [interval] [count] minor_pagefault: Happens when the page needed is already in memory but not allocated to the faulting process, in that case the kernel only has to create a new page-table entry pointing to the shared physical page (not required to load a memory page from disk). major_pagefault: Happens when the page needed is NOT in memory, the kernel has to create a new page-table entry and populate the physical page (required to load a memory page from disk).","breadcrumbs":"Resource analysis & monitor » pidstat » Page fault and memory utilization","id":"180","title":"Page fault and memory utilization"},"181":{"body":"pidstat -d -p [interval] [count]","breadcrumbs":"Resource analysis & monitor » pidstat » I/O statistics","id":"181","title":"I/O statistics"},"182":{"body":"pgrep [opts] -n only list newest matching process -u only show matching for user -l additionally list command -a additionally list command + arguments","breadcrumbs":"Resource analysis & monitor » pgrep » pgrep(1)","id":"182","title":"pgrep(1)"},"183":{"body":"For example attach gdb to newest zsh process from $USER. gdb -p $(pgrep -n -u $USER zsh)","breadcrumbs":"Resource analysis & monitor » pgrep » Debug newest process","id":"183","title":"Debug newest process"},"184":{"body":"pmap Dump virtual memory map of process. Compared to /proc//maps it shows the size of the mappings.","breadcrumbs":"Resource analysis & monitor » pmap » pmap(1)","id":"184","title":"pmap(1)"},"185":{"body":"pstack Dump stack for all threads of process.","breadcrumbs":"Resource analysis & monitor » pstack » pstack(1)","id":"185","title":"pstack(1)"},"186":{"body":"strace ltrace perf OProfile time","breadcrumbs":"Trace and Profile » Trace and Profile","id":"186","title":"Trace and Profile"},"187":{"body":"strace [opts] [prg] -f .......... follow child processes on fork(2) -p .... attach to running process -s ... max string size, truncate of longer (default: 32) -e ... expression for trace filtering -o ... log output into -c .......... dump syscall statitics at the end -k .......... dump stack trace for each syscall -P ... only trace syscall accesing path -y .......... print paths for FDs -tt ......... print absolute timestamp (with us precision) -r .......... print relative timestamp : trace=syscall[,syscall] .... trace only syscall listed trace=file ................. trace all syscall that take a filename as arg trace=process .............. trace process management related syscalls trace=signal ............... trace signal related syscalls signal ..................... trace signals delivered to the process","breadcrumbs":"Trace and Profile » strace » strace(1)","id":"187","title":"strace(1)"},"188":{"body":"Trace open(2) & socket(2) syscalls for a running process + child processes: strace -f -e trace=open,socket -p Trace signals delivered to a running process: strace -e signal -e 'trace=!all' -p ","breadcrumbs":"Trace and Profile » strace » Examples","id":"188","title":"Examples"},"189":{"body":"ltrace [opts] [prg] -f .......... follow child processes on fork(2) -p .... attach to running process -o ... log output into -l . show who calls into lib matched by -C .......... demangle","breadcrumbs":"Trace and Profile » ltrace » ltrace(1)","id":"189","title":"ltrace(1)"},"19":{"body":"* match any string\n? match any single char\n\\\\ match backslash\n[abc] match any char of 'a' 'b' 'c'\n[a-z] match any char between 'a' - 'z'\n[^ab] negate, match all not 'a' 'b'\n[:class:] match any char in class, available: alnum,alpha,ascii,blank,cntrl,digit,graph,lower, print,punct,space,upper,word,xdigit With extglob shell option enabled it is possible to have more powerful patterns. In the following pattern-list is one ore more patterns separated by | char. ?(pattern-list) matches zero or one occurrence of the given patterns\n*(pattern-list) matches zero or more occurrences of the given patterns\n+(pattern-list) matches one or more occurrences of the given patterns\n@(pattern-list) matches one of the given patterns\n!(pattern-list) matches anything except one of the given patterns Note: shopt -s extglob/shopt -u extglob to enable/disable extglob option.","breadcrumbs":"Tools » bash » Pathname","id":"19","title":"Pathname"},"190":{"body":"List which program/libs call into libstdc++: ltrace -l '*libstdc++*' -C -o ltrace.log ./main","breadcrumbs":"Trace and Profile » ltrace » Example","id":"190","title":"Example"},"191":{"body":"perf list show supported hw/sw events perf stat -p .. show stats for running process -I ... show stats periodically over interval -e ... filter for events perf top -p .. show stats for running process -F ... sampling frequency -K ........ hide kernel threads perf record -p ............... record stats for running process -F ................ sampling frequency --call-graph .. [fp, dwarf, lbr] method how to caputre backtrace fp : use frame-pointer, need to compile with -fno-omit-frame-pointer dwarf: use .cfi debug information lbr : use hardware last branch record facility -g ..................... short-hand for --call-graph fp -e ................ filter for events perf report -n .................... annotate symbols with nr of samples --stdio ............... report to stdio, if not presen tui mode -g graph,0.5,caller ... show caller based call chains with value >0.5 Useful : page-faults minor-faults major-faults cpu-cycles` task-clock","breadcrumbs":"Trace and Profile » perf » perf(1)","id":"191","title":"perf(1)"},"192":{"body":"","breadcrumbs":"Trace and Profile » perf » Flamegraph","id":"192","title":"Flamegraph"},"193":{"body":"perf record -g -e cpu-cycles -p \nperf script | FlameGraph/stackcollapse-perf.pl | FlameGraph/flamegraph.pl > cycles-flamegraph.svg","breadcrumbs":"Trace and Profile » perf » Flamegraph with single event trace","id":"193","title":"Flamegraph with single event trace"},"194":{"body":"perf record -g -e cpu-cycles,page-faults -p \nperf script --per-event-dump\n# fold & generate as above","breadcrumbs":"Trace and Profile » perf » Flamegraph with multiple event traces","id":"194","title":"Flamegraph with multiple event traces"},"195":{"body":"operf -g -p -g ...... caputre call-graph information opreport [opt] FILE show time spent per binary image -l ...... show time spent per symbol -c ...... show callgraph information (see below) -a ...... add column with time spent accumulated over child nodes ophelp show supported hw/sw events","breadcrumbs":"Trace and Profile » OProfile » OProfile","id":"195","title":"OProfile"},"196":{"body":"# statistics of process run\n/usr/bin/time -v ","breadcrumbs":"Trace and Profile » time » /usr/bin/time(1)","id":"196","title":"/usr/bin/time(1)"},"197":{"body":"od xxd readelf objdump nm","breadcrumbs":"Binary » Binary","id":"197","title":"Binary"},"198":{"body":"od [opts] -An don't print addr info -tx4 print hex in 4 byte chunks -ta print as named character -tc printable chars or backslash escape -w4 print 4 bytes per line -j skip bytes from (hex if start with 0x) -N dump bytes (hex of start with 0x)","breadcrumbs":"Binary » od » od(1)","id":"198","title":"od(1)"},"199":{"body":"echo -n AAAABBBB | od -An -w4 -tx4 >> 41414141 >> 42424242 echo -n '\\x7fELF\\n' | od -tx1 -ta -tc >> 0000000 7f 45 4c 46 0a # tx1 >> del E L F nl # ta >> 177 E L F \\n # tc","breadcrumbs":"Binary » od » ASCII to hex string","id":"199","title":"ASCII to hex string"},"2":{"body":"","breadcrumbs":"Tools » zsh » zsh(1)","id":"2","title":"zsh(1)"},"20":{"body":"Note: The trick with bash I/O redirection is to interpret from left-to-right. # stdout & stderr to file\ncommand >file 2>&1\n# equivalent\ncommand &>file # stderr to stdout & stdout to file\ncommand 2>&1 >file The article Bash One-Liners Explained, Part III: All about redirections contains some nice visualization to explain bash redirections.","breadcrumbs":"Tools » bash » I/O redirection","id":"20","title":"I/O redirection"},"200":{"body":"For example .rodata section from an elf file. We can use readelf to get the offset into the file where the .rodata section starts. readelf -W -S foo >> Section Headers: >> [Nr] Name Type Address Off Size ES Flg Lk Inf Al >> ... >> [15] .rodata PROGBITS 00000000004009c0 0009c0 000030 00 A 0 0 16 With the offset of -j 0x0009c0 we can dump -N 0x30 bytes from the beginning of the .rodata section as follows: od -j 0x0009c0 -N 0x30 -tx4 -w4 foo >> 0004700 00020001 >> 0004704 00000000 >> * >> 0004740 00000001 >> 0004744 00000002 >> 0004750 00000003 >> 0004754 00000004 Note : Numbers starting with 0x will be interpreted as hex by od.","breadcrumbs":"Binary » od » Extract parts of file","id":"200","title":"Extract parts of file"},"201":{"body":"xxd [opts] -p dump continuous hexdump -r convert hexdump into binary ('revert') -e dump as little endian mode -i output as C array","breadcrumbs":"Binary » xxd » xxd(1)","id":"201","title":"xxd(1)"},"202":{"body":"echo -n 'aabb' | xxd -p >> 61616262","breadcrumbs":"Binary » xxd » ASCII to hex stream","id":"202","title":"ASCII to hex stream"},"203":{"body":"echo -n '61616262' | xxd -p -r >> aabb","breadcrumbs":"Binary » xxd » Hex to binary stream","id":"203","title":"Hex to binary stream"},"204":{"body":"echo -n '\\x7fELF' | xxd -p | xxd -p -r | file -p - >> ELF","breadcrumbs":"Binary » xxd » ASCII to binary","id":"204","title":"ASCII to binary"},"205":{"body":"xxd -i <(echo -n '\\x7fELF') >> unsigned char _proc_self_fd_11[] = { >> 0x7f, 0x45, 0x4c, 0x46 >> }; >> unsigned int _proc_self_fd_11_len = 4;","breadcrumbs":"Binary » xxd » ASCII to C array (hex encoded)","id":"205","title":"ASCII to C array (hex encoded)"},"206":{"body":"readelf [opts] -W|--wide wide output, dont break output at 80 chars -h print ELF header -S print section headers -l print program headers + segment mapping -d print .dynamic section (dynamic link information) --syms print symbol tables (.symtab .dynsym) --dyn-syms print dynamic symbol table (exported symbols for dynamic linker) -r print relocation sections (.rel.*, .rela.*)","breadcrumbs":"Binary » readelf » readelf(1)","id":"206","title":"readelf(1)"},"207":{"body":"objdump [opts] -M intel use intil syntax -d disassemble text section -D disassemble all sections -S mix disassembly with source code -C demangle -j

display info for section --[no-]show-raw-insn [dont] show object code next to disassembly","breadcrumbs":"Binary » objdump » objdump(1)","id":"207","title":"objdump(1)"},"208":{"body":"For example .plt section: objdump -j .plt -d ","breadcrumbs":"Binary » objdump » Disassemble section","id":"208","title":"Disassemble section"},"209":{"body":"nm [opts] -C demangle -u undefined only","breadcrumbs":"Binary » nm » nm(1)","id":"209","title":"nm(1)"},"21":{"body":"j>&i Duplicate fd i to fd j, making j a copy of i. See dup2(2) . Example: command 2>&1 >file duplicate fd 1 to fd 2, effectively redirecting stderr to stdout redirect stdout to file","breadcrumbs":"Tools » bash » Explanation","id":"21","title":"Explanation"},"210":{"body":"c++filt c++ glibc gcc make ld.so symbol versioning python","breadcrumbs":"Development » Development","id":"210","title":"Development"},"211":{"body":"","breadcrumbs":"Development » c++filt » c++filt(1)","id":"211","title":"c++filt(1)"},"212":{"body":"c++-filt ","breadcrumbs":"Development » c++filt » Demangle symbol","id":"212","title":"Demangle symbol"},"213":{"body":"For example dynamic symbol table: readelf -W --dyn-syms | c++filt","breadcrumbs":"Development » c++filt » Demangle stream","id":"213","title":"Demangle stream"},"214":{"body":"","breadcrumbs":"Development » c++ » c++","id":"214","title":"c++"},"215":{"body":"Force compile error to see what auto is deduced to. auto foo = bar(); // force compile error\ntypename decltype(foo)::_;","breadcrumbs":"Development » c++ » Type deduction","id":"215","title":"Type deduction"},"216":{"body":"#include // -- Example 1 - print template value arguments. // Base case with one parameter.\ntemplate\nvoid show_int() { printf(\"%d\\n\", P);\n} // General case with at least two parameters, to disambiguate from base case.\ntemplate\nvoid show_int() { printf(\"%d, \", P0); show_int();\n} // -- Example 2 - print values of different types. // Base case with one parameter.\ntemplate\nvoid show(const T& t) { std::cout << t << '\\n';\n} // General case with at least two parameters, to disambiguate from base case.\ntemplate\nvoid show(const T0& t0, const T1& t1, const Types&... types) { std::cout << t0 << \", \"; show(t1, types...);\n} int main() { show_int<1, 2, 3, 4, 5>(); show(1, 1.0, \"foo\", 'a');\n}","breadcrumbs":"Development » c++ » Variadic templates ( parameter pack )","id":"216","title":"Variadic templates ( parameter pack )"},"217":{"body":"#include template\nstruct any_of : std::false_type {}; // Found our type T in the list of types U.\ntemplate\nstruct any_of : std::true_type {}; // Pop off the first element in the list of types U,\n// since it didn't match our type T.\ntemplate\nstruct any_of : any_of {}; // Convenience template variable to invoke meta function.\ntemplate\nconstexpr bool any_of_v = any_of::value; static_assert(any_of_v, \"\");\nstatic_assert(!any_of_v, \"\");","breadcrumbs":"Development » c++ » Example: any_of template meta function","id":"217","title":"Example: any_of template meta function"},"218":{"body":"Provide a single entry point Invoke to call some Operations. Use enable_if to enable/disable the template functions depending on the two available traits an operation can have: Operation returns a result Operation requires a context #include \n#include // Helper meta fns. template\nusing enable_if_bool = std::enable_if_t; template\nusing disable_if_bool = std::enable_if_t; template\nusing has_dst = std::integral_constant::value>; // Template meta programming invoke machinery. namespace impl { // Invoke an OPERATION which *USES* a context. template class Op, typename... P, enable_if_bool::HasCtx> = true> typename Op::Return Invoke(const Ctx& C, P... params) { return Op()(C, params...); } // Invoke an OPERATION which uses *NO* context. template class Op, typename... P, disable_if_bool::HasCtx> = true> typename Op::Return Invoke(const Ctx&, P... params) { return Op()(params...); }\n} // namespace impl // Invoke an OPERATION which *HAS* a DESTINATION with arbitrary number of arguments.\ntemplate class Op, typename... P, enable_if_bool>> = true>\nvoid Invoke(const Ctx& C, P... params) { std::cout << \"Invoke \" << Op::Name << '\\n'; typename Op::Return R = impl::Invoke(C, params...); std::cout << \"returned -> \" << R << '\\n';\n} // Invoke an OPERATION which has *NOT* a DESTINATION with arbitrary number of arguments.\ntemplate class Op, typename... P, disable_if_bool>> = true>\nvoid Invoke(const Ctx& C, P... params) { std::cout << \"Invoke \" << Op::Name << \" without destination.\" << '\\n'; impl::Invoke(C, params...);\n} // Custom context. struct Ctx { void out(const char* s, unsigned v) const { printf(\"%s%x\\n\", s, v); }\n}; // Operations to invoke. template\nstruct OpA { using HasCtx = std::false_type; using Return = int; static constexpr const char* const Name = \"OpA\"; constexpr Return operator()(int a, int b) const { return a + b; }\n}; template\nstruct OpB { using HasCtx = std::true_type; using Return = void; static constexpr const char* const Name = \"OpB\"; Return operator()(const Ctx& C, unsigned a) const { C.out(\"a = \", a); }\n}; int main() { Ctx C; Invoke(C, 1, 2); Invoke(C, 0xf00du); return 0;\n}","breadcrumbs":"Development » c++ » Example: SFINAE ( enable_if )","id":"218","title":"Example: SFINAE ( enable_if )"},"219":{"body":"","breadcrumbs":"Development » glibc » glibc","id":"219","title":"glibc"},"22":{"body":"The getopts builtin uses following global variables: OPTARG, value of last option argument OPTIND, index of the next argument to process (user must reset) OPTERR, display errors if set to 1 getopts [] specifies the names of supported options, eg f:c f: means -f option with an argument c means -c option without an argument specifies a variable name which getopts fills with the last parsed option argument optionally specify argument string to parse, by default getopts parses $@","breadcrumbs":"Tools » bash » Argument parsing with getopts","id":"22","title":"Argument parsing with getopts"},"220":{"body":"Trace memory allocation and de-allocation to detect memory leaks. Need to call mtrace(3) to install the tracing hooks. If we can't modify the binary to call mtrace we can create a small shared library and pre-load it. // libmtrace.c\n#include \n__attribute__((constructor)) static void init_mtrace() { mtrace(); } Compile as: gcc -shared -fPIC -o libmtrace.so libmtrace.c To generate the trace file run: export MALLOC_TRACE=\nLD_PRELOAD=./libmtrace.so Note : If MALLOC_TRACE is not set mtrace won't install tracing hooks. To get the results of the trace file: mtrace $MALLOC_TRACE","breadcrumbs":"Development » glibc » malloc tracer mtrace(3)","id":"220","title":"malloc tracer mtrace(3)"},"221":{"body":"Configure action when glibc detects memory error. export MALLOC_CHECK_= Useful values: 1 print detailed error & continue\n3 print detailed error + stack trace + memory mappings & abort\n7 print simple error message + stack trace + memory mappings & abort","breadcrumbs":"Development » glibc » malloc check mallopt(3)","id":"221","title":"malloc check mallopt(3)"},"222":{"body":"","breadcrumbs":"Development » gcc » gcc(1)","id":"222","title":"gcc(1)"},"223":{"body":"","breadcrumbs":"Development » gcc » CLI","id":"223","title":"CLI"},"224":{"body":"While debugging can be helpful to just pre-process files. gcc -E [-dM] ... -E run only preprocessor -dM list only #define statements -### dry-run, outputting exact compiler/linker invocations -print-multi-lib print available multilib configurations","breadcrumbs":"Development » gcc » Preprocessing","id":"224","title":"Preprocessing"},"225":{"body":"# List all target options with their description.\ngcc --help=target # Configure for current cpu arch and query (-Q) value of options.\ngcc -march=native -Q --help=target","breadcrumbs":"Development » gcc » Target options","id":"225","title":"Target options"},"226":{"body":"","breadcrumbs":"Development » gcc » Builtins","id":"226","title":"Builtins"},"227":{"body":"Give the compiler a hint which branch is hot, so it can lay out the code accordingly to reduce number of jump instructions. See on compiler explorer . The semantics of this hint are as follows, the compiler prioritises expr == cond. So __builtin_expect(expr, 0) means that we expect the expr to be 0 most of the time. echo \"\nextern void foo();\nextern void bar();\nvoid run0(int x) { if (__builtin_expect(x,0)) { foo(); } else { bar(); }\n}\nvoid run1(int x) { if (__builtin_expect(x,1)) { foo(); } else { bar(); }\n}\n\" | gcc -O2 -S -masm=intel -o /dev/stdout -xc - Will generate something similar to the following. run0: bar is on the path without branch run1: foo is on the path without branch run0: test edi, edi jne .L4 xor eax, eax jmp bar\n.L4: xor eax, eax jmp foo\nrun1: test edi, edi je .L6 xor eax, eax jmp foo\n.L6: xor eax, eax jmp bar","breadcrumbs":"Development » gcc » __builtin_expect(expr, cond)","id":"227","title":"__builtin_expect(expr, cond)"},"228":{"body":"C ABI - SystemV ABI C++ ABI - C++ Itanium ABI","breadcrumbs":"Development » gcc » ABI (Linux)","id":"228","title":"ABI (Linux)"},"229":{"body":"","breadcrumbs":"Development » make » make(1)","id":"229","title":"make(1)"},"23":{"body":"#!/bin/bash\nfunction parse_args() { while getopts \"f:c\" PARAM; do case $PARAM in f) echo \"GOT -f $OPTARG\";; c) echo \"GOT -c\";; *) echo \"ERR: print usage\"; exit 1;; esac done # users responsibility to reset OPTIND OPTIND=1\n} parse_args -f xxx -c\nparse_args -f yyy","breadcrumbs":"Tools » bash » Example","id":"23","title":"Example"},"230":{"body":"target .. : prerequisite .. recipe .. target: an output generated by the rule prerequisite: an input that is used to generate the target recipe: list of actions to generate the output from the input Use make -p to print all rules and variables (implicitly + explicitly defined).","breadcrumbs":"Development » make » Anatomy of make rules","id":"230","title":"Anatomy of make rules"},"231":{"body":"","breadcrumbs":"Development » make » Pattern rules & Automatic variables","id":"231","title":"Pattern rules & Automatic variables"},"232":{"body":"A pattern rule contains the % char (exactly one of them) and look like this example: %.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ The target matches files of the pattern %.o, where % matches any none-empty substring and other character match just them self. The substring matched by % is called the stem. % in the prerequisite stands for the matched stem in the target.","breadcrumbs":"Development » make » Pattern rules","id":"232","title":"Pattern rules"},"233":{"body":"As targets and prerequisites in pattern rules can't be spelled explicitly in the recipe, make provides a set of automatic variables to work with: $@: Name of the target that triggered the rule. $<: Name of the first prerequisite. $^: Names of all prerequisites (without duplicates). $+: Names of all prerequisites (with duplicates). $*: Stem of the pattern rule. # file: Makefile all: foobar blabla foo% bla%: aaa bbb bbb @echo \"@ = $@\" @echo \"< = $<\" @echo \"^ = $^\" @echo \"+ = $+\" @echo \"* = $*\" @echo \"----\" aaa:\nbbb: Running above Makefile gives: @ = foobar\n< = aaa\n^ = aaa bbb\n+ = aaa bbb bbb\n* = bar\n----\n@ = blabla\n< = aaa\n^ = aaa bbb\n+ = aaa bbb bbb\n* = bla\n---- Variables related to filesystem paths: $(CURDIR): Path of current working dir after using make -C path","breadcrumbs":"Development » make » Automatic variables","id":"233","title":"Automatic variables"},"234":{"body":"","breadcrumbs":"Development » make » Useful functions","id":"234","title":"Useful functions"},"235":{"body":"Substitute strings matching pattern in a list. in := a.o l.a c.o\nout := $(in:.o=.c)\n# => out = a.c l.a c.c","breadcrumbs":"Development » make » Substitution references","id":"235","title":"Substitution references"},"236":{"body":"Keep strings matching a pattern in a list. in := a.a b.b c.c d.d\nout := $(filter %.b %.c, $(in))\n# => out = b.b c.c","breadcrumbs":"Development » make » filter","id":"236","title":"filter"},"237":{"body":"Remove strings matching a pattern from a list. in := a.a b.b c.c d.d\nout := $(filter-out %.b %.c, $(in))\n# => out = a.a d.d","breadcrumbs":"Development » make » filter-out","id":"237","title":"filter-out"},"238":{"body":"Resolve each file name as absolute path (don't resolve symlinks). $(abspath fname1 fname2 ..) ### `realpath`\nResolve each file name as canonical path.\n```make\n$(realpath fname1 fname2 ..)","breadcrumbs":"Development » make » abspath","id":"238","title":"abspath"},"239":{"body":"","breadcrumbs":"Development » ld.so » ld.so(8)","id":"239","title":"ld.so(8)"},"24":{"body":"Bash supports regular expression matching with the binary operator =~. The match results can be accessed via the $BASH_REMATCH variable: ${BASH_REMATCH[0]} contains the full match ${BASH_REMATCH[1]} contains match of the first capture group INPUT='title foo : 1234'\nREGEX='^title (.+) : ([0-9]+)$'\nif [[ $INPUT =~ $REGEX ]]; then echo \"${BASH_REMATCH[0]}\" # title foo : 1234 echo \"${BASH_REMATCH[1]}\" # foo echo \"${BASH_REMATCH[2]}\" # 1234\nfi Caution : When specifying a regex in the [[ ]] block directly, quotes will be treated as part of the pattern. [[ $INPUT =~ \"foo\" ]] will match against \"foo\" not foo!","breadcrumbs":"Tools » bash » Regular Expressions","id":"24","title":"Regular Expressions"},"240":{"body":"LD_PRELOAD= colon separated list of libso's to be pre loaded LD_DEBUG= comma separated list of debug options =help list available options =libs show library search path =files processing of input files =symbols show search path for symbol lookup =bindings show against which definition a symbol is bound","breadcrumbs":"Development » ld.so » Environment Variables","id":"240","title":"Environment Variables"},"241":{"body":"Libraries specified in LD_PRELOAD are loaded from left-to-right but initialized from right-to-left. > ldd ./main >> libc.so.6 => /usr/lib/libc.so.6 > LD_PRELOAD=liba.so:libb.so ./main --> preloaded in this order <-- initialized in this order The preload order determines: the order libraries are inserted into the link map the initialization order for libraries For the example listed above the resulting link map will look like the following: +------+ +------+ +------+ +------+ | main | -> | liba | -> | libb | -> | libc | +------+ +------+ +------+ +------+ This can be seen when running with LD_DEBUG=files: > LD_DEBUG=files LD_PRELOAD=liba.so:libb.so ./main # load order (-> determines link map) >> file=liba.so [0]; generating link map >> file=libb.so [0]; generating link map >> file=libc.so.6 [0]; generating link map # init order >> calling init: /usr/lib/libc.so.6 >> calling init: /libb.so >> calling init: /liba.so >> initialize program: ./main To verify the link map order we let ld.so resolve the memcpy(3) libc symbol (used in main ) dynamically, while enabling LD_DEBUG=symbols,bindings to see the resolving in action. > LD_DEBUG=symbols,bindings LD_PRELOAD=liba.so:libb.so ./main >> symbol=memcpy; lookup in file=./main [0] >> symbol=memcpy; lookup in file=/liba.so [0] >> symbol=memcpy; lookup in file=/libb.so [0] >> symbol=memcpy; lookup in file=/usr/lib/libc.so.6 [0] >> binding file ./main [0] to /usr/lib/libc.so.6 [0]: normal symbol `memcpy' [GLIBC_2.14]","breadcrumbs":"Development » ld.so » LD_PRELOAD: Initialization Order and Link Map","id":"241","title":"LD_PRELOAD: Initialization Order and Link Map"},"242":{"body":"Dynamic linking basically works via one indirect jump. It uses a combination of function trampolines (.plt section) and a function pointer table (.got.plt section). On the first call the trampoline sets up some metadata and then jumps to the ld.so runtime resolve function, which in turn patches the table with the correct function pointer. .plt ....... procedure linkage table, contains function trampolines, usually located in code segment (rx permission) .got.plt ... global offset table for .plt, holds the function pointer table Using radare2 we can analyze this in more detail: [0x00401040]> pd 4 @ section..got.plt ;-- section..got.plt: ;-- .got.plt: ; [22] -rw- section size 32 named .got.plt ;-- _GLOBAL_OFFSET_TABLE_: [0] 0x00404000 .qword 0x0000000000403e10 ; section..dynamic [1] 0x00404008 .qword 0x0000000000000000 ; CODE XREF from section..plt @ +0x6 [2] 0x00404010 .qword 0x0000000000000000 ;-- reloc.puts: ; CODE XREF from sym.imp.puts @ 0x401030 [3] 0x00404018 .qword 0x0000000000401036 ; RELOC 64 puts [0x00401040]> pd 6 @ section..plt ;-- section..plt: ;-- .plt: ; [12] -r-x section size 32 named .plt ┌─> 0x00401020 ff35e22f0000 push qword [0x00404008] ╎ 0x00401026 ff25e42f0000 jmp qword [0x00404010] ╎ 0x0040102c 0f1f4000 nop dword [rax] ┌ 6: int sym.imp.puts (const char *s); └ ╎ 0x00401030 ff25e22f0000 jmp qword [reloc.puts] ╎ 0x00401036 6800000000 push 0 └─< 0x0040103b e9e0ffffff jmp sym..plt At address 0x00401030 in the .plt section we see the indirect jump for puts using the function pointer in _GLOBAL_OFFSET_TABLE_[3] (GOT). GOT[3] initially points to instruction after the puts trampoline 0x00401036. This pushes the relocation index 0 and then jumps to the first trampoline 0x00401020. The first trampoline jumps to GOT[2] which will be filled at program startup by the ld.so with its resolve function. The ld.so resolve function fixes the relocation referenced by the relocation index pushed by the puts trampoline. The relocation entry at index 0 tells the resolve function which symbol to search for and where to put the function pointer: > readelf -r
>> Relocation section '.rela.plt' at offset 0x4b8 contains 1 entry: >> Offset Info Type Sym. Value Sym. Name + Addend >> 000000404018 000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts@GLIBC_2.2.5 + 0 As we can see the offset from relocation at index 0 points to GOT[3].","breadcrumbs":"Development » ld.so » Dynamic Linking (x86_64)","id":"242","title":"Dynamic Linking (x86_64)"},"243":{"body":"The ELF symbol versioning mechanism allows to attach version information to symbols. This can be used to express symbol version requirements or to provide certain symbols multiple times in the same ELF file with different versions (eg for backwards compatibility). The libpthread.so library is an example which provides the pthread_cond_wait symbol multiple times but in different versions. With readelf the version of the symbol can be seen after the @. > readelf -W --dyn-syms /lib/libpthread.so Symbol table '.dynsym' contains 342 entries: Num: Value Size Type Bind Vis Ndx Name ... 141: 0000f080 696 FUNC GLOBAL DEFAULT 16 pthread_cond_wait@@GLIBC_2.3.2 142: 00010000 111 FUNC GLOBAL DEFAULT 16 pthread_cond_wait@GLIBC_2.2.5 The @@ denotes the default symbol version which will be used during static linking against the library. The following dump shows that the tmp program linked against lpthread will depend on the symbol version GLIBC_2.3.2, which is the default version. > echo \"#include int main() { return pthread_cond_wait(0,0); }\" | gcc -o tmp -xc - -lpthread; readelf -W --dyn-syms tmp | grep pthread_cond_wait; Symbol table '.dynsym' contains 7 entries: Num: Value Size Type Bind Vis Ndx Name ... 2: 00000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_wait@GLIBC_2.3.2 (2) Only one symbol can be annotated as the @@ default version. Using the --version-info flag with readelf, more details on the symbol version info compiled into the tmp ELF file can be obtained. The .gnu.version section contains the version definition for each symbol in the .dynsym section. pthread_cond_wait is at index 2 in the .dynsym section, the corresponding symbol version is at index 2 in the .gnu.version section. The .gnu.version_r section contains symbol version requirements per shared library dependency (DT_NEEDED dynamic entry). > readelf -W --version-info --dyn-syms tmp Symbol table '.dynsym' contains 7 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable 2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_cond_wait@GLIBC_2.3.2 (2) 3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (3) 4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 5: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 6: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5 (3) Version symbols section '.gnu.version' contains 7 entries: Addr: 0x0000000000000534 Offset: 0x000534 Link: 6 (.dynsym) 000: 0 (*local*) 0 (*local*) 2 (GLIBC_2.3.2) 3 (GLIBC_2.2.5) 004: 0 (*local*) 0 (*local*) 3 (GLIBC_2.2.5) Version needs section '.gnu.version_r' contains 2 entries: Addr: 0x0000000000000548 Offset: 0x000548 Link: 7 (.dynstr) 000000: Version: 1 File: libc.so.6 Cnt: 1 0x0010: Name: GLIBC_2.2.5 Flags: none Version: 3 0x0020: Version: 1 File: libpthread.so.0 Cnt: 1 0x0030: Name: GLIBC_2.3.2 Flags: none Version: 2 The gnu dynamic linker allows to inspect the version processing during runtime by setting the LD_DEBUG environment variable accordingly. # version: Display version dependencies.\n> LD_DEBUG=versions ./tmp 717904: checking for version `GLIBC_2.2.5' in file /usr/lib/libc.so.6 [0] required by file ./tmp [0] 717904: checking for version `GLIBC_2.3.2' in file /usr/lib/libpthread.so.0 [0] required by file ./tmp [0] ... # symbols : Display symbol table processing.\n# bindings: Display information about symbol binding.\n> LD_DEBUG=symbols,bindings ./tmp ... 718123: symbol=pthread_cond_wait; lookup in file=./tmp [0] 718123: symbol=pthread_cond_wait; lookup in file=/usr/lib/libpthread.so.0 [0] 718123: binding file ./tmp [0] to /usr/lib/libpthread.so.0 [0]: normal symbol `pthread_cond_wait' [GLIBC_2.3.2]","breadcrumbs":"Development » symbol versioning » ELF Symbol Versioning","id":"243","title":"ELF Symbol Versioning"},"244":{"body":"The following shows an example C++ library libfoo which provides the same symbol multiple times but in different versions. // file: libfoo.cc\n#include // Bind function symbols to version nodes.\n//\n// ..@ -> Is the unversioned symbol.\n// ..@@.. -> Is the default symbol. __asm__(\".symver func_v0,func@\");\n__asm__(\".symver func_v1,func@LIB_V1\");\n__asm__(\".symver func_v2,func@@LIB_V2\"); extern \"C\" { void func_v0() { puts(\"func_v0\"); } void func_v1() { puts(\"func_v1\"); } void func_v2() { puts(\"func_v2\"); }\n} __asm__(\".symver _Z11func_cpp_v1i,_Z8func_cppi@LIB_V1\");\n__asm__(\".symver _Z11func_cpp_v2i,_Z8func_cppi@@LIB_V2\"); void func_cpp_v1(int) { puts(\"func_cpp_v1\"); }\nvoid func_cpp_v2(int) { puts(\"func_cpp_v2\"); } void func_cpp(int) { puts(\"func_cpp_v2\"); } Version script for libfoo which defines which symbols for which versions are exported from the ELF file. # file: libfoo.ver\nLIB_V1 { global: func; extern \"C++\" { \"func_cpp(int)\"; }; local: *;\n}; LIB_V2 { global: func; extern \"C++\" { \"func_cpp(int)\"; };\n} LIB_V1; The local: section in LIB_V1 is a catch all, that matches any symbol not explicitly specified, and defines that the symbol is local and therefore not exported from the ELF file. The library libfoo can be linked with the version definitions in libfoo.ver by passing the version script to the linker with the --version-script flag. > g++ -shared -fPIC -o libfoo.so libfoo.cc -Wl,--version-script=libfoo.ver\n> readelf -W --dyn-syms libfoo.so | c++filt Symbol table '.dynsym' contains 14 entries: Num: Value Size Type Bind Vis Ndx Name ... 6: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS LIB_V1 7: 000000000000114b 29 FUNC GLOBAL DEFAULT 13 func_cpp(int)@LIB_V1 8: 0000000000001168 29 FUNC GLOBAL DEFAULT 13 func_cpp(int)@@LIB_V2 9: 0000000000001185 29 FUNC GLOBAL DEFAULT 13 func_cpp(int)@@LIB_V1 10: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS LIB_V2 11: 0000000000001109 22 FUNC GLOBAL DEFAULT 13 func 12: 000000000000111f 22 FUNC GLOBAL DEFAULT 13 func@LIB_V1 13: 0000000000001135 22 FUNC GLOBAL DEFAULT 13 func@@LIB_V2 The following program demonstrates how to make use of the different versions: // file: main.cc\n#include \n#include // Links against default symbol in the lib.so.\nextern \"C\" void func(); int main() { // Call the default version. func(); #ifdef _GNU_SOURCE typedef void (*fnptr)(); // Unversioned lookup. fnptr fn_v0 = (fnptr)dlsym(RTLD_DEFAULT, \"func\"); // Version lookup. fnptr fn_v1 = (fnptr)dlvsym(RTLD_DEFAULT, \"func\", \"LIB_V1\"); fnptr fn_v2 = (fnptr)dlvsym(RTLD_DEFAULT, \"func\", \"LIB_V2\"); assert(fn_v0 != 0); assert(fn_v1 != 0); assert(fn_v2 != 0); fn_v0(); fn_v1(); fn_v2();\n#endif return 0;\n} Compiling and running results in: > g++ -o main main.cc -ldl ./libfoo.so && ./main\nfunc_v2\nfunc_v0\nfunc_v1\nfunc_v2","breadcrumbs":"Development » symbol versioning » Example: version script","id":"244","title":"Example: version script"},"245":{"body":"ELF Symbol Versioning Binutils ld: Symbol Versioning LSB: Symbol Versioning How To Write Shared Libraries","breadcrumbs":"Development » symbol versioning » References","id":"245","title":"References"},"246":{"body":"","breadcrumbs":"Development » python » python","id":"246","title":"python"},"247":{"body":"Some decorator examples with type annotation. from typing import Callable def log(f: Callable[[int], None]) -> Callable[[int], None]: def inner(x: int): print(f\"log::inner f={f.__name__} x={x}\") f(x) return inner @log\ndef some_fn(x: int): print(f\"some_fn x={x}\") def log_tag(tag: str) -> Callable[[Callable[[int], None]], Callable[[int], None]]: def decorator(f: Callable[[int], None]) -> Callable[[int], None]: def inner(x: int): print(f\"log_tag::inner f={f.__name__} tag={tag} x={x}\") f(x) return inner return decorator @log_tag(\"some_tag\")\ndef some_fn2(x: int): print(f\"some_fn2 x={x}\")","breadcrumbs":"Development » python » Decorator [ run ]","id":"247","title":"Decorator [ run ]"},"248":{"body":"Walrus operator := added since python 3.8 . from typing import Optional # Example 1: if let statements def foo(ret: Optional[int]) -> Optional[int]: return ret if r := foo(None): print(f\"foo(None) -> {r}\") if r := foo(1337): print(f\"foo(1337) -> {r}\") # Example 2: while let statements toks = iter(['a', 'b', 'c'])\nwhile tok := next(toks, None): print(f\"{tok}\") # Example 3: list comprehension print([tok for t in [\" a\", \" \", \" b \"] if (tok := t.strip())])","breadcrumbs":"Development » python » Walrus operator [ run ]","id":"248","title":"Walrus operator [ run ]"},"249":{"body":"Run unittests directly from the command line as python3 -m unittest -v test Optionally pass -k to only run subset of tests. # file: test.py import unittest class MyTest(unittest.TestCase): def setUp(self): pass def tearDown(self): pass # Tests need to start with the prefix 'test'. def test_foo(self): self.assertEqual(1 + 2, 3) def test_bar(self): with self.assertRaises(IndexError): list()[0]","breadcrumbs":"Development » python » Unittest [ run ]","id":"249","title":"Unittest [ run ]"},"25":{"body":"The complete builtin is used to interact with the completion system. complete # print currently installed completion handler\ncomplete -F # install as completion handler for \ncomplete -r # uninstall completion handler for Variables available in completion functions: # in\n$1 # \n$2 # current word\n$3 # privous word COMP_WORDS # array with current command line words\nCOMP_CWORD # index into COMP_WORDS with current cursor position # out\nCOMPREPLY # array with possible completions The compgen builtin is used to generate possible matches by comparing word against words generated by option. compgen