[Lldb-commits] [PATCH] D53530: Fix (and improve) the support for C99 variable length array types

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 22 14:40:24 PDT 2018


aprantl created this revision.
aprantl added reviewers: jingham, clayborg.
aprantl added a project: LLDB.
Herald added a subscriber: JDevlieghere.

Clang recently improved its DWARF support for C VLA types. The DWARF now looks like this:

  0x00000051:         DW_TAG_variable [4]  
                       DW_AT_location( fbreg -32 )
                       DW_AT_name( "__vla_expr" )
                       DW_AT_type( {0x000000d3} ( long unsigned int ) )
                       DW_AT_artificial( true )
  ...
  0x000000da:     DW_TAG_array_type [10] *
                   DW_AT_type( {0x000000cc} ( int ) )
  
  0x000000df:         DW_TAG_subrange_type [11]  
                       DW_AT_type( {0x000000e9} ( __ARRAY_SIZE_TYPE__ ) )
                       DW_AT_count( {0x00000051} )

Without this patch LLDB will naively interpret the DIE offset 0x51 as the static size of the array, which is clearly wrong.
This patch uses LLDB's dynamic type mechanism to re-parse VLA types with an optional execution context, to dynamically resolve the size of the array correctly. These dynamic types are not being cached, since they are only valid in a single execution context.

See the testcase for an example:

     4          int foo(int a) {
     5             int vla[a];
     6   	  for (int i = 0; i < a; ++i)
     7   	    vla[i] = i;
     8   	
  -> 9   	  pause(); // break here
     10  	  return vla[a-1];
     11  	}
     12  	
  
  (lldb) fr v vla
  (int [4]) vla = ([0] = 0, [1] = 1, [2] = 2, [3] = 3)
  (lldb) quit


https://reviews.llvm.org/D53530

Files:
  include/lldb/Symbol/SymbolFile.h
  include/lldb/Symbol/Variable.h
  packages/Python/lldbsuite/test/lang/c/vla/Makefile
  packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py
  packages/Python/lldbsuite/test/lang/c/vla/main.c
  source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
  source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
  source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
  source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
  source/Symbol/ClangASTContext.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53530.170496.patch
Type: text/x-patch
Size: 30758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181022/562ecf35/attachment-0001.bin>


More information about the lldb-commits mailing list