[Lldb-commits] [PATCH] D48752: Quiet command regex instructions during batch execution
kastiglione updated this revision to Diff 187135. kastiglione added a comment. Herald added a subscriber: jdoerfert. Add interactive parameter CHANGES SINCE LAST ACTION https://reviews.llvm.org/D48752/new/ https://reviews.llvm.org/D48752 Files: include/lldb/Core/IOHandler.h include/lldb/Expression/REPL.h lit/Commands/command-regex-delete.test lit/Commands/command-regex-unalias.test source/Commands/CommandObjectBreakpointCommand.cpp source/Commands/CommandObjectCommands.cpp source/Commands/CommandObjectTarget.cpp source/Commands/CommandObjectType.cpp source/Commands/CommandObjectWatchpointCommand.cpp source/Core/IOHandler.cpp source/Expression/REPL.cpp source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h Index: source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h === --- source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h +++ source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h @@ -459,7 +459,7 @@ //-- // IOHandlerDelegate //-- - void IOHandlerActivated(IOHandler &io_handler) override; + void IOHandlerActivated(IOHandler &io_handler, bool interactive) override; void IOHandlerInputComplete(IOHandler &io_handler, std::string &data) override; Index: source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp === --- source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -430,7 +430,7 @@ uint32_t ScriptInterpreterPython::GetPluginVersion() { return 1; } -void ScriptInterpreterPython::IOHandlerActivated(IOHandler &io_handler) { +void ScriptInterpreterPython::IOHandlerActivated(IOHandler &io_handler, bool interactive) { const char *instructions = nullptr; switch (m_active_io_handler) { @@ -451,7 +451,7 @@ if (instructions) { StreamFileSP output_sp(io_handler.GetOutputStreamFile()); -if (output_sp) { +if (output_sp && interactive) { output_sp->PutCString(instructions); output_sp->Flush(); } Index: source/Expression/REPL.cpp === --- source/Expression/REPL.cpp +++ source/Expression/REPL.cpp @@ -99,7 +99,7 @@ return m_io_handler_sp; } -void REPL::IOHandlerActivated(IOHandler &io_handler) { +void REPL::IOHandlerActivated(IOHandler &io_handler, bool interactive) { lldb::ProcessSP process_sp = m_target.GetProcessSP(); if (process_sp && process_sp->IsAlive()) return; Index: source/Core/IOHandler.cpp === --- source/Core/IOHandler.cpp +++ source/Core/IOHandler.cpp @@ -327,7 +327,7 @@ void IOHandlerEditline::Activate() { IOHandler::Activate(); - m_delegate.IOHandlerActivated(*this); + m_delegate.IOHandlerActivated(*this, GetIsInteractive()); } void IOHandlerEditline::Deactivate() { Index: source/Commands/CommandObjectWatchpointCommand.cpp === --- source/Commands/CommandObjectWatchpointCommand.cpp +++ source/Commands/CommandObjectWatchpointCommand.cpp @@ -207,9 +207,9 @@ Options *GetOptions() override { return &m_options; } - void IOHandlerActivated(IOHandler &io_handler) override { + void IOHandlerActivated(IOHandler &io_handler, bool interactive) override { StreamFileSP output_sp(io_handler.GetOutputStreamFile()); -if (output_sp) { +if (output_sp && interactive) { output_sp->PutCString( "Enter your debugger command(s). Type 'DONE' to end.\n"); output_sp->Flush(); Index: source/Commands/CommandObjectType.cpp === --- source/Commands/CommandObjectType.cpp +++ source/Commands/CommandObjectType.cpp @@ -160,7 +160,7 @@ ~CommandObjectTypeSummaryAdd() override = default; - void IOHandlerActivated(IOHandler &io_handler) override { + void IOHandlerActivated(IOHandler &io_handler, bool interactive) override { static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n" "def function (valobj,internal_dict):\n" @@ -169,7 +169,7 @@ "internal_dict: an LLDB support object not to be used\"\"\"\n"; StreamFileSP output_sp(io_handler.GetOutputStreamFile()); -if (output_sp) { +if (output_sp && interactive) { output_sp->PutCString(g_summary_addreader_instructions); output_sp->Flush(); } @@ -412,9 +412,9 @@ } } - void IOHandlerActivated(IOHandler &io_handler) override { + void IO
[Lldb-commits] [lldb] r354202 - Fix TestDataFormatterLibcxxListLoop.py test
Author: teemperor Date: Sat Feb 16 04:13:30 2019 New Revision: 354202 URL: http://llvm.org/viewvc/llvm-project?rev=354202&view=rev Log: Fix TestDataFormatterLibcxxListLoop.py test Summary: The compilation of the TestDataFormatterLibcxxListLoop.py currently fails with this error: ``` functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp:19:24: error: no member named '__value_' in 'std::__1::__list_node_base' assert(third_elem->__value_ == 3); ~~ ^ ``` It seems the internal structure of list has changed with the 3.8 release. This patch makes the test compile with the current libc++ and with the previous libc++. Reviewers: shafik, zturner, labath Reviewed By: labath Subscribers: christof, jdoerfert, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D58273 Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp?rev=354202&r1=354201&r2=354202&view=diff == --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp (original) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp Sat Feb 16 04:13:30 2019 @@ -15,10 +15,18 @@ int main() int_list *numbers_list = new int_list{1,2,3,4,5,6,7,8,9,10}; printf("// Set break point at this line."); + +#if _LIBCPP_VERSION >= 3800 +auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; +assert(third_elem->__as_node()->__value_ == 3); +auto *fifth_elem = third_elem->__next_->__next_; +assert(fifth_elem->__as_node()->__value_ == 5); +#else auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; assert(third_elem->__value_ == 3); auto *fifth_elem = third_elem->__next_->__next_; assert(fifth_elem->__value_ == 5); +#endif fifth_elem->__next_ = third_elem; #endif ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D58273: Fix TestDataFormatterLibcxxListLoop.py test
This revision was automatically updated to reflect the committed changes. Closed by commit rL354202: Fix TestDataFormatterLibcxxListLoop.py test (authored by teemperor, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D58273?vs=186994&id=187137#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58273/new/ https://reviews.llvm.org/D58273 Files: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp === --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp @@ -15,10 +15,18 @@ int_list *numbers_list = new int_list{1,2,3,4,5,6,7,8,9,10}; printf("// Set break point at this line."); + +#if _LIBCPP_VERSION >= 3800 +auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; +assert(third_elem->__as_node()->__value_ == 3); +auto *fifth_elem = third_elem->__next_->__next_; +assert(fifth_elem->__as_node()->__value_ == 5); +#else auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; assert(third_elem->__value_ == 3); auto *fifth_elem = third_elem->__next_->__next_; assert(fifth_elem->__value_ == 5); +#endif fifth_elem->__next_ = third_elem; #endif Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp === --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp @@ -15,10 +15,18 @@ int_list *numbers_list = new int_list{1,2,3,4,5,6,7,8,9,10}; printf("// Set break point at this line."); + +#if _LIBCPP_VERSION >= 3800 +auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; +assert(third_elem->__as_node()->__value_ == 3); +auto *fifth_elem = third_elem->__next_->__next_; +assert(fifth_elem->__as_node()->__value_ == 5); +#else auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; assert(third_elem->__value_ == 3); auto *fifth_elem = third_elem->__next_->__next_; assert(fifth_elem->__value_ == 5); +#endif fifth_elem->__next_ = third_elem; #endif ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
Re: [Lldb-commits] [lldb] r354185 - Temporarily disable test:
On Fri, Feb 15, 2019 at 4:12 PM Richard Smith via lldb-commits wrote: > > Author: rsmith > Date: Fri Feb 15 16:13:26 2019 > New Revision: 354185 > > URL: http://llvm.org/viewvc/llvm-project?rev=354185&view=rev > Log: > Temporarily disable test: > > test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py > > It fails on Mac OS; apparently a VarDecl 'void *&C' is implicitly > declared there, making the class template name C ambiguous. > > Modified: > > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py > > Modified: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py?rev=354185&r1=354184&r2=354185&view=diff > == > --- > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py > (original) > +++ > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py > Fri Feb 15 16:13:26 2019 > @@ -4,4 +4,7 @@ from lldbsuite.test import decorators > lldbinline.MakeInlineTest( > __file__, globals(), [ > decorators.expectedFailureAll( > -compiler="gcc")]) > +compiler="gcc"), > +decorators.expectedFailureAll( > +oslist=['ios', 'watchos', 'tvos', 'bridgeos'], > +bugnumber="rdar://problem/48128064: class template declaration > unexpectedly shadowed by VarDecl on MacOS")]) > > I think you missed macOS, let me fix it. -- Davide ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] r354204 - [testsuite] Skip this test correctly also on macOS.
Author: davide Date: Sat Feb 16 09:16:53 2019 New Revision: 354204 URL: http://llvm.org/viewvc/llvm-project?rev=354204&view=rev Log: [testsuite] Skip this test correctly also on macOS. Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py?rev=354204&r1=354203&r2=354204&view=diff == --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py (original) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py Sat Feb 16 09:16:53 2019 @@ -5,6 +5,5 @@ lldbinline.MakeInlineTest( __file__, globals(), [ decorators.expectedFailureAll( compiler="gcc"), -decorators.expectedFailureAll( -oslist=['ios', 'watchos', 'tvos', 'bridgeos'], -bugnumber="rdar://problem/48128064: class template declaration unexpectedly shadowed by VarDecl on MacOS")]) +# rdar://problem/48128064 +decorators.skipIfDarwin]) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] r354206 - Add PythonBoolean type to the PythonDataObjects
Author: tkrasnukha Date: Sat Feb 16 10:39:14 2019 New Revision: 354206 URL: http://llvm.org/viewvc/llvm-project?rev=354206&view=rev Log: Add PythonBoolean type to the PythonDataObjects Differential Revision: https://reviews.llvm.org/D57817 Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=354206&r1=354205&r2=354206&view=diff == --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Sat Feb 16 10:39:14 2019 @@ -77,6 +77,8 @@ PyObjectType PythonObject::GetObjectType #endif if (PythonByteArray::Check(m_py_obj)) return PyObjectType::ByteArray; + if (PythonBoolean::Check(m_py_obj)) +return PyObjectType::Boolean; if (PythonInteger::Check(m_py_obj)) return PyObjectType::Integer; if (PythonFile::Check(m_py_obj)) @@ -178,6 +180,9 @@ StructuredData::ObjectSP PythonObject::C case PyObjectType::Dictionary: return PythonDictionary(PyRefType::Borrowed, m_py_obj) .CreateStructuredDictionary(); + case PyObjectType::Boolean: +return PythonBoolean(PyRefType::Borrowed, m_py_obj) +.CreateStructuredBoolean(); case PyObjectType::Integer: return PythonInteger(PyRefType::Borrowed, m_py_obj) .CreateStructuredInteger(); @@ -525,6 +530,55 @@ StructuredData::IntegerSP PythonInteger: return result; } +//-- +// PythonBoolean +//-- + +PythonBoolean::PythonBoolean(PyRefType type, PyObject *py_obj) +: PythonObject() { + Reset(type, py_obj); // Use "Reset()" to ensure that py_obj is a boolean type +} + +PythonBoolean::PythonBoolean(const PythonBoolean &object) +: PythonObject(object) {} + +PythonBoolean::PythonBoolean(bool value) { + SetValue(value); +} + +bool PythonBoolean::Check(PyObject *py_obj) { + return py_obj ? PyBool_Check(py_obj) : false; +} + +void PythonBoolean::Reset(PyRefType type, PyObject *py_obj) { + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. + PythonObject result(type, py_obj); + + if (!PythonBoolean::Check(py_obj)) { +PythonObject::Reset(); +return; + } + + // Calling PythonObject::Reset(const PythonObject&) will lead to stack + // overflow since it calls back into the virtual implementation. + PythonObject::Reset(PyRefType::Borrowed, result.get()); +} + +bool PythonBoolean::GetValue() const { + return m_py_obj ? PyObject_IsTrue(m_py_obj) : false; +} + +void PythonBoolean::SetValue(bool value) { + PythonObject::Reset(PyRefType::Owned, PyBool_FromLong(value)); +} + +StructuredData::BooleanSP PythonBoolean::CreateStructuredBoolean() const { + StructuredData::BooleanSP result(new StructuredData::Boolean); + result->SetValue(GetValue()); + return result; +} + //-- // PythonList //-- Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h?rev=354206&r1=354205&r2=354206&view=diff == --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h Sat Feb 16 10:39:14 2019 @@ -57,6 +57,7 @@ private: enum class PyObjectType { Unknown, None, + Boolean, Integer, Dictionary, List, @@ -297,6 +298,29 @@ public: StructuredData::IntegerSP CreateStructuredInteger() const; }; +class PythonBoolean : public PythonObject { +public: + PythonBoolean() = default; + explicit PythonBoolean(bool value); + PythonBoolean(PyRefType type, PyObject *o); + PythonBoolean(const PythonBoolean &object); + + ~PythonBoolean() override = default; + + static bool Check(PyObject *py_obj); + + // Bring in the no-argument base class version + using PythonObject::Reset; + + void Reset(PyRefType type, PyObject *py_obj) override; + + bool GetValue() const; + + void SetValue(bool value); + + StructuredData::BooleanSP CreateStructuredBoolean() const; +}; + class PythonList : public PythonObject { public: PythonList() {} Modified: lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTes
[Lldb-commits] [PATCH] D57817: Add PythonBoolean type to PythonDataObjects
This revision was automatically updated to reflect the committed changes. Closed by commit rLLDB354206: Add PythonBoolean type to the PythonDataObjects (authored by tkrasnukha, committed by ). Changed prior to commit: https://reviews.llvm.org/D57817?vs=185537&id=187142#toc Repository: rLLDB LLDB CHANGES SINCE LAST ACTION https://reviews.llvm.org/D57817/new/ https://reviews.llvm.org/D57817 Files: source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp Index: unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp === --- unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -195,6 +195,31 @@ EXPECT_EQ(7, constructed_int.GetInteger()); } +TEST_F(PythonDataObjectsTest, TestPythonBoolean) { + // Test PythonBoolean constructed from Py_True + EXPECT_TRUE(PythonBoolean::Check(Py_True)); + PythonBoolean python_true(PyRefType::Owned, Py_True); + EXPECT_EQ(PyObjectType::Boolean, python_true.GetObjectType()); + + // Test PythonBoolean constructed from Py_False + EXPECT_TRUE(PythonBoolean::Check(Py_False)); + PythonBoolean python_false(PyRefType::Owned, Py_False); + EXPECT_EQ(PyObjectType::Boolean, python_false.GetObjectType()); + + auto test_from_long = [](long value) { +PyObject *py_bool = PyBool_FromLong(value); +EXPECT_TRUE(PythonBoolean::Check(py_bool)); +PythonBoolean python_boolean(PyRefType::Owned, py_bool); +EXPECT_EQ(PyObjectType::Boolean, python_boolean.GetObjectType()); +EXPECT_EQ(bool(value), python_boolean.GetValue()); + }; + + // Test PythonBoolean constructed from long integer values. + test_from_long(0); // Test 'false' value. + test_from_long(1); // Test 'true' value. + test_from_long(~0); // Any value != 0 is 'true'. +} + TEST_F(PythonDataObjectsTest, TestPythonBytes) { static const char *test_bytes = "PythonDataObjectsTest::TestPythonBytes"; PyObject *py_bytes = PyBytes_FromString(test_bytes); Index: source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h === --- source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -57,6 +57,7 @@ enum class PyObjectType { Unknown, None, + Boolean, Integer, Dictionary, List, @@ -297,6 +298,29 @@ StructuredData::IntegerSP CreateStructuredInteger() const; }; +class PythonBoolean : public PythonObject { +public: + PythonBoolean() = default; + explicit PythonBoolean(bool value); + PythonBoolean(PyRefType type, PyObject *o); + PythonBoolean(const PythonBoolean &object); + + ~PythonBoolean() override = default; + + static bool Check(PyObject *py_obj); + + // Bring in the no-argument base class version + using PythonObject::Reset; + + void Reset(PyRefType type, PyObject *py_obj) override; + + bool GetValue() const; + + void SetValue(bool value); + + StructuredData::BooleanSP CreateStructuredBoolean() const; +}; + class PythonList : public PythonObject { public: PythonList() {} Index: source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp === --- source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -77,6 +77,8 @@ #endif if (PythonByteArray::Check(m_py_obj)) return PyObjectType::ByteArray; + if (PythonBoolean::Check(m_py_obj)) +return PyObjectType::Boolean; if (PythonInteger::Check(m_py_obj)) return PyObjectType::Integer; if (PythonFile::Check(m_py_obj)) @@ -178,6 +180,9 @@ case PyObjectType::Dictionary: return PythonDictionary(PyRefType::Borrowed, m_py_obj) .CreateStructuredDictionary(); + case PyObjectType::Boolean: +return PythonBoolean(PyRefType::Borrowed, m_py_obj) +.CreateStructuredBoolean(); case PyObjectType::Integer: return PythonInteger(PyRefType::Borrowed, m_py_obj) .CreateStructuredInteger(); @@ -526,6 +531,55 @@ } //-- +// PythonBoolean +//-- + +PythonBoolean::PythonBoolean(PyRefType type, PyObject *py_obj) +: PythonObject() { + Reset(type, py_obj); // Use "Reset()" to ensure that py_obj is a boolean type +} + +PythonBoolean::PythonBoolean(const PythonBoolean &object) +: PythonObject(object) {} + +PythonBoolean::PythonBoolean(bool value) { + SetValue(value); +} + +bool PythonBoolean::Check(PyObject *py_obj) { + return py_obj ? PyBool_Check(py_obj) : false; +} + +void PythonBoolean::Reset(PyRefType type, PyObject *py_obj) { + // Grab the desired reference type so that if we end up rej
[Lldb-commits] [PATCH] D55653: [lldb-mi] Check raw pointers before passing them to std::string ctor/assignment
tatyana-krasnukha updated this revision to Diff 187153. tatyana-krasnukha retitled this revision from "Check pointer results on nullptr before using them" to "[lldb-mi] Check raw pointers before passing them to std::string ctor/assignment". tatyana-krasnukha added a comment. Herald added subscribers: jfb, mgorny. Thank you for mentioning StringRef, you gave me the idea to keep pointers check inside the CMIUtilString to obviate undefined behavior. This is the best place to do it, however, a caller still should examine pointers he passes to CMIUtilString::Format as the ellipsis parameter. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D55653/new/ https://reviews.llvm.org/D55653 Files: tools/lldb-mi/MICmdCmdMiscellanous.cpp tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp tools/lldb-mi/MICmnLLDBDebugger.cpp tools/lldb-mi/MICmnMIOutOfBandRecord.cpp tools/lldb-mi/MICmnMIResultRecord.cpp tools/lldb-mi/MIDriverMgr.cpp tools/lldb-mi/MIUtilString.cpp tools/lldb-mi/MIUtilString.h unittests/tools/CMakeLists.txt unittests/tools/lldb-mi/CMakeLists.txt unittests/tools/lldb-mi/utils/CMakeLists.txt unittests/tools/lldb-mi/utils/StringTest.cpp Index: unittests/tools/lldb-mi/utils/StringTest.cpp === --- unittests/tools/lldb-mi/utils/StringTest.cpp +++ unittests/tools/lldb-mi/utils/StringTest.cpp @@ -0,0 +1,32 @@ +//===-- LLGSTest.cpp *- 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 "MIUtilString.h" +#include "gtest/gtest.h" + +TEST(StringTest, ConstructFromNullptr) { + auto str = CMIUtilString(nullptr); + EXPECT_TRUE(str.empty()); + EXPECT_NE(nullptr, str.c_str()); + EXPECT_EQ(CMIUtilString(""), str); +} + +TEST(StringTest, AssignNullptr) { + CMIUtilString str; + str = nullptr; + EXPECT_TRUE(str.empty()); + EXPECT_NE(nullptr, str.c_str()); + EXPECT_EQ(CMIUtilString(""), str); +} + +TEST(StringTest, IsAllValidAlphaAndNumeric) { + EXPECT_TRUE(CMIUtilString::IsAllValidAlphaAndNumeric("123abc")); + EXPECT_FALSE(CMIUtilString::IsAllValidAlphaAndNumeric("")); + EXPECT_FALSE(CMIUtilString::IsAllValidAlphaAndNumeric(nullptr)); +} + Index: unittests/tools/lldb-mi/utils/CMakeLists.txt === --- unittests/tools/lldb-mi/utils/CMakeLists.txt +++ unittests/tools/lldb-mi/utils/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(lldb-mi-utils OBJECT + ${LLDB_PROJECT_ROOT}/tools/lldb-mi/MIUtilString.cpp + ) + +add_lldb_unittest(LLDBMiUtilTests + StringTest.cpp + + LINK_COMPONENTS +Support + ) + +target_sources(LLDBMiUtilTests PRIVATE $) Index: unittests/tools/lldb-mi/CMakeLists.txt === --- unittests/tools/lldb-mi/CMakeLists.txt +++ unittests/tools/lldb-mi/CMakeLists.txt @@ -0,0 +1,2 @@ +include_directories(${LLDB_PROJECT_ROOT}/tools/lldb-mi) +add_subdirectory(utils) Index: unittests/tools/CMakeLists.txt === --- unittests/tools/CMakeLists.txt +++ unittests/tools/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(lldb-mi) if(CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|Linux|NetBSD") if ((CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_TEST_DEBUGSERVER) OR (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_LLDB_SERVER_BUILD)) # These tests are meant to test lldb-server/debugserver in isolation, and Index: tools/lldb-mi/MIUtilString.h === --- tools/lldb-mi/MIUtilString.h +++ tools/lldb-mi/MIUtilString.h @@ -33,7 +33,13 @@ static CMIUtilString FormatBinary(const MIuint64 vnDecimal); static CMIUtilString FormatValist(const CMIUtilString &vrFormating, va_list vArgs); + static bool IsAllValidAlphaAndNumeric(const char *vpText); + + static const char *WithNullAsEmpty(const char *vpText) { +return vpText ? vpText : ""; + } + static bool Compare(const CMIUtilString &vrLhs, const CMIUtilString &vrRhs); static CMIUtilString ConvertToPrintableASCII(const char vChar, bool bEscapeQuotes = false); Index: tools/lldb-mi/MIUtilString.cpp === --- tools/lldb-mi/MIUtilString.cpp +++ tools/lldb-mi/MIUtilString.cpp @@ -37,7 +37,8 @@ // Return: None. // Throws: None. //-- -CMIUtilString::CMIUtilString(const char *vpData) : std::string(vpData) {} +CMIUtilString::CMIUtilString(const char *vpData) + : std::string(WithNullAsEmpty(vpData)) {} //++ //---