<p>While trying to debug a panic in <code>kubelet</code>, I have been trying unsuccessfully to attach <code>delve</code> to <code>kubelet</code> executable:</p>

<pre><code>me@mycomputer:~$ sudo dlv attach 23796
could not attach to pid 23796: could not open debug info
</code></pre>

<p><code>file</code> and <code>objdump --syms</code> reveal no debug info is included in <code>kubelet</code>:</p>

<pre><code>me@mycomputer:~$ file _output/bin/kubelet 
_output/bin/kubelet: ELF 64-bit LSB executable, x86-64, version 1 
(SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, 
BuildID[sha1]=c7a1645940f91048eea9086bd0500deb7ec75b38, for 
GNU/Linux 3.2.0, stripped

me@mycomputer:~$ objdump --syms _output/bin/kubelet 

_output/bin/kubelet:     file format elf64-x86-64
SYMBOL TABLE:
no symbols
</code></pre>

<p>I have tried different options while building <code>kubelet</code>:</p>

<pre><code>make WHAT=cmd/kubelet GOGCFLAGS=-dwarf
</code></pre>

<p>or:</p>

<pre><code>make WHAT=cmd/kubelet GOFLAGS=-dwarf
</code></pre>

<p>but still no debug info is included in the executable. It seems to me that <code>-w</code> option is included by default in <code>go tool link</code>, which strips the DWARF symbol table to save on final executable size (see <a href="https://golang.org/cmd/link/" rel="nofollow noreferrer">here</a>). But I was not able to reverse that.</p>

<p>Any thoughts on how I should build <code>kubelet</code> to include debug info?</p>

Dani
<p>As <a href="https://stackoverflow.com/users/32880/jimb">JimB</a> advised, <code>go build</code> does the trick:</p>



<pre class="lang-none prettyprint-override"><code>me@mycomputer:~/kubernetes/cmd/kubelet$ sudo go build kubelet.go
me@mycomputer:~/kubernetes/cmd/kubelet$ file ./kubelet
kubelet: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically 
linked, interpreter /lib64/ld-linux-x86-64.so.2, 
BuildID[sha1]=a1377345bfab4ca57b28af60eed92f23c81d7ae8, for GNU/Linux 3.2.0, 
not stripped
</code></pre>

<p>As can be seen, the debug info is <em>not stripped</em> anymore. Now you can copy the output to <code>_output/bin</code> and debug it using <code>delve</code>.</p>
