Blame view

src/idl_extern/CMTotal_for_Dustemwrap/dxfinish.pro 2.72 KB
517b8f98   Annie Hughes   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;+
; NAME:
;   DXFINISH
;
; AUTHOR:
;   Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
;   craigm@lheamail.gsfc.nasa.gov
;
; PURPOSE:
;   Sets an IDL breakpoint to stop upon return of the current procedure
;
; CALLING SEQUENCE:
;   DXFINISH [ , NLEVELS ]
;
; DESCRIPTION: 
;
;   DXFINISH is a convenience routine for setting IDL breakpoints.
;
;   DXFINISH sets a breakpoint so that when the current procedure
;   finishes, execution will stop.  Often when debugging one wants to
;   let the current procedure complete but stop at the next level.
;   DXFINISH does exactly that.
;
;   DXFINISH examines the state of the current IDL call stack,
;   determines at what point the current procedure will return, and
;   sets a breakpoint there.  Note that the procedure in which the
;   breakpoint is set must be compiled and on disk.
;
;   By default the breakpoint is set with the ONCE keyword.
;
; INPUTS:
;
;   NLEVELS - Number of call levels up to set breakpoint.  Default is
;             1.
;
; KEYWORDS:
;
;   ONCE - if set, then the breakpoint will only occur once.  Default
;          value is SET, so ONCE=0 must be passed explicitly to
;          disable this function.
;
; EXAMPLE:
;
;   dxfinish
;
;   Set breakpoint in calling procedure.
;
; SEE ALSO:
;
;   BREAKPOINT, DXBREAK, DXCLEAR
;
; MODIFICATION HISTORY:
;   Written, 15 Apr 2000
;
;  $Id: dxfinish.pro,v 1.2 2001/02/09 04:57:16 craigm Exp $
;  
;-
; Copyright (C) 2000, Craig Markwardt
; This software is provided as is without any warranty whatsoever.
; Permission to use, copy, modify, and distribute modified or
; unmodified copies is granted, provided this copyright and disclaimer
; are included unchanged.
;-
pro dxfinish, nlevels0, once=once

@dxcommon.pro
  ;; Make sure we know what level we are in the call stack 
  dxlreset
  tb = dxptrace(dbtraceback)
  if n_elements(tb) LT 2 then begin
      print, 'INFO: this procedure will return to the main level'
      return
  endif

  ;; Pull the calling procedure
  if n_elements(nlevels0) EQ 0 then nlevels0 = 1L
  n = n_elements(tb)
  nlevels = floor(nlevels0(0)) > 0 < (n-1)
  path = (tb(nlevels).path)(0)
  name = (tb(nlevels).name)(0)
  fline = (tb(nlevels).line)(0)
  if fline EQ 0 OR name EQ '' OR path EQ '' OR path EQ '/dev/tty' $
    OR path EQ filepath(/terminal) then begin
      print, 'ERROR: calling procedure '+tb(nlevels).name+' is not on disk'
      return
  endif
  line = tb(nlevels).line
  line = line(0)
  if line EQ 0 then begin
      print, 'ERROR: calling procedure is not available'
      return
  endif

  ;; Add one to the line!
  line = line + 1
  if n_elements(once) EQ 0 then once = 1
  breakpoint, path, line, /set, once=keyword_set(once)
  print, 'Breakpoint set at: '+strupcase(name)+'    '+strtrim(line,2)
end