Skip to content

Commit ea52649

Browse files
committed
Address code style comments
1 parent 88b48a5 commit ea52649

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

lldb/tools/lldb-dap/JSONUtils.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,7 @@ std::optional<llvm::json::Value> CreateSource(lldb::SBFrame &frame) {
690690
// "instructionPointerReference": {
691691
// "type": "string",
692692
// "description": "A memory reference for the current instruction
693-
// pointer
694-
// in this frame."
693+
// pointer in this frame."
695694
// },
696695
// "moduleId": {
697696
// "type": ["integer", "string"],
@@ -1180,17 +1179,15 @@ std::string VariableDescription::GetResult(llvm::StringRef context) {
11801179
return description.trim().str();
11811180
}
11821181

1183-
lldb::addr_t GetMemoryReference(lldb::SBValue v) {
1184-
if (!v.GetType().IsPointerType() && !v.GetType().IsArrayType()) {
1185-
return LLDB_INVALID_ADDRESS;
1186-
}
1182+
std::optional<lldb::addr_t> GetMemoryReference(lldb::SBValue v) {
1183+
if (!v.GetType().IsPointerType() && !v.GetType().IsArrayType())
1184+
return std::nullopt;
11871185

11881186
lldb::SBValue deref = v.Dereference();
1189-
if (!deref.IsValid()) {
1190-
return LLDB_INVALID_ADDRESS;
1191-
}
1192-
1193-
return deref.GetLoadAddress();
1187+
lldb::addr_t load_addr = deref.GetLoadAddress();
1188+
if (load_addr != LLDB_INVALID_ADDRESS)
1189+
return load_addr;
1190+
return std::nullopt;
11941191
}
11951192

11961193
// "Variable": {
@@ -1369,9 +1366,8 @@ llvm::json::Value CreateVariable(lldb::SBValue v, int64_t variablesReference,
13691366
else
13701367
object.try_emplace("variablesReference", (int64_t)0);
13711368

1372-
if (lldb::addr_t addr = GetMemoryReference(v); addr != LLDB_INVALID_ADDRESS) {
1373-
object.try_emplace("memoryReference", "0x" + llvm::utohexstr(addr));
1374-
}
1369+
if (std::optional<lldb::addr_t> addr = GetMemoryReference(v))
1370+
object.try_emplace("memoryReference", "0x" + llvm::utohexstr(*addr));
13751371

13761372
object.try_emplace("$__lldb_extensions", desc.GetVariableExtensionsJSON());
13771373
return llvm::json::Value(std::move(object));

lldb/tools/lldb-dap/JSONUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ struct VariableDescription {
445445
///
446446
/// According to the DAP documentation, the `memoryReference` should
447447
/// refer to the pointee, not to the address of the pointer itself.
448-
lldb::addr_t GetMemoryReference(lldb::SBValue v);
448+
std::optional<lldb::addr_t> GetMemoryReference(lldb::SBValue v);
449449

450450
/// Create a "Variable" object for a LLDB thread object.
451451
///

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,10 +1617,8 @@ void request_evaluate(const llvm::json::Object &request) {
16171617
} else {
16181618
body.try_emplace("variablesReference", (int64_t)0);
16191619
}
1620-
if (lldb::addr_t addr = GetMemoryReference(value);
1621-
addr != LLDB_INVALID_ADDRESS) {
1622-
body.try_emplace("memoryReference", "0x" + llvm::utohexstr(addr));
1623-
}
1620+
if (std::optional<lldb::addr_t> addr = GetMemoryReference(value))
1621+
body.try_emplace("memoryReference", "0x" + llvm::utohexstr(*addr));
16241622
}
16251623
}
16261624
response.try_emplace("body", std::move(body));
@@ -3794,10 +3792,8 @@ void request_setVariable(const llvm::json::Object &request) {
37943792
variable, /*is_permanent=*/false);
37953793
body.try_emplace("variablesReference", newVariablesReference);
37963794

3797-
if (lldb::addr_t addr = GetMemoryReference(variable);
3798-
addr != LLDB_INVALID_ADDRESS) {
3799-
body.try_emplace("memoryReference", "0x" + llvm::utohexstr(addr));
3800-
}
3795+
if (std::optional<lldb::addr_t> addr = GetMemoryReference(variable))
3796+
body.try_emplace("memoryReference", "0x" + llvm::utohexstr(*addr));
38013797
} else {
38023798
EmplaceSafeString(body, "message", std::string(error.GetCString()));
38033799
}
@@ -4324,7 +4320,7 @@ void request_readMemory(const llvm::json::Object &request) {
43244320
}
43254321

43264322
addr += GetSigned(arguments, "offset", 0);
4327-
const auto requested_count = GetUnsigned(arguments, "count", 0);
4323+
const uint64_t requested_count = GetUnsigned(arguments, "count", 0);
43284324
lldb::SBMemoryRegionInfo region_info;
43294325
lldb::SBError memRegError = process.GetMemoryRegionInfo(addr, region_info);
43304326
if (memRegError.Fail()) {
@@ -4335,15 +4331,15 @@ void request_readMemory(const llvm::json::Object &request) {
43354331
g_dap.SendJSON(llvm::json::Value(std::move(response)));
43364332
return;
43374333
}
4338-
const auto available_count =
4334+
const uint64_t available_count =
43394335
std::min(requested_count, region_info.GetRegionEnd() - addr);
4340-
const auto unavailable_count = requested_count - available_count;
4336+
const uint64_t unavailable_count = requested_count - available_count;
43414337

43424338
std::vector<uint8_t> buf;
43434339
buf.resize(available_count);
43444340
if (available_count > 0) {
43454341
lldb::SBError memReadError;
4346-
auto bytes_read =
4342+
uint64_t bytes_read =
43474343
process.ReadMemory(addr, buf.data(), available_count, memReadError);
43484344
if (memReadError.Fail()) {
43494345
response["success"] = false;

0 commit comments

Comments
 (0)