Skip to content

Commit b5b9374

Browse files
committed
[lldb-dap] move create createAssemblyReference to DAP.cpp
1 parent 5d87638 commit b5b9374

File tree

4 files changed

+52
-65
lines changed

4 files changed

+52
-65
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,13 +624,8 @@ ReplMode DAP::DetectReplMode(lldb::SBFrame frame, std::string &expression,
624624
}
625625

626626
std::optional<protocol::Source> DAP::ResolveSource(lldb::SBAddress address) {
627-
628-
if (DisplayAssemblySource(debugger, address)) {
629-
auto create_reference = [this](lldb::addr_t addr) {
630-
return CreateSourceReference(addr);
631-
};
632-
return CreateAssemblySource(target, address, create_reference);
633-
}
627+
if (DisplayAssemblySource(debugger, address))
628+
return ResolveAssemblySource(address);
634629

635630
lldb::SBLineEntry line_entry = GetLineEntryForAddress(target, address);
636631
if (!line_entry.IsValid())
@@ -639,6 +634,44 @@ std::optional<protocol::Source> DAP::ResolveSource(lldb::SBAddress address) {
639634
return CreateSource(line_entry.GetFileSpec());
640635
}
641636

637+
std::optional<protocol::Source>
638+
DAP::ResolveAssemblySource(lldb::SBAddress address) {
639+
lldb::SBSymbol symbol = address.GetSymbol();
640+
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
641+
std::string name;
642+
if (symbol.IsValid()) {
643+
load_addr = symbol.GetStartAddress().GetLoadAddress(target);
644+
name = symbol.GetName();
645+
} else {
646+
load_addr = address.GetLoadAddress(target);
647+
name = GetLoadAddressString(load_addr);
648+
}
649+
650+
if (load_addr == LLDB_INVALID_ADDRESS)
651+
return std::nullopt;
652+
653+
protocol::Source source;
654+
source.sourceReference = CreateSourceReference(load_addr);
655+
lldb::SBModule module = address.GetModule();
656+
if (module.IsValid()) {
657+
lldb::SBFileSpec file_spec = module.GetFileSpec();
658+
if (file_spec.IsValid()) {
659+
std::string path = GetSBFileSpecPath(file_spec);
660+
if (!path.empty())
661+
source.path = path + '`' + name;
662+
}
663+
}
664+
665+
source.name = std::move(name);
666+
667+
// Mark the source as deemphasized since users will only be able to view
668+
// assembly for these frames.
669+
source.presentationHint =
670+
protocol::Source::eSourcePresentationHintDeemphasize;
671+
672+
return source;
673+
}
674+
642675
bool DAP::RunLLDBCommands(llvm::StringRef prefix,
643676
llvm::ArrayRef<std::string> commands) {
644677
bool required_command_failed = false;

lldb/tools/lldb-dap/DAP.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,18 @@ struct DAP {
265265
/// definition outlined by Microsoft.
266266
std::optional<protocol::Source> ResolveSource(lldb::SBAddress address);
267267

268+
/// Create a "Source" JSON object as described in the debug adapter
269+
/// definition.
270+
///
271+
/// \param[in] address
272+
/// The address to use when populating out the "Source" object.
273+
///
274+
/// \return
275+
/// An optional "Source" JSON object that follows the formal JSON
276+
/// definition outlined by Microsoft.
277+
std::optional<protocol::Source>
278+
ResolveAssemblySource(lldb::SBAddress address);
279+
268280
/// \return
269281
/// \b false if a fatal error was found while executing these commands,
270282
/// according to the rules of \a LLDBUtils::RunLLDBCommands.

lldb/tools/lldb-dap/ProtocolUtils.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,6 @@ static bool ShouldDisplayAssemblySource(
4646
return false;
4747
}
4848

49-
std::optional<protocol::Source> CreateAssemblySource(
50-
const lldb::SBTarget &target, lldb::SBAddress address,
51-
llvm::function_ref<int32_t(lldb::addr_t)> create_reference) {
52-
53-
lldb::SBSymbol symbol = address.GetSymbol();
54-
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
55-
std::string name;
56-
if (symbol.IsValid()) {
57-
load_addr = symbol.GetStartAddress().GetLoadAddress(target);
58-
name = symbol.GetName();
59-
} else {
60-
load_addr = address.GetLoadAddress(target);
61-
name = GetLoadAddressString(load_addr);
62-
}
63-
64-
if (load_addr == LLDB_INVALID_ADDRESS)
65-
return std::nullopt;
66-
67-
protocol::Source source;
68-
source.sourceReference = create_reference(load_addr);
69-
lldb::SBModule module = address.GetModule();
70-
if (module.IsValid()) {
71-
lldb::SBFileSpec file_spec = module.GetFileSpec();
72-
if (file_spec.IsValid()) {
73-
std::string path = GetSBFileSpecPath(file_spec);
74-
if (!path.empty())
75-
source.path = path + '`' + name;
76-
}
77-
}
78-
79-
source.name = std::move(name);
80-
81-
// Mark the source as deemphasized since users will only be able to view
82-
// assembly for these frames.
83-
source.presentationHint =
84-
protocol::Source::PresentationHint::eSourcePresentationHintDeemphasize;
85-
86-
return source;
87-
}
88-
8949
std::optional<protocol::Source> CreateSource(const lldb::SBFileSpec &file) {
9050
if (!file.IsValid())
9151
return std::nullopt;

lldb/tools/lldb-dap/ProtocolUtils.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,6 @@ namespace lldb_dap {
3030
/// definition outlined by Microsoft.
3131
std::optional<protocol::Source> CreateSource(const lldb::SBFileSpec &file);
3232

33-
/// Create a "Source" JSON object as described in the debug adapter definition.
34-
///
35-
/// \param[in] target
36-
/// The target that has the address.
37-
///
38-
/// \param[in] address
39-
/// The address to use when populating out the "Source" object.
40-
///
41-
/// \param[in] create_reference
42-
/// function used to create a source_reference
43-
///
44-
/// \return
45-
/// An optional "Source" JSON object that follows the formal JSON
46-
/// definition outlined by Microsoft.
47-
std::optional<protocol::Source> CreateAssemblySource(
48-
const lldb::SBTarget &target, lldb::SBAddress address,
49-
llvm::function_ref<int32_t(lldb::addr_t)> create_reference);
50-
5133
/// Checks if the given source is for assembly code.
5234
bool IsAssemblySource(const protocol::Source &source);
5335

0 commit comments

Comments
 (0)