Issue |
152504
|
Summary |
GetTemplateArgumentType from std::unordered_map allocator returns "No value"
|
Labels |
|
Assignees |
|
Reporter |
bea231
|
Hello, I'm trying to write my own variable printer for `std::unordered_map` for debugging GCC compiled program under LLDB (because the standard one always shows `size=0`). I've found an [example](https://github.com/llvm/llvm-project/commit/fcd288b52aa708e061ad633c8efa1183a7e6b926#diff-7edac4d10a9ab393c8232bb22b656cc8608e973b508a24e349a249dd06df4846R16) in the repository and but it seems like its `self.count` is always `None`.
I tried to set up some debug printing in the `extract_type` and got the following:
```python
def extract_type(self):
type = self.valobj.GetType()
template_arg_num = 4 if self.kind == "map" else 3
allocator_type = type.GetTemplateArgumentType(template_arg_num)
data_type = allocator_type.GetTemplateArgumentType(0)
print("allocator_type:", allocator_type) # Debug output
print("data_type:", data_type) # Debug output
print("allocator_type arguments count:", allocator_type.GetNumberOfTemplateArguments()) # Debug output
return data_type
```
It successfully fetches the `allocator_type` as:
```
(lldb) p someMap
allocator_type: class allocator<std::pair<char const, long unsigned int> > : public std::__new_allocator<std::pair<const char, unsigned long> > {
template <class _Tp1> struct rebind;
template<> struct rebind<std::__detail::_Hash_node<std::pair<const char, unsigned long>, false>> {
typedef std::allocator<std::__detail::_Hash_node<std::pair<char const, long unsigned int>, false> > other;
};
public:
void allocator();
void allocator(const std::allocator<std::pair<char const, long unsigned int> > &);
std::allocator<std::pair<char const, long unsigned int> > &operator=(const std::allocator<std::pair<char const, long unsigned int> > &);
~allocator<std::pair<char const, long unsigned int> >();
}
data_type: No value
allocator_type arguments count: 0
```
But `allocator_type.GetNumberOfTemplateArguments()` always returns 0 and `data_type` is "No value".
Here are some details to reproduce the issue:
<details>
<summary>Code to reproduce</summary>
### LLDB version
```bash
❯ lldb --version
lldb version 19.1.7
```
### GCC version
```bash
❯ g++ --version
g++ (GCC) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
### C++ code
```cpp
#include <bits/stdc++.h>
int main() {
std::unordered_map<char, size_t> someMap;
someMap.emplace('a', 2);
std::cout << someMap.size() << std::endl;
return 0;
}
```
### Compilation command
```bash
g++ -g -O0 main.cpp
LLDB_DEBUGSERVER_PATH=/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver lldb a.out
```
### OS and env
MacBook Air M1, 16GB, MacOS Sequoia Version 15.6 (24G84)
</details>
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs