00001 /* 00002 * ucdebugging.h - Debugging-related functions for usecode 00003 * 00004 * Copyright (C) 2002 The Exult Team 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #ifndef _UCDEBUGGING_H 00022 #define _UCDEBUGGING_H 00023 00024 #include <list> 00025 00026 class Stack_frame; 00027 00028 enum Breakpoint_type { BP_anywhere, BP_location, BP_stepover, BP_finish }; 00029 // BP_anywhere: break on any instruction (for "step into") 00030 // BP_location: break on a specific code offset (function + ip) 00031 // BP_stepover: break on next instruction in same function (or previous func) 00032 // BP_finish : finish current function and break in previous function 00033 00034 // other (future) possibilities: break on access to local/global vars, 00035 // break when usecode is run on a specific object, 00036 // break on errors, 00037 // break on a special 'break to debugger' opcode, 00038 // break on a specific or any intrinsic call 00039 00040 class Breakpoint 00041 { 00042 public: 00043 int id; // used to identify breakpoint to remote debugger 00044 bool once; // delete when triggered 00045 00046 virtual Breakpoint_type get_type() const =0; 00047 00048 virtual bool check(Stack_frame *frame) const =0; 00049 00050 virtual void serialize(int fd) const =0; 00051 00052 protected: 00053 Breakpoint(bool once); 00054 }; 00055 00056 class AnywhereBreakpoint : public Breakpoint 00057 { 00058 public: 00059 AnywhereBreakpoint(); 00060 00061 virtual Breakpoint_type get_type() const { return BP_anywhere; } 00062 virtual bool check(Stack_frame *frame) const { return true; } 00063 00064 virtual void serialize(int fd) const { } // +++++ implement this? 00065 }; 00066 00067 class LocationBreakpoint : public Breakpoint 00068 { 00069 public: 00070 LocationBreakpoint(int functionid, int ip, bool once = false); 00071 00072 virtual Breakpoint_type get_type() const { return BP_location; } 00073 virtual bool check(Stack_frame *frame) const; 00074 00075 virtual void serialize(int fd) const; 00076 00077 private: 00078 00079 int functionid; 00080 int ip; 00081 }; 00082 00083 class StepoverBreakpoint : public Breakpoint 00084 { 00085 public: 00086 StepoverBreakpoint(Stack_frame *frame); 00087 00088 virtual Breakpoint_type get_type() const { return BP_stepover; } 00089 virtual bool check(Stack_frame *frame) const; 00090 00091 virtual void serialize(int fd) const { } // +++++ implement this? 00092 00093 private: 00094 00095 int call_chain; 00096 int call_depth; 00097 }; 00098 00099 class FinishBreakpoint : public Breakpoint 00100 { 00101 public: 00102 FinishBreakpoint(Stack_frame *frame); 00103 00104 virtual Breakpoint_type get_type() const { return BP_finish; } 00105 virtual bool check(Stack_frame *frame) const; 00106 00107 virtual void serialize(int fd) const { } // +++++ implement this? 00108 00109 private: 00110 int call_chain; 00111 int call_depth; 00112 }; 00113 00114 00115 class Breakpoints 00116 { 00117 public: 00118 Breakpoints(); 00119 ~Breakpoints(); 00120 00121 void add(Breakpoint* breakpoint); 00122 void remove(Breakpoint* breakpoint); 00123 bool remove(int id); 00124 00125 int check(Stack_frame *frame); 00126 00127 void transmit(int fd); 00128 00129 static int getNewID() { return lastID++; } 00130 00131 private: 00132 static int lastID; 00133 00134 std::list<Breakpoint*> breaks; 00135 }; 00136 00137 #endif