<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I think that description was a bit too much inside baseball…. <div class=""><br class=""></div><div class="">Every time lldb stops outside a stepping range while stepping, it invokes a set of “should stop here” agents to determine what to do next. If any of those agents think we should NOT stop here, they are expected to produce a set of instructions (i.e. a ThreadPlan) that drive the thread back to the original code. </div><div class=""><br class=""></div><div class="">The “we stopped in a function with no debug information, step back out” behavior of lldb is implemented this way. So if you can make your emulated instruction regions look like function calls w/o debug info, you would get this behavior for free. But the mechanism is pretty flexible, and you just need to leave yourself enough information to (a) know you are in one of your regions and (b) how to drive the debugger to get back to the code that invoked this emulated instruction, in order to get lldb’s “should stop here” machinery to do what you want.<div class=""><br class=""></div><div class="">Jim</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 18, 2022, at 10:28 AM, Jim Ingham via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">On Jan 16, 2022, at 11:23 PM, Pavel Labath <<a href="mailto:pavel@labath.sk" class="">pavel@labath.sk</a>> wrote:<br class=""><br class="">Hi Kjell,<br class=""><br class="">if you say these instructions are similar to function calls, then it sounds to me like the best option would be to get lldb to treat them like function calls. I think (Jim can correct me if I'm wrong) this consists of two things:<br class="">- make sure lldb recognizes that these instructions can alter control flow (Disassembler::GetIndexOfNextBranchInstruction). You may have done this already.<br class="">- make sure lldb can unwind out of these "functions" when it winds up inside them. This will ensure the user does not stop in these functions when he does a "step over". This means providing it the correct unwind info so it knows where the functions will return. (As the functions know how to return to the original instructions, this information has to be somewhere, and is hopefully accessible to the debugger.) Probably the cleanest way to do that would be to create a new Module object, which would contain the implementations of all these functions, and all of their debug info. Then you could provide the unwind info through the usual channels (e.g. .debug_frame), and it has the advantage that you can also include any other information about these functions (names, line numbers, whatever...)<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Pavel is right, if these blobs look like function calls with no debug information, then lldb won’t stop in them by default. Note, the “no debug info" part is not a strict requirement, since lldb also has controls for “shared libraries we never stop in when stepping” and “name regular expressions for functions we don’t stop in”. At present, those controls are just for user-specification. But if you find you need to do something more programmatic, you can easily add another “don’t stop in me” check specific to your architecture.<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">All this will work pretty transparently if the unwinder is able to tell us how to get out of the function and back to it’s caller. But even if that’s not the case, the “should stop here” mechanism in lldb works by at a lower level by having the agent saying we should NOT stop here return a ThreadPlan telling us how to get to the caller frame. For a function call, you get the step out plan for free. But that’s not a requirement, your emulated instruction region doesn’t strictly need to be a function call, provided you know how to produce a thread plan that will step out of it.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Jim</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="">pl<br class=""><br class="">On 15/01/2022 07:49, Kjell Winblad via lldb-dev wrote:<br class=""><blockquote type="cite" class="">Hi!<br class="">I'm implementing LLDB support for a new processor architecture that<br class="">the company I'm working for has created. The processor architecture<br class="">has a few emulated instructions. An emulated instruction works by<br class="">jumping to a specific address that contains the start of a block of<br class="">instructions that emulates the emulated instructions. The emulated<br class="">instructions execute with interrupts turned off to be treated as<br class="">atomic by the programmer. So an emulated instruction is similar to a<br class="">function call. However, the address that the instruction jumps to is<br class="">implicit and not specified by the programmer.<br class="">I'm facing a problem with the emulated instructions when implementing<br class="">source-level stepping (the LLDB next and step commands) for C code in<br class="">LLDB. LLDB uses hardware stepping to step through the address range<br class="">that makes up a source-level statement. This algorithm works fine<br class="">until the PC jumps to the start of the block that implements an<br class="">emulated instruction. Then LLDB stops because the PC exited the<br class="">address range for the source-level statement. This behavior is not<br class="">what we want. Instead, LLDB should ideally step through the emulation<br class="">instructions and continue until the current source-level statement has<br class="">been completed.<br class="">My questions are:<br class="">1. Is there currently any LLDB plugin functionality or special DWARF<br class="">debug information to handle the kind of emulated instructions that I<br class="">have described? All the code for the emulated instructions is within<br class="">the same address range that does not contain any other code.<br class="">2. If the answer to question 1 is no, do you have suggestions for<br class="">extending LLVM to support this kind of emulated instructions?<br class="">Best regards,<br class="">Kjell Winblad<br class="">_______________________________________________<br class="">lldb-dev mailing list<br class=""><a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev<br class=""></blockquote><br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">lldb-dev mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="mailto:lldb-dev@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">lldb-dev@lists.llvm.org</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a></div></blockquote></div><br class=""></div></div></body></html>