Skip to content

Commit

Permalink
GDB: initial support for displaying registers
Browse files Browse the repository at this point in the history
  • Loading branch information
eranif committed May 29, 2014
1 parent 2f300ab commit 49866d7
Show file tree
Hide file tree
Showing 19 changed files with 1,157 additions and 951 deletions.
27 changes: 27 additions & 0 deletions Debugger/dbgcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,3 +1544,30 @@ bool DbgCmdHandlerDisassebleCurLine::ProcessOutput(const wxString& line)
EventNotifier::Get()->AddPendingEvent(event);
return true;
}

// +++-----------------------------
// DbgCmdHandlerRegisterNames
// +++-----------------------------

bool DbgCmdHandlerRegisterNames::ProcessOutput(const wxString& line)
{
// Sample output:
// ^done,register-names=["eax","ecx","edx","ebx","esp","ebp","esi","edi","eip","eflags","cs","ss","ds","es","fs","gs","st0","st1","st2","st3","st4","st5","st6","st7","fctrl","fstat","ftag","fiseg","fioff","foseg","fooff","fop","xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","mxcsr","","","","","","","","","al","cl","dl","bl","ah","ch","dh","bh","ax","cx","dx","bx","","bp","si","di","mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7"]
std::vector<std::string> names;
gdbParseRegisterNames( line.mb_str(wxConvUTF8).data(), names);

for(size_t i=0; i<names.size(); ++i) {
m_numberToName.insert( std::make_pair(i, names.at(i)) );
}

// Now trigger the register values call
return m_gdb->WriteCommand("-data-list-register-values --skip-unavailable N", new DbgCmdHandlerRegisterValues(m_observer, m_gdb, m_numberToName));
}

// +++-----------------------------
// DbgCmdHandlerRegisterValues
// +++-----------------------------
bool DbgCmdHandlerRegisterValues::ProcessOutput(const wxString& line)
{
// Process the output and report it back to codelite
}
43 changes: 43 additions & 0 deletions Debugger/dbgcmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,47 @@ class DbgCmdStopHandler : public DbgCmdHandler

virtual bool ProcessOutput(const wxString & line);
};

// +++-----------------------------
// DbgCmdHandlerRegisterNames
// +++-----------------------------

class DbgCmdHandlerRegisterNames : public DbgCmdHandler
{
DbgGdb* m_gdb;
std::map<int, wxString> m_numberToName;

public:
DbgCmdHandlerRegisterNames(IDebuggerObserver *observer, DbgGdb* gdbr)
: DbgCmdHandler(observer)
, m_gdb(gdbr)
{}

virtual ~DbgCmdHandlerRegisterNames()
{}

virtual bool ProcessOutput(const wxString &line);
};

// +++-----------------------------
// DbgCmdHandlerRegisterValues
// +++-----------------------------
class DbgCmdHandlerRegisterValues : public DbgCmdHandler
{
DbgGdb* m_gdb;
std::map<int, wxString> m_numberToName;

public:
DbgCmdHandlerRegisterValues(IDebuggerObserver *observer, DbgGdb* gdbr, const std::map<int, wxString>& numberToName)
: DbgCmdHandler(observer)
, m_gdb(gdbr)
{
m_numberToName = numberToName;
}

virtual ~DbgCmdHandlerRegisterValues()
{}

virtual bool ProcessOutput(const wxString &line);
};
#endif //DBGCMD_H
55 changes: 30 additions & 25 deletions Debugger/debuggergdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,15 @@ void DbgGdb::Poke()
// and are important to the CLI handler
bool consoleStream( false );
bool targetConsoleStream(false);

if ( curline.StartsWith( wxT( "~" ) ) ) {
consoleStream = true;
}

if ( curline.StartsWith( wxT( "@" ) ) ) {
targetConsoleStream = true;
}

// Filter out some gdb error lines...
if ( FilterMessage( curline ) ) {
continue;
Expand All @@ -716,16 +716,16 @@ void DbgGdb::Poke()
// the output view, concatenate it into the handler buffer
if ( targetConsoleStream ) {
m_observer->UpdateAddLine( curline );

} else if ( consoleStream && GetCliHandler()) {
GetCliHandler()->Append( curline );

} else if ( consoleStream ) {
// log message
m_observer->UpdateAddLine( curline );

}

} else if ( reCommand.Matches( curline ) ) {

//not a gdb message, get the command associated with the message
Expand Down Expand Up @@ -867,14 +867,14 @@ bool DbgGdb::EvaluateExpressionToString( const wxString &expression, const wxStr
bool DbgGdb::ListFrames()
{
int max = m_info.maxCallStackFrames;
#ifndef __WXMAC__
#ifndef __WXMAC__
wxString command = wxString::Format("-stack-list-frames 0 %i", max);

#else
// Under OSX GDB version is old and does not support the min-max version
// of callstack info
wxString command = "-stack-list-frames";

#endif

return WriteCommand(command, new DbgCmdStackList( m_observer ));
Expand Down Expand Up @@ -1078,12 +1078,12 @@ bool DbgGdb::DoInitializeGdb(const DebugSessionInfo& sessionInfo)
} else {
SetShouldBreakAtMain(false); // Needs explicitly to be set, in case the user has just changed his options
}

// Enable python based pretty printing?
if ( sessionInfo.enablePrettyPrinting ) {
WriteCommand( wxT( "-enable-pretty-printing" ), NULL );
}

// Add the additional search paths
for(size_t i=0; i<sessionInfo.searchPaths.GetCount(); ++i) {
wxString dirCmd;
Expand Down Expand Up @@ -1175,7 +1175,7 @@ void DbgGdb::OnDataRead( wxCommandEvent& e )

if( !m_gdbProcess || !m_gdbProcess->IsAlive() )
return;

CL_DEBUG("GDB>> %s", bufferRead);
wxArrayString lines = wxStringTokenize( bufferRead, wxT( "\n" ), wxTOKEN_STRTOK );
if(lines.IsEmpty())
Expand Down Expand Up @@ -1312,7 +1312,7 @@ void DbgGdb::GetDebugeePID(const wxString& line)
wxString msg;
msg << wxT( ">> Debuggee process ID: " ) << m_debuggeePid;
m_observer->UpdateAddLine( msg );

// Now there's a known pid, the debugger can be interrupted to let any to-be-disabled bps be disabled. So...
m_observer->DebuggerPidValid();
}
Expand Down Expand Up @@ -1351,33 +1351,33 @@ void DbgGdb::OnKillGDB(wxCommandEvent& e)
DoCleanup();
m_observer->UpdateGotControl( DBG_DBGR_KILLED );
}

bool DbgGdb::Disassemble(const wxString& filename, int lineNumber)

bool DbgGdb::Disassemble(const wxString& filename, int lineNumber)
{
// Trigger a "disasseble" call
if ( /*filename.IsEmpty() || lineNumber == wxNOT_FOUND*/ true ) {
// Use the $pc
if ( !WriteCommand("-data-disassemble -s \"$pc -100\" -e \"$pc + 100\" -- 0", new DbgCmdHandlerDisasseble(m_observer, this)) )
return false;

} else {
// else, use the file and line provided
wxString tmpfile = filename;
tmpfile.Replace("\\", "/"); // gdb does not like backslashes...
if ( !WriteCommand(wxString() << "-data-disassemble -f \"" << tmpfile << "\" -l " << lineNumber << " -n -1 -- 0",

if ( !WriteCommand(wxString() << "-data-disassemble -f \"" << tmpfile << "\" -l " << lineNumber << " -n -1 -- 0",
new DbgCmdHandlerDisasseble(m_observer, this)) )
return false;
}

// get the current instruction
if ( !WriteCommand("-data-disassemble -s \"$pc\" -e \"$pc + 1\" -- 0", new DbgCmdHandlerDisassebleCurLine(m_observer, this)) )
return false;
return false;

return true;
}

bool DbgGdb::Attach(const DebugSessionInfo& si)
return true;
}

bool DbgGdb::Attach(const DebugSessionInfo& si)
{
//set the environment variables
EnvSetter env( m_env, NULL, m_debuggeeProjectName );
Expand Down Expand Up @@ -1421,4 +1421,9 @@ bool DbgGdb::Attach(const DebugSessionInfo& si)
DoInitializeGdb( si );
m_observer->UpdateGotControl( DBG_END_STEPPING );
return true;
}

bool DbgGdb::ListRegisters()
{
return WriteCommand("-data-list-register-names", new DbgCmdHandlerRegisterNames(m_observer, this));
}
5 changes: 3 additions & 2 deletions Debugger/debuggergdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class DbgGdb : public wxEvtHandler, public IDebugger
virtual bool UpdateVariableObject(const wxString& name, int userReason);
virtual void AssignValue(const wxString& expression, const wxString& newValue);
virtual bool Jump(wxString filename, int line);

virtual bool ListRegisters();

/**
* @brief restart the debugger (execute 'run')
* @return true on success, false otherwise
Expand All @@ -172,4 +173,4 @@ class DbgGdb : public wxEvtHandler, public IDebugger
void OnKillGDB(wxCommandEvent &e);

};
#endif //DBGINTERFACE_H
#endif //DBGINTERFACE_H
1 change: 1 addition & 0 deletions Debugger/gdb_parser_incl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct GdbChildrenInfo {

extern bool setGdbLexerInput(const std::string &in, bool ascii, bool wantWhitespace = false);
extern void gdbParseListChildren( const std::string &in, GdbChildrenInfo &children);
extern void gdbParseRegisterNames( const std::string &in, std::vector<std::string>& names );
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 49866d7

Please sign in to comment.