<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014-02-22 12:46 GMT+01:00 Piotr Rak <span dir="ltr"><<a href="mailto:piotr.rak@gmail.com" target="_blank">piotr.rak@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Ed<div><br></div><div>Sorry for late reply and thanks for looking into it.</div>
<div><br></div><div>Your example fails same way as mine for all combinations static/dynamic gcc/clang.</div><div>Wonder if FreeBSD adds .text section to core files.</div>
<div><br></div><div>What would be result of disassembly for you?</div><div><br></div><div>For me it always looks like that:</div><div><br></div><div><div>dis -b -f</div><div>libc.so.6`__GI_raise:</div><div> 0x7f72a9b11330: 00 00 addb %al, (%rax)</div>
<div> 0x7f72a9b11332: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b11334: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b11336: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b11338: 00 00 addb %al, (%rax)</div>
<div> 0x7f72a9b1133a: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b1133c: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b1133e: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b11340: 00 00 addb %al, (%rax)</div>
<div> 0x7f72a9b11342: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b11344: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b11346: 00 00 addb %al, (%rax)</div><div> 0x7f72a9b11348: 00 00 addb %al, (%rax)</div>
</div><div>...</div><div><br></div><div>Could you please compare output of readelf/eu-readelf with mine?</div><div><br></div><div>For me it is:</div><div><div>eu-readelf -l core_lnx.1125 </div><div><br></div><div>Program Headers:<br>
</div><div><div> Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align</div><div> NOTE 0x000388 0x0000000000000000 0x0000000000000000 0x001940 0x000000 0x0</div><div> LOAD 0x002000 0x0000000000400000 0x0000000000000000 0x000000 0x0c2000 R E 0x1000</div>
<div> LOAD 0x002000 0x00000000004c2000 0x0000000000000000 0x003000 0x003000 RW 0x1000</div><div> LOAD 0x005000 0x00000000004c5000 0x0000000000000000 0x006000 0x006000 RW 0x1000</div><div> LOAD 0x00b000 0x0000000001906000 0x0000000000000000 0x002000 0x002000 RW 0x1000</div>
<div> LOAD 0x00d000 0x0000000001908000 0x0000000000000000 0x000000 0x021000 RW 0x1000</div><div> LOAD 0x00d000 0x00007f6e4be02000 0x0000000000000000 0x001000 0x001000 0x1000</div><div> LOAD 0x00e000 0x00007f6e4be03000 0x0000000000000000 0x800000 0x800000 RW 0x1000</div>
<div> LOAD 0x80e000 0x00007f6e4c603000 0x0000000000000000 0x001000 0x001000 0x1000</div><div> LOAD 0x80f000 0x00007f6e4c604000 0x0000000000000000 0x800000 0x800000 RW 0x1000</div><div> LOAD 0x100f000 0x00007f6e4ce04000 0x0000000000000000 0x001000 0x001000 0x1000</div>
<div> LOAD 0x1010000 0x00007f6e4ce05000 0x0000000000000000 0x800000 0x800000 RW 0x1000</div><div> LOAD 0x1810000 0x00007fffcef2b000 0x0000000000000000 0x022000 0x022000 RW 0x1000</div><div> LOAD 0x1832000 0x00007fffceffe000 0x0000000000000000 0x002000 0x002000 R E 0x1000</div>
<div> LOAD 0x1834000 0xffffffffff600000 0x0000000000000000 0x001000 0x001000 R E 0x1000</div></div></div><div><br></div><div>I am mostly interested if your core contain for .text sections is non-zero length for phdrs in loaded segments:</div>
<div><br></div><div>For me program .text is not clearly there:</div><div>LOAD 0x002000 0x0000000000400000 0x0000000000000000 0x000000 0x0c2000 R E 0x1000<br></div><div> ~~~~~~</div>
<div>That would explain the difference for what I and you see.</div><div><br></div><div>IIRC Target::ReadMemory seems to be using m_images at first, but after DynamicLoader kicks in it uses:</div><div><br></div><div>
<pre style="margin-top:0px;margin-bottom:0px">bytes_read<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(170,170,170)">=</span><span style="color:rgb(192,192,192)"> </span>m_process_sp<span style="color:rgb(170,170,170)">-></span>ReadMemory<span style="color:rgb(170,170,170)">(</span>load_addr<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>dst<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>dst_len<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>error<span style="color:rgb(170,170,170)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">which obviously returns only zeros for me since core did not contain any data for .text sections.</pre><pre style="margin-top:0px;margin-bottom:0px">
<br></pre><pre style="margin-top:0px;margin-bottom:0px"><div style="font-family:arial;white-space:normal">I wonder if:</div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span></pre>
<pre style="margin-top:0px;margin-bottom:0px">section_load_list<span style="color:rgb(170,170,170)">.</span>ResolveLoadAddress<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(170,170,170)">(</span>load_addr<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>resolved_addr<span style="color:rgb(170,170,170)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>is doing right thing for me, but I clearly do not understand yet how it works and how should it work.
<pre style="margin-top:0px;margin-bottom:0px"><br></pre></pre></div></div></blockquote><div><br></div><div>I am probably onto something because adding such hack fixes things for me:</div><div><br></div><div><div>diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp</div>
<div>index e781626..21cb29a 100644</div><div>--- a/source/Target/Target.cpp</div><div>+++ b/source/Target/Target.cpp</div><div>@@ -1311,7 +1311,7 @@ Target::ReadMemory (const Address& addr,</div><div> if (!addr.IsSectionOffset())</div>
<div> {</div><div> SectionLoadList §ion_load_list = GetSectionLoadList();</div><div>- if (section_load_list.IsEmpty())</div><div>+ if (true || section_load_list.IsEmpty())</div><div> {</div>
<div> // No sections are loaded, so we must assume we are not running</div><div> // yet and anything we are given is a file address.</div><div>@@ -1332,7 +1332,7 @@ Target::ReadMemory (const Address& addr,</div>
<div> resolved_addr = addr;</div><div> </div><div> </div><div>- if (prefer_file_cache)</div><div>+ if (true || prefer_file_cache)</div><div> {</div><div> bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);</div>
<div> if (bytes_read > 0)</div></div><div><br></div><div><br></div><div>This basically forces Target to totally ignore SectionLoadList and with this change applied it starts to work as expected:</div><div><br></div>
<div><div>Core file '/home/prak/tmp/userland-cores/Linux/3.12.8-1-ARCH/x86_64/clang/3.4/core_lnx.1112' (x86_64) was loaded.</div><div>Process 0 stopped</div><div>* thread #1: tid = 0, 0x00007f72a9b11369 libc.so.6`__GI_raise + 57, name = 'gen-core-v1', stop reason = signal SIGABRT</div>
<div> frame #0: 0x00007f72a9b11369 libc.so.6`__GI_raise + 57</div><div>libc.so.6`__GI_raise + 57:</div><div>-> 0x7f72a9b11369: cmpq $-0x1000, %rax</div><div> 0x7f72a9b1136f: ja 0x3538a ; __GI_raise + 90</div>
<div> 0x7f72a9b11371: rep </div><div> 0x7f72a9b11372: retq </div><div> thread #2: tid = 1, 0x00007f72a9b92aad libc.so.6, stop reason = signal SIGABRT</div><div> frame #0: 0x00007f72a9b92aad libc.so.6</div><div>
libc.so.6`??? + 45:</div><div>-> 0x7f72a9b92aad: movq (%rsp), %rdi</div><div><br></div><div>libc.so.6`??? + 49:</div><div> 0x7f72a9b92ab1: movq %rax, %rdx</div><div><br></div><div>libc.so.6`??? + 52:</div><div>
0x7f72a9b92ab4: callq 0xf1930 ; __libc_disable_asynccancel</div><div><br></div><div>libc.so.6`??? + 57:</div><div> 0x7f72a9b92ab9: movq %rdx, %rax</div><div> thread #3: tid = 2, 0x00007f72a9b92aad libc.so.6, stop reason = signal SIGABRT</div>
<div> frame #0: 0x00007f72a9b92aad libc.so.6</div><div>libc.so.6`??? + 45:</div><div>-> 0x7f72a9b92aad: movq (%rsp), %rdi</div><div><br></div><div>libc.so.6`??? + 49:</div><div> 0x7f72a9b92ab1: movq %rax, %rdx</div>
<div><br></div><div>libc.so.6`??? + 52:</div><div> 0x7f72a9b92ab4: callq 0xf1930 ; __libc_disable_asynccancel</div><div><br></div><div>libc.so.6`??? + 57:</div><div> 0x7f72a9b92ab9: movq %rdx, %rax</div>
<div> thread #4: tid = 3, 0x00007f72a9b92aad libc.so.6, stop reason = signal SIGABRT</div><div> frame #0: 0x00007f72a9b92aad libc.so.6</div><div>libc.so.6`??? + 45:</div><div>-> 0x7f72a9b92aad: movq (%rsp), %rdi</div>
<div><br></div><div>libc.so.6`??? + 49:</div><div> 0x7f72a9b92ab1: movq %rax, %rdx</div><div><br></div><div>libc.so.6`??? + 52:</div><div> 0x7f72a9b92ab4: callq 0xf1930 ; __libc_disable_asynccancel</div>
<div><br></div><div>libc.so.6`??? + 57:</div><div> 0x7f72a9b92ab9: movq %rdx, %rax</div></div><div><br></div><div>Also, I expect it might have been failing pretty long time without being noticed, since for live debugging it wouldn't matter if we load those values using SectionLoadList or Process::DoReadMemory, because this information is same and correct in both places.</div>
<div><br></div><div>Hints more than welcome :)</div><div><br></div><div>Will dig bit more...</div><div><br></div><div>Cheers,</div><div>/Piotr</div></div></div></div>