OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtk/] [library/] [browserwin.itb] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Browswer window for Insight.
2
# Copyright 1998, 1999, 2001 Red Hat
3
#
4
# This program is free software; you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License (GPL) as published by
6
# the Free Software Foundation; either version 2 of the License, or (at
7
# your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
 
14
 
15
# ----------------------------------------------------------------------
16
# Implements Browser window for gdb
17
#
18
# ----------------------------------------------------------------------
19
 
20
# ------------------------------------------------------------------
21
#  CONSTRUCTOR - create new browser window
22
# ------------------------------------------------------------------
23
 
24
option add *BrowserWin.textBackground  white
25
 
26
body BrowserWin::constructor {args} {
27
  #eval itk_initialize $args
28
  window_name "Function Browser"
29
 
30
  set Current(filename) {}
31
  set Current(function) {}
32
  _build_win
33
 
34
  eval itk_initialize $args
35
 
36
  # Create the toplevel binding for this class
37
  bind Configure_Browser_$this  [code $this _resize]
38
 
39
  add_hook file_changed_hook [code $this _fill_file_box]
40
}
41
 
42
# ------------------------------------------------------------------
43
#  DESTRUCTOR - destroy window containing widget
44
# ------------------------------------------------------------------
45
body BrowserWin::destructor {} {
46
 
47
  if {$resize_after != ""} {
48
    after cancel $resize_after
49
  }
50
  if {$filter_trace_after != ""} {
51
    after cancel $filter_trace_after
52
  }
53
 
54
  if {$MoreVisible} {
55
    pref set gdb/browser/view_is_open 1
56
  } else {
57
    pref set gdb/browser/view_is_open 0
58
  }
59
 
60
  remove_hook file_changed_hook [code $this _fill_file_box]
61
  trace vdelete [pref varname gdb/search/last_symbol] \
62
    w [code $this _filter_trace_proc]
63
}
64
 
65
# ------------------------------------------------------------------
66
#  METHOD:  _build_win - build the main browser window
67
# ------------------------------------------------------------------
68
body BrowserWin::_build_win {} {
69
  global PREFS_state gdb_ImageDir
70
 
71
  # Three frames: regexp, listboxes, and drop-down pane
72
 
73
  itk_component add filter {
74
    iwidgets::labeledframe $itk_interior.filter -labeltext "Filter" \
75
      -labelrelief groove -labelborderwidth 2 -ipadx 6 -ipady 4
76
  }
77
 
78
  append labelUpdateCode [$itk_component(filter) clientHandlesConfigure 1] "\n"
79
 
80
  itk_component add browser {
81
    frame $itk_interior.browser
82
  }
83
 
84
  itk_component add view {
85
    frame $itk_interior.view
86
  }
87
 
88
  # Set up the contents of the Filter frame
89
 
90
  itk_component add filt_label {
91
    label [$itk_component(filter) childsite].lbl -text {Show if function } \
92
      -font src-font
93
  }
94
 
95
  itk_component add filt_type {
96
    combobox::combobox [$itk_component(filter) childsite].type -height 4 \
97
      -width 15 -editable 0 \
98
      -command [code $this _set_filter_mode] \
99
      -font src-font
100
  } { }
101
 
102
  # Fill the filter mode combo-box
103
 
104
  foreach elem $filter_modes {
105
    $itk_component(filt_type) list insert end $elem
106
  }
107
 
108
  set cur_filter_mode [pref get gdb/search/filter_mode]
109
  if {[lsearch $filter_modes $cur_filter_mode] < 0} {
110
    set cur_filter_mode [lindex $filter_modes 0]
111
  }
112
  $itk_component(filt_type) entryset $cur_filter_mode
113
 
114
  itk_component add filt_entry {
115
    entry [$itk_component(filter) childsite].ent -font src-font \
116
      -textvariable [pref varname gdb/search/last_symbol] -background white
117
  } {
118
    usual Entry
119
    rename -background -textbackground textBackground Background
120
  }
121
 
122
  # Watch keystrokes into the entry box and filter on them...
123
 
124
  trace variable [pref varname gdb/search/last_symbol] w \
125
    [code $this _filter_trace_proc]
126
 
127
  pack $itk_component(filt_label) -side left
128
  pack $itk_component(filt_type) -side left -padx 4 -fill y -pady 5
129
  pack $itk_component(filt_entry) -side right -fill both -expand 1 \
130
    -padx 6 -pady 5
131
 
132
  # Files Listbox for the Browser frame
133
  itk_component add file_box {
134
    iwidgets::scrolledlistbox $itk_component(browser).files \
135
      -selectmode extended -exportselection false \
136
      -labeltext "Files" -labelpos nw -labelrelief groove \
137
      -labelborderwidth 2 -ipadx 8 -ipady 6 \
138
      -childsitepos s -hscrollmode none -textbackground white
139
  }
140
 
141
  append labelUpdateCode [$itk_component(file_box) clientHandlesConfigure 1] \
142
    "\n"
143
 
144
  bind [$itk_component(file_box) component listbox]  \
145
    [code $this _process_file_selection %y]
146
 
147
  itk_component add file_sep {
148
    frame [$itk_component(file_box) childsite].sep -relief raised -height 2 \
149
      -borderwidth 1
150
  }
151
 
152
  itk_component add file_hide {
153
    checkbutton [$itk_component(file_box) childsite].hide \
154
      -text {Hide .h files} \
155
      -variable [pref varname gdb/browser/hide_h] \
156
      -command [code $this _file_hide_h]
157
  }
158
 
159
  itk_component add file_all {
160
    button [$itk_component(file_box) childsite].sel \
161
      -text {Select All} -width 12 \
162
      -command [code $this _select 1]
163
  }
164
 
165
  # Pack the file box in, and grid in the separate bits of the child-site.
166
 
167
  pack $itk_component(file_box) -side left -fill both -expand yes \
168
    -padx 5 -pady 5
169
 
170
  grid $itk_component(file_sep) -column 0 -row 0 -columnspan 2 \
171
    -sticky ew -pady 8
172
  grid $itk_component(file_hide) -column 0 -row 1 -padx 5 -sticky w
173
  grid $itk_component(file_all) -column 1 -row 1 -padx 5 -sticky e
174
 
175
  grid columnconfigure [$itk_component(file_box) childsite] 0 -weight 1
176
 
177
  # Functions Listbox for the Browser frame
178
 
179
  itk_component add func_box {
180
    iwidgets::scrolledlistbox $itk_component(browser).funcs \
181
      -selectmode extended \
182
      -exportselection false \
183
      -labeltext "Functions" -labelpos nw -labelrelief groove \
184
      -labelborderwidth 2 -ipadx 8 -ipady 6 \
185
      -childsitepos s -hscrollmode none -textbackground white
186
  }
187
 
188
  append labelUpdateCode [$itk_component(func_box) clientHandlesConfigure 1] \
189
    "\n"
190
 
191
  bind [$itk_component(func_box) component listbox]  \
192
    [code $this _process_func_selection %y]
193
 
194
  itk_component add func_sep {
195
    frame [$itk_component(func_box) childsite].sep -relief raised \
196
      -height 2 -borderwidth 1
197
  }
198
 
199
  itk_component add func_bp_label {
200
    label [$itk_component(func_box) childsite].bpl -text {Breakpoints:}
201
  }
202
 
203
  itk_component add func_add_bp {
204
    button [$itk_component(func_box) childsite].abp -text {Set} \
205
      -command [code $this do_all_bp 1]
206
  }
207
 
208
  itk_component add func_remove_bp {
209
    button [$itk_component(func_box) childsite].rbp -text {Delete} \
210
      -command [code $this do_all_bp 0]
211
  }
212
 
213
  # Pack in the Function box, and grid in the bits of the child-site
214
 
215
  pack $itk_component(func_box) -side right -fill both -expand yes \
216
    -padx 5 -pady 5
217
 
218
  grid $itk_component(func_sep) -row 0 -column 0 -columnspan 3 \
219
    -sticky ew -pady 8
220
  grid $itk_component(func_bp_label) -row 1 -column 0 -padx 5
221
  grid $itk_component(func_remove_bp) -row 1 -column 1  -padx 5
222
  grid $itk_component(func_add_bp) -row 1 -column 2  -padx 5
223
 
224
  grid columnconfigure [$itk_component(func_box) childsite] 1 -weight 1
225
  grid columnconfigure [$itk_component(func_box) childsite] 2 -weight 1
226
 
227
  # "More" frame for viewing source
228
 
229
  if {[lsearch [image names] _MORE_] == -1} {
230
    image create photo _MORE_ -file [file join $gdb_ImageDir more.gif]
231
    image create photo _LESS_ -file [file join $gdb_ImageDir less.gif]
232
  }
233
 
234
  itk_component add view_vis {
235
    frame $itk_interior.view.visible
236
  }
237
 
238
  itk_component add view_more {
239
    button $itk_component(view_vis).btn -image _MORE_ -relief flat \
240
                    -command [code $this _toggle_more]
241
  }
242
 
243
  itk_component add view_label {
244
    label $itk_component(view_vis).lbl -text {View Source}
245
  }
246
 
247
  itk_component add view_sep {
248
    frame $itk_component(view_vis).sep -relief raised -borderwidth 1 -height 2
249
  }
250
 
251
  pack $itk_component(view_more) -side left -padx 10 -pady 10
252
  pack $itk_component(view_label) -side left -padx 10 -pady 10
253
  pack $itk_component(view_sep) -padx 4 -pady 10 -fill x -expand 1
254
 
255
  grid columnconfigure $itk_component(view_vis) 2 -weight 1
256
 
257
  pack $itk_component(view_vis) -side top -fill x -expand yes
258
 
259
  # Key bindings for "visible" frames
260
  bind_plain_key $itk_component(filt_entry) Return [list $this search]
261
  bind $itk_component(func_box) <3> [code $this _toggle_bp %y]
262
 
263
  # Construct hidden frame
264
 
265
  itk_component add view_hidden {
266
    frame $itk_interior.hidden
267
  }
268
 
269
  itk_component add view_src {
270
    SrcTextWin $itk_component(view_hidden).src -Tracing 0 \
271
      -parent $this -ignore_var_balloons 1
272
  } {
273
    rename -background -textbackground textBackground Background
274
  }
275
 
276
  $itk_component(view_src) configure -textheight 2i
277
 
278
  itk_component add view_bottom {
279
    frame $itk_component(view_hidden).bottom
280
  }
281
 
282
  itk_component add view_name {
283
    label $itk_component(view_hidden).name -font src-font
284
  }
285
 
286
  itk_component add view_func {
287
    combobox::combobox $itk_component(view_bottom).combo -maxheight 15 \
288
      -font src-font \
289
      -command [code $this _goto_func]
290
  } {
291
    # Should be able to do this, but can't cause the combobox doesn't
292
    # fake up a MegaWidget well enough
293
    #rename -background -textbackground textBackground Background
294
  }
295
 
296
  itk_component add view_mode {
297
    combobox::combobox $itk_component(view_bottom).mode -width 9 \
298
      -font src-font \
299
      -command [code $this mode]
300
  } {
301
    #rename -background -textbackground textBackground Background
302
  }
303
 
304
  itk_component add view_search {
305
    entry $itk_component(view_bottom).search -borderwidth 2 \
306
      -font src-font -width 10 \
307
      -background white
308
  } {
309
    rename -background -textbackground textBackground Background
310
  }
311
 
312
  # Pack all the components of view_hidden into the frame:
313
 
314
  pack $itk_component(view_search) -side right -padx 5 -fill none \
315
    -expand 1 -anchor e
316
  pack $itk_component(view_mode) -side right -padx 5
317
  pack $itk_component(view_func) -side left
318
 
319
  pack $itk_component(view_name) -side top -fill x -padx 5 -pady 3
320
  pack $itk_component(view_bottom) -side bottom -fill x -pady 3 -padx 5
321
  pack $itk_component(view_src) -fill both -expand 1 -padx 5 -pady 3
322
 
323
 
324
  # Fill combo boxes
325
  $itk_component(view_mode) list insert end SOURCE
326
  $itk_component(view_mode) list insert end ASSEMBLY
327
  $itk_component(view_mode) list insert end MIXED
328
 
329
  # don't allow SRC+ASM mode... $itk_component(view_mode) insert end SRC+ASM
330
  $itk_component(view_mode) entryset [$itk_component(view_src) mode_get]
331
 
332
  # Key bindings for hidden frame
333
  bind_plain_key $itk_component(view_search) Return \
334
    [code $this _search_src forwards]
335
  bind_plain_key $itk_component(view_search) Shift-Return \
336
    [code $this _search_src backwards]
337
 
338
  # Now map everything onto the screen
339
  grid $itk_component(filter) -column 0 -row 0 -padx 6 -pady 4 -sticky ew
340
  grid $itk_component(browser) -column 0 -row 1 -sticky nsew
341
  grid $itk_component(view)  -column 0 -row 2 -pady 4 -padx 6 -sticky ew
342
 
343
  # Now set up any initial values:
344
 
345
  set MoreVisible [pref get gdb/browser/view_is_open]
346
  set BrowserHeight [pref get gdb/browser/top_height]
347
  set Width [pref get gdb/browser/width]
348
 
349
  if {$BrowserHeight > 0} {
350
    grid rowconfigure $itk_component(hull) $componentToRow(browser) \
351
      -minsize $BrowserHeight
352
  }
353
 
354
  if {$Width > 0} {
355
    grid columnconfigure $itk_component(hull) 0 -minsize $Width
356
  }
357
 
358
  grid rowconfigure $itk_component(hull) 1 -weight 1
359
  grid columnconfigure $itk_component(hull) 0 -weight 1
360
 
361
  update idletasks
362
  eval $labelUpdateCode
363
 
364
  if {$MoreVisible} {
365
    debug "Got moreVisible at 1"
366
    set MoreVisible 0
367
    _toggle_more 1
368
  }
369
 
370
  # Fill file box
371
  _fill_file_box
372
 
373
  after idle "
374
    update idletasks
375
    grid rowconfigure $itk_component(hull) 2 \
376
        -minsize \[winfo height $itk_component(view)\]
377
  "
378
 
379
  # Finally set up the top level bindings:
380
  _bind_toplevel 1
381
 
382
}
383
 
384
# ------------------------------------------------------------------
385
#  METHOD:  _filter_trace_proc
386
#           This is called when something is entered in the filter
387
#           box.  The actual filtering is done in an after to avoid
388
#           flashing too much if the user is typing quickly.
389
# ------------------------------------------------------------------
390
body BrowserWin::_filter_trace_proc {v1 v2 mode} {
391
  if {$filter_trace_after != ""} {
392
    after cancel $filter_trace_after
393
  }
394
  set filter_trace_after [after 100 [code $this _filter_trace_after]]
395
}
396
 
397
# ------------------------------------------------------------------
398
#  METHOD:  _filter_trace_after
399
#           This is a wrapper around search, needed to pass to trace
400
# ------------------------------------------------------------------
401
body BrowserWin::_filter_trace_after {} {
402
  set filter_trace_after ""
403
  search
404
}
405
 
406
# ------------------------------------------------------------------
407
#  METHOD:  _search_src
408
#           Search for text or jump to a specific line
409
#           in source window, going in the specified DIRECTION.
410
# ------------------------------------------------------------------
411
body BrowserWin::_search_src {direction} {
412
  set exp [$itk_component(view_search) get]
413
  $itk_component(view_src) search $exp $direction
414
}
415
 
416
# ------------------------------------------------------------------
417
#  METHOD:  search
418
#           Search for functions matching regexp/pattern
419
#           in specified files
420
# ------------------------------------------------------------------
421
body BrowserWin::search {} {
422
 
423
  set files [$itk_component(file_box) getcurselection]
424
 
425
  if {[llength $files] == 0} {
426
    return
427
  }
428
 
429
  _freeze_me
430
 
431
  set filt_pat [format $filter_regexp($cur_filter_mode) \
432
                  [pref get gdb/search/last_symbol]]
433
 
434
  if {[llength $files] == [$itk_component(file_box) size]} {
435
    set err [catch {gdb_search functions $filt_pat \
436
                    -filename 1} matches]
437
  } else {
438
    set err [catch {gdb_search functions $filt_pat \
439
                      -files $files -filename 1} matches]
440
  }
441
 
442
  if {$err} {
443
    debug "ERROR searching for [pref get gdb/search/last_symbol]: $matches"
444
    _thaw_me
445
    return
446
  }
447
 
448
  $itk_component(func_box) delete 0 end
449
 
450
  set i -1
451
  catch {unset index_to_file}
452
 
453
  foreach func [lsort -command "list_element_strcmp 0" $matches] {
454
    $itk_component(func_box) insert end [lindex $func 0]
455
    set index_to_file([incr i]) [lindex $func 1]
456
  }
457
  _thaw_me
458
}
459
 
460
# ------------------------------------------------------------------
461
#  METHOD:  _toggle_more
462
#           Toggle display of source listing
463
# ------------------------------------------------------------------
464
body BrowserWin::_toggle_more {{in_constructor 0}} {
465
 
466
  debug "Running toggle_more with MoreVisible: $MoreVisible"
467
  # Temporarily disable the resize bindings before opening the window.
468
  _bind_toplevel 0
469
 
470
  set topHeight [winfo height $_top]
471
  set topWidth  [winfo width $_top]
472
 
473
  if {!$MoreVisible} {
474
 
475
    $itk_component(view_label) configure -text {Hide Source}
476
    $itk_component(view_more) configure -image _LESS_
477
    grid $itk_component(view_hidden) -row 3 -column 0 -sticky nsew \
478
      -padx 6 -pady 4
479
 
480
    # Check the stored height.  Restore the view to this if it will fit on the
481
    # screen.  Otherwise, figure out how big to make it...
482
 
483
    set height [pref get gdb/browser/view_height]
484
    set bottom [expr {[winfo y $_top] + $topHeight}]
485
 
486
    set extra [expr {[winfo screenheight $_top] - $bottom - 20}]
487
 
488
    if {$height < 0} {
489
      set default [winfo pixels $_top 3i]
490
      set height [expr {$extra > $default ? $default : $extra}]
491
    } else {
492
      set height [expr {$extra > $height ? $height : $extra}]
493
    }
494
 
495
    wm geometry $_top ${topWidth}x[expr {$topHeight + $height}]
496
    grid rowconfigure $itk_component(hull) $componentToRow(view_hidden) \
497
      -weight 1
498
    grid rowconfigure $itk_component(hull) $componentToRow(browser) -weight 0
499
 
500
    pref set gdb/browser/view_height $height
501
 
502
    set MoreVisible 1
503
    update idletasks
504
 
505
    # If we have a selected function, display it in the window
506
 
507
    set f [$itk_component(func_box) getcurselection]
508
 
509
    if {$f != ""} {
510
      # FIXME - If there is more than 1 function selected, I just load the
511
      # first.  It would probably be better to load the one nearest to the
512
      # middle of the current window on the listbox.  But I am running out
513
      # of time for this round...
514
 
515
      if {[llength $f] > 1} {
516
        set f [lindex $f 0]
517
      }
518
 
519
      _fill_source $f
520
    } else {
521
      # If no function was chosen, try the file box...
522
 
523
      set f [$itk_component(file_box) getcurselection]
524
      if { $f != "" } {
525
        if {[llength $f] > 1} {
526
          set f [lindex $f 0]
527
        }
528
        _fill_source $f 0
529
      }
530
    }
531
  } else {
532
    if {!$in_constructor} {
533
      pref set gdb/browser/view_height \
534
        [winfo height $itk_component(view_hidden)]
535
    }
536
 
537
    $itk_component(view_label) configure -text {View Source}
538
    $itk_component(view_more) configure -image _MORE_
539
 
540
    grid propagate $itk_component(func_box) 0
541
    grid propagate $itk_component(file_box) 0
542
 
543
    set newTopHeight [expr {$topHeight - \
544
                              [winfo height $itk_component(view_hidden)]}]
545
    wm geometry $_top ${topWidth}x$newTopHeight
546
 
547
    if {!$in_constructor} {
548
      grid rowconfigure $itk_component(hull) $componentToRow(browser) -weight 1
549
      grid forget $itk_component(view_hidden)
550
      grid rowconfigure $itk_component(hull) $componentToRow(view_hidden) \
551
        -minsize 0 -weight 0
552
    }
553
 
554
    set MoreVisible 0
555
 
556
    # Flush the changes
557
 
558
    update idletasks
559
 
560
    grid propagate $itk_component(func_box) 1
561
    grid propagate $itk_component(file_box) 1
562
 
563
  }
564
 
565
  # restore the bindings
566
 
567
  _bind_toplevel 1
568
 
569
}
570
 
571
# ------------------------------------------------------------------
572
#  METHOD:  _bind_toplevel
573
#            Setup the bindings for the toplevel.
574
# ------------------------------------------------------------------
575
body BrowserWin::_bind_toplevel {install} {
576
 
577
  set bindings [bindtags $_top]
578
  if {$install} {
579
    bindtags $_top [linsert $bindings 0 Configure_Browser_$this]
580
  } else {
581
    set bindLoc [lsearch $bindings Configure_Browser_$this]
582
    bindtags $_top [lreplace $bindings $bindLoc $bindLoc]
583
  }
584
}
585
 
586
# ------------------------------------------------------------------
587
#  METHOD:  _do_resize
588
#            Does the actual work of the resize.
589
# ------------------------------------------------------------------
590
body BrowserWin::_do_resize {} {
591
 
592
  update idletasks
593
  debug "Running _do_resize"
594
 
595
  set width [winfo width $itk_component(hull)]
596
  pref set gdb/browser/width      $width
597
  grid columnconfigure $itk_component(hull) 0 -minsize $width
598
 
599
  if {$MoreVisible} {
600
    set v_height [winfo height $itk_component(view_hidden)]
601
    pref set gdb/browser/view_height $v_height
602
    grid rowconfigure $itk_component(hull) $componentToRow(view_hidden) \
603
      -minsize $v_height
604
    grid rowconfigure $itk_component(hull) $componentToRow(browser)
605
  } else {
606
    set b_height [winfo height $itk_component(browser)]
607
    pref set gdb/browser/top_height $b_height
608
    grid rowconfigure $itk_component(hull) $componentToRow(browser) \
609
      -minsize $b_height
610
  }
611
 
612
  eval $labelUpdateCode
613
  pack propagate $_top 1
614
 
615
  set resize_after ""
616
 
617
}
618
 
619
# ------------------------------------------------------------------
620
#  METHOD:  _resize
621
#            Resize "itk_component(view_hidden)" after all configure events
622
# ------------------------------------------------------------------
623
body BrowserWin::_resize {} {
624
 
625
  pack propagate $_top 0
626
 
627
  if {$MoreVisible} {
628
    grid rowconfigure $itk_component(hull) $componentToRow(view_hidden) \
629
      -minsize 0
630
  } else {
631
    grid rowconfigure $itk_component(hull) 1 -minsize 0
632
  }
633
 
634
  grid columnconfigure $itk_component(hull) 0 -minsize 0
635
 
636
  if {$resize_after != ""} {
637
    after cancel $resize_after
638
  }
639
  set resize_after [after 100 "[code $this _do_resize]"]
640
 
641
}
642
 
643
# ------------------------------------------------------------------
644
#  METHOD:  _process_file_selection
645
#            This fills the func combo, and the more window if it
646
#            is currently open with the hit in the File combobox.
647
# ------------------------------------------------------------------
648
body BrowserWin::_process_file_selection {y} {
649
 
650
  set curIndex [$itk_component(file_box) nearest $y]
651
  set curSelection [$itk_component(file_box) curselection]
652
 
653
  # We got a button-release - First make sure the click selected the item...
654
 
655
  if {[lsearch $curIndex $curSelection] >= 0} {
656
    _fill_source [$itk_component(file_box) get $curIndex] 0
657
  } else {
658
    # If the item was deselected, go back to the first one in the list...
659
    # It would be better to keep a stack of the clicked items, and go to the
660
    # last one on the stack.  But in extended mode, this is tricky.  FIXME
661
 
662
    if {[llength $curSelection] > 0} {
663
      _fill_source [$itk_component(file_box) get [lindex $curSelection 0]] 0
664
    } else {
665
      _fill_source ""
666
    }
667
  }
668
 
669
  search
670
 
671
}
672
 
673
# ------------------------------------------------------------------
674
#  METHOD:  _process_func_selection
675
#            This points the  more window to the hit in the Func combobox
676
#            if it is currently open.
677
# ------------------------------------------------------------------
678
body BrowserWin::_process_func_selection {y} {
679
 
680
  set curIndex [$itk_component(func_box) nearest $y]
681
  set curSelection [$itk_component(func_box) curselection]
682
 
683
  # We got a button-release - First make sure the click selected the item...
684
 
685
  if {[lsearch $curIndex $curSelection] >= 0} {
686
    set funcName [$itk_component(func_box) get $curIndex]
687
    set fileName $index_to_file($curIndex)
688
    _fill_source $funcName 1 $fileName
689
  }
690
 
691
}
692
 
693
# ------------------------------------------------------------------
694
#  METHOD:  do_all_bp
695
#           Toggle a bp at every selected function in FuncLB
696
# ------------------------------------------------------------------
697
body BrowserWin::do_all_bp {onp} {
698
 
699
  set funcs [$itk_component(func_box) getcurselection]
700
  _freeze_me
701
 
702
  foreach f $funcs {
703
    if {[catch {gdb_loc $f} linespec]} {
704
      dbug W "Could not gdb_loc \"$f\""
705
      return
706
    }
707
    set bpnum [bp_exists $linespec]
708
    if {$bpnum == -1 && $onp} {
709
 
710
      # FIXME: gdb_set_bp is the preferred method, but it requires
711
      # a file and line number. This doesn't work very well for
712
      # templates...
713
      gdb_cmd "break $f"
714
    } elseif {!$onp} {
715
      catch {gdb_cmd "delete $bpnum"}
716
    }
717
  }
718
  _thaw_me
719
}
720
 
721
# ------------------------------------------------------------------
722
#  METHOD:  _toggle_bp
723
#           Toggle bp at function specified by the given Y
724
#           coordinate in the listbox
725
# ------------------------------------------------------------------
726
body BrowserWin::_toggle_bp {y} {
727
 
728
  set f [$itk_component(func_box) get [$itk_component(func_box) nearest $y]]
729
  if {$f != ""} {
730
    if {[catch {gdb_loc $f} linespec]} {
731
      return
732
    }
733
    set bpnum [bp_exists $linespec]
734
    if {$bpnum == -1} {
735
      # FIXME: gdb_set_bp is the preferred method, but it requires
736
      # a file and line number. This doesn't work very well for
737
      # templates...
738
      gdb_cmd "break $f"
739
    } else {
740
      catch {gdb_cmd "delete $bpnum"}
741
    }
742
  }
743
}
744
 
745
# ------------------------------------------------------------------
746
#  METHOD:  _select
747
#           (Un/Highlight all files in the files list
748
# ------------------------------------------------------------------
749
body BrowserWin::_select {highlight} {
750
  if {$highlight} {
751
    $itk_component(file_box) selection set 0 end
752
  } else {
753
    $itk_component(file_box) selection clear 0 end
754
  }
755
  search
756
}
757
 
758
# ------------------------------------------------------------------
759
#  METHOD:  _set_filter_mode
760
#           React to changes in the filter mode
761
# ------------------------------------------------------------------
762
body BrowserWin::_set_filter_mode {w mode} {
763
  if {[string compare $mode $cur_filter_mode] != 0} {
764
    set cur_filter_mode $mode
765
    pref set gdb/search/filter_mode $mode
766
    search
767
  }
768
}
769
 
770
# ------------------------------------------------------------------
771
#  METHOD:  _file_hide_h
772
#           Run when the "Hide .h files" preference is chosen.
773
# ------------------------------------------------------------------
774
body BrowserWin::_file_hide_h {} {
775
 
776
  _fill_file_box
777
  search
778
 
779
}
780
 
781
# ------------------------------------------------------------------
782
#  METHOD:  _fill_source
783
#           Helper function to fill the srctextwin
784
#           when needed.
785
# ------------------------------------------------------------------
786
body BrowserWin::_fill_source {f {funcp 1} {filename ""}} {
787
 
788
  if {!$MoreVisible } {
789
    return
790
  }
791
 
792
  if {($funcp && [string compare $f $Current(function)]) \
793
        || [string compare $f $Current(filename)]} {
794
    if {!$funcp} {
795
      if {$filename == ""} {
796
        set f $f:1
797
      } else {
798
        set f $f:$filename
799
      }
800
    }
801
 
802
    if {[catch {gdb_loc $f} linespec]} {
803
      return
804
    }
805
 
806
    lassign $linespec foo funcname name line addr pc_addr lib
807
    set file_changed [string compare $Current(filename) $name]
808
    # fill srctextwin
809
 
810
    if {$file_changed} {
811
      # Set the file name label:
812
      $itk_component(view_name) configure -text $name:
813
      _freeze_me
814
    }
815
 
816
    $itk_component(view_src) location BROWSE_TAG $name $funcname \
817
      $line $addr $pc_addr lib
818
 
819
    if {$file_changed} {
820
      _thaw_me
821
    }
822
 
823
    set Current(function) $funcname
824
    # fill func combo
825
    if {$file_changed} {
826
      set Current(filename) $name
827
      _fill_funcs_combo $name
828
    }
829
    # Set current function in combo box
830
    $itk_component(view_func) entryset $f
831
 
832
  }
833
}
834
 
835
# ------------------------------------------------------------------
836
#  METHOD:  mode
837
#           Function called by srctextwin when the display
838
#           mode changes
839
# ------------------------------------------------------------------
840
body BrowserWin::mode {w {mode ""} {go 1}} {
841
  if {$mode != ""} {
842
    $itk_component(view_src) mode_set $mode $go
843
    $itk_component(view_mode) entryset $mode
844
  }
845
}
846
 
847
# ------------------------------------------------------------------
848
# METHOD:  _goto_func
849
#          Callback for the function combo box which
850
#          sets the srctextwin looking at the given function (VAL)
851
# ------------------------------------------------------------------
852
body BrowserWin::_goto_func {w {val ""}} {
853
  if {$val != ""} {
854
    set mang 0
855
    if {[info exists _mangled_func($val)]} {
856
      set mang $_mangled_func($val)
857
    }
858
    if {$mang} {
859
      set loc $val
860
    } else {
861
      set fn [lindex [::file split $Current(filename)] end]
862
      set loc $fn:$val
863
    }
864
    debug "GOTO \"$loc\""
865
    if {![catch {gdb_loc $loc} result]} {
866
      lassign $result foo funcname name line addr pc_addr lib
867
      $itk_component(view_src) location BROWSE_TAG $name $funcname \
868
        $line $addr $pc_addr lib
869
    } else {
870
      dbug W "gdb_loc returned \"$result\""
871
    }
872
  }
873
}
874
# ------------------------------------------------------------------
875
#  METHOD:  _fill_file_box
876
#           This private method fills the file listbox
877
# ------------------------------------------------------------------
878
body BrowserWin::_fill_file_box {} {
879
  # It would be cool if gdb_listfiles took a regexp to match,
880
  # but it doesn't...
881
 
882
  $itk_component(file_box) clear
883
  set allFiles [gdb_listfiles]
884
 
885
  if {[pref get gdb/browser/hide_h]} {
886
    foreach file $allFiles {
887
      if {[string compare [file extension $file] ".h"]} {
888
        $itk_component(file_box) insert end $file
889
      }
890
    }
891
  } else {
892
    foreach file $allFiles {
893
      $itk_component(file_box) insert end $file
894
    }
895
  }
896
  search
897
}
898
# ------------------------------------------------------------------
899
#  METHOD:  _fill_funcs_combo
900
#           This private method fills the functions combo box
901
#           with all the functions in NAME.
902
# ------------------------------------------------------------------
903
body BrowserWin::_fill_funcs_combo {name} {
904
 
905
  $itk_component(view_func) list delete 0 end
906
  if {$name != ""} {
907
    set maxlen 10
908
    if {[catch {gdb_listfuncs $name} listfuncs]} {
909
      tk_messageBox -icon error -default ok \
910
        -title "GDB" -type ok -modal system \
911
        -message "This file can not be found or does not contain\ndebugging information."
912
      return
913
    }
914
    foreach f $listfuncs {
915
      lassign $f func mang
916
      if {$func == "global constructors keyed to main"} {continue}
917
      set _mangled_func($func) $mang
918
      $itk_component(view_func) list insert end $func
919
      if {[string length $func] > $maxlen} {
920
        set maxlen [string length $func]
921
      }
922
    }
923
    $itk_component(view_func) configure -width [expr {$maxlen + 1}]
924
  }
925
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.