<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55670>55670</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lldb] Inaccurate mapping between program location and memory address
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yangyibiao
      </td>
    </tr>
</table>

<pre>
    $ clang --version
```
Ubuntu clang version 15.0.0-++20220520091548+a61835b1e3f5-1~exp1~20220520091641.498
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
$ cat small.c
```
int v;

void foo (char *p, char *q)
{
  v = p > q;
}

int main ()
{
  char *heap1 = (char *)__builtin_malloc(42);
  char *heap2 = (char *)__builtin_malloc(42);

  foo (heap1, heap2);
  __builtin_free(heap1); __builtin_free(heap2);

  return 0;
}
```
$ clang -g -O1 small.c; lldb a.out
```
(lldb) target create "a.out"
Current executable set to '/root/a.out' (x86_64).
(lldb) b 11
Breakpoint 1: where = a.out`main + 17 at small.c:11:25, address = 0x00000000000006b1
(lldb) r
Process 7693 launched: '/root/a.out' (x86_64)
Process 7693 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00005555555546b1 a.out`main at small.c:11:25
   8    int main ()
   9    {
   10     char *heap1 = (char *)__builtin_malloc(42);
-> 11          char *heap2 = (char *)__builtin_malloc(42);
   12   
   13     foo (heap1, heap2);
   14     __builtin_free(heap1); __builtin_free(heap2);
(lldb) s
Process 7693 stopped
* thread #1, name = 'a.out', stop reason = step in
    frame #0: 0x00005555555546be a.out`main at small.c:13:3
   10     char *heap1 = (char *)__builtin_malloc(42);
   11     char *heap2 = (char *)__builtin_malloc(42);
   12   
-> 13          foo (heap1, heap2);
   14     __builtin_free(heap1); __builtin_free(heap2);
   15   
   16     return 0;
(lldb) s
Process 7693 stopped
* thread #1, name = 'a.out', stop reason = step in
    frame #0: 0x00005555555546be a.out`main [inlined] foo(p="", q="") at small.c:5:9
   2    
   3    void foo (char *p, char *q)
   4    {
-> 5           v = p > q;
   6    }
   7    
   8    int main ()
(lldb)
```

We can find that:

1.  ``small.c:5:9`` and ``small.c:13:3`` both mapped to the address ``0x00005555555546be``.

$ clang -g -O1 small.c; lldb a.out
```
(lldb) target create "a.out"
Current executable set to '/root/a.out' (x86_64).
(lldb) b 11
Breakpoint 1: where = a.out`main + 17 at small.c:11:25, address = 0x00000000000006b1
(lldb) run
Process 7750 launched: '/root/a.out' (x86_64)
Process 7750 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00005555555546b1 a.out`main at small.c:11:25
   8    int main ()
   9    {
   10     char *heap1 = (char *)__builtin_malloc(42);
-> 11          char *heap2 = (char *)__builtin_malloc(42);
   12   
   13     foo (heap1, heap2);
   14     __builtin_free(heap1); __builtin_free(heap2);
(lldb) s
Process 7750 stopped
* thread #1, name = 'a.out', stop reason = step in
    frame #0: 0x00005555555546be a.out`main at small.c:13:3
   10     char *heap1 = (char *)__builtin_malloc(42);
   11     char *heap2 = (char *)__builtin_malloc(42);
   12   
-> 13          foo (heap1, heap2);
   14     __builtin_free(heap1); __builtin_free(heap2);
   15   
   16     return 0;
(lldb) si
Process 7750 stopped
* thread #1, name = 'a.out', stop reason = instruction step into
    frame #0: 0x00005555555546c0 a.out`main [inlined] foo(p="", q="") at small.c:5:9
   2    
   3    void foo (char *p, char *q)
   4    {
-> 5           v = p > q;
   6    }
   7    
   8    int main ()
(lldb) 
```
At this time, we can find that:

1. ``small.c:13:3`` is mapped to ``0x00005555555546be``.
2. ``small.c:5:9`` is mapped to the address ``0x00005555555546c0``. 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWEtv4zgM_jXORYghye9DDmkzBeY0c9jFHgvZVmLtOrZHktv03y8pK02aetvOo1gM0MCxY5H8SJGfJCJlXz-sA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