Skip to content

Commit 355cdcd

Browse files
committed
[LLDB] Avoid crashes when inspecting MS STL types
1 parent e08ec06 commit 355cdcd

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ lldb::ChildCacheState GenericOptionalFrontend::Update() {
7474

7575
if (m_stdlib == StdLib::LibCxx)
7676
engaged_sp = m_backend.GetChildMemberWithName("__engaged_");
77-
else if (m_stdlib == StdLib::LibStdcpp)
78-
engaged_sp = m_backend.GetChildMemberWithName("_M_payload")
79-
->GetChildMemberWithName("_M_engaged");
77+
else if (m_stdlib == StdLib::LibStdcpp) {
78+
if (ValueObjectSP payload = m_backend.GetChildMemberWithName("_M_payload"))
79+
engaged_sp = payload->GetChildMemberWithName("_M_engaged");
80+
}
8081

8182
if (!engaged_sp)
8283
return lldb::ChildCacheState::eRefetch;

lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ LibStdcppSharedPtrSyntheticFrontEnd::CalculateNumChildren() {
379379

380380
lldb::ValueObjectSP
381381
LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
382+
if (!m_ptr_obj)
383+
return nullptr;
384+
382385
if (idx == 0)
383386
return m_ptr_obj->GetSP();
384387
if (idx == 1) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// clang-format off
2+
3+
// REQUIRES: target-windows
4+
// RUN: %build --compiler=clang-cl -o %t.exe --std c++20 -- %s
5+
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -o "b main" -o "run" -o "fr v" -o c | FileCheck %s
6+
7+
#include <bitset>
8+
#include <coroutine>
9+
#include <deque>
10+
#include <forward_list>
11+
#include <list>
12+
#include <map>
13+
#include <memory>
14+
#include <optional>
15+
#include <set>
16+
#include <string>
17+
#include <tuple>
18+
#include <unordered_map>
19+
#include <unordered_set>
20+
#include <variant>
21+
#include <vector>
22+
23+
int main() {
24+
std::shared_ptr<int> foo;
25+
std::weak_ptr<int> weak = foo;
26+
std::unique_ptr<int> unique(new int(42));
27+
std::optional<int> opt;
28+
std::string str = "str";
29+
std::string longStr =
30+
"string that is long enough such that no SSO can happen";
31+
std::wstring wStr = L"wstr";
32+
std::wstring longWStr =
33+
L"string that is long enough such that no SSO can happen";
34+
std::tuple<int, bool, float> tuple{1, false, 4.2};
35+
std::coroutine_handle<> coroHandle;
36+
std::bitset<16> bitset(123);
37+
38+
std::map<int, int> map{{1, 2}, {2, 4}, {3, 6}, {4, 8}, {5, 10}};
39+
auto mapIt = map.find(3);
40+
auto mapItEnd = map.find(9);
41+
std::set<int> set{1, 2, 3};
42+
std::multimap<int, int> mMap{{1, 2}, {1, 1}, {2, 4}};
43+
std::multiset<int> mSet{1, 2, 3};
44+
45+
std::variant<int, float, std::string, std::monostate> variant;
46+
std::list<int> list{1, 2, 3};
47+
std::forward_list<int> fwList{1, 2, 3};
48+
49+
std::unordered_map<int, int> uMap{{1, 2}, {2, 4}, {3, 6}};
50+
std::unordered_set<int> uSet{1, 2, 4};
51+
std::unordered_multimap<int, int> uMMap{{1, 2}, {1, 1}, {2, 4}};
52+
std::unordered_multiset<int> uMSet{1, 1, 2};
53+
std::deque<int> deque{1, 2, 3};
54+
std::vector<int> vec{1, 2, 3};
55+
}
56+
57+
// CHECK: Process {{.*}} exited with status = 0 (0x00000000)

0 commit comments

Comments
 (0)