<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 - Inconsistent debug info between step and stepi at -O1"
   href="https://bugs.llvm.org/show_bug.cgi?id=46042">46042</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inconsistent debug info between step and stepi at -O1
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>DebugInfo
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yangyibiao@hust.edu.cn
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23524" name="attach_23524" title="the binary">attachment 23524</a> <a href="attachment.cgi?id=23524&action=edit" title="the binary">[details]</a></span>
the binary

$ clang --version
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ lldb --version
lldb version 11.0.0
  clang revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af
  llvm revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af




$ clang -O1 -g small.c

$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Debugger/a.out' (x86_64).
(lldb) b main
Breakpoint 1: where = a.out`main + 1 at small.c:26:8, address =
0x00000000004011a1
(lldb) r
Process 79491 launched: '/home/yibiao/Debugger/a.out' (x86_64)
Process 79491 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00000000004011a1 a.out`main at small.c:26:8
   23   }
   24   
   25   int main() {
-> 26     if (!f("u3"))
   27       return 1;
   28     return 0;
   29   }
(lldb) step
Process 79491 stopped
* thread #1, name = 'a.out', stop reason = step in
    frame #0: 0x0000000000401157 a.out`f(p="u3") at small.c:9:11
   6      int s=0, m=3, l=3, lm=6, r;
   7    
   8      while(1) {
-> 9        m = (s+l)/2;
   10       if (lm==m) {
   11         break;
   12       }
(lldb) step
Process 79491 stopped
* thread #1, name = 'a.out', stop reason = step in
    frame #0: 0x0000000000401164 a.out`f(p="u3") at small.c:10:11
   7    
   8      while(1) {
   9        m = (s+l)/2;
-> 10       if (lm==m) {
   11         break;
   12       }
   13       r = strcmp(p, T[m]);
(lldb) step
Process 79491 stopped
* thread #1, name = 'a.out', stop reason = step in
    frame #0: 0x000000000040116c a.out`f(p="u3") at small.c:13:19
   10       if (lm==m) {
   11         break;
   12       }
-> 13       r = strcmp(p, T[m]);
   14       if (r < 0) {
   15         l = m;
   16       } else if (r > 0) {
(lldb) fr var s
(int) s = 1
(lldb) 



/*********************************************
As showed above, step into Line 13 (first hit), the value of "s" is 1.
When using step-i, the value of "s" is 0 which is as expected. 
*********************************************/

$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Debugger/a.out' (x86_64).
(lldb) b main
Breakpoint 1: where = a.out`main + 1 at small.c:26:8, address =
0x00000000004011a1
(lldb) r
Process 79554 launched: '/home/yibiao/Debugger/a.out' (x86_64)
Process 79554 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00000000004011a1 a.out`main at small.c:26:8
   23   }
   24   
   25   int main() {
-> 26     if (!f("u3"))
   27       return 1;
   28     return 0;
   29   }
(lldb) si -c 12
Process 79554 stopped
* thread #1, name = 'a.out', stop reason = instruction step into
    frame #0: 0x000000000040116c a.out`f(p="u3") at small.c:13:19
   10       if (lm==m) {
   11         break;
   12       }
-> 13       r = strcmp(p, T[m]);
   14       if (r < 0) {
   15         l = m;
   16       } else if (r > 0) {
(lldb) fr var s
(int) s = 0
(lldb)



$ cat small.c
#include <string.h>

char *T[3] = {"u1", "u2", "u3"};

int f(char *p) {
  int s=0, m=3, l=3, lm=6, r;

  while(1) {
    m = (s+l)/2;
    if (lm==m) {
      break;
    }
    r = strcmp(p, T[m]);
    if (r < 0) {
      l = m;
    } else if (r > 0) {
      s = m;
    } else {
      return 1;
    }
  }
  return 0;
}

int main() {
  if (!f("u3"))
    return 1;
  return 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>