Skip to content

Commit

Permalink
Added support for gdb pretty printers ( atm, codelite will install th…
Browse files Browse the repository at this point in the history
…e pretty printers for stdcxx, qt and wx )

Fixed various parsing issues in gdb's MI output parser to support "displayhint" and "has_more" attributes
  • Loading branch information
eranif committed Mar 15, 2013
1 parent 78c6e04 commit 66a0b3a
Show file tree
Hide file tree
Showing 31 changed files with 3,190 additions and 1,379 deletions.
74 changes: 38 additions & 36 deletions Debugger/dbgcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ bool DbgCmdHandlerAsyncCmd::ProcessOutput(const wxString &line)
m_gdb->GetDebugeePID(line);

// Get the reason
std::vector<std::map<std::string, std::string> > children;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), children);
GdbChildrenInfo info;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), info);

wxString func;
bool foundReason;

foundReason = false;
for (size_t i=0; i<children.size(); i++) {
std::map<std::string, std::string> attr = children.at(i);
for (size_t i=0; i<info.children.size(); i++) {
std::map<std::string, std::string> attr = info.children.at(i);
std::map<std::string, std::string >::const_iterator iter;

iter = attr.find("reason");
Expand Down Expand Up @@ -600,11 +600,11 @@ bool DbgCmdHandlerLocals::ProcessOutput(const wxString &line)
{
LocalVariables locals;

std::vector<std::map<std::string, std::string> > children;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), children);
GdbChildrenInfo info;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), info);

for (size_t i=0; i<children.size(); i++) {
std::map<std::string, std::string> attr = children.at(i);
for (size_t i=0; i<info.children.size(); i++) {
std::map<std::string, std::string> attr = info.children.at(i);
LocalVariable var;
std::map<std::string, std::string >::const_iterator iter;

Expand Down Expand Up @@ -657,11 +657,11 @@ bool DbgCmdHandlerFuncArgs::ProcessOutput(const wxString &line)
{
LocalVariables locals;

std::vector<std::map<std::string, std::string> > children;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), children);
GdbChildrenInfo info;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), info);

for (size_t i=0; i<children.size(); i++) {
std::map<std::string, std::string> attr = children.at(i);
for (size_t i=0; i<info.children.size(); i++) {
std::map<std::string, std::string> attr = info.children.at(i);
LocalVariable var;
std::map<std::string, std::string >::const_iterator iter;

Expand Down Expand Up @@ -934,15 +934,15 @@ bool DbgCmdBreakList::ProcessOutput(const wxString& line)
{
wxString dbg_output( line );
std::vector<BreakpointInfo> li;
std::vector<std::map<std::string, std::string> > children;
gdbParseListChildren(dbg_output.mb_str(wxConvUTF8).data(), children);
GdbChildrenInfo info;
gdbParseListChildren(dbg_output.mb_str(wxConvUTF8).data(), info);

// Children is a vector of map of attribues.
// Each map represents an information about a breakpoint
// the way gdb sees it
for(size_t i=0; i<children.size(); i++) {
for(size_t i=0; i<info.children.size(); i++) {
BreakpointInfo breakpoint;
std::map<std::string, std::string> attr = children.at(i);
std::map<std::string, std::string> attr = info.children.at(i);
std::map<std::string, std::string >::const_iterator iter;

iter = attr.find("what");
Expand Down Expand Up @@ -1150,11 +1150,11 @@ bool DbgCmdCreateVarObj::ProcessOutput(const wxString& line)
// Variable object was created
// Output sample:
// ^done,name="var1",numchild="2",value="{...}",type="ChildClass",thread-id="1",has_more="0"
std::vector<std::map<std::string, std::string> > children;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), children);
GdbChildrenInfo info;
gdbParseListChildren(line.mb_str(wxConvUTF8).data(), info);

if( children.size() ) {
std::map<std::string, std::string> attr = children.at(0);
if( info.children.size() ) {
std::map<std::string, std::string> attr = info.children.at(0);
VariableObject vo;
std::map<std::string, std::string >::const_iterator iter;

Expand Down Expand Up @@ -1203,7 +1203,9 @@ bool DbgCmdCreateVarObj::ProcessOutput(const wxString& line)
vo.isPtrPtr = true;
}
}


vo.has_more = info.has_more;

if ( vo.gdbId.IsEmpty() == false ) {

// set frozeness of the variable object
Expand Down Expand Up @@ -1264,15 +1266,15 @@ bool DbgCmdListChildren::ProcessOutput(const wxString& line)
DebuggerEvent e;
std::string cbuffer = line.mb_str(wxConvUTF8).data();

std::vector< std::map<std::string, std::string > > children;
gdbParseListChildren(cbuffer, children);
GdbChildrenInfo info;
gdbParseListChildren(cbuffer, info);

// Convert the parser output to codelite data structure
for (size_t i=0; i<children.size(); i++) {
e.m_varObjChildren.push_back( FromParserOutput( children.at(i) ) );
for (size_t i=0; i<info.children.size(); i++) {
e.m_varObjChildren.push_back( FromParserOutput( info.children.at(i) ) );
}

if ( children.size() > 0 ) {
if ( info.children.size() > 0 ) {
e.m_updateReason = DBG_UR_LISTCHILDREN;
e.m_expression = m_variable;
e.m_userReason = m_userReason;
Expand All @@ -1284,11 +1286,11 @@ bool DbgCmdListChildren::ProcessOutput(const wxString& line)
bool DbgCmdEvalVarObj::ProcessOutput(const wxString& line)
{
std::string cbuffer = line.mb_str(wxConvUTF8).data();
std::vector< std::map<std::string, std::string > > children;
gdbParseListChildren(cbuffer, children);
GdbChildrenInfo info;
gdbParseListChildren(cbuffer, info);

if(children.empty() == false) {
wxString display_line = ExtractGdbChild(children.at(0), wxT("value"));
if(info.children.empty() == false) {
wxString display_line = ExtractGdbChild(info.children.at(0), wxT("value"));
display_line.Trim().Trim(false);
if ( display_line.IsEmpty() == false ) {
if(m_userReason == DBG_USERR_WATCHTABLE || display_line != wxT("{...}")) {
Expand Down Expand Up @@ -1355,13 +1357,13 @@ bool DbgVarObjUpdate::ProcessOutput(const wxString& line)
}

std::string cbuffer = line.mb_str(wxConvUTF8).data();
std::vector< std::map<std::string, std::string > > children;
gdbParseListChildren(cbuffer, children);
GdbChildrenInfo info;
gdbParseListChildren(cbuffer, info);

for(size_t i=0; i<children.size(); i++) {
wxString name = ExtractGdbChild(children.at(i), wxT("name"));
wxString in_scope = ExtractGdbChild(children.at(i), wxT("in_scope"));
wxString type_changed = ExtractGdbChild(children.at(i), wxT("type_changed"));
for(size_t i=0; i<info.children.size(); i++) {
wxString name = ExtractGdbChild(info.children.at(i), wxT("name"));
wxString in_scope = ExtractGdbChild(info.children.at(i), wxT("in_scope"));
wxString type_changed = ExtractGdbChild(info.children.at(i), wxT("type_changed"));
if(in_scope == wxT("false") || type_changed == wxT("true")) {
e.m_varObjUpdateInfo.removeIds.Add(name);

Expand Down
2 changes: 2 additions & 0 deletions Debugger/debuggergdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,8 @@ bool DbgGdb::DoInitializeGdb( const std::vector<BreakpointInfo> &bpList, const w
} else {
SetShouldBreakAtMain(false); // Needs explicitly to be set, in case the user has just changed his options
}
//enable python based pretty printing
WriteCommand( wxT( "-enable-pretty-printing" ), NULL );
return true;
}

Expand Down
35 changes: 34 additions & 1 deletion Debugger/gdb_parser_incl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,42 @@
#include <string>

extern std::string gdb_result_string;
typedef std::map<std::string, std::string> GdbStringMap_t;
typedef std::vector<GdbStringMap_t> GdbChildren_t;

struct GdbChildrenInfo {
GdbChildren_t children;
bool has_more;

GdbChildrenInfo() {
clear();
}

void push_back( const GdbStringMap_t& m ) {
children.push_back( m );
}

void clear() {
children.clear();
has_more = false;
}

void print() {
printf("has_more : %d\n", has_more ? 1 : 0);
for(size_t i=0; i<children.size(); i++) {
printf("--------------\n");
std::map<std::string, std::string> attr = children.at(i);
std::map<std::string, std::string>::iterator iter = attr.begin();
for( ; iter != attr.end(); iter++ ) {
printf("%s : %s\n", iter->first.c_str(), iter->second.c_str());
}
}
}

};

extern bool setGdbLexerInput(const std::string &in, bool ascii, bool wantWhitespace = false);
extern void gdbParseListChildren( const std::string &in, std::vector<std::map<std::string, std::string> > &children);
extern void gdbParseListChildren( const std::string &in, GdbChildrenInfo &children);
extern void gdb_parse_result(const std::string &in);
extern void gdb_result_push_buffer(const std::string &new_input);
extern void gdb_result_pop_buffer();
Expand Down
Loading

0 comments on commit 66a0b3a

Please sign in to comment.