<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.hoenzb
{mso-style-name:hoenzb;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Let me echo what Vince is saying; I’m about to dig into the unwinder and currently have no idea how it works. The conversation in this thread has helped a ton.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>We’re currently using the default unwinder, but I need to add some special case stuff. Any thoughts on where to look to see a custom implementation?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>--<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Qualcomm Innovation Center, Inc.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> lldb-dev-bounces@cs.uiuc.edu [mailto:lldb-dev-bounces@cs.uiuc.edu] <b>On Behalf Of </b>Vince Harron<br><b>Sent:</b> Friday, January 16, 2015 4:13 PM<br><b>To:</b> Greg Clayton<br><b>Cc:</b> lldb-dev@cs.uiuc.edu<br><b>Subject:</b> Re: [lldb-dev] Problem unwinding from inside of a CRT function<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>> <span style='font-size:10.0pt'>be sure think about the problem in a wider scope than "the code I am thinking about is linear" and think about all sorts of single stepping and what you would expect to happen.</span><o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt'>Thanks very much for helping us understand this stuff. I was also super curious how this single step stuff works and what the non-obvious (to us) cases are.</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt'>When we're up to speed we should be able to really contribute some good stuff.</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt'>Vince</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Fri, Jan 16, 2015 at 1:53 PM, Greg Clayton <<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>> wrote:<o:p></o:p></p><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal style='margin-bottom:12.0pt'>><br>> On Jan 16, 2015, at 1:12 PM, Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br>><br>><br>><br>> On Fri Jan 16 2015 at 12:45:00 PM <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br>><br>> > On Jan 16, 2015, at 12:14 PM, Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br>> ><br>> > I'm still trying to wrap my head around the way LLDB does things.<br>> ><br>> > If I understand correctly, when you run thread step-over, it enters single step mode (by setting the trap flag on the CPU). Every time the CPU traps, LLDB picks this up and asks the ThreadPlan "should i stop now?" "should i stop now?" until the ThreadPlan returns true. And part of this "should i stop now" involves generating an unwind.<br>> ><br>><br>> That's close, but not quite correct.<br>><br>> 1) In the original implementation, (and this is how gdb does it, BTW) lldb single-stepped till "something interesting happened." As an optimization, when you are doing any kind of step through source range, I changed lldb so it runs from "instruction that could branch" to "instruction that could branch" using breakpoints. Then when it hits an instruction that could branch it single steps that instruction, and then figures out from where that went what to do next.<br>><br>> BTW, if it were helpful to figure out what to do next, we could store some info (the old stack frame or whatever) when we hit a branch instruction, and then use it when the single-step completed. I haven't needed to do that yet, however; Jason's always been able to get the unwinder work reliably enough not to require this.<br>> Let's say you're stopped at the first line of foo() here.<br>><br>> 1. void foo()<br>> 2. {<br>> 3. -> printf(<br>> 4. "Line 1\n");<br>> 5. printf("Line 2\n");<br>> 6. printf("Line 3\n");<br>> 7. }<br>><br>> When you step-over, why can't it just say: Ok, current source line is 3. Debug info tells me that the next instruction begins on line 5. Line 5 corresponds to address 0x12345678. Put a breakpoint on 0x12345678. To account for the fact that foo() may be recursive, also save off a copy of the stack pointer. When the breakpoint is hit, stop if the stack pointer is the same or less than the saved value (depending on the definition of "less" for your architecture), otherwise don't stop.<o:p></o:p></p></div></div><p class=MsoNormal>How about:<br><br>2 for (int i=0; i<100; i++)<br>3 -> printf ("i = %i\n", i); //<br>4 printf ("this won't be executed after line 3 except for the last time\n");<br><br>If you set a breakpoint on line 4 after line 3 when you will fail to return to line 3 when single stepping.<br><br>How about:<br><br>2 -> goto carp;<br>3 puts("won't ever be executed");<br>4 carp:<br>5 puts("will get executed");<br><br>If you set a breakpoint at line 3 you won't stop.<br><br>Another:<br><br>2 -> throw foo();<br>3 puts("this will never get hit");<br><br>If you set a breakpoint at line 3 you will never hit it.<br><br>Please trust that we know what we are doing when it comes to single stepping. I am glad you are thinking about how things are done, but just be sure think about the problem in a wider scope than "the code I am thinking about is linear" and think about all sorts of single stepping and what you would expect to happen.<br><br><br>Also, did you get my comment about improving functions bounds in the COFF parser? If you can do this, you won't really need to do any of the unwinding stuff because the assembly unwinder will take care of it, you just need to get good function bounds for everything using any means necessary in the ObjectFileCOFF parser by making all the symbols you can. You also need to identify what parts are trampolines. For example a call to printf usually goes through a PLT entry. These are often in one place in your binary and often there are not symbols in the symbol table for these. Identifying the symbols with a name like "printf" and also making the symbol a eSymbolTypeTrampoline will allow us to not set a breakpoint on your "printf" trampoline when you say "b printf" on the command line, and it will also give function bounds to these small trampoline code sections so we can step and unwind through them.<br><span style='color:#888888'><br><span class=hoenzb>Greg</span></span><o:p></o:p></p><div><div><p class=MsoNormal><br><br><br><br>_______________________________________________<br>lldb-dev mailing list<br><a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><o:p></o:p></p></div></div></blockquote></div><p class=MsoNormal><br><br clear=all><o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>-- <o:p></o:p></p><div><div><p class=MsoNormal><o:p> </o:p></p><table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0><tr><td nowrap style='border:none;border-top:solid #D50F25 1.5pt;padding:0in 0in 0in 0in'><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#555555'>Vince Harron |<o:p></o:p></span></p></td><td nowrap style='border:none;border-top:solid #3369E8 1.5pt;padding:0in 0in 0in 0in'><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#555555'> Technical Lead Manager |<o:p></o:p></span></p></td><td nowrap style='border:none;border-top:solid #009939 1.5pt;padding:0in 0in 0in 0in'><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#555555'> <a href="mailto:vharron@google.com" target="_blank">vharron@google.com</a> |<o:p></o:p></span></p></td><td nowrap style='border:none;border-top:solid #EEB211 1.5pt;padding:0in 0in 0in 0in'><p class=MsoNormal><span style='font-family:"Arial",sans-serif;color:#555555'> 858-442-0868<o:p></o:p></span></p></td></tr></table><p class=MsoNormal><o:p> </o:p></p></div></div></div></div></body></html>