aboutsummaryrefslogtreecommitdiffhomepage
path: root/print.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2020-04-28 09:11:18 +0000
committerjohannst <johannst@users.noreply.github.com>2020-04-28 09:11:18 +0000
commit15230bbb9b1f69def9b0e1b41a097638c0fda734 (patch)
tree2b490b2f0b8d6f3eab0af91c7ba5cc557b540af6 /print.html
parentce1a0eaa58f7ad07c5389996a90c4b02bdf573fc (diff)
downloadnotes-15230bbb9b1f69def9b0e1b41a097638c0fda734.tar.gz
notes-15230bbb9b1f69def9b0e1b41a097638c0fda734.zip
deploy: fef4d6ff2ad9f48e6dccde0f061453e6a3ac624e
Diffstat (limited to 'print.html')
-rw-r--r--print.html835
1 files changed, 428 insertions, 407 deletions
diff --git a/print.html b/print.html
index 66f1ebe..c10b517 100644
--- a/print.html
+++ b/print.html
@@ -83,7 +83,7 @@
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div id="sidebar-scrollbox" class="sidebar-scrollbox">
- <ol class="chapter"><li class="expanded "><a href="ld.so.html"><strong aria-hidden="true">1.</strong> ld.so</a></li><li class="expanded "><a href="git.html"><strong aria-hidden="true">2.</strong> git</a></li><li class="expanded "><a href="bash.html"><strong aria-hidden="true">3.</strong> bash</a></li><li class="expanded "><a href="zsh.html"><strong aria-hidden="true">4.</strong> zsh</a></li><li class="expanded "><a href="tmux.html"><strong aria-hidden="true">5.</strong> tmux</a></li><li class="expanded "><a href="awk.html"><strong aria-hidden="true">6.</strong> awk</a></li><li class="expanded "><a href="gdb.html"><strong aria-hidden="true">7.</strong> gdb</a></li><li class="expanded "><a href="radare2.html"><strong aria-hidden="true">8.</strong> radare2</a></li><li class="expanded "><a href="emacs.html"><strong aria-hidden="true">9.</strong> emacs</a></li><li class="expanded "><a href="fish.html"><strong aria-hidden="true">10.</strong> fish</a></li><li class="expanded "><a href="strace.html"><strong aria-hidden="true">11.</strong> strace</a></li><li class="expanded "><a href="lsof.html"><strong aria-hidden="true">12.</strong> lsof</a></li><li class="expanded "><a href="pidstat.html"><strong aria-hidden="true">13.</strong> pidstat</a></li><li class="expanded "><a href="time.html"><strong aria-hidden="true">14.</strong> time</a></li><li class="expanded "><a href="pgrep.html"><strong aria-hidden="true">15.</strong> pgrep</a></li><li class="expanded "><a href="pstack.html"><strong aria-hidden="true">16.</strong> pstack</a></li><li class="expanded "><a href="perf.html"><strong aria-hidden="true">17.</strong> perf</a></li><li class="expanded "><a href="oprofile.html"><strong aria-hidden="true">18.</strong> OProfile</a></li><li class="expanded "><a href="od.html"><strong aria-hidden="true">19.</strong> od</a></li><li class="expanded "><a href="xxd.html"><strong aria-hidden="true">20.</strong> xxd</a></li><li class="expanded "><a href="readelf.html"><strong aria-hidden="true">21.</strong> readelf</a></li><li class="expanded "><a href="objdump.html"><strong aria-hidden="true">22.</strong> objdump</a></li><li class="expanded "><a href="nm.html"><strong aria-hidden="true">23.</strong> nm</a></li><li class="expanded "><a href="c++filt.html"><strong aria-hidden="true">24.</strong> c++filt</a></li><li class="expanded "><a href="c++.html"><strong aria-hidden="true">25.</strong> c++</a></li><li class="expanded "><a href="glibc.html"><strong aria-hidden="true">26.</strong> glibc</a></li><li class="expanded "><a href="gcc.html"><strong aria-hidden="true">27.</strong> gcc</a></li></ol>
+ <ol class="chapter"><li class="expanded "><a href="misc/index.html"><strong aria-hidden="true">1.</strong> Misc</a></li><li><ol class="section"><li class="expanded "><a href="misc/zsh.html"><strong aria-hidden="true">1.1.</strong> zsh</a></li><li class="expanded "><a href="misc/bash.html"><strong aria-hidden="true">1.2.</strong> bash</a></li><li class="expanded "><a href="misc/fish.html"><strong aria-hidden="true">1.3.</strong> fish</a></li><li class="expanded "><a href="misc/tmux.html"><strong aria-hidden="true">1.4.</strong> tmux</a></li><li class="expanded "><a href="misc/git.html"><strong aria-hidden="true">1.5.</strong> git</a></li><li class="expanded "><a href="misc/awk.html"><strong aria-hidden="true">1.6.</strong> awk</a></li><li class="expanded "><a href="misc/emacs.html"><strong aria-hidden="true">1.7.</strong> emacs</a></li><li class="expanded "><a href="misc/gdb.html"><strong aria-hidden="true">1.8.</strong> gdb</a></li><li class="expanded "><a href="misc/radare2.html"><strong aria-hidden="true">1.9.</strong> radare2</a></li></ol></li><li class="expanded "><a href="monitor/index.html"><strong aria-hidden="true">2.</strong> Resource analysis &amp; monitor</a></li><li><ol class="section"><li class="expanded "><a href="monitor/lsof.html"><strong aria-hidden="true">2.1.</strong> lsof</a></li><li class="expanded "><a href="monitor/pidstat.html"><strong aria-hidden="true">2.2.</strong> pidstat</a></li><li class="expanded "><a href="monitor/pgrep.html"><strong aria-hidden="true">2.3.</strong> pgrep</a></li><li class="expanded "><a href="monitor/pmap.html"><strong aria-hidden="true">2.4.</strong> pmap</a></li><li class="expanded "><a href="monitor/pstack.html"><strong aria-hidden="true">2.5.</strong> pstack</a></li></ol></li><li class="expanded "><a href="trace_profile/index.html"><strong aria-hidden="true">3.</strong> Trace and Profile</a></li><li><ol class="section"><li class="expanded "><a href="trace_profile/strace.html"><strong aria-hidden="true">3.1.</strong> strace</a></li><li class="expanded "><a href="trace_profile/ltrace.html"><strong aria-hidden="true">3.2.</strong> ltrace</a></li><li class="expanded "><a href="trace_profile/perf.html"><strong aria-hidden="true">3.3.</strong> perf</a></li><li class="expanded "><a href="trace_profile/oprofile.html"><strong aria-hidden="true">3.4.</strong> OProfile</a></li><li class="expanded "><a href="trace_profile/time.html"><strong aria-hidden="true">3.5.</strong> time</a></li></ol></li><li class="expanded "><a href="binary/index.html"><strong aria-hidden="true">4.</strong> Binary</a></li><li><ol class="section"><li class="expanded "><a href="binary/od.html"><strong aria-hidden="true">4.1.</strong> od</a></li><li class="expanded "><a href="binary/xxd.html"><strong aria-hidden="true">4.2.</strong> xxd</a></li><li class="expanded "><a href="binary/readelf.html"><strong aria-hidden="true">4.3.</strong> readelf</a></li><li class="expanded "><a href="binary/objdump.html"><strong aria-hidden="true">4.4.</strong> objdump</a></li><li class="expanded "><a href="binary/nm.html"><strong aria-hidden="true">4.5.</strong> nm</a></li></ol></li><li class="expanded "><a href="development/index.html"><strong aria-hidden="true">5.</strong> Development</a></li><li><ol class="section"><li class="expanded "><a href="development/c++filt.html"><strong aria-hidden="true">5.1.</strong> c++filt</a></li><li class="expanded "><a href="development/c++.html"><strong aria-hidden="true">5.2.</strong> c++</a></li><li class="expanded "><a href="development/glibc.html"><strong aria-hidden="true">5.3.</strong> glibc</a></li><li class="expanded "><a href="development/gcc.html"><strong aria-hidden="true">5.4.</strong> gcc</a></li><li class="expanded "><a href="development/ld.so.html"><strong aria-hidden="true">5.5.</strong> ld.so</a></li></ol></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav>
@@ -150,221 +150,106 @@
<div id="content" class="content">
<main>
- <h1><a class="header" href="#ldso8" id="ldso8">ld.so(8)</a></h1>
-<h2><a class="header" href="#environment-variables" id="environment-variables">Environment Variables</a></h2>
-<pre><code class="language-console"> LD_PRELOAD=&lt;l_so&gt; colon separated list of libso's to be pre loaded
- LD_DEBUG=&lt;opts&gt; 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
+ <h1><a class="header" href="#zsh1" id="zsh1">zsh(1)</a></h1>
+<h2><a class="header" href="#keybindings" id="keybindings">Keybindings</a></h2>
+<p>Change input mode:</p>
+<pre><code class="language-zsh">bindkey -v change to vi keymap
+bindkey -e change to emacs keymap
</code></pre>
-<h2><a class="header" href="#ld_preload-initialization-order-and-link-map" id="ld_preload-initialization-order-and-link-map">LD_PRELOAD: Initialization Order and Link Map</a></h2>
-<p>Libraries specified in <code>LD_PRELOAD</code> are loaded from <code>left-to-right</code> but
-initialized from <code>right-to-left</code>.</p>
-<pre><code class="language-markdown"> &gt; ldd ./main
- &gt;&gt; libc.so.6 =&gt; /usr/lib/libc.so.6
+<p>Define key-mappings:</p>
+<pre><code class="language-zsh">bindkey list mappings in current keymap
+bindkey in-str cmd create mapping for `in-str` to `cmd`
+bindkey -r in-str remove binding for `in-str`
- &gt; LD_PRELOAD=liba.so:libb.so ./main
- --&gt;
- preloaded in this order
- &lt;--
- initialized in this order
-</code></pre>
-<p>The preload order determines:</p>
-<ul>
-<li>the order libraries are inserted into the <code>link map</code></li>
-<li>the initialization order for libraries</li>
-</ul>
-<p>For the example listed above the resulting <code>link map</code> will look like the
-following:</p>
-<pre><code class="language-makrdown"> +------+ +------+ +------+ +------+
- | main | -&gt; | liba | -&gt; | libb | -&gt; | libc |
- +------+ +------+ +------+ +------+
+# C-v &lt;key&gt; dump &lt;key&gt; code, which can be used in `in-str`
+# zle -l list all functions for keybindings
+# man zshzle(1) STANDARD WIDGETS: get description of functions
</code></pre>
-<p>This can be seen when running with <code>LD_DEBUG=files</code>:</p>
-<pre><code class="language-makrdown"> &gt; LD_DEBUG=files LD_PRELOAD=liba.so:libb.so ./main
- # load order (-&gt; determines link map)
- &gt;&gt; file=liba.so [0]; generating link map
- &gt;&gt; file=libb.so [0]; generating link map
- &gt;&gt; file=libc.so.6 [0]; generating link map
+<h2><a class="header" href="#completion" id="completion">Completion</a></h2>
+<h3><a class="header" href="#installation" id="installation">Installation</a></h3>
+<p>Completion functions are provided via files and need to be placed in a location
+covered by <code>$fpath</code>. By convention the completion files are names as <code>_&lt;CMD&gt;</code>.</p>
+<p>A completion skeleton for the command <code>foo</code>, stored in <code>_foo</code></p>
+<pre><code class="language-zsh">#compdef _foo foo
- # init order
- &gt;&gt; calling init: /usr/lib/libc.so.6
- &gt;&gt; calling init: &lt;path&gt;/libb.so
- &gt;&gt; calling init: &lt;path&gt;/liba.so
- &gt;&gt; initialize program: ./main
-</code></pre>
-<p>To verify the <code>link map</code> order we let <code>ld.so</code> resolve the <code>memcpy(3)</code> libc
-symbol (used in <em>main</em>) dynamically, while enabling <code>LD_DEBUG=symbols,bindings</code>
-to see the resolving in action.</p>
-<pre><code class="language-makrdown"> &gt; LD_DEBUG=symbols,bindings LD_PRELOAD=liba.so:libb.so ./main
- &gt;&gt; symbol=memcpy; lookup in file=./main [0]
- &gt;&gt; symbol=memcpy; lookup in file=&lt;path&gt;/liba.so [0]
- &gt;&gt; symbol=memcpy; lookup in file=&lt;path&gt;/libb.so [0]
- &gt;&gt; symbol=memcpy; lookup in file=/usr/lib/libc.so.6 [0]
- &gt;&gt; binding file ./main [0] to /usr/lib/libc.so.6 [0]: normal symbol `memcpy' [GLIBC_2.14]
-</code></pre>
-<h2><a class="header" href="#dynamic-linking-x86_64" id="dynamic-linking-x86_64">Dynamic Linking (x86_64)</a></h2>
-<p>Dynamic linking basically works via one indirect jump. It uses a combination of
-function trampolines (<code>.plt</code> section) and a function pointer table (<code>.got.plt</code>
-section).
-On the first call the trampoline sets up some metadata and then jumps to the
-<code>ld.so</code> runtime resolve function, which in turn patches the table with the
-correct function pointer.</p>
-<pre><code class="language-makrdown"> .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
+function _foo() {
+ ...
+}
</code></pre>
-<p>Using <code>radare2</code> we can analyze this in more detail:</p>
-<pre><code class="language-makrdown"> [0x00401040]&gt; 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]&gt; pd 6 @ section..plt
- ;-- section..plt:
- ;-- .plt: ; [12] -r-x section size 32 named .plt
- ┌─&gt; 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
- └─&lt; 0x0040103b e9e0ffffff jmp sym..plt
+<p>Alternatively one can install a completion function explicitly by calling <code>compdef &lt;FUNC&gt; &lt;CMD&gt;</code>.</p>
+<h3><a class="header" href="#completion-variables" id="completion-variables">Completion Variables</a></h3>
+<p>Following variables are available in Completion functions:</p>
+<pre><code class="language-zsh">$words # array with command line in words
+$#words # number words
+$CURRENT # index into $words for cursor position
+$words[CURRENT-1] # previous word (relative to cursor position)
</code></pre>
+<h3><a class="header" href="#completion-functions" id="completion-functions">Completion Functions</a></h3>
<ul>
-<li>At address <code>0x00401030</code> in the <code>.plt</code> section we see the indirect jump for
-<code>puts</code> using the function pointer in <code>_GLOBAL_OFFSET_TABLE_[3] (GOT)</code>.</li>
-<li><code>GOT[3]</code> initially points to instruction after the <code>puts</code> trampoline
-<code>0x00401036</code>.</li>
-<li>This pushes the relocation index <code>0</code> and then jumps to the first trampoline
-<code>0x00401020</code>.</li>
-<li>The first trampoline jumps to <code>GOT[2]</code> which will be filled at program
-startup by the <code>ld.so</code> with its resolve function.</li>
-<li>The <code>ld.so</code> resolve function fixes the relocation referenced by the
-relocation index pushed by the <code>puts</code> trampoline.</li>
-<li>The relocation entry at index <code>0</code> tells the resolve function which symbol to
-search for and where to put the function pointer:
-<pre><code class="language-makrdown"> &gt; readelf -r &lt;main&gt;
- &gt;&gt; Relocation section '.rela.plt' at offset 0x4b8 contains 1 entry:
- &gt;&gt; Offset Info Type Sym. Value Sym. Name + Addend
- &gt;&gt; 000000404018 000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts@GLIBC_2.2.5 + 0
-</code></pre>
-As we can see the offset from relocation at index <code>0</code> points to <code>GOT[3]</code>.</li>
+<li><code>_describe</code> simple completion, just words + description</li>
+<li><code>_arguments</code> sophisticated completion, allow to specify actions</li>
</ul>
-<h1><a class="header" href="#git1" id="git1">git(1)</a></h1>
-<h2><a class="header" href="#staging" id="staging">staging</a></h2>
-<pre><code class="language-markdown"> git add -p [&lt;file&gt;] ............ partial staging (interactive)
-</code></pre>
-<h2><a class="header" href="#remote" id="remote">Remote</a></h2>
-<pre><code class="language-markdown"> git remote -v .................. list remotes verbose (with URLs)
- git remote show [-n] &lt;remote&gt; .. list info for &lt;remote&gt; (like remote HEAD,
- remote branches, tracking mapping)
-</code></pre>
-<h2><a class="header" href="#branching" id="branching">Branching</a></h2>
-<pre><code class="language-markdown"> git branch [-a] ................ list available branches; -a to include
- remote branches
- git branch -vv ................. list branch &amp; annotate with head sha1 &amp;
- remote tracking branch
- git branch &lt;bname&gt; ............. create branch with name &lt;bname&gt;
- git checkout &lt;bname&gt; ........... switch to branch with name &lt;bname&gt;
- git push -u origin &lt;rbname&gt; .... push branch to origin (or other remote), and
- setup &lt;rbname&gt; as tracking branch
-</code></pre>
-<h2><a class="header" href="#resetting" id="resetting">Resetting</a></h2>
-<pre><code class="language-markdown"> git reset [opt] &lt;ref|commit&gt;
- opt:
- --mixed .................... resets index, but not working tree
- --hard ..................... matches the working tree and index to that
- of the tree being switched to any changes to
- tracked files in the working tree since
- &lt;commit&gt; are lost
- git reset HEAD &lt;file&gt; .......... remove file from staging
- git reset --soft HEAD~1 ........ delete most recent commit but keep work
- git reset --hard HEAD~1 ........ delete most recent commit and delete work
+<h4><a class="header" href="#completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_describea" id="completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_describea">Completion with <a href="http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions"><code>_describe</code></a></a></h4>
+<pre><code class="language-zsh">_describe MSG COMP
</code></pre>
-<h2><a class="header" href="#tags" id="tags">Tags</a></h2>
-<pre><code class="language-markdown"> git tag -a &lt;tname&gt; -m &quot;descr&quot; ........ creates an annotated tag (full object
- containing tagger, date, ...)
- git tag -l ........................... list available tags
- git checkout tag/&lt;tname&gt; ............. checkout specific tag
- git checkout tag/&lt;tname&gt; -b &lt;bname&gt; .. checkout specific tag in a new branch
+<ul>
+<li><code>MSG</code> simple string with header message</li>
+<li><code>COMP</code> array of completions where each entry is <code>&quot;opt:description&quot;</code></li>
+</ul>
+<pre><code class="language-zsh">function _foo() {
+ local -a opts
+ opts=('bla:desc for bla' 'blu:desc for blu')
+ _describe 'foo-msg' opts
+}
+compdef _foo foo
+
+foo &lt;TAB&gt;&lt;TAB&gt;
+ -- foo-msg --
+bla -- desc for bla
+blu -- desc for blu
</code></pre>
-<h2><a class="header" href="#diff" id="diff">Diff</a></h2>
-<pre><code class="language-markdown"> git diff HEAD:&lt;fname&gt; origin/HEAD:&lt;fname&gt; ... diff files for different refs
- git diff -U$(wc -l &lt;fname&gt;) &lt;fname&gt; ......... shows complete file with diffs
- instead of usual diff snippets
+<h4><a class="header" href="#completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_argumentsa" id="completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_argumentsa">Completion with <a href="http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions"><code>_arguments</code></a></a></h4>
+<pre><code class="language-zsh">_arguments SPEC [SPEC...]
</code></pre>
-<h2><a class="header" href="#log" id="log">Log</a></h2>
-<pre><code class="language-markdown"> git log --oneline .... shows log in single line per commit -&gt; alias for
- '--pretty=oneline --abbrev-commit'
- git log --graph ...... text based graph of commit history
- git log --decorate ... decorate log with REFs
+<p>where <code>SPEC</code> can have one of the following forms:</p>
+<ul>
+<li><code>OPT[DESC]:MSG:ACTION</code></li>
+<li><code>N:MSG:ACTION</code></li>
+</ul>
+<p>Available actions</p>
+<pre><code class="language-zsh">(op1 op2) list possible matches
+-&gt;VAL set $state=VAL and continue, `$state` can be checked later in switch case
+FUNC call func to generate matches
+{STR} evaluate `STR` to generate matches
</code></pre>
-<h2><a class="header" href="#file-history" id="file-history">File history</a></h2>
-<pre><code class="language-markdown"> git log -p &lt;file&gt; ......... show commit history + diffs for &lt;file&gt;
- git log --oneline &lt;file&gt; .. show commit history for &lt;file&gt; in compact format
+<h3><a class="header" href="#example" id="example">Example</a></h3>
+<p>Skeleton to copy/paste for writing simple completions.</p>
+<p>Assume a program <code>foo</code> with the following interface:</p>
+<pre><code class="language-zsh">foo -c green|red|blue -s low|high -f &lt;file&gt; -d &lt;dir&gt; -h
</code></pre>
-<h2><a class="header" href="#patching" id="patching">Patching</a></h2>
-<pre><code class="language-markdown"> git format-patch &lt;opt&gt; &lt;since&gt;/&lt;revision range&gt;
- opt:
- -N ................... use [PATCH] instead [PATCH n/m] in subject when
- generating patch description (for patches spanning
- multiple commits)
- --start-number &lt;n&gt; ... start output file generation with &lt;n&gt; as start
- number instead '1'
- since spcifier:
- -3 .................. e.g: create a patch from last three commits
- &lt;commit hash&gt; ....... create patch with commits starting after &lt;commit hash&gt;
-
- git am &lt;patch&gt; ......... apply patch and create a commit for it
+<p>The completion handler could be implemented as follows in a file called <code>_foo</code>:</p>
+<pre><code class="language-zsh">#compdef _foo foo
- git apply --stat &lt;PATCH&gt; ... see which files the patch would change
- git apply --check &lt;PATCH&gt; .. see if the patch can be applied cleanly
- git apply &lt;PATCH&gt; .......... apply the patch locally without creating a commit
+function _foo_color() {
+ local colors=()
+ colors+=('green:green color')
+ colors+=('red:red color')
+ colors+=('blue:blue color')
+ _describe &quot;color&quot; colors
+}
- # eg: generate patches for each commit from initial commit on
- git format-patch -N $(git rev-list --max-parents=0 HEAD)
+function _foo() {
+ _arguments \
+ &quot;-c[define color]:color:-&gt;s_color&quot; \
+ &quot;-s[select sound]:color:(low high)&quot; \
+ &quot;-f[select file]:file:_files&quot; \
+ &quot;-d[select dir]:fir:_files -/&quot; \
+ &quot;-h[help]&quot;
- # generate single patch file from a certain commit/ref
- git format-patch &lt;COMMIT/REF&gt; --stdout &gt; my-patch.patch
-</code></pre>
-<h2><a class="header" href="#submodules" id="submodules">Submodules</a></h2>
-<pre><code class="language-markdown"> git submodule add &lt;url&gt; [&lt;path&gt;] .......... add new submodule to current project
- git clone --recursive &lt;url&gt; ............... clone project and recursively all
- submodules (same as using
- 'git submodule update --init
- --recursive' after clone)
- git submodule update --init --recursive ... checkout submodules recursively
- using the commit listed in the
- super-project (in detached HEAD)
- git submodule update --remote &lt;submod&gt; .... fetch &amp; merge remote changes for
- &lt;submod&gt;, this will pull
- origin/HEAD or a branch specified
- for the submodule
- git diff --submodule ...................... show commits that are part of the
- submodule diff
-</code></pre>
-<h2><a class="header" href="#inspection" id="inspection">Inspection</a></h2>
-<pre><code class="language-markdown"> git ls-tree [-r] &lt;ref&gt; .... show git tree for &lt;ref&gt;, -r to recursively ls sub-trees
- git show &lt;obj&gt; ............ show &lt;obj&gt;
- git cat-file -p &lt;obj&gt; ..... print content of &lt;obj&gt;
-</code></pre>
-<h2><a class="header" href="#revision-specifier" id="revision-specifier">Revision Specifier</a></h2>
-<pre><code class="language-markdown"> HEAD ........ last commit
- HEAD~1 ...... last commit-1
- HEAD~N ...... last commit-N (linear backwards when in tree structure, check
- difference between HEAD^ and HEAD~)
- git rev-list --max-parents=0 HEAD ........... first commit
+ case $state in
+ s_color) _foo_color;;
+ esac
+}
</code></pre>
<h1><a class="header" href="#bash1" id="bash1">bash(1)</a></h1>
<h2><a class="header" href="#expansion" id="expansion">Expansion</a></h2>
@@ -402,7 +287,7 @@ ${foo/pattern/string} # replace pattern with string when expanding foo
# '%' pattern match at end
</code></pre>
<blockquote>
-<p>Note: <code>prefix</code>/<code>suffix</code>/<code>pattern</code> are expanded as <a href="bash.html#pathname">pathnames</a>.</p>
+<p>Note: <code>prefix</code>/<code>suffix</code>/<code>pattern</code> are expanded as <a href="misc/bash.html#pathname">pathnames</a>.</p>
</blockquote>
<h3><a class="header" href="#pathname" id="pathname">Pathname</a></h3>
<pre><code class="language-bash">* match any string
@@ -451,7 +336,7 @@ command 2&gt;&amp;1 &gt;file
<li>duplicate <code>fd 1</code> to <code>fd 2</code>, effectively redirecting <code>stderr</code> to <code>stdout</code></li>
<li>redirect <code>stdout</code> to <code>file</code></li>
</ol>
-<h2><a class="header" href="#completion" id="completion">Completion</a></h2>
+<h2><a class="header" href="#completion-1" id="completion-1">Completion</a></h2>
<p>The <code>complete</code> builtin is used to interact with the completion system.</p>
<pre><code class="language-bash">complete # print currently installed completion handler
complete -F &lt;func&gt; &lt;cmd&gt; # install &lt;func&gt; as completion handler for &lt;cmd&gt;
@@ -486,7 +371,7 @@ compgen -W &quot;foo foobar bar&quot; &quot;f&quot;
# compare &quot;hom&quot; against file/dir names and generate matches
compgen -d -f &quot;hom&quot;
</code></pre>
-<h3><a class="header" href="#example" id="example">Example</a></h3>
+<h3><a class="header" href="#example-1" id="example-1">Example</a></h3>
<p>Skeleton to copy/paste for writing simple completions.</p>
<p>Assume a program <code>foo</code> with the following interface:</p>
<pre><code class="language-bash">foo -c green|red|blue -s low|high -f &lt;file&gt; -h
@@ -507,106 +392,17 @@ compgen -d -f &quot;hom&quot;
complete -F _foo foo
</code></pre>
-<h1><a class="header" href="#zsh1" id="zsh1">zsh(1)</a></h1>
-<h2><a class="header" href="#keybindings" id="keybindings">Keybindings</a></h2>
-<p>Change input mode:</p>
-<pre><code class="language-zsh">bindkey -v change to vi keymap
-bindkey -e change to emacs keymap
-</code></pre>
-<p>Define key-mappings:</p>
-<pre><code class="language-zsh">bindkey list mappings in current keymap
-bindkey in-str cmd create mapping for `in-str` to `cmd`
-bindkey -r in-str remove binding for `in-str`
-
-# C-v &lt;key&gt; dump &lt;key&gt; code, which can be used in `in-str`
-# zle -l list all functions for keybindings
-# man zshzle(1) STANDARD WIDGETS: get description of functions
-</code></pre>
-<h2><a class="header" href="#completion-1" id="completion-1">Completion</a></h2>
-<h3><a class="header" href="#installation" id="installation">Installation</a></h3>
-<p>Completion functions are provided via files and need to be placed in a location
-covered by <code>$fpath</code>. By convention the completion files are names as <code>_&lt;CMD&gt;</code>.</p>
-<p>A completion skeleton for the command <code>foo</code>, stored in <code>_foo</code></p>
-<pre><code class="language-zsh">#compdef _foo foo
-
-function _foo() {
- ...
-}
-</code></pre>
-<p>Alternatively one can install a completion function explicitly by calling <code>compdef &lt;FUNC&gt; &lt;CMD&gt;</code>.</p>
-<h3><a class="header" href="#completion-variables" id="completion-variables">Completion Variables</a></h3>
-<p>Following variables are available in Completion functions:</p>
-<pre><code class="language-zsh">$words # array with command line in words
-$#words # number words
-$CURRENT # index into $words for cursor position
-$words[CURRENT-1] # previous word (relative to cursor position)
-</code></pre>
-<h3><a class="header" href="#completion-functions" id="completion-functions">Completion Functions</a></h3>
-<ul>
-<li><code>_describe</code> simple completion, just words + description</li>
-<li><code>_arguments</code> sophisticated completion, allow to specify actions</li>
-</ul>
-<h4><a class="header" href="#completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_describea" id="completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_describea">Completion with <a href="http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions"><code>_describe</code></a></a></h4>
-<pre><code class="language-zsh">_describe MSG COMP
-</code></pre>
-<ul>
-<li><code>MSG</code> simple string with header message</li>
-<li><code>COMP</code> array of completions where each entry is <code>&quot;opt:description&quot;</code></li>
-</ul>
-<pre><code class="language-zsh">function _foo() {
- local -a opts
- opts=('bla:desc for bla' 'blu:desc for blu')
- _describe 'foo-msg' opts
-}
-compdef _foo foo
-
-foo &lt;TAB&gt;&lt;TAB&gt;
- -- foo-msg --
-bla -- desc for bla
-blu -- desc for blu
-</code></pre>
-<h4><a class="header" href="#completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_argumentsa" id="completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_argumentsa">Completion with <a href="http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions"><code>_arguments</code></a></a></h4>
-<pre><code class="language-zsh">_arguments SPEC [SPEC...]
-</code></pre>
-<p>where <code>SPEC</code> can have one of the following forms:</p>
-<ul>
-<li><code>OPT[DESC]:MSG:ACTION</code></li>
-<li><code>N:MSG:ACTION</code></li>
-</ul>
-<p>Available actions</p>
-<pre><code class="language-zsh">(op1 op2) list possible matches
--&gt;VAL set $state=VAL and continue, `$state` can be checked later in switch case
-FUNC call func to generate matches
-{STR} evaluate `STR` to generate matches
-</code></pre>
-<h3><a class="header" href="#example-1" id="example-1">Example</a></h3>
-<p>Skeleton to copy/paste for writing simple completions.</p>
-<p>Assume a program <code>foo</code> with the following interface:</p>
-<pre><code class="language-zsh">foo -c green|red|blue -s low|high -f &lt;file&gt; -d &lt;dir&gt; -h
+<h1><a class="header" href="#fish1" id="fish1">fish(1)</a></h1>
+<h2><a class="header" href="#keymaps" id="keymaps">keymaps</a></h2>
+<pre><code class="language-markdown"> Shift-Tab ........... tab-completion with search
+ Alt-Up / Alt-Down ... search history with token under the cursor
+ Alt-l ............... list content of dir under cursor
+ Alt-p ............... append '2&gt;&amp;1 | less;' to current cmdline
</code></pre>
-<p>The completion handler could be implemented as follows in a file called <code>_foo</code>:</p>
-<pre><code class="language-zsh">#compdef _foo foo
-
-function _foo_color() {
- local colors=()
- colors+=('green:green color')
- colors+=('red:red color')
- colors+=('blue:blue color')
- _describe &quot;color&quot; colors
-}
-
-function _foo() {
- _arguments \
- &quot;-c[define color]:color:-&gt;s_color&quot; \
- &quot;-s[select sound]:color:(low high)&quot; \
- &quot;-f[select file]:file:_files&quot; \
- &quot;-d[select dir]:fir:_files -/&quot; \
- &quot;-h[help]&quot;
-
- case $state in
- s_color) _foo_color;;
- esac
-}
+<h2><a class="header" href="#debug" id="debug">debug</a></h2>
+<pre><code class="language-markdown"> status print-stack-trace .. prints function stacktrace (can be used in scripts)
+ breakpoint ................ halt script execution and gives shell (C-d | exit
+ to continue)
</code></pre>
<h1><a class="header" href="#tmux1" id="tmux1">tmux(1)</a></h1>
<p>Terminology:</p>
@@ -705,6 +501,111 @@ y yank selected text
<pre><code class="language-markdown">setw synchronize-panes on/off enables/disables synchronized input to all panes
list-keys -t vi-copy list keymaps for vi-copy mode
</code></pre>
+<h1><a class="header" href="#git1" id="git1">git(1)</a></h1>
+<h2><a class="header" href="#staging" id="staging">staging</a></h2>
+<pre><code class="language-markdown"> git add -p [&lt;file&gt;] ............ partial staging (interactive)
+</code></pre>
+<h2><a class="header" href="#remote" id="remote">Remote</a></h2>
+<pre><code class="language-markdown"> git remote -v .................. list remotes verbose (with URLs)
+ git remote show [-n] &lt;remote&gt; .. list info for &lt;remote&gt; (like remote HEAD,
+ remote branches, tracking mapping)
+</code></pre>
+<h2><a class="header" href="#branching" id="branching">Branching</a></h2>
+<pre><code class="language-markdown"> git branch [-a] ................ list available branches; -a to include
+ remote branches
+ git branch -vv ................. list branch &amp; annotate with head sha1 &amp;
+ remote tracking branch
+ git branch &lt;bname&gt; ............. create branch with name &lt;bname&gt;
+ git checkout &lt;bname&gt; ........... switch to branch with name &lt;bname&gt;
+ git push -u origin &lt;rbname&gt; .... push branch to origin (or other remote), and
+ setup &lt;rbname&gt; as tracking branch
+</code></pre>
+<h2><a class="header" href="#resetting" id="resetting">Resetting</a></h2>
+<pre><code class="language-markdown"> git reset [opt] &lt;ref|commit&gt;
+ opt:
+ --mixed .................... resets index, but not working tree
+ --hard ..................... matches the working tree and index to that
+ of the tree being switched to any changes to
+ tracked files in the working tree since
+ &lt;commit&gt; are lost
+ git reset HEAD &lt;file&gt; .......... remove file from staging
+ git reset --soft HEAD~1 ........ delete most recent commit but keep work
+ git reset --hard HEAD~1 ........ delete most recent commit and delete work
+</code></pre>
+<h2><a class="header" href="#tags" id="tags">Tags</a></h2>
+<pre><code class="language-markdown"> git tag -a &lt;tname&gt; -m &quot;descr&quot; ........ creates an annotated tag (full object
+ containing tagger, date, ...)
+ git tag -l ........................... list available tags
+ git checkout tag/&lt;tname&gt; ............. checkout specific tag
+ git checkout tag/&lt;tname&gt; -b &lt;bname&gt; .. checkout specific tag in a new branch
+</code></pre>
+<h2><a class="header" href="#diff" id="diff">Diff</a></h2>
+<pre><code class="language-markdown"> git diff HEAD:&lt;fname&gt; origin/HEAD:&lt;fname&gt; ... diff files for different refs
+ git diff -U$(wc -l &lt;fname&gt;) &lt;fname&gt; ......... shows complete file with diffs
+ instead of usual diff snippets
+</code></pre>
+<h2><a class="header" href="#log" id="log">Log</a></h2>
+<pre><code class="language-markdown"> git log --oneline .... shows log in single line per commit -&gt; alias for
+ '--pretty=oneline --abbrev-commit'
+ git log --graph ...... text based graph of commit history
+ git log --decorate ... decorate log with REFs
+</code></pre>
+<h2><a class="header" href="#file-history" id="file-history">File history</a></h2>
+<pre><code class="language-markdown"> git log -p &lt;file&gt; ......... show commit history + diffs for &lt;file&gt;
+ git log --oneline &lt;file&gt; .. show commit history for &lt;file&gt; in compact format
+</code></pre>
+<h2><a class="header" href="#patching" id="patching">Patching</a></h2>
+<pre><code class="language-markdown"> git format-patch &lt;opt&gt; &lt;since&gt;/&lt;revision range&gt;
+ opt:
+ -N ................... use [PATCH] instead [PATCH n/m] in subject when
+ generating patch description (for patches spanning
+ multiple commits)
+ --start-number &lt;n&gt; ... start output file generation with &lt;n&gt; as start
+ number instead '1'
+ since spcifier:
+ -3 .................. e.g: create a patch from last three commits
+ &lt;commit hash&gt; ....... create patch with commits starting after &lt;commit hash&gt;
+
+ git am &lt;patch&gt; ......... apply patch and create a commit for it
+
+ git apply --stat &lt;PATCH&gt; ... see which files the patch would change
+ git apply --check &lt;PATCH&gt; .. see if the patch can be applied cleanly
+ git apply &lt;PATCH&gt; .......... apply the patch locally without creating a commit
+
+ # eg: generate patches for each commit from initial commit on
+ git format-patch -N $(git rev-list --max-parents=0 HEAD)
+
+ # generate single patch file from a certain commit/ref
+ git format-patch &lt;COMMIT/REF&gt; --stdout &gt; my-patch.patch
+</code></pre>
+<h2><a class="header" href="#submodules" id="submodules">Submodules</a></h2>
+<pre><code class="language-markdown"> git submodule add &lt;url&gt; [&lt;path&gt;] .......... add new submodule to current project
+ git clone --recursive &lt;url&gt; ............... clone project and recursively all
+ submodules (same as using
+ 'git submodule update --init
+ --recursive' after clone)
+ git submodule update --init --recursive ... checkout submodules recursively
+ using the commit listed in the
+ super-project (in detached HEAD)
+ git submodule update --remote &lt;submod&gt; .... fetch &amp; merge remote changes for
+ &lt;submod&gt;, this will pull
+ origin/HEAD or a branch specified
+ for the submodule
+ git diff --submodule ...................... show commits that are part of the
+ submodule diff
+</code></pre>
+<h2><a class="header" href="#inspection" id="inspection">Inspection</a></h2>
+<pre><code class="language-markdown"> git ls-tree [-r] &lt;ref&gt; .... show git tree for &lt;ref&gt;, -r to recursively ls sub-trees
+ git show &lt;obj&gt; ............ show &lt;obj&gt;
+ git cat-file -p &lt;obj&gt; ..... print content of &lt;obj&gt;
+</code></pre>
+<h2><a class="header" href="#revision-specifier" id="revision-specifier">Revision Specifier</a></h2>
+<pre><code class="language-markdown"> HEAD ........ last commit
+ HEAD~1 ...... last commit-1
+ HEAD~N ...... last commit-N (linear backwards when in tree structure, check
+ difference between HEAD^ and HEAD~)
+ git rev-list --max-parents=0 HEAD ........... first commit
+</code></pre>
<h1><a class="header" href="#awk1" id="awk1">awk(1)</a></h1>
<pre><code class="language-markdown">awk [opt] program [input]
-F &lt;sepstr&gt; field separator string (can be regex)
@@ -820,6 +721,70 @@ done | sort -k2 -n
</code></pre>
<p>We build a <code>ps</code> command line and capture the first line of the processes output
in the <code>user</code> variable and then print it.</p>
+<h1><a class="header" href="#emacs1" id="emacs1">emacs(1)</a></h1>
+<h2><a class="header" href="#help" id="help">help</a></h2>
+<pre><code class="language-markdown"> C-h ? list available help modes
+ C-h f describe function
+ C-h v describe variable
+ C-h c &lt;KEY&gt; print command bound to &lt;KEY&gt;
+ C-h k &lt;KEY&gt; describe command bound to &lt;KEY&gt;
+ C-h b list buffer local key-bindings
+ &lt;kseq&gt; C-h list possible key-bindings with &lt;kseq&gt;
+ eg C-x C-h -&gt; list key-bindings beginning with C-x
+</code></pre>
+<h2><a class="header" href="#package-manager" id="package-manager">package manager</a></h2>
+<pre><code class="language-markdown"> package-refresh-contents refresh package list
+ package-list-packages list available/installed packages
+</code></pre>
+<h2><a class="header" href="#window" id="window">window</a></h2>
+<pre><code class="language-markdown"> C-x 0 kill focused window
+ C-x 1 kill all other windows
+ C-x 2 split horizontal
+ C-x 3 split vertical
+</code></pre>
+<h2><a class="header" href="#yankpaste" id="yankpaste">yank/paste</a></h2>
+<pre><code class="language-markdown"> C-&lt;SPACE&gt; set start mark to select text
+ M-w copy selected text
+ C-w kill selected text
+ C-y paste selected text
+ M-y cycle through kill-ring
+</code></pre>
+<h2><a class="header" href="#blockrect" id="blockrect">block/rect</a></h2>
+<pre><code class="language-markdown"> C-x &lt;SPC&gt; activate rectangle-mark-mode
+ M-x string-rectangle &lt;RET&gt; insert text in marked rect
+</code></pre>
+<h2><a class="header" href="#mass-edit" id="mass-edit">mass edit</a></h2>
+<pre><code class="language-makrdown"> C-x h mark whole buffer (mark-whole-buffer)
+ M-x delete-matching-line &lt;RET&gt; delete lines matching regex
+ M-x % search &amp; replace region (query-replace)
+ C-M-x % search &amp; replace regex (query-replace-regexp)
+</code></pre>
+<h2><a class="header" href="#grep" id="grep">grep</a></h2>
+<pre><code class="language-markdown"> M-x find-grep &lt;RET&gt; run find-grep result in *grep* buffer
+ n/p navigate next/previous match in *grep* buffer
+</code></pre>
+<h2><a class="header" href="#lisp-mode" id="lisp-mode">lisp mode</a></h2>
+<pre><code class="language-markdown"> M-x lisp-interaction-mode activate lisp mode
+ C-M-x evaluate top expr under cursor
+ C-x C-e eval-last-sexp
+ C-u C-x C-e eval-last-sexp and prints result in current buffer
+</code></pre>
+<h2><a class="header" href="#narrow" id="narrow">narrow</a></h2>
+<pre><code class="language-markdown"> C-x n n show only focused region (narrow)
+ C-x n w show whole buffer (wide)
+</code></pre>
+<h2><a class="header" href="#org" id="org">org</a></h2>
+<pre><code class="language-markdown"> M-up/M-down re-arrange items in same hierarchy
+ M-left/M-right change item hierarchy
+ C-RET create new item below current
+ C-S-RET create new TODO item below current
+ S-left/S-right cycle TODO states
+</code></pre>
+<h3><a class="header" href="#org-source" id="org-source">org source</a></h3>
+<pre><code class="language-markdown"> &lt;s TAB generate a source block
+ C-c ' edit source block (in lang specific buffer)
+ C-c C-c eval source block
+</code></pre>
<h1><a class="header" href="#gdb1" id="gdb1">gdb(1)</a></h1>
<h1><a class="header" href="#cli" id="cli">CLI</a></h1>
<pre><code class="language-markdown"> gdb [opts] [prg [-c coredump | -p pid]]
@@ -970,7 +935,7 @@ executed. To workaround that bug one can create a wrapper function which calls
fs &lt;fs&gt; # select flag-space &lt;fs&gt;
f # print flags of selected flag-space
</code></pre>
-<h2><a class="header" href="#help" id="help">help</a></h2>
+<h2><a class="header" href="#help-1" id="help-1">help</a></h2>
<pre><code class="language-markdown"> ?*~&lt;kw&gt; # '?*' list all commands and '~' grep for &lt;kw&gt;
?*~... # '..' less mode /'...' interactive search
</code></pre>
@@ -978,105 +943,7 @@ executed. To workaround that bug one can create a wrapper function which calls
<pre><code class="language-markdown"> &gt; r2 -B &lt;baddr&gt; &lt;exe&gt; # open &lt;exe&gt; mapped to addr &lt;baddr&gt;
oob &lt;addr&gt; # reopen current file at &lt;baddr&gt;
</code></pre>
-<h1><a class="header" href="#emacs1" id="emacs1">emacs(1)</a></h1>
-<h2><a class="header" href="#help-1" id="help-1">help</a></h2>
-<pre><code class="language-markdown"> C-h ? list available help modes
- C-h f describe function
- C-h v describe variable
- C-h c &lt;KEY&gt; print command bound to &lt;KEY&gt;
- C-h k &lt;KEY&gt; describe command bound to &lt;KEY&gt;
- C-h b list buffer local key-bindings
- &lt;kseq&gt; C-h list possible key-bindings with &lt;kseq&gt;
- eg C-x C-h -&gt; list key-bindings beginning with C-x
-</code></pre>
-<h2><a class="header" href="#package-manager" id="package-manager">package manager</a></h2>
-<pre><code class="language-markdown"> package-refresh-contents refresh package list
- package-list-packages list available/installed packages
-</code></pre>
-<h2><a class="header" href="#window" id="window">window</a></h2>
-<pre><code class="language-markdown"> C-x 0 kill focused window
- C-x 1 kill all other windows
- C-x 2 split horizontal
- C-x 3 split vertical
-</code></pre>
-<h2><a class="header" href="#yankpaste" id="yankpaste">yank/paste</a></h2>
-<pre><code class="language-markdown"> C-&lt;SPACE&gt; set start mark to select text
- M-w copy selected text
- C-w kill selected text
- C-y paste selected text
- M-y cycle through kill-ring
-</code></pre>
-<h2><a class="header" href="#blockrect" id="blockrect">block/rect</a></h2>
-<pre><code class="language-markdown"> C-x &lt;SPC&gt; activate rectangle-mark-mode
- M-x string-rectangle &lt;RET&gt; insert text in marked rect
-</code></pre>
-<h2><a class="header" href="#mass-edit" id="mass-edit">mass edit</a></h2>
-<pre><code class="language-makrdown"> C-x h mark whole buffer (mark-whole-buffer)
- M-x delete-matching-line &lt;RET&gt; delete lines matching regex
- M-x % search &amp; replace region (query-replace)
- C-M-x % search &amp; replace regex (query-replace-regexp)
-</code></pre>
-<h2><a class="header" href="#grep" id="grep">grep</a></h2>
-<pre><code class="language-markdown"> M-x find-grep &lt;RET&gt; run find-grep result in *grep* buffer
- n/p navigate next/previous match in *grep* buffer
-</code></pre>
-<h2><a class="header" href="#lisp-mode" id="lisp-mode">lisp mode</a></h2>
-<pre><code class="language-markdown"> M-x lisp-interaction-mode activate lisp mode
- C-M-x evaluate top expr under cursor
- C-x C-e eval-last-sexp
- C-u C-x C-e eval-last-sexp and prints result in current buffer
-</code></pre>
-<h2><a class="header" href="#narrow" id="narrow">narrow</a></h2>
-<pre><code class="language-markdown"> C-x n n show only focused region (narrow)
- C-x n w show whole buffer (wide)
-</code></pre>
-<h2><a class="header" href="#org" id="org">org</a></h2>
-<pre><code class="language-markdown"> M-up/M-down re-arrange items in same hierarchy
- M-left/M-right change item hierarchy
- C-RET create new item below current
- C-S-RET create new TODO item below current
- S-left/S-right cycle TODO states
-</code></pre>
-<h3><a class="header" href="#org-source" id="org-source">org source</a></h3>
-<pre><code class="language-markdown"> &lt;s TAB generate a source block
- C-c ' edit source block (in lang specific buffer)
- C-c C-c eval source block
-</code></pre>
-<h1><a class="header" href="#fish1" id="fish1">fish(1)</a></h1>
-<h2><a class="header" href="#keymaps" id="keymaps">keymaps</a></h2>
-<pre><code class="language-markdown"> Shift-Tab ........... tab-completion with search
- Alt-Up / Alt-Down ... search history with token under the cursor
- Alt-l ............... list content of dir under cursor
- Alt-p ............... append '2&gt;&amp;1 | less;' to current cmdline
-</code></pre>
-<h2><a class="header" href="#debug" id="debug">debug</a></h2>
-<pre><code class="language-markdown"> status print-stack-trace .. prints function stacktrace (can be used in scripts)
- breakpoint ................ halt script execution and gives shell (C-d | exit
- to continue)
-</code></pre>
-<h1><a class="header" href="#strace1" id="strace1">strace(1)</a></h1>
-<pre><code class="language-markdown">strace [opts] [prg]
- -f .......... follow child processes on fork(2)
- -p &lt;pid&gt; .... attach to running process
- -s &lt;size&gt; ... max string size, truncate of longer (default: 32)
- -e &lt;expr&gt; ... expression for trace filtering
- -o &lt;file&gt; ... log output into &lt;file&gt;
- -c .......... dump syscall statitics at the end
-</code></pre>
-<pre><code class="language-markdown">&lt;expr&gt;:
- 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
-</code></pre>
-<h1><a class="header" href="#examples-2" id="examples-2">Examples</a></h1>
-<p>Trace <code>open(2)</code> &amp; <code>socket(2)</code> syscalls for a running process + child processes:</p>
-<pre><code class="language-markdown">strace -f -e trace=open,socket -p &lt;pid&gt;
-</code></pre>
-<p>Trace signals delivered to a running process:</p>
-<pre><code class="language-markdown">strace -f -e signal -p &lt;pid&gt;
-</code></pre>
+<h1><a class="header" href="#resource-analysis--monitor" id="resource-analysis--monitor">Resource analysis &amp; monitor</a></h1>
<h1><a class="header" href="#lsof8" id="lsof8">lsof(8)</a></h1>
<pre><code class="language-markdown">lsof
-a ......... AND slection filters instead ORing (OR: default)
@@ -1092,7 +959,7 @@ executed. To workaround that bug one can create a wrapper function which calls
AP ......... append
TR ......... truncate
</code></pre>
-<h1><a class="header" href="#examples-3" id="examples-3">Examples</a></h1>
+<h1><a class="header" href="#examples-2" id="examples-2">Examples</a></h1>
<h2><a class="header" href="#file-flags" id="file-flags">File flags</a></h2>
<p>Show open files with file flags for process:</p>
<pre><code class="language-markdown">lsof +fg -p &lt;pid&gt;
@@ -1130,10 +997,6 @@ major_pagefault: Happens when the page needed is NOT in memory, the kernel
<h1><a class="header" href="#io-statistics" id="io-statistics">I/O statistics</a></h1>
<pre><code class="language-markdown">pidstat -d -p &lt;pid&gt; [interval] [count]
</code></pre>
-<h1><a class="header" href="#usrbintime1" id="usrbintime1">/usr/bin/time(1)</a></h1>
-<pre><code class="language-markdown"># statistics of process run
-/usr/bin/time -v &lt;cmd&gt;
-</code></pre>
<h1><a class="header" href="#pgrep1" id="pgrep1">pgrep(1)</a></h1>
<pre><code class="language-markdown">pgrep [opts] &lt;pattern&gt;
-n only list newest matching process
@@ -1145,10 +1008,51 @@ major_pagefault: Happens when the page needed is NOT in memory, the kernel
<p>For example attach gdb to newest zsh process from <code>$USER</code>.</p>
<pre><code class="language-markdown">gdb -p $(pgrep -n -u $USER zsh)
</code></pre>
+<h1><a class="header" href="#pmap1" id="pmap1">pmap(1)</a></h1>
+<pre><code class="language-markdown">pmap &lt;pid&gt;
+ Dump virtual memory map of process.
+ Compared to /proc/&lt;pid&gt;/maps it shows the size of the mappings.
+</code></pre>
<h1><a class="header" href="#pstack1" id="pstack1">pstack(1)</a></h1>
<pre><code class="language-markdown">pstack &lt;pid&gt;
Dump stack for all threads of process.
</code></pre>
+<h1><a class="header" href="#trace-and-profile" id="trace-and-profile">Trace and Profile</a></h1>
+<h1><a class="header" href="#strace1" id="strace1">strace(1)</a></h1>
+<pre><code class="language-markdown">strace [opts] [prg]
+ -f .......... follow child processes on fork(2)
+ -p &lt;pid&gt; .... attach to running process
+ -s &lt;size&gt; ... max string size, truncate of longer (default: 32)
+ -e &lt;expr&gt; ... expression for trace filtering
+ -o &lt;file&gt; ... log output into &lt;file&gt;
+ -c .......... dump syscall statitics at the end
+</code></pre>
+<pre><code class="language-markdown">&lt;expr&gt;:
+ 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
+</code></pre>
+<h1><a class="header" href="#examples-3" id="examples-3">Examples</a></h1>
+<p>Trace <code>open(2)</code> &amp; <code>socket(2)</code> syscalls for a running process + child processes:</p>
+<pre><code class="language-markdown">strace -f -e trace=open,socket -p &lt;pid&gt;
+</code></pre>
+<p>Trace signals delivered to a running process:</p>
+<pre><code class="language-markdown">strace -f -e signal -p &lt;pid&gt;
+</code></pre>
+<h1><a class="header" href="#ltrace1" id="ltrace1">ltrace(1)</a></h1>
+<pre><code class="language-markdown">ltrace [opts] [prg]
+ -f .......... follow child processes on fork(2)
+ -p &lt;pid&gt; .... attach to running process
+ -o &lt;file&gt; ... log output into &lt;file&gt;
+ -l &lt;filter&gt; . show who calls into lib matched by &lt;filter&gt;
+ -C .......... demangle
+</code></pre>
+<h1><a class="header" href="#example-2" id="example-2">Example</a></h1>
+<p>List which program/libs call into <code>libstdc++</code>:</p>
+<pre><code class="language-bash">ltrace -l '*libstdc++*' -C -o ltrace.log ./main
+</code></pre>
<h1><a class="header" href="#perf1" id="perf1">perf(1)</a></h1>
<pre><code class="language-markdown">perf list show supported hw/sw events
@@ -1207,6 +1111,11 @@ opreport [opt] FILE
ophelp show supported hw/sw events
</code></pre>
+<h1><a class="header" href="#usrbintime1" id="usrbintime1">/usr/bin/time(1)</a></h1>
+<pre><code class="language-markdown"># statistics of process run
+/usr/bin/time -v &lt;cmd&gt;
+</code></pre>
+<h1><a class="header" href="#binary" id="binary">Binary</a></h1>
<h1><a class="header" href="#od1" id="od1">od(1)</a></h1>
<pre><code class="language-markdown"> od [opts] &lt;file&gt;
-An don't print addr info
@@ -1304,6 +1213,7 @@ the <code>.rodata</code> section as follows:</p>
-C demangle
-u undefined only
</code></pre>
+<h1><a class="header" href="#development" id="development">Development</a></h1>
<h1><a class="header" href="#cfilt1" id="cfilt1">c++filt(1)</a></h1>
<h2><a class="header" href="#demangle-symbol" id="demangle-symbol">Demangle symbol</a></h2>
<pre><code class="language-markdown"> c++-filt &lt;symbol_str&gt;
@@ -1400,6 +1310,117 @@ run1:
xor eax, eax
jmp bar
</code></pre>
+<h1><a class="header" href="#ldso8" id="ldso8">ld.so(8)</a></h1>
+<h2><a class="header" href="#environment-variables" id="environment-variables">Environment Variables</a></h2>
+<pre><code class="language-console"> LD_PRELOAD=&lt;l_so&gt; colon separated list of libso's to be pre loaded
+ LD_DEBUG=&lt;opts&gt; 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
+</code></pre>
+<h2><a class="header" href="#ld_preload-initialization-order-and-link-map" id="ld_preload-initialization-order-and-link-map">LD_PRELOAD: Initialization Order and Link Map</a></h2>
+<p>Libraries specified in <code>LD_PRELOAD</code> are loaded from <code>left-to-right</code> but
+initialized from <code>right-to-left</code>.</p>
+<pre><code class="language-markdown"> &gt; ldd ./main
+ &gt;&gt; libc.so.6 =&gt; /usr/lib/libc.so.6
+
+ &gt; LD_PRELOAD=liba.so:libb.so ./main
+ --&gt;
+ preloaded in this order
+ &lt;--
+ initialized in this order
+</code></pre>
+<p>The preload order determines:</p>
+<ul>
+<li>the order libraries are inserted into the <code>link map</code></li>
+<li>the initialization order for libraries</li>
+</ul>
+<p>For the example listed above the resulting <code>link map</code> will look like the
+following:</p>
+<pre><code class="language-makrdown"> +------+ +------+ +------+ +------+
+ | main | -&gt; | liba | -&gt; | libb | -&gt; | libc |
+ +------+ +------+ +------+ +------+
+</code></pre>
+<p>This can be seen when running with <code>LD_DEBUG=files</code>:</p>
+<pre><code class="language-makrdown"> &gt; LD_DEBUG=files LD_PRELOAD=liba.so:libb.so ./main
+ # load order (-&gt; determines link map)
+ &gt;&gt; file=liba.so [0]; generating link map
+ &gt;&gt; file=libb.so [0]; generating link map
+ &gt;&gt; file=libc.so.6 [0]; generating link map
+
+ # init order
+ &gt;&gt; calling init: /usr/lib/libc.so.6
+ &gt;&gt; calling init: &lt;path&gt;/libb.so
+ &gt;&gt; calling init: &lt;path&gt;/liba.so
+ &gt;&gt; initialize program: ./main
+</code></pre>
+<p>To verify the <code>link map</code> order we let <code>ld.so</code> resolve the <code>memcpy(3)</code> libc
+symbol (used in <em>main</em>) dynamically, while enabling <code>LD_DEBUG=symbols,bindings</code>
+to see the resolving in action.</p>
+<pre><code class="language-makrdown"> &gt; LD_DEBUG=symbols,bindings LD_PRELOAD=liba.so:libb.so ./main
+ &gt;&gt; symbol=memcpy; lookup in file=./main [0]
+ &gt;&gt; symbol=memcpy; lookup in file=&lt;path&gt;/liba.so [0]
+ &gt;&gt; symbol=memcpy; lookup in file=&lt;path&gt;/libb.so [0]
+ &gt;&gt; symbol=memcpy; lookup in file=/usr/lib/libc.so.6 [0]
+ &gt;&gt; binding file ./main [0] to /usr/lib/libc.so.6 [0]: normal symbol `memcpy' [GLIBC_2.14]
+</code></pre>
+<h2><a class="header" href="#dynamic-linking-x86_64" id="dynamic-linking-x86_64">Dynamic Linking (x86_64)</a></h2>
+<p>Dynamic linking basically works via one indirect jump. It uses a combination of
+function trampolines (<code>.plt</code> section) and a function pointer table (<code>.got.plt</code>
+section).
+On the first call the trampoline sets up some metadata and then jumps to the
+<code>ld.so</code> runtime resolve function, which in turn patches the table with the
+correct function pointer.</p>
+<pre><code class="language-makrdown"> .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
+</code></pre>
+<p>Using <code>radare2</code> we can analyze this in more detail:</p>
+<pre><code class="language-makrdown"> [0x00401040]&gt; 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]&gt; pd 6 @ section..plt
+ ;-- section..plt:
+ ;-- .plt: ; [12] -r-x section size 32 named .plt
+ ┌─&gt; 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
+ └─&lt; 0x0040103b e9e0ffffff jmp sym..plt
+</code></pre>
+<ul>
+<li>At address <code>0x00401030</code> in the <code>.plt</code> section we see the indirect jump for
+<code>puts</code> using the function pointer in <code>_GLOBAL_OFFSET_TABLE_[3] (GOT)</code>.</li>
+<li><code>GOT[3]</code> initially points to instruction after the <code>puts</code> trampoline
+<code>0x00401036</code>.</li>
+<li>This pushes the relocation index <code>0</code> and then jumps to the first trampoline
+<code>0x00401020</code>.</li>
+<li>The first trampoline jumps to <code>GOT[2]</code> which will be filled at program
+startup by the <code>ld.so</code> with its resolve function.</li>
+<li>The <code>ld.so</code> resolve function fixes the relocation referenced by the
+relocation index pushed by the <code>puts</code> trampoline.</li>
+<li>The relocation entry at index <code>0</code> tells the resolve function which symbol to
+search for and where to put the function pointer:
+<pre><code class="language-makrdown"> &gt; readelf -r &lt;main&gt;
+ &gt;&gt; Relocation section '.rela.plt' at offset 0x4b8 contains 1 entry:
+ &gt;&gt; Offset Info Type Sym. Value Sym. Name + Addend
+ &gt;&gt; 000000404018 000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts@GLIBC_2.2.5 + 0
+</code></pre>
+As we can see the offset from relocation at index <code>0</code> points to <code>GOT[3]</code>.</li>
+</ul>
</main>