2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 15:55:40 +01:00
|
|
|
#include "debugtree.hpp"
|
|
|
|
|
#include "prefs.hpp"
|
2019-01-18 17:04:34 +01:00
|
|
|
#include "stdafx.hpp"
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 15:55:40 +01:00
|
|
|
//#include "basic.hpp"
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
IMPLEMENT_DYNAMIC(DebugTree, CTreeCtrl)
|
|
|
|
|
BEGIN_MESSAGE_MAP(DebugTree, CTreeCtrl)
|
|
|
|
|
ON_WM_CREATE()
|
2014-01-31 08:23:00 +13:00
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
DebugTree::DebugTree() : st_nest(0) {}
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
DebugTree::~DebugTree() {}
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
int DebugTree::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
|
|
|
{
|
|
|
|
|
CTreeCtrl::OnCreate(lpCreateStruct);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
SetBkColor(prefs.rgb_bkgrnd);
|
|
|
|
|
SetTextColor(prefs.rgb_default);
|
|
|
|
|
SetFont(&prefs.debugFont);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
static string typeTag(Type* t)
|
|
|
|
|
{
|
|
|
|
|
if (t->intType())
|
|
|
|
|
return "";
|
|
|
|
|
if (t->floatType())
|
|
|
|
|
return "#";
|
|
|
|
|
if (t->stringType())
|
|
|
|
|
return "$";
|
|
|
|
|
if (StructType* s = t->structType())
|
|
|
|
|
return "." + s->ident;
|
|
|
|
|
if (VectorType* v = t->vectorType()) {
|
|
|
|
|
string s = typeTag(v->elementType) + "[";
|
|
|
|
|
for (int k = 0; k < v->sizes.size(); ++k) {
|
|
|
|
|
if (k)
|
|
|
|
|
s += ",";
|
|
|
|
|
s += itoa(v->sizes[k] - 1);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
2019-01-18 17:04:34 +01:00
|
|
|
return s + "]";
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
HTREEITEM DebugTree::insertVar(void* var, Decl* d, const string& name, HTREEITEM it, HTREEITEM parent)
|
|
|
|
|
{
|
|
|
|
|
string s = name;
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
ConstType* ct = d->type->constType();
|
|
|
|
|
StructType* st = d->type->structType();
|
|
|
|
|
VectorType* vt = d->type->vectorType();
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
if (ct) {
|
|
|
|
|
Type* t = ct->valueType;
|
|
|
|
|
s += typeTag(t);
|
|
|
|
|
if (t->intType()) {
|
|
|
|
|
s += "=" + itoa(ct->intValue);
|
|
|
|
|
} else if (t->floatType()) {
|
|
|
|
|
s += "=" + ftoa(ct->floatValue);
|
|
|
|
|
} else if (t->stringType()) {
|
|
|
|
|
s += "=\"" + ct->stringValue + '\"';
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
2019-01-18 17:04:34 +01:00
|
|
|
} else if (var) {
|
|
|
|
|
Type* t = d->type;
|
|
|
|
|
s += typeTag(t);
|
|
|
|
|
if (t->intType()) {
|
|
|
|
|
s += "=" + itoa(*(int*)var);
|
|
|
|
|
} else if (t->floatType()) {
|
|
|
|
|
s += "=" + ftoa(*(float*)var);
|
|
|
|
|
} else if (t->stringType()) {
|
|
|
|
|
BBStr* str = *(BBStr**)var;
|
|
|
|
|
if (str)
|
|
|
|
|
s += "=\"" + *str + '\"';
|
|
|
|
|
else
|
|
|
|
|
s += "=\"\"";
|
|
|
|
|
} else if (st) {
|
|
|
|
|
var = *(void**)var;
|
|
|
|
|
if (var)
|
|
|
|
|
var = *(void**)var;
|
|
|
|
|
if (!var)
|
|
|
|
|
s += " (Null)";
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
if (it) {
|
|
|
|
|
if (GetItemText(it) != s.c_str()) {
|
|
|
|
|
SetItemText(it, s.c_str());
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
2019-01-18 17:04:34 +01:00
|
|
|
} else {
|
|
|
|
|
it = InsertItem(s.c_str(), parent);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++st_nest;
|
2019-01-18 17:04:34 +01:00
|
|
|
if (st) {
|
|
|
|
|
if (var) {
|
|
|
|
|
if (st_nest < 4) {
|
|
|
|
|
HTREEITEM st_it = GetChildItem(it);
|
|
|
|
|
for (int k = 0; k < st->fields->size(); ++k) {
|
|
|
|
|
Decl* st_d = st->fields->decls[k];
|
|
|
|
|
void* st_var = (char*)var + st_d->offset;
|
2014-01-31 08:23:00 +13:00
|
|
|
|
|
|
|
|
char name[256];
|
2019-01-18 17:04:34 +01:00
|
|
|
st_d->getName(name);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
st_it = insertVar(st_var, st_d, name, st_it, it);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
}
|
2019-01-18 17:04:34 +01:00
|
|
|
} else {
|
|
|
|
|
while (HTREEITEM t = GetChildItem(it)) {
|
|
|
|
|
DeleteItem(t);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
--st_nest;
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
return it ? GetNextSiblingItem(it) : 0;
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************* CONSTS ***********************************/
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
ConstsTree::ConstsTree() {}
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void ConstsTree::reset(Environ* env)
|
|
|
|
|
{
|
|
|
|
|
HTREEITEM it = GetChildItem(TVI_ROOT);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
for (int k = 0; k < env->decls->size(); ++k) {
|
|
|
|
|
Decl* d = env->decls->decls[k];
|
|
|
|
|
if (!(d->kind & (DECL_GLOBAL)))
|
|
|
|
|
continue;
|
|
|
|
|
if (d->type->constType()) {
|
2014-01-31 08:23:00 +13:00
|
|
|
char name[256];
|
2019-01-18 17:04:34 +01:00
|
|
|
d->getName(name);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
it = insertVar(0, d, name, it, TVI_ROOT);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************* GLOBALS **********************************/
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
GlobalsTree::GlobalsTree() : module(0), envron(0) {}
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void GlobalsTree::reset(Module* mod, Environ* env)
|
|
|
|
|
{
|
|
|
|
|
module = mod;
|
|
|
|
|
envron = env;
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void GlobalsTree::refresh()
|
|
|
|
|
{
|
|
|
|
|
if (!module || !envron)
|
|
|
|
|
return;
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
HTREEITEM it = GetChildItem(TVI_ROOT);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
for (int k = 0; k < envron->decls->size(); ++k) {
|
|
|
|
|
Decl* d = envron->decls->decls[k];
|
|
|
|
|
if (!(d->kind & (DECL_GLOBAL)))
|
|
|
|
|
continue;
|
|
|
|
|
if (!d->type->constType()) {
|
2014-01-31 08:23:00 +13:00
|
|
|
char name[256];
|
2019-01-18 17:04:34 +01:00
|
|
|
d->getName(name);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void* var = 0;
|
|
|
|
|
module->findSymbol(("_v" + string(name)).c_str(), (int*)&var);
|
|
|
|
|
it = insertVar(var, d, name, it, TVI_ROOT);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************** LOCALS **********************************/
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
LocalsTree::LocalsTree() : envron(0) {}
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void LocalsTree::reset(Environ* env)
|
|
|
|
|
{
|
|
|
|
|
envron = env;
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void LocalsTree::refresh()
|
|
|
|
|
{
|
|
|
|
|
if (!envron || !frames.size())
|
|
|
|
|
return;
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
HTREEITEM item = GetChildItem(TVI_ROOT);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
int n = 0;
|
|
|
|
|
for (n = 0; n < frames.size(); ++n) {
|
|
|
|
|
if (!item || item != frames[n].item)
|
|
|
|
|
break;
|
|
|
|
|
item = GetNextSiblingItem(item);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
while (item) {
|
|
|
|
|
HTREEITEM next = GetNextSiblingItem(item);
|
|
|
|
|
DeleteItem(item);
|
|
|
|
|
item = next;
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
for (; n < frames.size(); ++n) {
|
|
|
|
|
item = frames[n].item = InsertItem(frames[n].func, TVI_ROOT, TVI_LAST);
|
|
|
|
|
if (n < frames.size() - 1)
|
|
|
|
|
refreshFrame(frames[n]);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
refreshFrame(frames.back());
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void LocalsTree::refreshFrame(const Frame& f)
|
|
|
|
|
{
|
|
|
|
|
HTREEITEM it = GetChildItem(f.item);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
for (int n = 0; n < f.env->decls->size(); ++n) {
|
|
|
|
|
Decl* d = f.env->decls->decls[n];
|
|
|
|
|
if (!(d->kind & (DECL_LOCAL | DECL_PARAM)))
|
|
|
|
|
continue;
|
2014-01-31 08:23:00 +13:00
|
|
|
|
|
|
|
|
char name[256];
|
2019-01-18 17:04:34 +01:00
|
|
|
d->getName(name);
|
2014-01-31 08:23:00 +13:00
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
if (!isalpha(name[0]))
|
|
|
|
|
continue;
|
|
|
|
|
it = insertVar((char*)f.frame + d->offset, d, name, it, f.item);
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void LocalsTree::pushFrame(void* f, void* e, const char* func)
|
|
|
|
|
{
|
|
|
|
|
frames.push_back(Frame(f, (Environ*)e, func));
|
2014-01-31 08:23:00 +13:00
|
|
|
}
|
|
|
|
|
|
2019-01-18 17:04:34 +01:00
|
|
|
void LocalsTree::popFrame()
|
|
|
|
|
{
|
2014-01-31 08:23:00 +13:00
|
|
|
frames.pop_back();
|
|
|
|
|
}
|