llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.03k stars 11.58k forks source link

Wrong line information during debug at Og #57840

Open ycwan9 opened 2 years ago

ycwan9 commented 2 years ago

When compiled with -Og, after function e finishes, LLDB remains at line 9 in the next step, while displayes function main as the current top frame. This behavior is not present in GDB.

Source program:

$ cat a.c
#include <stdint.h>
volatile uint32_t a,  c;
uint16_t b[][1] = {1, 1, 1, 1, 1, 1};
int8_t d[1][5][9]
 ;
uint8_t e(void) {
  uint8_t f = b[5][0];
  int g =  c;
  d[0][4][7] =
      g >= 8 ? f : f >> g;
  return 0
; }
int main(void) {
  int i;
  e();
  for (i = 0; i < 8; i++)
    a = i;
}
$ clang --version
clang version 16.0.0 (https://github.com/llvm/llvm-project.git c63e05dc0776b4a0a75685ba8a8d7667e0dbaee3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /scratch/software/clang-trunk/bin

$ lldb --version
lldb version 16.0.0git (https://github.com/llvm/llvm-project.git revision c63e05dc0776b4a0a75685ba8a8d7667e0dbaee3)
  clang revision c63e05dc0776b4a0a75685ba8a8d7667e0dbaee3
  llvm revision c63e05dc0776b4a0a75685ba8a8d7667e0dbaee3

$ gdb -v
GNU gdb (GDB) 13.0.50.20220831-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Compile flags:

$ clang -Og -g -o a.elf a.c

LLDB trace:

$ lldb a.elf
(lldb) target create "a.elf"
Current executable set to '/scratch/ycwang/vio-work/a.elf' (x86_64).
(lldb) b main
Breakpoint 1: where = a.elf`main [inlined] e at a.c:10:7, address = 0x0000000000001150
(lldb) r
Process 3376730 launched: '/scratch/ycwang/vio-work/a.elf' (x86_64)
Process 3376730 stopped
* thread #1, name = 'a.elf', stop reason = breakpoint 1.1
    frame #0: 0x0000555555555150 a.elf`main [inlined] e at a.c:10:7
   7      uint8_t f = b[5][0];
   8      int g =  c;
   9      d[0][4][7] =
-> 10         g >= 8 ? f : f >> g;
   11     return 0
   12   ; }
   13   int main(void) {
(lldb) s
Process 3376730 stopped
* thread #1, name = 'a.elf', stop reason = step in
    frame #0: 0x0000555555555157 a.elf`main [inlined] e at a.c:8:12
   5     ;
   6    uint8_t e(void) {
   7      uint8_t f = b[5][0];
-> 8      int g =  c;
   9      d[0][4][7] =
   10         g >= 8 ? f : f >> g;
   11     return 0
(lldb) s
Process 3376730 stopped
* thread #1, name = 'a.elf', stop reason = step in
    frame #0: 0x000055555555515f a.elf`main [inlined] e at a.c:10:9
   7      uint8_t f = b[5][0];
   8      int g =  c;
   9      d[0][4][7] =
-> 10         g >= 8 ? f : f >> g;
   11     return 0
   12   ; }
   13   int main(void) {
(lldb) s
Process 3376730 stopped
* thread #1, name = 'a.elf', stop reason = step in
    frame #0: 0x0000555555555167 a.elf`main [inlined] e at a.c:9:14
   6    uint8_t e(void) {
   7      uint8_t f = b[5][0];
   8      int g =  c;
-> 9      d[0][4][7] =
   10         g >= 8 ? f : f >> g;
   11     return 0
   12   ; }
(lldb) s
Process 3376730 stopped
* thread #1, name = 'a.elf', stop reason = step in
    frame #0: 0x000055555555516d a.elf`main at a.c:9:14
   6    uint8_t e(void) {
   7      uint8_t f = b[5][0];
   8      int g =  c;
-> 9      d[0][4][7] =
   10         g >= 8 ? f : f >> g;
   11     return 0
   12   ; }
(lldb) bt
* thread #1, name = 'a.elf', stop reason = step in
  * frame #0: 0x000055555555516d a.elf`main at a.c:9:14
    frame #1: 0x00007ffff7de80b3 libc.so.6`__libc_start_main + 243
    frame #2: 0x000055555555506e a.elf`_start + 46
(lldb) frame var
(int) i = 0

GDB trace:

$ gdb a.elf
GNU gdb (GDB) 13.0.50.20220831-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.elf...
(gdb) start
Temporary breakpoint 1 at 0x1150: file a.c, line 10.
Starting program: /scratch/ycwang/vio-work/a.elf 

Temporary breakpoint 1, main () at a.c:15
15    e();
(gdb) s
e () at a.c:10
10        g >= 8 ? f : f >> g;
(gdb) s
8     int g =  c;
(gdb) s
10        g >= 8 ? f : f >> g;
(gdb) s
9     d[0][4][7] =
(gdb) bt
#0  e () at a.c:9
#1  main () at a.c:15
(gdb) info locals
f = <optimized out>
g = <optimized out>
(gdb) s
main () at a.c:17
17      a = i;
(gdb) bt
#0  main () at a.c:17
(gdb) info locals
i = 0
llvmbot commented 2 years ago

@llvm/issue-subscribers-debuginfo

varunkumare99 commented 1 year ago

is this still open to work on ?

llvmbot commented 1 year ago

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

1) Assign the issue to you. 2) Fix the issue locally. 3) Run the test suite locally. 3.1) Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests. 4) Create a git commit 5) Run git clang-format HEAD~1 to format your changes. 6) Submit the patch to Phabricator. 6.1) Detailed instructions can be found here

For more instructions on how to submit a patch to LLVM, see our documentation.

If you have any further questions about this issue, don't hesitate to ask via a comment on this Github issue.

@llvm/issue-subscribers-good-first-issue

robincaloudis commented 6 months ago

Is this issue already fixed? Under clang and lldm version 17.0.6, I was not able to reproduce this issue. Instead of displaying the function main as the top frame at line 9, lldb in the meantime displays the inlined function e explicitly.

LLDB trace:

➜  lldb-error git:(master) ✗ clang -Og -g -o a.elf a.c
➜  lldb-error git:(master) ✗ lldb a.elf
(lldb) target create "a.elf"
Current executable set to '/Users/robincaloudis/lldb-error/a.elf' (arm64).
(lldb) b main
Breakpoint 1: where = a.elf`main + 4 [inlined] e at a.c:7:15, address = 0x0000000100003f78
(lldb) r
Process 55952 launched: '/Users/robincaloudis/lldb-error/a.elf' (arm64)
Process 55952 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f78 a.elf`main [inlined] e at a.c:7:15 [opt]
   4    int8_t d[1][5][9]
   5     ;
   6    uint8_t e(void) {
-> 7      uint8_t f = b[5][0];
   8      int g =  c;
   9      d[0][4][7] =
   10         g >= 8 ? f : f >> g;
warning: a.elf was compiled with optimization - stepping may behave oddly; variables may not be available.
(lldb) s
Process 55952 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x0000000100003f7c a.elf`main [inlined] e at a.c:10:7 [opt]
   7      uint8_t f = b[5][0];
   8      int g =  c;
   9      d[0][4][7] =
-> 10         g >= 8 ? f : f >> g;
   11     return 0
   12   ; }
   13   int main(void) {
(lldb) s
Process 55952 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x0000000100003f80 a.elf`main [inlined] e at a.c:8:12 [opt]
   5     ;
   6    uint8_t e(void) {
   7      uint8_t f = b[5][0];
-> 8      int g =  c;
   9      d[0][4][7] =
   10         g >= 8 ? f : f >> g;
   11     return 0
(lldb) s
Process 55952 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x0000000100003f88 a.elf`main [inlined] e at a.c:10:7 [opt]
   7      uint8_t f = b[5][0];
   8      int g =  c;
   9      d[0][4][7] =
-> 10         g >= 8 ? f : f >> g;
   11     return 0
   12   ; }
   13   int main(void) {
(lldb) s
Process 55952 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x0000000100003f94 a.elf`main [inlined] e at a.c:9:14 [opt]
   6    uint8_t e(void) {
   7      uint8_t f = b[5][0];
   8      int g =  c;
-> 9      d[0][4][7] =
   10         g >= 8 ? f : f >> g;
   11     return 0
   12   ; }
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
  * frame #0: 0x0000000100003f94 a.elf`main [inlined] e at a.c:9:14 [opt]
    frame #1: 0x0000000100003f78 a.elf`main at a.c:15:3 [opt]
    frame #2: 0x0000000181403f28 dyld`start + 2236
(lldb) r
There is a running process, kill it and restart?: [Y/n] n
(lldb) s
Process 55952 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x0000000100003fa0 a.elf`main at a.c:17:7 [opt]
   14     int i;
   15     e();
   16     for (i = 0; i < 8; i++)
-> 17       a = i;
   18   }
(lldb) 

Versions:

➜  lldb-error git:(master) ✗ clang --version
Homebrew clang version 17.0.6
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
➜  lldb-error git:(master) ✗ lldb --version
lldb version 17.0.6