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 <iostream>
00026 #include <iomanip>
00027
00028 #include "stackframe.h"
00029 #include "useval.h"
00030 #include "ucinternal.h"
00031 #include "utils.h"
00032 #include "ucfunction.h"
00033
00034
00035 int Stack_frame::LastCallChainID = 0;
00036
00037 Stack_frame::Stack_frame(Usecode_function *fun,
00038 int event,
00039 Game_object *caller,
00040 int chain, int depth)
00041 : function(fun), ip(0), data(0), externs(0), code(0), endp(0),
00042 line_number(-1), call_chain(chain), call_depth(depth),
00043 num_externs(0), num_args(0), num_vars(0), locals(0), eventid(event),
00044 caller_item(caller), save_sp(0)
00045 {
00046 ip = function->code;
00047 endp = ip + function->len;
00048
00049 int data_len;
00050 if (!fun->extended)
00051 data_len = Read2(ip);
00052 else
00053 data_len = (sint32)(Read4(ip));
00054
00055 data = ip;
00056
00057 ip += data_len;
00058 num_args = Read2(ip);
00059
00060
00061 num_vars = Read2(ip);
00062
00063
00064 int num_locals = num_vars + num_args;
00065 locals = new Usecode_value[num_locals];
00066
00067 num_externs = Read2(ip);
00068 externs = ip;
00069
00070 ip += 2 * num_externs;
00071
00072 code = ip;
00073 }
00074
00075 Stack_frame::~Stack_frame()
00076 {
00077 delete[] locals;
00078 }
00079
00080 std::ostream& operator<<(std::ostream& out, Stack_frame& frame)
00081 {
00082
00083
00084
00085
00086
00087 out << "#" << frame.call_depth << ": 0x"
00088 << std::hex << std::setw(4) << std::setfill('0')
00089 << (int)(frame.ip - frame.code) << " in 0x"
00090 << std::setw(4) << frame.function->id
00091 << "(obj=" << std::setw(8) << (long)frame.caller_item
00092 << ",ev=" << frame.eventid
00093 << std::setfill(' ') << std::dec;
00094
00095 for (int i=0; i < frame.num_args; i++)
00096 out << ", " << frame.locals[i];
00097
00098 out << ")";
00099
00100 return out;
00101 }