@@ -5,6 +5,7 @@ import Actions from "./Actions.js";
55import Util from "./Util.js" ;
66import FileOps from "./FileOps.jsx" ;
77import { FileLink } from "./Links" ;
8+ import constants from "./constants.js" ;
89
910const BreakpointSourceLineCache = {
1011 _cache : { } ,
@@ -26,6 +27,13 @@ const BreakpointSourceLineCache = {
2627} ;
2728
2829class 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 ) {
0 commit comments