15
15
16
16
namespace lldb_dap {
17
17
18
- static llvm::Expected<protocol::DataBreakpointInfoResponseBody>
18
+ namespace {
19
+ std::vector<protocol::DataBreakpointAccessType>
20
+ GetBreakpointAccessTypes (lldb::SBMemoryRegionInfo region) {
21
+ std::vector<protocol::DataBreakpointAccessType> types;
22
+ if (region.IsReadable ())
23
+ types.emplace_back (protocol::eDataBreakpointAccessTypeRead);
24
+ if (region.IsWritable ())
25
+ types.emplace_back (protocol::eDataBreakpointAccessTypeWrite);
26
+ if (region.IsReadable () && region.IsWritable ())
27
+ types.emplace_back (protocol::eDataBreakpointAccessTypeReadWrite);
28
+
29
+ return types;
30
+ }
31
+
32
+ llvm::Expected<protocol::DataBreakpointInfoResponseBody>
19
33
HandleDataBreakpointBytes (DAP &dap,
20
34
const protocol::DataBreakpointInfoArguments &args) {
21
- llvm::StringRef raw_address = args.name ;
35
+ const llvm::StringRef raw_address = args.name ;
22
36
23
37
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
24
38
if (raw_address.getAsInteger <lldb::addr_t >(0 , load_addr)) {
@@ -35,29 +49,35 @@ HandleDataBreakpointBytes(DAP &dap,
35
49
const uint32_t byte_size =
36
50
args.bytes .value_or (dap.target .GetAddressByteSize ());
37
51
38
- protocol::DataBreakpointInfoResponseBody response;
39
- response.dataId = llvm::formatv (" {:x-}/{}" , load_addr, byte_size);
40
-
41
52
lldb::SBMemoryRegionInfo region;
42
53
lldb::SBError err =
43
54
dap.target .GetProcess ().GetMemoryRegionInfo (load_addr, region);
44
- // Only lldb-server supports "qMemoryRegionInfo". So, don't fail this
45
- // request if SBProcess::GetMemoryRegionInfo returns error.
46
- if (err.Success () && !(region.IsReadable () || region.IsWritable ())) {
55
+ std::vector<protocol::DataBreakpointAccessType> access_types =
56
+ GetBreakpointAccessTypes (region);
57
+
58
+ protocol::DataBreakpointInfoResponseBody response;
59
+ if (err.Fail ()) {
60
+ response.dataId = std::nullopt;
61
+ response.description = err.GetCString ();
62
+ return response;
63
+ }
64
+
65
+ if (access_types.empty ()) {
66
+ response.dataId = std::nullopt;
47
67
response.description = llvm::formatv (
48
68
" memory region for address {} has no read or write permissions" ,
49
69
load_addr);
50
-
51
- } else {
52
- response.description =
53
- llvm::formatv (" {} bytes at {:x}" , byte_size, load_addr);
54
- response.accessTypes = {protocol::eDataBreakpointAccessTypeRead,
55
- protocol::eDataBreakpointAccessTypeWrite,
56
- protocol::eDataBreakpointAccessTypeReadWrite};
70
+ return response;
57
71
}
58
72
73
+ response.dataId = llvm::formatv (" {:x-}/{}" , load_addr, byte_size);
74
+ response.description =
75
+ llvm::formatv (" {} bytes at {:x}" , byte_size, load_addr);
76
+ response.accessTypes = std::move (access_types);
77
+
59
78
return response;
60
79
}
80
+ } // namespace
61
81
62
82
// / Obtains information on a possible data breakpoint that could be set on an
63
83
// / expression or variable. Clients should only call this request if the
0 commit comments