Skip to content

Commit c3dabbf

Browse files
MatthiasKreilederChad Smith
authored andcommitted
Conditional Breakpoints: UI-support (#287)
1 parent 4ea7cb6 commit c3dabbf

File tree

3 files changed

+104
-5
lines changed

3 files changed

+104
-5
lines changed

gdbgui/src/js/Breakpoints.jsx

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Actions from "./Actions.js";
55
import Util from "./Util.js";
66
import FileOps from "./FileOps.jsx";
77
import { FileLink } from "./Links";
8+
import constants from "./constants.js";
89

910
const BreakpointSourceLineCache = {
1011
_cache: {},
@@ -26,6 +27,13 @@ const BreakpointSourceLineCache = {
2627
};
2728

2829
class Breakpoint extends React.Component {
30+
constructor(props) {
31+
super(props);
32+
this.state = {
33+
breakpoint_condition: "",
34+
editing_breakpoint_condition: false
35+
};
36+
}
2937
get_source_line(fullname, linenum) {
3038
// if we have the source file cached, we can display the line of text
3139
const MAX_CHARS_TO_SHOW_FROM_SOURCE = 40;
@@ -78,6 +86,23 @@ class Breakpoint extends React.Component {
7886
return `${bkpt.times} hits`;
7987
}
8088
}
89+
on_change_bkpt_cond(e) {
90+
this.setState({
91+
breakpoint_condition: e.target.value,
92+
editing_breakpoint_condition: true
93+
});
94+
}
95+
on_key_up_bktp_cond(number, e) {
96+
if (e.keyCode === constants.ENTER_BUTTON_NUM) {
97+
this.setState({ editing_breakpoint_condition: false });
98+
Breakpoints.set_breakpoint_condition(e.target.value, number);
99+
}
100+
}
101+
on_break_cond_click(e) {
102+
this.setState({
103+
editing_breakpoint_condition: true
104+
});
105+
}
81106
render() {
82107
let b = this.props.bkpt,
83108
checked = b.enabled === "y" ? "checked" : "",
@@ -122,17 +147,63 @@ class Breakpoint extends React.Component {
122147
);
123148
} else {
124149
let func = b.func === undefined ? "(unknown function)" : b.func;
150+
let break_condition = (
151+
<div
152+
onClick={this.on_break_cond_click.bind(this)}
153+
className="inline"
154+
title={`${
155+
this.state.breakpoint_condition ? "Modify or remove" : "Add"
156+
} breakpoint condition`}
157+
>
158+
<span className="glyphicon glyphicon-edit"></span>
159+
<span className={`italic ${this.state.breakpoint_condition ? "bold" : ""}`}>
160+
condition
161+
</span>
162+
</div>
163+
);
164+
if (this.state.editing_breakpoint_condition) {
165+
break_condition = (
166+
<input
167+
type="text"
168+
style={{
169+
display: "inline",
170+
width: "110px",
171+
padding: "10px 10px",
172+
height: "25px",
173+
fontSize: "1em"
174+
}}
175+
placeholder="Break condition"
176+
className="form-control"
177+
onKeyUp={this.on_key_up_bktp_cond.bind(this, b.number)}
178+
onChange={this.on_change_bkpt_cond.bind(this)}
179+
value={this.state.breakpoint_condition}
180+
/>
181+
);
182+
}
125183

126184
const times_hit = this.get_num_times_hit(b);
127185
function_jsx = (
128186
<div style={{ display: "inline" }}>
129187
<span className="monospace" style={{ paddingRight: "5px" }}>
130188
{info_glyph} {func}
131189
</span>
132-
<span style={{ color: "#bbbbbb", fontStyle: "italic" }}>
190+
<span
191+
style={{
192+
color: "#bbbbbb",
193+
fontStyle: "italic",
194+
paddingRight: "5px"
195+
}}
196+
>
133197
thread groups: {b["thread-groups"]}
134198
</span>
135-
<span style={{ color: "#bbbbbb", fontStyle: "italic", paddingLeft: "5px" }}>
199+
<span>{break_condition}</span>
200+
<span
201+
style={{
202+
color: "#bbbbbb",
203+
fontStyle: "italic",
204+
paddingLeft: "5px"
205+
}}
206+
>
136207
{times_hit}
137208
</span>
138209
</div>
@@ -203,6 +274,12 @@ class Breakpoints extends React.Component {
203274
GdbApi.run_gdb_command([`-break-enable ${bkpt_num}`, GdbApi.get_break_list_cmd()]);
204275
}
205276
}
277+
static set_breakpoint_condition(condition, bkpt_num) {
278+
GdbApi.run_gdb_command([
279+
`-break-condition ${bkpt_num} ${condition}`,
280+
GdbApi.get_break_list_cmd()
281+
]);
282+
}
206283
static remove_breakpoint_if_present(fullname, line) {
207284
if (Breakpoints.has_breakpoint(fullname, line)) {
208285
let number = Breakpoints.get_breakpoint_number(fullname, line);
@@ -256,6 +333,12 @@ class Breakpoints extends React.Component {
256333
.filter(b => b.fullname_to_display === fullname && b.enabled !== "y")
257334
.map(b => parseInt(b.line));
258335
}
336+
static get_conditional_breakpoint_lines_for_file(fullname) {
337+
return store
338+
.get("breakpoints")
339+
.filter(b => b.fullname_to_display === fullname && b.cond !== undefined)
340+
.map(b => parseInt(b.line));
341+
}
259342
static save_breakpoints(payload) {
260343
store.set("breakpoints", []);
261344
if (payload && payload.BreakpointTable && payload.BreakpointTable.body) {

gdbgui/src/js/SourceCode.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class SourceCode extends React.Component {
159159
line_num_being_rendered,
160160
has_bkpt,
161161
has_disabled_bkpt,
162+
has_conditional_bkpt,
162163
assembly_for_line,
163164
paused_addr
164165
) {
@@ -188,10 +189,12 @@ class SourceCode extends React.Component {
188189
}
189190

190191
let gutter_cls = "";
191-
if (has_bkpt) {
192-
gutter_cls = "breakpoint";
193-
} else if (has_disabled_bkpt) {
192+
if (has_disabled_bkpt) {
194193
gutter_cls = "disabled_breakpoint";
194+
} else if (has_conditional_bkpt) {
195+
gutter_cls = "conditional_breakpoint";
196+
} else if (has_bkpt) {
197+
gutter_cls = "breakpoint";
195198
}
196199

197200
let assembly_content = [];
@@ -359,6 +362,9 @@ class SourceCode extends React.Component {
359362
disabled_breakpoint_lines = Breakpoints.get_disabled_breakpoint_lines_for_file(
360363
this.state.fullname_to_render
361364
),
365+
conditional_breakpoint_lines = Breakpoints.get_conditional_breakpoint_lines_for_file(
366+
this.state.fullname_to_render
367+
),
362368
line_gdb_is_paused_on = this.state.paused_on_frame
363369
? parseInt(this.state.paused_on_frame.line)
364370
: 0;
@@ -380,6 +386,8 @@ class SourceCode extends React.Component {
380386
let has_bkpt = bkpt_lines.indexOf(line_num_being_rendered) !== -1,
381387
has_disabled_bkpt =
382388
disabled_breakpoint_lines.indexOf(line_num_being_rendered) !== -1,
389+
has_conditional_bkpt =
390+
conditional_breakpoint_lines.indexOf(line_num_being_rendered) !== -1,
383391
is_gdb_paused_on_this_line = this.is_gdb_paused_on_this_line(
384392
line_num_being_rendered,
385393
line_gdb_is_paused_on
@@ -394,6 +402,7 @@ class SourceCode extends React.Component {
394402
line_num_being_rendered,
395403
has_bkpt,
396404
has_disabled_bkpt,
405+
has_conditional_bkpt,
397406
assembly_for_line,
398407
paused_addr
399408
)

gdbgui/static/css/gdbgui.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ td{
2929
.bold{
3030
font-weight: bold;
3131
}
32+
.italic{
33+
font-style: italic;
34+
}
3235
.pre{
3336
white-space: pre;
3437
}
@@ -170,6 +173,10 @@ div.breakpoint:hover div.breakpoint_trashcan,
170173
.line_num.disabled_breakpoint{
171174
background: #ffd6d7 !important;
172175
}
176+
.line_num.conditional_breakpoint{
177+
background: #ff9966 !important;
178+
color:black;
179+
}
173180
td.assembly{
174181
padding-bottom: 0px;
175182
padding-top: 0px;

0 commit comments

Comments
 (0)