<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62835>62835</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
lldb points to the wrong address of codes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
NeumoNeumo
</td>
</tr>
</table>
<pre>
# Description
When using `lldb` to debug an operating system running on `qemu-system-i386`, I find that the current running code lldb pointed to is incorrect. The correct address should be determined by \$cs:\$ip (\$cs * 0x10 + \$ip) in real mode. But `lldb` only considered the value of \$ip.
For example, if `eip = 0x0000e05b` and `cs = 0x0000f000`, the it should point to `0x000fe05b` However, lldb only considered cs and pointed to `0xe05b`.
# Reproduction
```bash
# In one terminal, we start a qemu debug server hosted on localhost:1234 by default.
git clone --depth 1 https://github.com/NeumoNeumo/Linux-0.11
cd Linux-0.11
make
make debug
# Then, in another one, we connect to the debug server with `lldb`
lldb
(lldb) gdb-remote 1234
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
frame #0: 0x0000fff0
-> 0xfff0: addb %al, (%eax)
0xfff2: addb %al, (%eax)
0xfff4: addb %al, (%eax)
0xfff6: addb %al, (%eax)
(lldb) n
Process 1 stopped
* thread #1, stop reason = instruction step over
frame #0: 0x0000e05b
-> 0xe05b: addb %al, (%eax)
0xe05d: addb %al, (%eax)
0xe05f: addb %al, (%eax)
0xe061: addb %al, (%eax)
(lldb) reg read
general:
eax = 0x00000000
ecx = 0x00000000
edx = 0x00000663
ebx = 0x00000000
esp = 0x00000000
ebp = 0x00000000
esi = 0x00000000
edi = 0x00000000
eip = 0x0000e05b
eflags = 0x00000002
cs = 0x0000f000
...
...
```
**Note that `eip = 0x0000e05b` and `cs = 0x0000f000`. However, lldb only considered cs and pointed to `0xe05b`.**
# Environment
1. lldb version 16.0.4
2. OS
```txt
OS: Ubuntu 22.04.2 LTS x86_64
Host: Inspiron 5409
Kernel: 5.19.0-41-generic
Uptime: 20 days, 5 hours, 41 mins
Packages: 2687 (dpkg)
Shell: fish 3.3.1
Resolution: 1920x1080
DE: GNOME 42.5
WM: Mutter
WM Theme: Adwaita
Theme: Yaru-dark [GTK2/3]
Icons: Yaru [GTK2/3]
Terminal: tmux
CPU: 11th Gen Intel i5-1135G7 (8) @ 4.200GHz
GPU: Intel TigerLake-LP GT2 [Iris Xe Graphics]
Memory: 7376MiB / 15728MiB
```
3. qemu-system-i386 --version
```txt
QEMU emulator version 6.2.0 (Debian 1:6.2+dfsg-2ubuntu6.8)
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykV0tz2zgS_jXwpYssEHyIOuggx5bimjjxxk7N7mkLJJok1iTABUBb3l-_BZCSHzNOjScul0SiH2h8_XWjxa2VrULckPyc5BdnfHKdNpuvOA06fJxVWjxtCEvhAm1t5OikVoReELr9vUMFk5WqBVLQvhcVKSg4DQKrqQWuQI9ouPMK9sk6HMBMSvlXrbzJf3GYolkSybQsSEEJ-wRX0EglwHXcgesQ6skYVO5kXGuB4LeDUUvlUPg9pQWpam0M1i6GO282vwAXwqC1YDs99QIqBIEOzSAVCqiegOSfCMtqS9Lt_ChHIKw8LgNhW6CHhAJh53DUIGwNUoFB3sOgBcZwPrmXMGjVP0GtlZUCjQ-xQ3jg_YSgm5OXeAZy_txpA3jgw9ijR0E23h36YNILoAdKKUWaB-dcCS_0wZ1kDaV0AdDvJd3xwAEkDxEpaFBtjm4-60d8QONNApxvY65t2OkFysHFYv4qeE-Q7zgaLab6mSE-nvBfcds9K14p0AphTgLv_f6PCNZx44CDZ8VCIYvmAQ102vr9tYJe17z3ryTdJizNfP4ENnzq3RJOKx3UvXcfRQJH10ECnXNjSC_bEbZrpeumKq71QNjumeiE7b5INR0iGifJ7KsW8HZp4Pf4_DSH-RaHuw5VyKACrrTr0PjjLqestVKelU6HNL0656N03QsO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