Skip to content

Commit c964741

Browse files
committed
[lldb/API] Add CommandInterpreter::{Get,Set}PrintErrors to SBAPI (NFC)
This patch exposes the getter and setter methods for the command interpreter `print_errors` run option. rdar://74816984 Differential Revision: https://reviews.llvm.org/D98001 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 36eab46 commit c964741

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

lldb/bindings/interface/SBCommandInterpreterRunOptions.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ A default SBCommandInterpreterRunOptions object has:
1818
* StopOnCrash: false
1919
* EchoCommands: true
2020
* PrintResults: true
21+
* PrintErrors: true
2122
* AddToHistory: true
2223
2324
") SBCommandInterpreterRunOptions;
@@ -58,6 +59,12 @@ public:
5859
void
5960
SetPrintResults (bool);
6061

62+
bool
63+
GetPrintErrors () const;
64+
65+
void
66+
SetPrintErrors (bool);
67+
6168
bool
6269
GetAddToHistory () const;
6370

lldb/include/lldb/API/SBCommandInterpreterRunOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class LLDB_API SBCommandInterpreterRunOptions {
5656

5757
void SetPrintResults(bool);
5858

59+
bool GetPrintErrors() const;
60+
61+
void SetPrintErrors(bool);
62+
5963
bool GetAddToHistory() const;
6064

6165
void SetAddToHistory(bool);

lldb/source/API/SBCommandInterpreterRunOptions.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ void SBCommandInterpreterRunOptions::SetPrintResults(bool print_results) {
131131
m_opaque_up->SetPrintResults(print_results);
132132
}
133133

134+
bool SBCommandInterpreterRunOptions::GetPrintErrors() const {
135+
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
136+
GetPrintErrors);
137+
138+
return m_opaque_up->GetPrintErrors();
139+
}
140+
141+
void SBCommandInterpreterRunOptions::SetPrintErrors(bool print_errors) {
142+
LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetPrintErrors,
143+
(bool), print_errors);
144+
145+
m_opaque_up->SetPrintErrors(print_errors);
146+
}
147+
134148
bool SBCommandInterpreterRunOptions::GetAddToHistory() const {
135149
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
136150
GetAddToHistory);
@@ -269,6 +283,10 @@ template <> void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) {
269283
GetPrintResults, ());
270284
LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults,
271285
(bool));
286+
LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
287+
GetPrintErrors, ());
288+
LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetPrintErrors,
289+
(bool));
272290
LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
273291
GetAddToHistory, ());
274292
LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory,

lldb/test/API/python_api/interpreter/TestRunCommandInterpreterAPI.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,40 @@ def test_run_session_with_error_and_quit(self):
7373
self.assertGreater(n_errors, 0)
7474
self.assertTrue(quit_requested)
7575
self.assertFalse(has_crashed)
76+
77+
class SBCommandInterpreterRunOptionsCase(TestBase):
78+
79+
NO_DEBUG_INFO_TESTCASE = True
80+
mydir = TestBase.compute_mydir(__file__)
81+
82+
def test_command_interpreter_run_options(self):
83+
"""Test SBCommandInterpreterRunOptions default values, getters & setters """
84+
85+
opts = lldb.SBCommandInterpreterRunOptions()
86+
87+
# Check getters with default values
88+
self.assertEqual(opts.GetStopOnContinue(), False)
89+
self.assertEqual(opts.GetStopOnError(), False)
90+
self.assertEqual(opts.GetStopOnCrash(), False)
91+
self.assertEqual(opts.GetEchoCommands(), True)
92+
self.assertEqual(opts.GetPrintResults(), True)
93+
self.assertEqual(opts.GetPrintErrors(), True)
94+
self.assertEqual(opts.GetAddToHistory(), True)
95+
96+
# Invert values
97+
opts.SetStopOnContinue(not opts.GetStopOnContinue())
98+
opts.SetStopOnError(not opts.GetStopOnError())
99+
opts.SetStopOnCrash(not opts.GetStopOnCrash())
100+
opts.SetEchoCommands(not opts.GetEchoCommands())
101+
opts.SetPrintResults(not opts.GetPrintResults())
102+
opts.SetPrintErrors(not opts.GetPrintErrors())
103+
opts.SetAddToHistory(not opts.GetAddToHistory())
104+
105+
# Check the value changed
106+
self.assertEqual(opts.GetStopOnContinue(), True)
107+
self.assertEqual(opts.GetStopOnError(), True)
108+
self.assertEqual(opts.GetStopOnCrash(), True)
109+
self.assertEqual(opts.GetEchoCommands(), False)
110+
self.assertEqual(opts.GetPrintResults(), False)
111+
self.assertEqual(opts.GetPrintErrors(), False)
112+
self.assertEqual(opts.GetAddToHistory(), False)

0 commit comments

Comments
 (0)