Skip to content

Commit 4562055

Browse files
committed
Allow any size for Watchpoints
Current released versions of lldb have seeming partial support for "large" watchpoints. That is they break a user requested watchpoint and size into specific minimal set of working hardware watchpoints supported by the target. Full support for this is in progress in master and works well, allowing to watch any address that's part of some larger structure. In any case, CodeLLDB rejecting a watch due to its size is swimming against the tide and by removing the size restriction we can take advantage of whatever support LLDB adds in the future versions without code changes. The drawback is that we get a slightly less precise error "Setting one of the watchpoint resources failed" in the case where the size is not currently supported.
1 parent fd4762b commit 4562055

File tree

1 file changed

+25
-62
lines changed

1 file changed

+25
-62
lines changed

adapter/codelldb/src/debug_session.rs

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,27 +1054,19 @@ impl DebugSession {
10541054
if let Some(child) = child {
10551055
let addr = child.load_address();
10561056
if addr != lldb::INVALID_ADDRESS {
1057-
let size = child.byte_size();
1058-
if self.is_valid_watchpoint_size(size) {
1059-
let data_id = format!("{}/{}", addr, size);
1060-
let desc = child.name().unwrap_or("");
1061-
Ok(DataBreakpointInfoResponseBody {
1062-
data_id: Some(data_id),
1063-
access_types: Some(vec![
1064-
DataBreakpointAccessType::Read,
1065-
DataBreakpointAccessType::Write,
1066-
DataBreakpointAccessType::ReadWrite,
1067-
]),
1068-
description: format!("{} bytes at {:X} ({})", size, addr, desc),
1069-
..Default::default()
1070-
})
1071-
} else {
1072-
Ok(DataBreakpointInfoResponseBody {
1073-
data_id: None,
1074-
description: "Invalid watchpoint size.".into(),
1075-
..Default::default()
1076-
})
1077-
}
1057+
let size = args.bytes.unwrap_or(child.byte_size() as i64) as usize;
1058+
let data_id = format!("{}/{}", addr, size);
1059+
let desc = child.name().unwrap_or("");
1060+
Ok(DataBreakpointInfoResponseBody {
1061+
data_id: Some(data_id),
1062+
access_types: Some(vec![
1063+
DataBreakpointAccessType::Read,
1064+
DataBreakpointAccessType::Write,
1065+
DataBreakpointAccessType::ReadWrite,
1066+
]),
1067+
description: format!("{} bytes at {:X} ({})", size, addr, desc),
1068+
..Default::default()
1069+
})
10781070
} else {
10791071
Ok(DataBreakpointInfoResponseBody {
10801072
data_id: None,
@@ -1120,12 +1112,6 @@ impl DebugSession {
11201112
description: format!("Invalid address {}", addr),
11211113
..Default::default()
11221114
})
1123-
} else if self.is_valid_watchpoint_size(size) {
1124-
Ok(DataBreakpointInfoResponseBody {
1125-
data_id: None,
1126-
description: format!("Invalid size {} for watchpoint", size),
1127-
..Default::default()
1128-
})
11291115
} else {
11301116
Ok(DataBreakpointInfoResponseBody {
11311117
data_id: Some(format!("{}/{}", addr, size)),
@@ -1145,26 +1131,18 @@ impl DebugSession {
11451131
let addr = result.load_address();
11461132
if addr != lldb::INVALID_ADDRESS {
11471133
let size = args.bytes.unwrap_or(result.byte_size() as i64) as usize;
1148-
if self.is_valid_watchpoint_size(size) {
1149-
let data_id = format!("{}/{}", addr, size);
1150-
let desc = result.name().unwrap_or(expr);
1151-
Ok(DataBreakpointInfoResponseBody {
1152-
data_id: Some(data_id),
1153-
access_types: Some(vec![
1154-
DataBreakpointAccessType::Read,
1155-
DataBreakpointAccessType::Write,
1156-
DataBreakpointAccessType::ReadWrite,
1157-
]),
1158-
description: format!("{} bytes at {:X} ({})", size, addr, desc),
1159-
..Default::default()
1160-
})
1161-
} else {
1162-
Ok(DataBreakpointInfoResponseBody {
1163-
data_id: None,
1164-
description: format!("Expression '{}' results in invalid watchpoint size: {}.", expr, size),
1165-
..Default::default()
1166-
})
1167-
}
1134+
let data_id = format!("{}/{}", addr, size);
1135+
let desc = result.name().unwrap_or(expr);
1136+
Ok(DataBreakpointInfoResponseBody {
1137+
data_id: Some(data_id),
1138+
access_types: Some(vec![
1139+
DataBreakpointAccessType::Read,
1140+
DataBreakpointAccessType::Write,
1141+
DataBreakpointAccessType::ReadWrite,
1142+
]),
1143+
description: format!("{} bytes at {:X} ({})", size, addr, desc),
1144+
..Default::default()
1145+
})
11681146
} else {
11691147
Ok(DataBreakpointInfoResponseBody {
11701148
data_id: None,
@@ -1176,21 +1154,6 @@ impl DebugSession {
11761154
}
11771155
}
11781156

1179-
fn is_valid_watchpoint_size(&self, size: usize) -> bool {
1180-
let addr_size = self.target.address_byte_size();
1181-
match addr_size {
1182-
4 => match size {
1183-
1 | 2 | 4 => true,
1184-
_ => false,
1185-
},
1186-
8 => match size {
1187-
1 | 2 | 4 | 8 => true,
1188-
_ => false,
1189-
},
1190-
_ => true, // No harm in allowing to set an invalid watchpoint, other than user confusion.
1191-
}
1192-
}
1193-
11941157
fn handle_set_data_breakpoints(
11951158
&mut self,
11961159
args: SetDataBreakpointsArguments,

0 commit comments

Comments
 (0)