Skip to content

Commit 3ad8dec

Browse files
committed
[lldb-dap] move create createAssemblyReference to DAP.cpp
1 parent 4064ac6 commit 3ad8dec

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
@@ -638,13 +638,8 @@ ReplMode DAP::DetectReplMode(lldb::SBFrame frame, std::string &expression,
638638
}
639639

640640
std::optional<protocol::Source> DAP::ResolveSource(lldb::SBAddress address) {
641-
642-
if (DisplayAssemblySource(debugger, address)) {
643-
auto create_reference = [this](lldb::addr_t addr) {
644-
return CreateSourceReference(addr);
645-
};
646-
return CreateAssemblySource(target, address, create_reference);
647-
}
641+
if (DisplayAssemblySource(debugger, address))
642+
return ResolveAssemblySource(address);
648643

649644
lldb::SBLineEntry line_entry = GetLineEntryForAddress(target, address);
650645
if (!line_entry.IsValid())
@@ -653,6 +648,44 @@ std::optional<protocol::Source> DAP::ResolveSource(lldb::SBAddress address) {
653648
return CreateSource(line_entry.GetFileSpec());
654649
}
655650

651+
std::optional<protocol::Source>
652+
DAP::ResolveAssemblySource(lldb::SBAddress address) {
653+
lldb::SBSymbol symbol = address.GetSymbol();
654+
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
655+
std::string name;
656+
if (symbol.IsValid()) {
657+
load_addr = symbol.GetStartAddress().GetLoadAddress(target);
658+
name = symbol.GetName();
659+
} else {
660+
load_addr = address.GetLoadAddress(target);
661+
name = GetLoadAddressString(load_addr);
662+
}
663+
664+
if (load_addr == LLDB_INVALID_ADDRESS)
665+
return std::nullopt;
666+
667+
protocol::Source source;
668+
source.sourceReference = CreateSourceReference(load_addr);
669+
lldb::SBModule module = address.GetModule();
670+
if (module.IsValid()) {
671+
lldb::SBFileSpec file_spec = module.GetFileSpec();
672+
if (file_spec.IsValid()) {
673+
std::string path = GetSBFileSpecPath(file_spec);
674+
if (!path.empty())
675+
source.path = path + '`' + name;
676+
}
677+
}
678+
679+
source.name = std::move(name);
680+
681+
// Mark the source as deemphasized since users will only be able to view
682+
// assembly for these frames.
683+
source.presentationHint =
684+
protocol::Source::eSourcePresentationHintDeemphasize;
685+
686+
return source;
687+
}
688+
656689
bool DAP::RunLLDBCommands(llvm::StringRef prefix,
657690
llvm::ArrayRef<std::string> commands) {
658691
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
@@ -29,24 +29,6 @@ namespace lldb_dap {
2929
/// definition outlined by Microsoft.
3030
std::optional<protocol::Source> CreateSource(const lldb::SBFileSpec &file);
3131

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

0 commit comments

Comments
 (0)