-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 959adb4
Showing
178 changed files
with
54,285 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
|
||
<!DOCTYPE html> | ||
<html lang='en-US'> | ||
<head> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>NixOS Notes</title> | ||
<meta name="description" content="I had bought a new laptop recently, which was a perfect opportunity to take a | ||
fresh look at my NixOS setup."> | ||
<link rel="icon" href="/favicon.png" type="image/png"> | ||
<link rel="icon" href="/favicon.svg" type="image/svg+xml"> | ||
<link rel="canonical" href="https://matklad.github.io/2017/03/25/nixos-notes.html"> | ||
<link rel="alternate" type="application/rss+xml" title="matklad" href="https://matklad.github.io/feed.xml"> | ||
<style> | ||
@font-face { | ||
font-family: 'Open Sans'; src: url('/css/OpenSans-300-Normal.woff2') format('woff2'); | ||
font-weight: 300; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'JetBrains Mono'; src: url('/css/JetBrainsMono-400-Normal.woff2') format('woff2'); | ||
font-weight: 400; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'JetBrains Mono'; src: url('/css/JetBrainsMono-700-Normal.woff2') format('woff2'); | ||
font-weight: 700; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-400-Normal.woff2') format('woff2'); | ||
font-weight: 400; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-400-Italic.woff2') format('woff2'); | ||
font-weight: 400; font-style: italic; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-700-Normal.woff2') format('woff2'); | ||
font-weight: 700; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-700-Italic.woff2') format('woff2'); | ||
font-weight: 700; font-style: italic; | ||
} | ||
|
||
* { box-sizing: border-box; margin: 0; padding: 0; margin-block-start: 0; margin-block-end: 0; } | ||
|
||
body { | ||
max-width: 80ch; | ||
padding: 2ch; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
|
||
header { margin-bottom: 2rem; } | ||
header > nav { display: flex; column-gap: 2ch; align-items: baseline; flex-wrap: wrap; } | ||
header a { font-style: normal; color: rgba(0, 0, 0, .8); text-decoration: none; } | ||
header a:hover { color: rgba(0, 0, 0, .8); text-decoration: underline; } | ||
header .title { font-size: 1.25em; flex-grow: 2; } | ||
|
||
footer { margin-top: 2rem; } | ||
footer > p { display: flex; column-gap: 2ch; justify-content: center; flex-wrap: wrap; } | ||
footer a { color: rgba(0, 0, 0, .8); text-decoration: none; white-space: nowrap; } | ||
footer i { vertical-align: middle; color: rgba(0, 0, 0, .8) } | ||
|
||
</style> | ||
|
||
<link rel="stylesheet" href="/css/main.css"> | ||
|
||
</head> | ||
|
||
<body> | ||
<header> | ||
<nav> | ||
<a class="title" href="/">matklad</a> | ||
<a href="/about.html">About</a> | ||
<a href="/links.html">Links</a> | ||
<a href="/blogroll.html">Blogroll</a> | ||
</nav> | ||
</header> | ||
|
||
<main> | ||
<article > | ||
|
||
<h1><span>NixOS Notes</span> <time class="meta" datetime="2017-03-25">Mar 25, 2017</time></h1> | ||
<p><span>I had bought a new laptop recently, which was a perfect opportunity to take a</span> | ||
<span>fresh look at my </span><a href="http://nixos.org/"><span>NixOS</span></a><span> setup.</span></p> | ||
<p><span>As usual, there are some hacks and not obvious things which I would like to</span> | ||
<span>document just in case :)</span></p> | ||
<section id="If-it-does-not-work-update"> | ||
|
||
<h2> | ||
<a href="#If-it-does-not-work-update"><span>If it does not work, update</span> </a> | ||
</h2> | ||
<p><span>I</span>’<span>ve tried installed a stable 16.09 version first, but live CD didn</span>’<span>t manage to</span> | ||
<span>start the X server properly. This was easy to fix by switching to the then beta</span> | ||
<span>17.03.</span></p> | ||
</section> | ||
<section id="UEFI"> | ||
|
||
<h2> | ||
<a href="#UEFI"><span>UEFI</span> </a> | ||
</h2> | ||
<p><span>It is my first system which uses </span><a href="https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface"><span>UEFI</span></a><span> instead of BIOS, and I was</span> | ||
<span>pleasantly surprised by how everything just worked. Documentation contains only</span> | ||
<span>a short paragraph about UEFI, but it</span>’<span>s everything you need. The only hiccup on</span> | ||
<span>my side happened when I enabled GRUB together with </span><code>systemd-boot</code><span>: you don</span>’<span>t</span> | ||
<span>need GRUB at all, </span><code>system-boot</code><span> is a bootloader which handles everything.</span></p> | ||
</section> | ||
<section id="If-it-does-not-work-fix-the-obvious-problem"> | ||
|
||
<h2> | ||
<a href="#If-it-does-not-work-fix-the-obvious-problem"><span>If it does not work, fix the obvious problem</span> </a> | ||
</h2> | ||
<p><span>After I</span>’<span>ve installed everything, I was presented with a blank screen</span> | ||
<span>instead of my desktop environment (with the live CD everything</span> | ||
<span>worked). It took me ages to debug the issue, while the fix was super</span> | ||
<span>trivial: add </span><code>videoDrivers = [ "intel" ];</code><span> to </span><code>xserver</code><span> config and</span> | ||
<code>"noveau"</code><span> to </span><code>blacklistedKernelModules</code><span>.</span></p> | ||
</section> | ||
<section id="Rust"> | ||
|
||
<h2> | ||
<a href="#Rust"><span>Rust</span> </a> | ||
</h2> | ||
<p><span>While nix is the best way to manage Linux desktop I am aware of,</span> | ||
<a href="https://github.com/rust-lang-nursery/rustup.rs"><span>rustup</span></a><span> is the most convenient way of managing Rust toolchains.</span> | ||
<span>Unfortunately it</span>’<span>s not easy to make rustup play nicely with NixOS (UPDATE:</span> | ||
<span>rustup is now packaged in nixpkgs and just works). Rustup downloads binaries of</span> | ||
<span>the compiler and Cargo, but it is impossible to launch unmodified binaries on</span> | ||
<span>NixOS because it a lacks conventional loader.</span></p> | ||
<p><span>The fix I came up with is a horrible hack which goes against</span> | ||
<span>everything in NixOS. Here it is:</span></p> | ||
|
||
<figure class="code-block"> | ||
|
||
|
||
<pre><code><span class="line">environment.<span class="hl-attr">extraInit</span> = <span class="hl-keyword">let</span> <span class="hl-attr">loader</span> = <span class="hl-string">"ld-linux-x86-64.so.2"</span>; <span class="hl-keyword">in</span> <span class="hl-string">''</span></span> | ||
<span class="line"><span class="hl-string"> export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/run/current-system/sw/lib:<span class="hl-subst">${pkgs.stdenv.cc.cc.lib}</span>/lib"</span></span> | ||
<span class="line"><span class="hl-string"> ln -fs <span class="hl-subst">${pkgs.stdenv.cc.libc.out}</span>/lib/<span class="hl-subst">${loader}</span> /lib64/<span class="hl-subst">${loader}</span></span></span> | ||
<span class="line"><span class="hl-string">''</span>;</span></code></pre> | ||
|
||
</figure> | ||
<p><span>It makes the loader and shared libraries (rustup needs </span><code>zlib</code><span>) visible</span> | ||
<span>to binaries compiled for x64 Linux.</span></p> | ||
</section> | ||
<section id="Idea"> | ||
|
||
<h2> | ||
<a href="#Idea"><span>Idea</span> </a> | ||
</h2> | ||
<p><span>Another software which I wish to update somewhat more frequently than</span> | ||
<span>other packages is </span><a href="https://www.jetbrains.com/idea/"><span>IntelliJ IDEA</span></a><span> (I write a fair amount of Kotlin and</span> | ||
<span>Rust). NixOS has a super convenient mechanism to do this:</span> | ||
<a href="https://nixos.org/wiki/Nix_Modifying_Packages#Overriding_Existing_Packages"><code>packageOverrides</code></a><span>. Here is my </span><code>~/nixpkgs/config.nix</code><span>:</span></p> | ||
|
||
<figure class="code-block"> | ||
|
||
|
||
<pre><code><span class="line">{</span> | ||
<span class="line"> <span class="hl-attr">packageOverrides</span> = pkgs: <span class="hl-keyword">rec</span> {</span> | ||
<span class="line"> <span class="hl-attr">idea-community</span> = <span class="hl-keyword">let</span></span> | ||
<span class="line"> <span class="hl-attr">version</span> = <span class="hl-string">"2017.1"</span>;</span> | ||
<span class="line"> <span class="hl-attr">sha256</span> = <span class="hl-string">"750b517742157475bb690c1cc8f21ac151a754a38fec5c99a4bb473efd71da5d"</span>;</span> | ||
<span class="line"> <span class="hl-keyword">in</span></span> | ||
<span class="line"> pkgs.idea.idea-community.overrideDerivation (attrs: <span class="hl-keyword">rec</span> {</span> | ||
<span class="line"> <span class="hl-keyword">inherit</span> version;</span> | ||
<span class="line"> <span class="hl-attr">name</span> = <span class="hl-string">"idea-community-<span class="hl-subst">${version}</span>"</span>;</span> | ||
<span class="line"> <span class="hl-attr">src</span> = pkgs.fetchurl {</span> | ||
<span class="line"> <span class="hl-keyword">inherit</span> sha256;</span> | ||
<span class="line"> <span class="hl-attr">url</span> = <span class="hl-string">"https://download.jetbrains.com/idea/ideaIC-<span class="hl-subst">${version}</span>.tar.gz"</span>;</span> | ||
<span class="line"> };</span> | ||
<span class="line"> });</span> | ||
<span class="line"> };</span> | ||
<span class="line">}</span></code></pre> | ||
|
||
</figure> | ||
<p><span>It allows to use the most recent IDEA with the stable NixOS channel.</span></p> | ||
</section> | ||
</article> | ||
</main> | ||
|
||
<footer> | ||
<p> | ||
<a href="https://github.com/matklad/matklad.github.io/edit/master/content/posts/2017-03-25-nixos-notes.dj"> | ||
<svg class="icon"><use href="/assets/icons.svg#edit"/></svg> | ||
Fix typo | ||
</a> | ||
<a href="/feed.xml"> | ||
<svg class="icon"><use href="/assets/icons.svg#rss"/></svg> | ||
Subscribe | ||
</a> | ||
<a href="mailto:[email protected]"> | ||
<svg class="icon"><use href="/assets/icons.svg#email"/></svg> | ||
Get in touch | ||
</a> | ||
<a href="https://github.com/matklad"> | ||
<svg class="icon"><use href="/assets/icons.svg#github"/></svg> | ||
matklad | ||
</a> | ||
</p> | ||
</footer> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
|
||
<!DOCTYPE html> | ||
<html lang='en-US'> | ||
<head> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Dynamic types in LLDB</title> | ||
<meta name="description" content="If you are wondering how debuggers work, I suggest reading Eli Bendersky's | ||
eli-on-debuggers. However after having read these notes myself, I still | ||
had one question unanswered. Namely, how can debugger show fields of a class, if | ||
the type of the class is known only at runtime?"> | ||
<link rel="icon" href="/favicon.png" type="image/png"> | ||
<link rel="icon" href="/favicon.svg" type="image/svg+xml"> | ||
<link rel="canonical" href="https://matklad.github.io/2017/10/21/lldb-dynamic-type.html"> | ||
<link rel="alternate" type="application/rss+xml" title="matklad" href="https://matklad.github.io/feed.xml"> | ||
<style> | ||
@font-face { | ||
font-family: 'Open Sans'; src: url('/css/OpenSans-300-Normal.woff2') format('woff2'); | ||
font-weight: 300; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'JetBrains Mono'; src: url('/css/JetBrainsMono-400-Normal.woff2') format('woff2'); | ||
font-weight: 400; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'JetBrains Mono'; src: url('/css/JetBrainsMono-700-Normal.woff2') format('woff2'); | ||
font-weight: 700; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-400-Normal.woff2') format('woff2'); | ||
font-weight: 400; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-400-Italic.woff2') format('woff2'); | ||
font-weight: 400; font-style: italic; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-700-Normal.woff2') format('woff2'); | ||
font-weight: 700; font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'EB Garamond'; src: url('/css/EBGaramond-700-Italic.woff2') format('woff2'); | ||
font-weight: 700; font-style: italic; | ||
} | ||
|
||
* { box-sizing: border-box; margin: 0; padding: 0; margin-block-start: 0; margin-block-end: 0; } | ||
|
||
body { | ||
max-width: 80ch; | ||
padding: 2ch; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
|
||
header { margin-bottom: 2rem; } | ||
header > nav { display: flex; column-gap: 2ch; align-items: baseline; flex-wrap: wrap; } | ||
header a { font-style: normal; color: rgba(0, 0, 0, .8); text-decoration: none; } | ||
header a:hover { color: rgba(0, 0, 0, .8); text-decoration: underline; } | ||
header .title { font-size: 1.25em; flex-grow: 2; } | ||
|
||
footer { margin-top: 2rem; } | ||
footer > p { display: flex; column-gap: 2ch; justify-content: center; flex-wrap: wrap; } | ||
footer a { color: rgba(0, 0, 0, .8); text-decoration: none; white-space: nowrap; } | ||
footer i { vertical-align: middle; color: rgba(0, 0, 0, .8) } | ||
|
||
</style> | ||
|
||
<link rel="stylesheet" href="/css/main.css"> | ||
|
||
</head> | ||
|
||
<body> | ||
<header> | ||
<nav> | ||
<a class="title" href="/">matklad</a> | ||
<a href="/about.html">About</a> | ||
<a href="/links.html">Links</a> | ||
<a href="/blogroll.html">Blogroll</a> | ||
</nav> | ||
</header> | ||
|
||
<main> | ||
<article > | ||
|
||
<h1><span>Dynamic types in LLDB</span> <time class="meta" datetime="2017-10-21">Oct 21, 2017</time></h1> | ||
<p><span>If you are wondering how debuggers work, I suggest reading Eli Bendersky</span>’<span>s</span> | ||
<a href="https://eli.thegreenplace.net/tag/debuggers"><span>eli-on-debuggers</span></a><span>. However after having read these notes myself, I still</span> | ||
<span>had one question unanswered. Namely, how can debugger show fields of a class, if</span> | ||
<span>the type of the class is known only at runtime?</span></p> | ||
<section id="Example"> | ||
|
||
<h2> | ||
<a href="#Example"><span>Example</span> </a> | ||
</h2> | ||
<p><span>Consider this situation: you have a pointer of type </span><code>A*</code><span>, which at runtime holds</span> | ||
<span>a value of some subtype of </span><code>A</code><span>. Could the debugger display the fields of the</span> | ||
<span>actual type? Turns out, it can handle cases like the one below just fine!</span></p> | ||
|
||
<figure class="code-block"> | ||
|
||
|
||
<pre><code><span class="line"><span class="hl-keyword">struct</span> <span class="hl-title class_">Base</span> { ... };</span> | ||
<span class="line"></span> | ||
<span class="line"><span class="hl-keyword">struct</span> <span class="hl-title class_">Derived</span>: Base { ... };</span> | ||
<span class="line"></span> | ||
<span class="line"><span class="hl-function"><span class="hl-type">void</span> <span class="hl-title">foo</span><span class="hl-params">(Base& x)</span> </span>{</span> | ||
<span class="line"> <span class="hl-comment">// `x` can be `Derived` or `Base` here.</span></span> | ||
<span class="line"> <span class="hl-comment">// How can debugger show fields of `Derived` then?</span></span> | ||
<span class="line">}</span></code></pre> | ||
|
||
</figure> | ||
</section> | ||
<section id="DWARF"> | ||
|
||
<h2> | ||
<a href="#DWARF"><span>DWARF</span> </a> | ||
</h2> | ||
<p><span>Could it be possible that information about dynamic types is present in DWARF?</span> | ||
<span>If we look at the DWARF, we</span>’<span>ll see that there</span>’<span>s layout information for both</span> | ||
<code>Base</code><span> and </span><code>Derive</code><span> types, as well as a entry for </span><code>x</code><span> parameter, which says that</span> | ||
<span>it has type </span><code>Base</code><span>. And this makes sense: we don</span>’<span>t know that </span><code>x</code><span> is </span><code>Derived</code> | ||
<span>until runtime! So debugger must somehow figure the type of the variable</span> | ||
<span>dynamically.</span></p> | ||
</section> | ||
<section id="No-Magic"> | ||
|
||
<h2> | ||
<a href="#No-Magic"><span>No Magic</span> </a> | ||
</h2> | ||
<p><span>As usual, there</span>’<span>s no magic. For example, LLDB has a hard-coded knowledge of C++</span> | ||
<span>programming language, which allows debugger to inspect types at runtime.</span> | ||
<span>Specifically, this is handled by </span><code>LanguageRuntime</code><span> LLDB </span><strong><span>plugin</span></strong><span>, which has a</span> | ||
<span>curious function </span><a href="https://github.com/llvm-mirror/lldb/blob/bc19e289f759c26e4840aab450443d4a85071139/include/lldb/Target/LanguageRuntime.h#L82"><code>GetDynamicTypeAndAddress</code></a><span>, whose job is to poke the</span> | ||
<span>representation of value to get its real type and adjust pointer, if necessary</span> | ||
<span>(remember, with multiple inheritance, casts may change the value of the</span> | ||
<span>pointer).</span></p> | ||
<p><span>The implementation of this function for C++ language lives in</span> | ||
<a href="https://github.com/llvm-mirror/lldb/blob/bc19e289f759c26e4840aab450443d4a85071139/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp#L185"><span>ItaniumABILanguageRuntime.cpp</span></a><span> although, unlike C, C++ lacks a</span> | ||
<span>standardized ABI, almost all compilers on all non-windows platforms use a</span> | ||
<a href="http://refspecs.linuxbase.org/cxxabi-1.83.html"><span>specific ABI</span></a><span>, confusingly called Itanium (after a now effectively dead</span> | ||
<span>64-bit CPU architecture).</span></p> | ||
</section> | ||
</article> | ||
</main> | ||
|
||
<footer> | ||
<p> | ||
<a href="https://github.com/matklad/matklad.github.io/edit/master/content/posts/2017-10-21-lldb-dynamic-type.dj"> | ||
<svg class="icon"><use href="/assets/icons.svg#edit"/></svg> | ||
Fix typo | ||
</a> | ||
<a href="/feed.xml"> | ||
<svg class="icon"><use href="/assets/icons.svg#rss"/></svg> | ||
Subscribe | ||
</a> | ||
<a href="mailto:[email protected]"> | ||
<svg class="icon"><use href="/assets/icons.svg#email"/></svg> | ||
Get in touch | ||
</a> | ||
<a href="https://github.com/matklad"> | ||
<svg class="icon"><use href="/assets/icons.svg#github"/></svg> | ||
matklad | ||
</a> | ||
</p> | ||
</footer> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.