[Lldb-commits] [lldb] r247672 - Add support for DW_OP_GNU_const_index to dwarf expression

Tamas Berghammer via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 15 03:33:54 PDT 2015


Author: tberghammer
Date: Tue Sep 15 05:33:54 2015
New Revision: 247672

URL: http://llvm.org/viewvc/llvm-project?rev=247672&view=rev
Log:
Add support for DW_OP_GNU_const_index to dwarf expression

DW_OP_GNU_const_index is a new opcode used when split dwarf is enabled

Differential revision: http://reviews.llvm.org/D12849

Modified:
    lldb/trunk/include/lldb/Expression/DWARFExpression.h
    lldb/trunk/source/Expression/DWARFExpression.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFLocationDescription.cpp
    lldb/trunk/test/lang/c/const_variables/Makefile

Modified: lldb/trunk/include/lldb/Expression/DWARFExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/DWARFExpression.h?rev=247672&r1=247671&r2=247672&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/DWARFExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/DWARFExpression.h Tue Sep 15 05:33:54 2015
@@ -442,7 +442,7 @@ protected:
     DataExtractor m_data;                       ///< A data extractor capable of reading opcode bytes
     DWARFCompileUnit* m_dwarf_cu;               ///< The DWARF compile unit this expression belongs to. It is used
                                                 ///< to evaluate values indexing into the .debug_addr section (e.g.
-                                                ///< DW_OP_GNU_addr_index
+                                                ///< DW_OP_GNU_addr_index, DW_OP_GNU_const_index)
     lldb::RegisterKind m_reg_kind;              ///< One of the defines that starts with LLDB_REGKIND_
     lldb::addr_t m_loclist_slide;               ///< A value used to slide the location list offsets so that 
                                                 ///< they are relative to the object that owns the location list

Modified: lldb/trunk/source/Expression/DWARFExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/DWARFExpression.cpp?rev=247672&r1=247671&r2=247672&view=diff
==============================================================================
--- lldb/trunk/source/Expression/DWARFExpression.cpp (original)
+++ lldb/trunk/source/Expression/DWARFExpression.cpp Tue Sep 15 05:33:54 2015
@@ -199,6 +199,7 @@ DW_OP_value_to_name (uint32_t val)
     case 0x99: return "DW_OP_call4";
     case 0x9a: return "DW_OP_call_ref";
     case 0xfb: return "DW_OP_GNU_addr_index";
+    case 0xfc: return "DW_OP_GNU_const_index";
 //    case DW_OP_APPLE_array_ref: return "DW_OP_APPLE_array_ref";
 //    case DW_OP_APPLE_extern: return "DW_OP_APPLE_extern";
     case DW_OP_APPLE_uninit: return "DW_OP_APPLE_uninit";
@@ -637,6 +638,9 @@ DWARFExpression::DumpLocation (Stream *s
         case DW_OP_GNU_addr_index:                                          // 0xfb
             s->Printf("DW_OP_GNU_addr_index(0x%" PRIx64 ")", m_data.GetULEB128(&offset));
             break;
+        case DW_OP_GNU_const_index:                                         // 0xfc
+            s->Printf("DW_OP_GNU_const_index(0x%" PRIx64 ")", m_data.GetULEB128(&offset));
+            break;
         case DW_OP_GNU_push_tls_address:
             s->PutCString("DW_OP_GNU_push_tls_address");  // 0xe0
             break;
@@ -1040,9 +1044,10 @@ GetOpcodeDataSize (const DataExtractor &
         case DW_OP_regx:        // 0x90 1 ULEB128 register
         case DW_OP_fbreg:       // 0x91 1 SLEB128 offset
         case DW_OP_piece:       // 0x93 1 ULEB128 size of piece addressed
-        case DW_OP_GNU_addr_index: // 0xfb 1 ULEB128 index
+        case DW_OP_GNU_addr_index:  // 0xfb 1 ULEB128 index
+        case DW_OP_GNU_const_index: // 0xfc 1 ULEB128 index
             data.Skip_LEB128(&offset); 
-            return offset - data_offset;   
+            return offset - data_offset;
             
             // All opcodes that have a 2 ULEB (signed or unsigned) arguments
         case DW_OP_bregx:       // 0x92 2 ULEB128 register followed by SLEB128 offset
@@ -3022,7 +3027,7 @@ DWARFExpression::Evaluate
                 if (!dwarf_cu)
                 {
                     if (error_ptr)
-                        error_ptr->SetErrorString ("DW_OP_GNU_addr_index found without a compile being specified");
+                        error_ptr->SetErrorString ("DW_OP_GNU_addr_index found without a compile unit being specified");
                     return false;
                 }
                 uint64_t index = opcodes.GetULEB128(&offset);
@@ -3035,6 +3040,43 @@ DWARFExpression::Evaluate
             }
             break;
 
+        //----------------------------------------------------------------------
+        // OPCODE: DW_OP_GNU_const_index
+        // OPERANDS: 1
+        //      ULEB128: index to the .debug_addr section
+        // DESCRIPTION: Pushes an constant with the size of a machine address to
+        // the stack from the .debug_addr section with the base address specified
+        // by the DW_AT_addr_base attribute and the 0 based index is the ULEB128
+        // encoded index.
+        //----------------------------------------------------------------------
+        case DW_OP_GNU_const_index:
+            {
+                if (!dwarf_cu)
+                {
+                    if (error_ptr)
+                        error_ptr->SetErrorString ("DW_OP_GNU_const_index found without a compile unit being specified");
+                    return false;
+                }
+                uint64_t index = opcodes.GetULEB128(&offset);
+                uint32_t index_size = dwarf_cu->GetAddressByteSize();
+                dw_offset_t addr_base = dwarf_cu->GetAddrBase();
+                lldb::offset_t offset = addr_base + index * index_size;
+                const DWARFDataExtractor& debug_addr = dwarf_cu->GetSymbolFileDWARF()->get_debug_addr_data();
+                switch (index_size)
+                {
+                    case 4:
+                        stack.push_back(Scalar(debug_addr.GetU32(&offset)));
+                        break;
+                    case 8:
+                        stack.push_back(Scalar(debug_addr.GetU64(&offset)));
+                        break;
+                    default:
+                        assert(false && "Unhandled index size");
+                        return false;
+                }
+            }
+            break;
+
         default:
             if (log)
                 log->Printf("Unhandled opcode %s in DWARFExpression.", DW_OP_value_to_name(op));

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFLocationDescription.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFLocationDescription.cpp?rev=247672&r1=247671&r2=247672&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFLocationDescription.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFLocationDescription.cpp Tue Sep 15 05:33:54 2015
@@ -150,6 +150,7 @@ print_dwarf_exp_op (Stream &s,
         case DW_OP_regx:
             size = 128; break;
         case DW_OP_GNU_addr_index:
+        case DW_OP_GNU_const_index:
             size = 128; break;
         default:
             s.Printf("UNKNOWN ONE-OPERAND OPCODE, #%u", opcode);

Modified: lldb/trunk/test/lang/c/const_variables/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/const_variables/Makefile?rev=247672&r1=247671&r2=247672&view=diff
==============================================================================
--- lldb/trunk/test/lang/c/const_variables/Makefile (original)
+++ lldb/trunk/test/lang/c/const_variables/Makefile Tue Sep 15 05:33:54 2015
@@ -2,6 +2,6 @@ LEVEL = ../../../make
 
 C_SOURCES := main.c functions.c
 
-CFLAGS ?= -g -O3
+CFLAGS_EXTRAS += -O3
 
 include $(LEVEL)/Makefile.rules




More information about the lldb-commits mailing list