[PATCH] D93497: Salvage debug info for function arguments in coro-split funclets.

Yifeng Dong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 28 02:43:23 PST 2020


dongAxis1944 added a comment.

I think the patch might occur an error when compilling the following code (commit id of clang is 9d70dbdc2bf294abffd4b2c9ae524055f72d017a <https://reviews.llvm.org/rG9d70dbdc2bf294abffd4b2c9ae524055f72d017a>).

  // clang++ -fcoroutines-ts  -std=c++2a coro-debug-1.cpp  -O0 -g -o e2.out
  struct test {
      int i;
      int j;
      double k;
  };
  
  struct coro {
    ...
  };
  
  coro foo(struct test & t) {
    int i = 0;
    int j = 0;
    i = t.i + t.j + t.k;
    printf("%d\n", i);
  
    co_await suspend_always();
    printf("%d, %d, %d\n", i, j, t.i); // --> A
  
    co_await suspend_always();
    ++i;
    ++j;
    printf("%d, %d, %d\n", j, i, t.k); 
  
    co_await suspend_always();
    printf("%d \n", j);
  }
  
  int main(int argc, char *argv[]) {
    struct test t = {0xee,0xff, 1.0};
    auto c = foo(t);
    c.handle.resume();
    c.handle.resume();
    c.handle.resume();
  }

when compiling finished, I use the debugger to load the elf and print variable named t:
lldb (commit id is 9d70dbdc2bf294abffd4b2c9ae524055f72d017a <https://reviews.llvm.org/rG9d70dbdc2bf294abffd4b2c9ae524055f72d017a>) prints:

  Process 106638 stopped
  * thread #1, name = 'a.out', stop reason = breakpoint 1.2
      frame #0: 0x0000000000401bd0 a.out`foo(t=0x0000000000000000) at coro-debug-1.cpp:39:26
     36     //   (int) i = 1
     37
     38     co_await suspend_always();
  -> 39     printf("%d, %d, %d\n", i, j, t.i); // 2, 1
                                   ^
     40     // Breakpoint 2:
     41     //   (lldb) frame variable i
     42     //   (int) i = <variable not available>
  (lldb) p t
  error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory: 0

According to the output of lldb, i think it might be wrong when lldb read dwarf,
so I download the dwarf info of this elf:

   cpp
  0x00002319:   DW_TAG_subprogram
                  DW_AT_low_pc    (0x0000000000401e90)
                  DW_AT_high_pc   (0x0000000000402490)
                  DW_AT_frame_base        (DW_OP_reg6 RBP)
                  DW_AT_linkage_name      ("_Z3fooR4test")
                  DW_AT_name      ("foo")
                  DW_AT_decl_file ("/disk1/yifeng.dongyifeng/debug_coro/debug/debug1/coro-debug-1.cpp")
                  DW_AT_decl_line (29)
                  DW_AT_type      (0x00000106 "coro")
                  DW_AT_external  (true)
  
  0x00002336:     DW_TAG_formal_parameter
                    DW_AT_location        (DW_OP_fbreg -128)
                    DW_AT_name    ("t")
                    DW_AT_decl_file       ("/disk1/yifeng.dongyifeng/debug_coro/debug/debug1/coro-debug-1.cpp")
                    DW_AT_decl_line       (29)
                    DW_AT_type    (0x00002442 "test&")
  
  ...
  
  0x00002355:     DW_TAG_variable
                    DW_AT_location        (DW_OP_fbreg -8, DW_OP_deref, DW_OP_deref, DW_OP_plus_uconst 0x18)
                    DW_AT_name    ("t")
                    DW_AT_type    (0x00002442 "test&")
                    DW_AT_artificial      (true)
  
  ...

There are two variables named t in the same scope (named DW_TAG_subprogram), 
and the patch just change the location list of the second one (because it attached to an alloc ), but not the first one.
When lldb wants to print variable t, it will get the first t, but unluckily it is not right.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93497/new/

https://reviews.llvm.org/D93497



More information about the llvm-commits mailing list