Skip to content

Commit 326bdd3

Browse files
committed
export StopDisassemblyType enum
1 parent b8659b2 commit 326bdd3

16 files changed

+69
-59
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,6 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
232232

233233
void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
234234

235-
// Properties Functions
236-
enum StopDisassemblyType {
237-
eStopDisassemblyTypeNever = 0,
238-
eStopDisassemblyTypeNoDebugInfo,
239-
eStopDisassemblyTypeNoSource,
240-
eStopDisassemblyTypeAlways
241-
};
242-
243235
Status SetPropertyValue(const ExecutionContext *exe_ctx,
244236
VarSetOperationType op, llvm::StringRef property_path,
245237
llvm::StringRef value) override;
@@ -336,7 +328,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
336328

337329
uint64_t GetStopSourceLineCount(bool before) const;
338330

339-
StopDisassemblyType GetStopDisassemblyDisplay() const;
331+
lldb::StopDisassemblyType GetStopDisassemblyDisplay() const;
340332

341333
uint64_t GetDisassemblyLineCount() const;
342334

lldb/include/lldb/lldb-enumerations.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,14 @@ enum CommandReturnObjectCallbackResult {
13831383
eCommandReturnObjectPrintCallbackHandled = 1,
13841384
};
13851385

1386+
// Used to determine when to show disassembly
1387+
enum StopDisassemblyType {
1388+
eStopDisassemblyTypeNever = 0,
1389+
eStopDisassemblyTypeNoDebugInfo,
1390+
eStopDisassemblyTypeNoSource,
1391+
eStopDisassemblyTypeAlways
1392+
};
1393+
13861394
} // namespace lldb
13871395

13881396
#endif // LLDB_LLDB_ENUMERATIONS_H

lldb/source/Core/CoreProperties.td

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ let Definition = "debugger" in {
9191
Global,
9292
DefaultUnsignedValue<4>,
9393
Desc<"The number of disassembly lines to show when displaying a stopped context.">;
94-
def StopDisassemblyDisplay: Property<"stop-disassembly-display", "Enum">,
95-
Global,
96-
DefaultEnumValue<"Debugger::eStopDisassemblyTypeNoDebugInfo">,
97-
EnumValues<"OptionEnumValues(g_show_disassembly_enum_values)">,
98-
Desc<"Control when to display disassembly when displaying a stopped context.">;
94+
def StopDisassemblyDisplay
95+
: Property<"stop-disassembly-display", "Enum">,
96+
Global,
97+
DefaultEnumValue<"eStopDisassemblyTypeNoDebugInfo">,
98+
EnumValues<"OptionEnumValues(g_show_disassembly_enum_values)">,
99+
Desc<"Control when to display disassembly when displaying a stopped "
100+
"context.">;
99101
def StopDisassemblyMaxSize: Property<"stop-disassembly-max-size", "UInt64">,
100102
Global,
101103
DefaultUnsignedValue<32000>,

lldb/source/Core/Debugger.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,24 @@ static llvm::DefaultThreadPool *g_thread_pool = nullptr;
112112

113113
static constexpr OptionEnumValueElement g_show_disassembly_enum_values[] = {
114114
{
115-
Debugger::eStopDisassemblyTypeNever,
115+
lldb::eStopDisassemblyTypeNever,
116116
"never",
117117
"Never show disassembly when displaying a stop context.",
118118
},
119119
{
120-
Debugger::eStopDisassemblyTypeNoDebugInfo,
120+
lldb::eStopDisassemblyTypeNoDebugInfo,
121121
"no-debuginfo",
122122
"Show disassembly when there is no debug information.",
123123
},
124124
{
125-
Debugger::eStopDisassemblyTypeNoSource,
125+
lldb::eStopDisassemblyTypeNoSource,
126126
"no-source",
127127
"Show disassembly when there is no source information, or the source "
128128
"file "
129129
"is missing when displaying a stop context.",
130130
},
131131
{
132-
Debugger::eStopDisassemblyTypeAlways,
132+
lldb::eStopDisassemblyTypeAlways,
133133
"always",
134134
"Always show disassembly when displaying a stop context.",
135135
},
@@ -611,10 +611,10 @@ uint64_t Debugger::GetStopSourceLineCount(bool before) const {
611611
idx, g_debugger_properties[idx].default_uint_value);
612612
}
613613

614-
Debugger::StopDisassemblyType Debugger::GetStopDisassemblyDisplay() const {
614+
lldb::StopDisassemblyType Debugger::GetStopDisassemblyDisplay() const {
615615
const uint32_t idx = ePropertyStopDisassemblyDisplay;
616-
return GetPropertyAtIndexAs<Debugger::StopDisassemblyType>(
617-
idx, static_cast<Debugger::StopDisassemblyType>(
616+
return GetPropertyAtIndexAs<lldb::StopDisassemblyType>(
617+
idx, static_cast<lldb::StopDisassemblyType>(
618618
g_debugger_properties[idx].default_uint_value));
619619
}
620620

lldb/source/Interpreter/OptionValueEnumeration.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ llvm::json::Value
4141
OptionValueEnumeration::ToJSON(const ExecutionContext *exe_ctx) {
4242
const size_t count = m_enumerations.GetSize();
4343
for (size_t i = 0; i < count; ++i) {
44-
if (m_enumerations.GetValueAtIndexUnchecked(i).value == m_current_value) {
44+
if (m_enumerations.GetValueAtIndexUnchecked(i).value == m_current_value)
4545
return m_enumerations.GetCStringAtIndex(i).GetStringRef();
46-
}
4746
}
4847

4948
return m_current_value;

lldb/source/Target/StackFrame.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,8 +2030,7 @@ bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
20302030
if (show_source) {
20312031
ExecutionContext exe_ctx(shared_from_this());
20322032
bool have_source = false, have_debuginfo = false;
2033-
Debugger::StopDisassemblyType disasm_display =
2034-
Debugger::eStopDisassemblyTypeNever;
2033+
lldb::StopDisassemblyType disasm_display = lldb::eStopDisassemblyTypeNever;
20352034
Target *target = exe_ctx.GetTargetPtr();
20362035
if (target) {
20372036
Debugger &debugger = target->GetDebugger();
@@ -2064,20 +2063,20 @@ bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
20642063
}
20652064
}
20662065
switch (disasm_display) {
2067-
case Debugger::eStopDisassemblyTypeNever:
2066+
case lldb::eStopDisassemblyTypeNever:
20682067
break;
20692068

2070-
case Debugger::eStopDisassemblyTypeNoDebugInfo:
2069+
case lldb::eStopDisassemblyTypeNoDebugInfo:
20712070
if (have_debuginfo)
20722071
break;
20732072
[[fallthrough]];
20742073

2075-
case Debugger::eStopDisassemblyTypeNoSource:
2074+
case lldb::eStopDisassemblyTypeNoSource:
20762075
if (have_source)
20772076
break;
20782077
[[fallthrough]];
20792078

2080-
case Debugger::eStopDisassemblyTypeAlways:
2079+
case lldb::eStopDisassemblyTypeAlways:
20812080
if (target) {
20822081
const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
20832082
if (disasm_lines > 0) {

lldb/tools/lldb-dap/DAP.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ struct DAP {
203203
lldb::SBFormat frame_format;
204204
lldb::SBFormat thread_format;
205205

206-
/// The value of stop-disassembly-display setting in LLDB.
207-
std::string stop_disassembly_display;
208-
209206
// This is used to allow request_evaluate to handle empty expressions
210207
// (ie the user pressed 'return' and expects the previous expression to
211208
// repeat). If the previous expression was a command, this string will be

lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
108108
}
109109

110110
SetSourceMapFromArguments(*arguments);
111-
SetStopDisassemblyDisplayFromSettings();
112111

113112
lldb::SBError status;
114113
dap.SetTarget(dap.CreateTargetFromArguments(*arguments, status));

lldb/tools/lldb-dap/Handler/LaunchRequestHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ void LaunchRequestHandler::operator()(const llvm::json::Object &request) const {
9595
}
9696

9797
SetSourceMapFromArguments(*arguments);
98-
SetStopDisassemblyDisplayFromSettings();
9998

10099
lldb::SBError status;
101100
dap.SetTarget(dap.CreateTargetFromArguments(*arguments, status));

lldb/tools/lldb-dap/Handler/RequestHandler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ void BaseRequestHandler::SetSourceMapFromArguments(
9999
}
100100
}
101101

102-
void BaseRequestHandler::SetStopDisassemblyDisplayFromSettings() const {
103-
dap.stop_disassembly_display = GetStopDisassemblyDisplay(dap.debugger);
104-
}
105-
106102
static llvm::Error RunInTerminal(DAP &dap,
107103
const llvm::json::Object &launch_request,
108104
const uint64_t timeout_seconds) {

lldb/tools/lldb-dap/Handler/RequestHandler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ class BaseRequestHandler {
6363
/// argument (or neither), from which we need to set the target.source-map.
6464
void SetSourceMapFromArguments(const llvm::json::Object &arguments) const;
6565

66-
/// Sets the stop-disassembly-display setting
67-
void SetStopDisassemblyDisplayFromSettings() const;
68-
6966
/// Prints a welcome message on the editor if the preprocessor variable
7067
/// LLDB_DAP_WELCOME_MESSAGE is defined.
7168
void PrintWelcomeMessage() const;

lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include "DAP.h"
1010
#include "EventHelper.h"
1111
#include "JSONUtils.h"
12+
#include "LLDBUtils.h"
1213
#include "RequestHandler.h"
14+
#include "lldb/lldb-enumerations.h"
1315

1416
namespace lldb_dap {
1517

@@ -51,6 +53,8 @@ static constexpr int StackPageSize = 20;
5153
static bool FillStackFrames(DAP &dap, lldb::SBThread &thread,
5254
llvm::json::Array &stack_frames, int64_t &offset,
5355
const int64_t start_frame, const int64_t levels) {
56+
lldb::StopDisassemblyType stop_disassembly_display =
57+
GetStopDisassemblyDisplay(dap.debugger);
5458
bool reached_end_of_stack = false;
5559
for (int64_t i = start_frame;
5660
static_cast<int64_t>(stack_frames.size()) < levels; i++) {
@@ -67,8 +71,8 @@ static bool FillStackFrames(DAP &dap, lldb::SBThread &thread,
6771
break;
6872
}
6973

70-
stack_frames.emplace_back(CreateStackFrame(frame, dap.frame_format,
71-
dap.stop_disassembly_display));
74+
stack_frames.emplace_back(
75+
CreateStackFrame(frame, dap.frame_format, stop_disassembly_display));
7276
}
7377

7478
if (dap.configuration.displayExtendedBacktrace && reached_end_of_stack) {

lldb/tools/lldb-dap/JSONUtils.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,13 @@ llvm::json::Value CreateSource(llvm::StringRef source_path) {
658658
return llvm::json::Value(std::move(source));
659659
}
660660

661-
bool ShouldDisplayAssemblySource(const lldb::SBLineEntry &line_entry,
662-
const std::string &stop_disassembly_display) {
663-
if (stop_disassembly_display == "never")
661+
bool ShouldDisplayAssemblySource(
662+
const lldb::SBLineEntry &line_entry,
663+
lldb::StopDisassemblyType stop_disassembly_display) {
664+
if (stop_disassembly_display == lldb::eStopDisassemblyTypeNever)
664665
return false;
665666

666-
if (stop_disassembly_display == "always")
667+
if (stop_disassembly_display == lldb::eStopDisassemblyTypeAlways)
667668
return true;
668669

669670
// A line entry of 0 indicates the line is compiler generated i.e. no source
@@ -673,7 +674,8 @@ bool ShouldDisplayAssemblySource(const lldb::SBLineEntry &line_entry,
673674
line_entry.GetLine() == LLDB_INVALID_LINE_NUMBER)
674675
return true;
675676

676-
if (stop_disassembly_display == "no-source" && !file_spec.Exists()) {
677+
if (stop_disassembly_display == lldb::eStopDisassemblyTypeNoSource &&
678+
!file_spec.Exists()) {
677679
return true;
678680
}
679681

@@ -743,7 +745,7 @@ bool ShouldDisplayAssemblySource(const lldb::SBLineEntry &line_entry,
743745
// }
744746
llvm::json::Value
745747
CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
746-
const std::string &stop_disassembly_display) {
748+
lldb::StopDisassemblyType stop_disassembly_display) {
747749
llvm::json::Object object;
748750
int64_t frame_id = MakeDAPFrameID(frame);
749751
object.try_emplace("id", frame_id);

lldb/tools/lldb-dap/JSONUtils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,9 @@ llvm::json::Value CreateSource(llvm::StringRef source_path);
356356
/// \return
357357
/// True if the line entry should be displayed as assembly, false
358358
/// otherwise.
359-
bool ShouldDisplayAssemblySource(const lldb::SBLineEntry &line_entry,
360-
const std::string &stop_disassembly_display);
359+
bool ShouldDisplayAssemblySource(
360+
const lldb::SBLineEntry &line_entry,
361+
lldb::StopDisassemblyType stop_disassembly_display);
361362

362363
/// Create a "StackFrame" object for a LLDB frame object.
363364
///
@@ -384,7 +385,7 @@ bool ShouldDisplayAssemblySource(const lldb::SBLineEntry &line_entry,
384385
/// A "StackFrame" JSON object with that follows the formal JSON
385386
/// definition outlined by Microsoft.
386387
llvm::json::Value CreateStackFrame(lldb::SBFrame &frame, lldb::SBFormat &format,
387-
const std::string &stop_disassembly_display);
388+
lldb::StopDisassemblyType);
388389

389390
/// Create a "StackFrame" label object for a LLDB thread.
390391
///

lldb/tools/lldb-dap/LLDBUtils.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "DAP.h"
1111
#include "JSONUtils.h"
1212
#include "lldb/API/SBStringList.h"
13+
#include "llvm/ADT/StringSwitch.h"
1314

1415
#include <mutex>
1516

@@ -163,17 +164,31 @@ GetEnvironmentFromArguments(const llvm::json::Object &arguments) {
163164
return envs;
164165
}
165166

166-
std::string GetStopDisassemblyDisplay(lldb::SBDebugger &debugger) {
167-
lldb::SBStructuredData result =
167+
lldb::StopDisassemblyType
168+
GetStopDisassemblyDisplay(lldb::SBDebugger &debugger) {
169+
lldb::StopDisassemblyType result =
170+
lldb::StopDisassemblyType::eStopDisassemblyTypeNoDebugInfo;
171+
lldb::SBStructuredData string_result =
168172
debugger.GetSetting("stop-disassembly-display");
169-
const size_t result_length = result.GetStringValue(nullptr, 0);
173+
const size_t result_length = string_result.GetStringValue(nullptr, 0);
170174
if (result_length > 0) {
171175
std::string result_string(result_length, '\0');
172-
result.GetStringValue(result_string.data(), result_length + 1);
173-
return result_string;
176+
string_result.GetStringValue(result_string.data(), result_length + 1);
177+
178+
result =
179+
llvm::StringSwitch<lldb::StopDisassemblyType>(result_string)
180+
.Case("never", lldb::StopDisassemblyType::eStopDisassemblyTypeNever)
181+
.Case("always",
182+
lldb::StopDisassemblyType::eStopDisassemblyTypeAlways)
183+
.Case("no-source",
184+
lldb::StopDisassemblyType::eStopDisassemblyTypeNoSource)
185+
.Case("no-debuginfo",
186+
lldb::StopDisassemblyType::eStopDisassemblyTypeNoDebugInfo)
187+
.Default(
188+
lldb::StopDisassemblyType::eStopDisassemblyTypeNoDebugInfo);
174189
}
175190

176-
return "no-debuginfo";
191+
return result;
177192
}
178193

179194
llvm::Error ToError(const lldb::SBError &error) {

lldb/tools/lldb-dap/LLDBUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ GetEnvironmentFromArguments(const llvm::json::Object &arguments);
163163
///
164164
/// \return
165165
/// The value of the stop-disassembly-display setting
166-
std::string GetStopDisassemblyDisplay(lldb::SBDebugger &debugger);
166+
lldb::StopDisassemblyType GetStopDisassemblyDisplay(lldb::SBDebugger &debugger);
167167

168168
/// Take ownership of the stored error.
169169
llvm::Error ToError(const lldb::SBError &error);

0 commit comments

Comments
 (0)