<div dir="ltr"><div>That's totally fine for our use case.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 5, 2016 at 11:57 AM, Jim Ingham <span dir="ltr"><<a href="mailto:jingham@apple.com" target="_blank">jingham@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You would have to be really careful about using "debugger variables" whose name is not decorated with a "$".  After all, this is introducing a global variable, which will be shadowed by local variables, ivars, file statics for the current frame's CU, etc.  So using the code you've added at various stop points in the debugging session will be fragile.  That's the primary reason that we don't encourage defining debugger variables in the common identifier namespace of your program.<br>
<span class="HOEnZb"><font color="#888888"><br>
Jim<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> On Oct 5, 2016, at 11:41 AM, Rex Fenley <<a href="mailto:rex@remind101.com">rex@remind101.com</a>> wrote:<br>
><br>
> Hey Kate! Thanks for all this info, it's really helpful :)<br>
><br>
> We'd like to have more complex expressions being used from the debugger. Some of this would be code written in separate files. It will be difficult or at least very tedious to have all our code use "$", is there a way to void using "$"? Is there an option we could add to lldb to avoid using "$" and still have variables and data-structures globally accessible? I notice that within "repl" "$" it's not necessary to use any "$" variables, is there a way to elevate the logic "repl" uses into expr?<br>
><br>
> On Wed, Oct 5, 2016 at 11:29 AM, Kate Stone <<a href="mailto:k8stone@apple.com">k8stone@apple.com</a>> wrote:<br>
>> On Oct 5, 2016, at 10:14 AM, Rex Fenley via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>> Maybe I have that incorrectly, this does seem to work when using lldb from Xcode's console. This doesn't work when typing `lldb` into the terminal and using it from there. I assumed the two were the same.<br>
><br>
> The same underlying debugger is used in both cases.  There can be subtle reasons for differences in behavior in the different contexts, but I don’t see how they’d apply here.  Let’s get to a specific scenario and ensure that we can resolve that for you.<br>
><br>
>> On a separate note, --top-level doesn't seem to work for swift (from Xcode console lldb). We need it to work with swift for the scripts we'll be writing.<br>
>> (lldb) expr -l swift --top-level -- let i = 10<br>
>><br>
>> expr -l swift --top-level -- let a = i<br>
>><br>
>> error: <EXPR>:3:9: error: use of unresolved identifier 'i'<br>
>><br>
> The --top-level option isn’t meaningful for Swift, so it’s completely ignored.  The less ambiguous nature of the language allows us to automatically determine what are top-level constructs and what’s intended to be evaluated in scope.  We introduced --top-level for Objective-C / C++ primarily to enable declaring functions and anything else that literally cannot be written in a local scope.<br>
><br>
> In your particular example the reason you can’t refer to “i” is completely unrelated.  Conceptually, every expression you evaluate is wrapped in its own scope.  So your two subsequent expressions act like this construct :<br>
><br>
> do {<br>
>     let i = 10<br>
> }<br>
> do {<br>
>     let a = i<br>
> }<br>
><br>
> As you can see, “i” is defined in this expression scope and then goes out of scope immediately after execution.  This is useful when you want to write a multi-line expression that introduces declarations for immediate use without having them cluttering up your namespace afterwards.  The convention used by LLDB for any declaration that you intend to use in later expressions is to prefix the name with a dollar sign.  So you can do the following:<br>
><br>
> (lldb) expr -l swift -- let $i = 10<br>
> (lldb) expr -l swift -- let $a = i<br>
><br>
> … and both “$a” and “$i" will be available in subsequent expressions.<br>
><br>
> Kate Stone <a href="mailto:k8stone@apple.com">k8stone@apple.com</a><br>
>  Xcode Low Level Tools<br>
><br>
>> On Wed, Oct 5, 2016 at 10:06 AM, Rex Fenley <<a href="mailto:rex@remind101.com">rex@remind101.com</a>> wrote:<br>
>> Jim,<br>
>><br>
>> That doesn't seem to work for us. We're using lldb packaged with Xcode 8 fyi.<br>
>> (lldb) expr --top-level -- NSString *string = [NSString stringWithUTF8String: "This is a string"];<br>
>><br>
>><br>
>><br>
>> ; Function Attrs: nounwind<br>
>><br>
>> define internal void @_GLOBAL__sub_I__null_() #0 section "__TEXT,__StaticInit,regular,<wbr>pure_instructions" {<br>
>><br>
>>   call void @__cxx_global_var_init()<br>
>><br>
>>   ret void<br>
>><br>
>> }<br>
>><br>
>><br>
>> On Tue, Oct 4, 2016 at 4:09 PM, Jim Ingham <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br>
>> This isn't an issue with ObjC support in general, but rather shows that ObjC string constants are odd beasts.  You can work around this pretty easily by making dynamic strings:<br>
>><br>
>> (lldb) expr --top-level -- NSString *string = [NSString stringWithUTF8String: "This is a string"];<br>
>> (lldb) expr string<br>
>> (__NSCFString *) $0 = 0x00000001002001b0 @"This is a string"<br>
>><br>
>> Please file a bug about the problem with ObjC constant strings.<br>
>><br>
>> Jim<br>
>><br>
>><br>
>> > On Oct 4, 2016, at 3:57 PM, Rex Fenley via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br>
>> ><br>
>> > Hey lldb team!<br>
>> ><br>
>> > I'm trying to use `expr --top-level` from lldb in Xcode but it throws errors like the following:<br>
>> ><br>
>> > (lldb) expression --top-level -- NSString *str = @"This is a string";<br>
>> > Error [IRForTarget]: Couldn't replace an Objective-C constant string with a dynamic string<br>
>> > error: cannot import unsupported AST node ObjCStringLiteral<br>
>> > error: The expression could not be prepared to run in the target<br>
>> ><br>
>> > It seems like top-level only supports raw C code and not Objective-C. Is there an option we can set to support this? Is there somewhere in lldb's source code that could help point us to fixing this?<br>
>> ><br>
>> > Thank you, you guys rule!<br>
>> ><br>
>> > --<br>
>> > Rex Fenley  |  IOS DEVELOPER<br>
>> ><br>
>> ><br>
>> > Remind.com |  BLOG  |  FOLLOW US  |  LIKE US<br>
>> > ______________________________<wbr>_________________<br>
>> > lldb-dev mailing list<br>
>> > <a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
>> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/lldb-dev</a><br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
>> Rex Fenley  |  IOS DEVELOPER<br>
>><br>
>><br>
</div></div><span class="im HOEnZb">>> Remind.com |  BLOG  |  FOLLOW US  |  LIKE US<br>
>><br>
>><br>
>><br>
>> --<br>
>> Rex Fenley  |  IOS DEVELOPER<br>
>><br>
>><br>
</span><div class="HOEnZb"><div class="h5">>> Remind.com |  BLOG  |  FOLLOW US  |  LIKE US<br>
>> ______________________________<wbr>_________________<br>
>> lldb-dev mailing list<br>
>> <a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/lldb-dev</a><br>
><br>
><br>
><br>
><br>
> --<br>
> Rex Fenley  |  IOS DEVELOPER<br>
><br>
><br>
> Remind.com |  BLOG  |  FOLLOW US  |  LIKE US<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="font-size:16px;font-family:Arial;background-color:transparent;font-style:italic;vertical-align:baseline;white-space:pre-wrap">Rex Fenley</span><span style="font-size:16px;font-family:Arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">  </span><span style="font-size:11px;font-family:Arial;color:rgb(153,153,153);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">|</span><span style="line-height:1.15;font-family:Arial;color:rgb(153,153,153);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">  </span><span style="font-size:11px;font-family:Arial;color:rgb(153,153,153);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">IOS DEVELOPER</span><br></p></span><span><br><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11px;font-family:Arial;color:rgb(153,153,153);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><img src="https://lh5.googleusercontent.com/xMgzw3JkFL3DLkdwyq0WxJzKs_XP57gVVCaBMvgi1FKCjSeue0xdx3JZeCWBlxN4KRHhHOfdvJbc1N-AjTwXcKIq4cjJg9H7iaFpQ8WbO4N3c9Y5dzi19cPOs_owPquuqw" width="250px;" height="53px;" style="border:none"></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><a href="https://www.remind.com/" style="text-decoration:none" target="_blank"><span style="font-size:11px;font-family:Arial;color:rgb(17,85,204);font-weight:bold;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">Remind.com</span></a><span style="font-family:Arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span><span style="font-size:11px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">|  </span><a href="http://blog.remind.com/" style="text-decoration:none" target="_blank"><span style="font-size:11px;font-family:Arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">BLOG</span></a><span style="font-size:11px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">  |  </span><a href="https://twitter.com/remindhq" style="text-decoration:none" target="_blank"><span style="font-size:11px;font-family:Arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">FOLLOW US</span></a><span style="font-size:11px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">  | </span><span style="font-family:Arial;vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> </span><span style="text-decoration:underline;font-size:11px;font-family:Arial;color:rgb(17,85,204);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><a href="https://www.facebook.com/remindhq" style="text-decoration:none" target="_blank">LIKE US</a></span></p></span></div></div>
</div>