00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 # include <config.h>
00023 #endif
00024
00025 #include "servemsg.h"
00026 #include "ucserial.h"
00027 #include "useval.h"
00028 #include "utils.h"
00029 #include "debugmsg.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 template <class Serial>
00040 void Stack_frame_io
00041 (
00042 Serial& io,
00043 int& functionid,
00044 int& ip,
00045 int& call_chain,
00046 int& call_depth,
00047 int& eventid,
00048 int& caller_item,
00049 int& num_args,
00050 int& num_vars
00051 )
00052 {
00053 unsigned char c = (unsigned char)Exult_server::dbg_stackframe;
00054 io << c << functionid << ip << call_chain << call_depth
00055 << eventid << caller_item << num_args << num_vars;
00056
00057 }
00058
00059 int Stack_frame_out
00060 (
00061 int fd,
00062 int functionid,
00063 int ip,
00064 int call_chain,
00065 int call_depth,
00066 int eventid,
00067 int caller_item,
00068 int num_args,
00069 int num_vars,
00070 Usecode_value* locals
00071 )
00072 {
00073 static unsigned char buf[Exult_server::maxlength];
00074 unsigned char *ptr = &buf[0];
00075 Serial_out io(ptr);
00076 Stack_frame_io<Serial_out>(io, functionid, ip, call_chain, call_depth,
00077 eventid, caller_item, num_args, num_vars);
00078
00079 int remaining = Exult_server::maxlength - (ptr - buf);
00080 for (int i = 0; i < num_args + num_vars; i++) {
00081 int vallen = locals[i].save(ptr, remaining);
00082
00083 ptr += vallen;
00084 remaining -= vallen;
00085 }
00086
00087 return Exult_server::Send_data(fd, Exult_server::usecode_debugging,
00088 buf, ptr - buf);
00089
00090 }
00091
00092
00093 bool Stack_frame_in
00094 (
00095 unsigned char *data,
00096 int datalen,
00097 int& functionid,
00098 int& ip,
00099 int& call_chain,
00100 int& call_depth,
00101 int& eventid,
00102 int& caller_item,
00103 int& num_args,
00104 int& num_vars,
00105 Usecode_value*& locals
00106 )
00107 {
00108 unsigned char *ptr = data;
00109 Serial_in io(ptr);
00110 Stack_frame_io<Serial_in>(io, functionid, ip, call_chain, call_depth,
00111 eventid, caller_item, num_args, num_vars);
00112
00113 int remaining = datalen - (ptr - data);
00114 locals = new Usecode_value[num_args + num_vars];
00115 for (int i = 0; i < num_args + num_vars; i++) {
00116 unsigned char *tmpptr = ptr;
00117 locals[i].restore(ptr, remaining);
00118
00119 remaining -= (ptr - tmpptr);
00120 }
00121
00122
00123 return (ptr - data) == datalen;
00124
00125 }