src/Pure/Tools/debugger.scala
changeset 60876 52edced9cce5
parent 60875 ee23c1d21ac3
child 60878 1f0d2bbcf38b
equal deleted inserted replaced
60875:ee23c1d21ac3 60876:52edced9cce5
    15     pos: Position.T,
    15     pos: Position.T,
    16     function: String)
    16     function: String)
    17 
    17 
    18   sealed case class State(
    18   sealed case class State(
    19     session: Session = new Session(Resources.empty),
    19     session: Session = new Session(Resources.empty),
       
    20     active: Int = 0,
       
    21     active_breakpoints: Set[Long] = Set.empty,
    20     focus: Option[Position.T] = None,  // position of active GUI component
    22     focus: Option[Position.T] = None,  // position of active GUI component
    21     threads: Map[String, List[Debug_State]] = Map.empty,  // thread name ~> stack of debug states
    23     threads: Map[String, List[Debug_State]] = Map.empty,  // thread name ~> stack of debug states
    22     output: Map[String, Command.Results] = Map.empty)  // thread name ~> output messages
    24     output: Map[String, Command.Results] = Map.empty)  // thread name ~> output messages
    23   {
    25   {
    24     def set_session(new_session: Session): State =
    26     def set_session(new_session: Session): State =
    25       copy(session = new_session)
    27       copy(session = new_session)
       
    28 
       
    29     def inc_active: State = copy(active = active + 1)
       
    30     def dec_active: State = copy(active = active - 1)
       
    31 
       
    32     def toggle_breakpoint(serial: Long): State =
       
    33     {
       
    34       val active_breakpoints1 =
       
    35         if (active_breakpoints(serial)) active_breakpoints - serial
       
    36       else active_breakpoints + serial
       
    37       copy(active_breakpoints = active_breakpoints1)
       
    38     }
    26 
    39 
    27     def set_focus(new_focus: Option[Position.T]): State =
    40     def set_focus(new_focus: Option[Position.T]): State =
    28       copy(focus = new_focus)
    41       copy(focus = new_focus)
    29 
    42 
    30     def get_thread(thread_name: String): List[Debug_State] =
    43     def get_thread(thread_name: String): List[Debug_State] =
   122   {
   135   {
   123     global_state.change(_.set_session(session))
   136     global_state.change(_.set_session(session))
   124     current_state().session.protocol_command("Debugger.init")
   137     current_state().session.protocol_command("Debugger.init")
   125   }
   138   }
   126 
   139 
       
   140   def is_active(): Boolean = current_state().active > 0
       
   141   def inc_active(): Unit = global_state.change(_.inc_active)
       
   142   def dec_active(): Unit = global_state.change(_.dec_active)
       
   143 
       
   144   def breakpoint_active(serial: Long): Option[Boolean] =
       
   145   {
       
   146     val state = current_state()
       
   147     if (state.active > 0) Some(state.active_breakpoints(serial)) else None
       
   148   }
       
   149 
       
   150   def toggle_breakpoint(serial: Long): Unit =
       
   151     global_state.change(_.toggle_breakpoint(serial))
       
   152 
   127   def focus(new_focus: Option[Position.T]): Boolean =
   153   def focus(new_focus: Option[Position.T]): Boolean =
   128     global_state.change_result(state => (state.focus != new_focus, state.set_focus(new_focus)))
   154     global_state.change_result(state => (state.focus != new_focus, state.set_focus(new_focus)))
   129 
   155 
   130   def cancel(thread_name: String): Unit =
   156   def cancel(thread_name: String): Unit =
   131     current_state().session.protocol_command("Debugger.cancel", thread_name)
   157     current_state().session.protocol_command("Debugger.cancel", thread_name)