<body><table border="1" cellspacing="0" cellpadding="8">
title="NEW - Wrong handling of DW_OP_deref with global variables"
<td>Wrong handling of DW_OP_deref with global variables
<pre>Created <span class=""><a href="attachment.cgi?id=20106" name="attach_20106" title="Reduced test-case">attachment 20106</a> <a href="attachment.cgi?id=20106&action=edit" title="Reduced test-case">[details]</a></span>
I'm trying to achieve the following:
- I have a global variable BaseAddress that holds the base address of
a contiguous dynamically allocated memory block.
- I have a number of logical variables of different types that are
mapped on certain address ranges inside the memory block pointed to by
BaseAddress. The offset and the size of each such logical variable
inside the memory block are known constants.
- I'd like to make it possible to access these logical variables
inside the debugger as if they are normal global variables.
My idea was to create the debug information for each of these logical
variables by using DIBuilder::createGlobalVariableExpression called
GVE and provide a DIExpression called DIE that should basically take
the value of the global variable GVE is added to, i.e. the value of
BaseAddress, and add a constant offset corresponding to the logical
variable. This should be the address of the logical variable.
So, the DIExpression DIE would look something like:
DW_OP_deref, DW_OP_constu, offset, DW_OP_plus
But this does not work. I tried the variants with and without
DW_OP_deref, but I always get the same wrong result when I test with
LLDB. The offset is always added to the address of BaseAddress and not
to its value.
The code for creating logical variables looks roughly like:
llvm::SmallVector<uint64_t, 4> ops;
size_t offset = getOffset(logicalVariable);
// Get the value of the global variable that contains a pointer to
the memory block.
// NOTE: Even if DW_OP_deref is omitted, the results under LLDB
are the same.
// Add a constant offset to the value of the global variable.
auto *DIE = DIBuilder_->createExpression(ops);
auto *GVE = DIBuilder_->createGlobalVariableExpression(
cu, name, "", file, 0, type,
/* isLocalToUnit */ false, DIE);
// Add GVE as debug info to BaseAddress.
GDB does not have the issue. So, it seems like a bug in LLDB.
See the following thread for a discussion of the issue:
The attached lldb_bug.ll file contains a reduced example. It has a global
variable "baseAddress", which contains a pointer to a memory block. And it
defines a logical global variable "var1" by means of debug information, which
should be at address (value of (baseAddress) + 0).
I used the following commands to produce the executable:
llvm-as lldb_bug.ll -f
llc -filetype=obj lldb_bug.bc
clang lldb_bug.o -o lldb_bug
Then you simply start LLDB with lldb_bug as executable.
If you then try this command:
you'll see something different from the expected 0.
Most likely, the problem is that DW_OP_deref is not handled correctly when
applied to global variables or something like this.</pre>
<span>You are receiving this mail because:</span>
<li>You are the assignee for the bug.</li>