Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

The LLDB DWARF parser parses incorrectly DW_AT_const_value when the DIE has no location #46226

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR47257
Status CONFIRMED
Importance P normal
Reported by Luca Massarelli (massarelli@diag.uniroma1.it)
Reported on 2020-08-20 10:27:54 -0700
Last modified on 2020-08-24 02:38:44 -0700
Version unspecified
Hardware All All
CC ditaliano@apple.com, jdevlieghere@apple.com, keith.walker@arm.com, labath@google.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com, vsk@apple.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Error message from lldb when printing variable l_125 at line 11 or 12.

$ cat -n a.c
     1  int a, b;
     2  int *c = &b, *d;
     3  int **g_122 = &c;
     4  void func_11() {
     5    int e = a;
     6    int *f = &e;
     7    int **l_120 = &f;
     8    int *g = l_120;
     9    {
    10      int *l_125 = 0;
    11      d = &g;
    12      (**g_122) = ((**l_120) = l_125);
    13    }
    14  }
    15  int main() { func_11(); }

$ cat a.c
int a, b;
int *c = &b, *d;
int **g_122 = &c;
void func_11() {
  int e = a;
  int *f = &e;
  int **l_120 = &f;
  int *g = l_120;
  {
    int *l_125 = 0;
    d = &g;
    (**g_122) = ((**l_120) = l_125);
  }
}
int main() { func_11(); }

$ clang -v
clang version 12.0.0 (https://github.com/llvm/llvm-project.git
bc8be3054067ac822fc6d9f4f8e64c841f530f16)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

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

$ lldb opt
lldb) target create "opt"
Current executable set to '/home/stepping/output/opt' (x86_64).
(lldb) b -l 11
Breakpoint 1: where = opt`func_11 + 35 at a.c:11:7, address = 0x00000000004004a3
(lldb) r
Process 138 launched: '/home/stepping/output/opt' (x86_64)
Process 138 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x00000000004004a3 opt`func_11 at a.c:11:7
   8      int *g = l_120;
   9      {
   10       int *l_125 = 0;
-> 11       d = &g;
   12       (**g_122) = ((**l_120) = l_125);
   13     }
   14   }
(lldb) p l_125
error: <lldb wrapper prefix>:43:31: no member named 'l_125' in namespace
'$__lldb_local_vars'
    using $__lldb_local_vars::l_125;
          ~~~~~~~~~~~~~~~~~~~~^
error: <user expression 0>:1:1: use of undeclared identifier 'l_125'
l_125
^
(lldb) s
Process 195 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x00000000004004aa opt`func_11 at a.c:12:28
   9      {
   10       int *l_125 = 0;
   11       d = &g;
-> 12       (**g_122) = ((**l_120) = l_125);
   13     }
   14   }
   15   int main() { func_11(); }
(lldb) p l_125
error: <lldb wrapper prefix>:43:31: no member named 'l_125' in namespace
'$__lldb_local_vars'
    using $__lldb_local_vars::l_125;
          ~~~~~~~~~~~~~~~~~~~~^
error: <user expression 0>:1:1: use of undeclared identifier 'l_125'
l_125
Quuxplusone commented 4 years ago

Reproduced & confirmed.

Quuxplusone commented 4 years ago
(lldb) frame var l_125
(int *) l_125 = <empty constant data>

^ this is interesting.
Quuxplusone commented 4 years ago
It comes from lldb.

  if (variable->GetLocationIsConstantValueData()) {
    // expr doesn't contain DWARF bytes, it contains the constant variable
    // value bytes themselves...
    if (expr.GetExpressionData(m_data))
      m_value.SetContext(Value::eContextTypeVariable, variable);
    else
      m_error.SetErrorString("empty constant data");
    // constant bytes can't be edited - sorry
    m_resolved_value.SetContext(Value::eContextTypeInvalid, nullptr);
  } else {
Quuxplusone commented 4 years ago
The DWARF is correct.

0x00000106:       DW_TAG_variable
                    DW_AT_const_value   (0)
                    DW_AT_name  ("l_125")
                    DW_AT_decl_file     ("/Users/davide/work/build/bin/a.c")
                    DW_AT_decl_line     (10)
                    DW_AT_type  (0x00000043 "int*")

This is a bug in the DWARF parser in lldb, likely.
Quuxplusone commented 4 years ago
Looks like GetExpressionData returns false:

   211    bool GetExpressionData(DataExtractor &data) const {
-> 212      data = m_data;
   213      return data.GetByteSize() > 0;
   214    }
   215
Target 0: (lldb) stopped.
(lldb) p m_data
(lldb_private::DataExtractor) $2 = {
  m_start = 0x0000000000000000
  m_end = 0x0000000000000000
  m_byte_order = eByteOrderLittle
  m_addr_size = 8
  m_data_sp = nullptr {
    __ptr_ = 0x0000000000000000
  }
  m_target_byte_size = 1
}
Quuxplusone commented 4 years ago

I've been doing some const_value work these days. I'll take a look at this too.

Quuxplusone commented 4 years ago

Bug caused by a typo. Fix is in D86436.