<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LLDB fails to evaluate expressions which include string literals when linked against libLLVM.so"
   href="https://bugs.llvm.org/show_bug.cgi?id=34194">34194</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLDB fails to evaluate expressions which include string literals when linked against libLLVM.so
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tschelle@redhat.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18986" name="attach_18986" title="Shell script to reproduce the bug.">attachment 18986</a> <a href="attachment.cgi?id=18986&action=edit" title="Shell script to reproduce the bug.">[details]</a></span>
Shell script to reproduce the bug.

Description of problem:
LLDB fails to evaluate expressions which include string literals if built with
-DLLVM_LINK_LLVM_DYLIB=ON.

Version-Release number of selected component (if applicable):
Reproduces with trunk (r310911)

How reproducible:
100%

Steps to Reproduce:
1.
$ cat >test.c
#include <stdio.h>

int main(void) {
  return 0;
}

2. gcc -g test.c -o test
3.
$ lldb ./test
(lldb) target create "./test"
Current executable set to './test' (x86_64).
(lldb) b main
Breakpoint 1: where = test`main + 4 at test.c:4, address = 0x00000000004004f1
(lldb) r
Process 196442 launched: './test' (x86_64)
Process 196442 stopped
* thread #1, name = 'test', stop reason = breakpoint 1.1
    frame #0: test`main at test.c:4
   1    #include <stdio.h>
   2
   3    int main(void) {
-> 4      return 0;
   5    }
(lldb) expr "hello"
error: Couldn't apply expression side effects : Couldn't dematerialize a result
variable: couldn't read its memory
(lldb) expr printf("hello")
error: Execution was interrupted, reason: signal SIGSEGV: invalid address
(fault address: 0x7fdbfac1e000).
The process has been returned to the state before expression evaluation.

Actual results:
(lldb) expr "hello"
error: Couldn't apply expression side effects : Couldn't dematerialize a result
variable: couldn't read its memory
(lldb) expr printf("hello")
error: Execution was interrupted, reason: signal SIGSEGV: invalid address
(fault address: 0x7fdbfac1e000).
The process has been returned to the state before expression evaluation.

Expected results:
(lldb) expr "hello"
(const char [6]) $0 = "hello"
(lldb) expr printf("hello")


Additional info:

Works fine in the static build (see expected results) but doesn't work with
-DLLVM_LINK_LLVM_DYLIB=ON active.

Attached is a shell script which builds trunk LLVM/Clang/LLDB separately and
with -DLLVM_LINK_LLVM_DYLIB=ON. Once the build is complete it also runs the
above test case.

I have spent a significant amount of time to debug this already and it looks
like some sort of memory corruption that happens early on during the evaluation
of the 'expr "hello"' command. E.g. in a release build of Clang/LLVM/LLDB and
with "log enable lldb all" you can see that the generated LLVM IR for the
expression is slightly different in the static and dynamic build. These
differences are not visible in the debug build but it seems that there's
definitely some memory corruption going on somewhere.

Also tried to run this with AddressSanitizer but didn't get any suspicious
reports.

Reproduces at least with GCC 4.8, GCC 6.3.1 and Clang 4.0.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>