[llvm] [ADT] Add standalone_debug attribute to SmallVectorBase (PR #82527)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 13:27:40 PST 2024


arichardson wrote:

> I think it's worth debugging this a bit further first. Can you elaborate on the platform and tools you are using where the issue occurs?
> 
> I think the issue may be that `SmallVectorBase` has explicit template instantiations:
> 
> * declaration: https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/SmallVector.h#L1330
> * definition: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/SmallVector.cpp#L159
> 
> This will cause clang to only emit debug info for `SmallVectorBase<uint(32|64)_t>` in `SmallVector.cpp`.
> 
> In your build, can you confirm that the LLVM support library is compiled with debug info, and that your debugger can find it? If not, I think the solution would be to address that.


I am using LLDB bundled with CLion, `lldb version 17.0.6 (LLVM; JetBrains IDE bundle; build 262)` and it can find debug info for other LLVMSupport types. The LLVMSupport.so file includes the expected debug info sections as well and `objdump -g` on that file has quite a few references to SmallVectorBase<unsigned int>.

LLVM is built with the following flags using clang 16:
```
-G Ninja
-DCMAKE_BUILD_TYPE=Debug
-DLLVM_CCACHE_BUILD=TRUE
-DLLVM_ENABLE_LLD=TRUE
-DLLVM_OPTIMIZED_TABLEGEN=TRUE
-DLLVM_USE_SPLIT_DWARF=TRUE
-DLLVM_ENABLE_ASSERTIONS=TRUE
-DLLVM_LIT_ARGS="--max-time 3600 --timeout 300 -s -vv"
-DCMAKE_INSTALL_PREFIX=/some/invalid/path
-DCMAKE_C_COMPILER=/usr/bin/clang
-DCMAKE_CXX_COMPILER=/usr/bin/clang++
-DCMAKE_ASM_COMPILER=/usr/bin/clang
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
-DLLVM_ENABLE_IDE=ON
-DLLVM_ENABLE_EXPENSIVE_CHECKS=TRUE
-DLLVM_CCACHE_BUILD=TRUE
-DBUILD_SHARED_LIBS=ON
```

It's possible that this is caused by `-DBUILD_SHARED_LIBS=ON` combined with `-DLLVM_USE_SPLIT_DWARF=TRUE`

If I print a non-empty SmallVector<StringRef> I get the following output from `print(self.valobj)` inside the pretty printer:
```
(llvm::SmallVector<llvm::StringRef, 4>) HelperStaticRuntimes = size=0 {
  llvm::SmallVectorImpl<llvm::StringRef> = size=0 {
    llvm::SmallVectorTemplateBase<llvm::StringRef, true> = {
      llvm::SmallVectorTemplateCommon<llvm::StringRef, void> = (llvm::SmallVectorBase<unsigned int> = <incomplete type>)
    }
  }
  llvm::SmallVectorStorage<llvm::StringRef, 4> = (InlineElts = "\U00000010\x88\x8d\x9a\U00000012\U0000007f\0\0\v\0\0\0\0\0\0\0\xf5\U00000013:<\xfc\U0000007f\0\0\b\U00000014:<\xfc\U0000007f\0\0\0\0\xff\0\0\0\0\0\xff\0\0\0\xff\0\0\0\0\0\xff")
}
(llvm::SmallVector<llvm::StringRef, 4>) size=0 {}
```

It could be related to the split dwarf, since I do see some SmallVectorBase<unsigned int> DWARF. 
```
0x00004048:     DW_TAG_class_type
                  DW_AT_name    ("SmallVectorImpl<char>")
                  DW_AT_declaration     (true)

0x0000404b:     DW_TAG_class_type
                  DW_AT_calling_convention      (DW_CC_pass_by_value)
                  DW_AT_name    ("SmallVectorBase<unsigned int>")
                  DW_AT_byte_size       (0x10)
                  DW_AT_decl_file       (0x01)
                  DW_AT_decl_line       (1330)

0x00004053:       DW_TAG_template_type_parameter
                    DW_AT_type  (0x00004495 "unsigned int")
                    DW_AT_name  ("Size_T")

0x0000405a:       DW_TAG_member
                    DW_AT_name  ("BeginX")
                    DW_AT_type  (0x000045b2 "void *")
                    DW_AT_decl_file     (0x01)
                    DW_AT_decl_line     (54)
                    DW_AT_data_member_location  (0x00)
                    DW_AT_accessibility (DW_ACCESS_protected)

0x00004065:       DW_TAG_member
                    DW_AT_name  ("Size")
                    DW_AT_type  (0x00004495 "unsigned int")
                    DW_AT_decl_file     (0x01)
                    DW_AT_decl_line     (55)
                    DW_AT_data_member_location  (0x08)
                    DW_AT_accessibility (DW_ACCESS_protected)

0x00004070:       DW_TAG_member
                    DW_AT_name  ("Capacity")
                    DW_AT_type  (0x00004495 "unsigned int")
                    DW_AT_decl_file     (0x01)
                    DW_AT_decl_line     (55)
                    DW_AT_data_member_location  (0x0c)
                    DW_AT_accessibility (DW_ACCESS_protected)


```

I will try to compile without split DWARF and see if the same problem persists.


https://github.com/llvm/llvm-project/pull/82527


More information about the llvm-commits mailing list