Skip to content

[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value #96985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class ScriptedThreadPlanInterface : public ScriptedInterface {

virtual lldb::StateType GetRunState() { return lldb::eStateStepping; }

virtual llvm::Expected<bool> GetStopDescription(lldb_private::Stream *s) {
return true;
virtual llvm::Error GetStopDescription(lldb::StreamSP &stream) {
return llvm::Error::success();
}
};
} // namespace lldb_private
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Interpreter/ScriptInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class ScriptInterpreter : public PluginInterface {

Event *GetOpaqueTypeFromSBEvent(const lldb::SBEvent &event) const;

Stream *GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
lldb::StreamSP GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;

lldb::BreakpointSP
GetOpaqueTypeFromSBBreakpoint(const lldb::SBBreakpoint &breakpoint) const;
Expand Down
9 changes: 6 additions & 3 deletions lldb/source/Interpreter/ScriptInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const lldb::SBEvent &event) const {
return event.m_opaque_ptr;
}

Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
const lldb::SBStream &stream) const {
if (stream.m_opaque_up)
return const_cast<lldb::SBStream &>(stream).m_opaque_up.get();
if (stream.m_opaque_up) {
lldb::StreamSP s = std::make_shared<lldb_private::StreamString>();
*s << const_cast<lldb::SBStream &>(stream).GetData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a dependency cycle: lldb::SBStream is in source/API, so this makes Interpreter depend on API. But API already depends on Interpreter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an idle complaint: It has the effect that lldb-test no longer links after this PR if you don't pass -Wl,-dead_strip to the linker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chances are it also breaks building on Windows, where /OPT:REF might not be strong enough to remove this.

Also, we do have a LLVM_NO_DEAD_STRIP option, which presumably no longer builds after this change either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in a2e3af5 for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is what broke my linux build with the following linker error:

mold: error: undefined symbol: lldb::SBStream::GetData()
>>> referenced by ScriptInterpreter.cpp
>>>               lib/liblldbInterpreter.a(ScriptInterpreter.cpp.o):(lldb_private::ScriptInterpreter::GetOpaqueTypeFromSBStream(lldb::SBStream const&) const)

lld complains in the same way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it broke the windows bot: https://lab.llvm.org/buildbot/#/builders/141/builds/369

@nico Thanks to the revert, I think I have a fix for this.

return s;
}

return nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ ScriptedPythonInterface::ScriptedPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedInterface(), m_interpreter(interpreter) {}

template <>
void ScriptedPythonInterface::ReverseTransform(
lldb_private::Stream *&original_arg, python::PythonObject transformed_arg,
Status &error) {
Stream *s = ExtractValueFromPythonObject<Stream *>(transformed_arg, error);
*original_arg = *s;
original_arg->PutCString(static_cast<StreamString *>(s)->GetData());
}

template <>
StructuredData::ArraySP
ScriptedPythonInterface::ExtractValueFromPythonObject<StructuredData::ArraySP>(
Expand Down Expand Up @@ -74,7 +65,8 @@ Event *ScriptedPythonInterface::ExtractValueFromPythonObject<Event *>(
}

template <>
Stream *ScriptedPythonInterface::ExtractValueFromPythonObject<Stream *>(
lldb::StreamSP
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StreamSP>(
python::PythonObject &p, Status &error) {
if (lldb::SBStream *sb_stream = reinterpret_cast<lldb::SBStream *>(
python::LLDBSWIGPython_CastPyObjectToSBStream(p.get())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
return python::SWIGBridge::ToSWIGWrapper(arg);
}

python::PythonObject Transform(Stream *arg) {
return python::SWIGBridge::ToSWIGWrapper(arg);
python::PythonObject Transform(lldb::StreamSP arg) {
return python::SWIGBridge::ToSWIGWrapper(arg.get());
}

python::PythonObject Transform(lldb::DataExtractorSP arg) {
Expand Down Expand Up @@ -447,7 +447,8 @@ Event *ScriptedPythonInterface::ExtractValueFromPythonObject<Event *>(
python::PythonObject &p, Status &error);

template <>
Stream *ScriptedPythonInterface::ExtractValueFromPythonObject<Stream *>(
lldb::StreamSP
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StreamSP>(
python::PythonObject &p, Status &error);

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ lldb::StateType ScriptedThreadPlanPythonInterface::GetRunState() {
static_cast<uint32_t>(lldb::eStateStepping)));
}

llvm::Expected<bool>
ScriptedThreadPlanPythonInterface::GetStopDescription(lldb_private::Stream *s) {
llvm::Error
ScriptedThreadPlanPythonInterface::GetStopDescription(lldb::StreamSP &stream) {
Status error;
Dispatch("stop_description", error, s);
Dispatch("stop_description", error, stream);

if (error.Fail())
return error.ToError();

return true;
return llvm::Error::success();
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ScriptedThreadPlanPythonInterface : public ScriptedThreadPlanInterface,

lldb::StateType GetRunState() override;

llvm::Expected<bool> GetStopDescription(lldb_private::Stream *s) override;
llvm::Error GetStopDescription(lldb::StreamSP &stream) override;
};
} // namespace lldb_private

Expand Down
11 changes: 7 additions & 4 deletions lldb/source/Target/ThreadPlanPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,16 @@ void ThreadPlanPython::GetDescription(Stream *s, lldb::DescriptionLevel level) {
if (m_implementation_sp) {
ScriptInterpreter *script_interp = GetScriptInterpreter();
if (script_interp) {
auto desc_or_err = m_interface->GetStopDescription(s);
if (!desc_or_err || !*desc_or_err) {
LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), desc_or_err.takeError(),
lldb::StreamSP stream = std::make_shared<lldb_private::StreamString>();
llvm::Error err = m_interface->GetStopDescription(stream);
if (err) {
LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), std::move(err),
"Can't call ScriptedThreadPlan::GetStopDescription.");
s->Printf("Python thread plan implemented by class %s.",
m_class_name.c_str());
}
} else
s->PutCString(
reinterpret_cast<StreamString *>(stream.get())->GetData());
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *


class StepScriptedTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True

Expand All @@ -15,14 +16,12 @@ def setUp(self):
self.main_source_file = lldb.SBFileSpec("main.c")
self.runCmd("command script import Steps.py")

@expectedFailureAll()
def test_standard_step_out(self):
"""Tests stepping with the scripted thread plan laying over a standard
thread plan for stepping out."""
self.build()
self.step_out_with_scripted_plan("Steps.StepOut")

@expectedFailureAll()
def test_scripted_step_out(self):
"""Tests stepping with the scripted thread plan laying over an another
scripted thread plan for stepping out."""
Expand Down Expand Up @@ -63,12 +62,10 @@ def test_misspelled_plan_name(self):
# Make sure we didn't let the process run:
self.assertEqual(stop_id, process.GetStopID(), "Process didn't run")

@expectedFailureAll()
def test_checking_variable(self):
"""Test that we can call SBValue API's from a scripted thread plan - using SBAPI's to step"""
self.do_test_checking_variable(False)

@expectedFailureAll()
def test_checking_variable_cli(self):
"""Test that we can call SBValue API's from a scripted thread plan - using cli to step"""
self.do_test_checking_variable(True)
Expand Down
Loading