
When reading a value as a scalar, the type size is required. It's returned as a `std::optional`. This optional isn't checked for scalar values, where it is unconditionally accessed. This came up in the [Shell/Process/Windows/msstl_smoke.cpp](4e10b62442/lldb/test/Shell/Process/Windows/msstl_smoke.cpp
) test. There, LLDB breaks at the function entry, so all locals aren't initialized yet. Most values will contain garbage. The [`std::list` synthetic provider](4e10b62442/lldb/source/Plugins/Language/CPlusPlus/GenericList.cpp (L517)
) tries to read the value using `GetData`. However, in [`ValueObject::GetData`](4e10b62442/lldb/source/ValueObject/ValueObject.cpp (L766)
), [`ValueObjectChild::UpdateValue`](88c993fbc5/lldb/source/ValueObject/ValueObjectChild.cpp (L102)
) fails because the parent already failed to read its data, so `m_value` won't have a compiler type, thus the size can't be read.
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Core/Value.h"
|
|
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
|
|
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
|
|
#include "TestingSupport/SubsystemRAII.h"
|
|
#include "TestingSupport/Symbol/ClangTestUtils.h"
|
|
|
|
#include "lldb/Utility/DataExtractor.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace lldb_private;
|
|
using namespace lldb_private::clang_utils;
|
|
|
|
TEST(ValueTest, GetValueAsData) {
|
|
SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX> subsystems;
|
|
auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>("test");
|
|
auto *clang = holder->GetAST();
|
|
|
|
Value v(Scalar(42));
|
|
DataExtractor extractor;
|
|
|
|
// no compiler type
|
|
Status status = v.GetValueAsData(nullptr, extractor, nullptr);
|
|
ASSERT_TRUE(status.Fail());
|
|
|
|
// with compiler type
|
|
v.SetCompilerType(clang->GetBasicType(lldb::BasicType::eBasicTypeChar));
|
|
|
|
status = v.GetValueAsData(nullptr, extractor, nullptr);
|
|
ASSERT_TRUE(status.Success());
|
|
}
|