The idea is to auto-dereference a pointer
when a pointer is found when GDB send it's output, I add a child (a dot)
Then, the tree is populated and there is a + to expand (dereference) the pointer
class GdbCmd_InfoLocals : public DebuggerCmd
{
DebuggerTree* m_pDTree;
public:
/** @param tree The tree to display the locals. */
GdbCmd_InfoLocals(DebuggerDriver* driver, DebuggerTree* dtree)
: DebuggerCmd(driver),
m_pDTree(dtree)
{
m_Cmd << _T("info locals");
}
void ParseOutput(const wxString& output)
{
wxArrayString lines = GetArrayFromString(output, _T('\n'));
wxString locals;
locals << _T("Local variables = {");
for (unsigned int i = 0; i < lines.GetCount(); ++i){
if(lines[i].Contains(_T("0x")))
{
locals << lines[i] << _T(" = {.}");
}
else
{
locals << lines[i];
}
locals << _T(',');
}
locals << _T("}") << _T('\n');
m_pDTree->BuildTree(0, locals, wsfGDB);
}
};
void DebuggerTree::OnTreeExpand(wxTreeEvent& event)
{
wxTreeItemIdValue cookie;
wxTreeItemId currentTreeItem = event.GetItem();
wxTreeItemId firstChildTreeItem = m_pTree->GetFirstChild(currentTreeItem, cookie);
DebuggerDriver* pDriver = m_pDebugger->GetState().GetDriver();
if(m_pTree->GetItemText(firstChildTreeItem) == wxT(".")){
m_pTree->SetItemText(firstChildTreeItem, _T('*') + m_pTree->GetItemText(currentTreeItem).BeforeFirst(_T('=')));
GdbCmd_Output *cmd = new GdbCmd_Output(pDriver, this, _T("*") + TreeItemToPath(firstChildTreeItem));
pDriver->QueueCommand(cmd)
NotifyForChangedWatches();
}
}
I created a new command
class GdbCmd_Output : public DebuggerCmd
{
DebuggerTree* m_pDTree;
wxString m_Variable;
public:
/** @param tree The tree to display. */
GdbCmd_Output(DebuggerDriver* driver, DebuggerTree* dtree, wxString variable)
: DebuggerCmd(driver),
m_pDTree(dtree),
m_Variable(variable)
{
m_Cmd << _T("output ") + variable;
}
void ParseOutput(const wxString& output)
{
wxArrayString lines = GetArrayFromString(output, _T('\n'));
wxString locals;
locals << output;
m_pDTree->ParseEntry(entry, watch, locals, -1);
//m_pDTree->BuildTree(0, output, wsfGDB); //TODO append output to the wxTreeItem that matches m_Variable
}
};
This is a first implementation of the idea, I don't know if it will possible in the future to have an auto-dereference feature, because there are a lot of problems (ex : Multiple dereference like StructPointer1.StructPointer2.StructPointer3, since a auto-dereference is a 'child' of a pointer in the tree, we must ignore some nodes to auto dereference StructPointer3.
Maybe by populating the struct WatchTreeEntry first and refresh the tree after, but I did not understand how to use that struct.