/// <summary> /// Uses the ANTLR parser to parse the GDB string into a GDBMIResponse. /// </summary> /// <param name="raw">the GDB command reply string</param> /// <returns>GDBMIResponse</returns> private GDBMIParser.GDBMIResponse ParseRawGdbResponse(string raw) { Logger.Instance.Debug("Parsing:\r\n" + raw); ANTLRStringStream ss = new ANTLRStringStream(raw); GDBMILexer lex = new GDBMILexer(ss); CommonTokenStream ts = new CommonTokenStream(lex); GDBMIParserStrict parser = new GDBMIParserStrict(ts); GDBMIParser.GDBMIResponse res = null; try { res = parser.output(); } catch (RecognitionException m) { Logger.Instance.Error("While parsing:\r\n" + m.Input.ToString() + "\r\nGot error:\r\n" + m.ToString()); throw m; } catch (Exception m) { Logger.Instance.Error(m.StackTrace); throw m; } return(res); }
public override void SetReturnValue(GDBMIParser.GDBMIResponse resp) { foreach (GDBMIParser.GDBMIStreamRecord sr in resp.stream) { if (sr.type != GDBMIParser.GDBMIStreamRecord.GDBMIStreamRecordType.console) { continue; } Match match = regex.Match(sr.str); if (match.Success) { Return = new BreakpoitInfo(); Return.raw = match.Groups[0].Value; try { Return.id = Int32.Parse(match.Groups[1].Value); Return.file = match.Groups[3].Value; Return.line = Int32.Parse(match.Groups[4].Value); } catch (Exception m) { throw new ExecutionException("Failed to parse response value while parsing \" " + sr.str + "\"", m); } break; } } }
protected void CheckResponseAndThrowExecutionException(GDBMIParser.GDBMIResponse resp) { if (resp == null) { throw new ExecutionException("null GDBMIResponse received"); } else if (resp.result == null) { throw new ExecutionException("null GDBMIResultRecord in GDBMIResponse received"); } else if (resp.result.cls == GDBMIParser.GDBMIResultRecord.ResultClass.error) { if (resp.result.ContainsKey("msg")) { throw new ExecutionException((string)resp.result["msg"]); } throw new ExecutionException("Command did not execute successfully (no extra msg)"); } else if (resp.result.cls != GDBMIParser.GDBMIResultRecord.ResultClass.done) { string log = ""; foreach (GDBMIParser.GDBMIStreamRecord r in resp.stream) { log += r.str + "| "; } throw new ExecutionException("Command did not execute successfully. IO log: " + log); } }
public override void SetReturnValue(GDBMIParser.GDBMIResponse resp) { foreach (GDBMIParser.GDBMIStreamRecord sr in resp.stream) { if (sr.type != GDBMIParser.GDBMIStreamRecord.GDBMIStreamRecordType.console) { continue; } Match match = regexSrc.Match(sr.str); if (match.Success) { Return = new LocationInfo(); Return.raw = match.Groups[0].Value; int val = 0; if (Int32.TryParse(match.Groups[1].Value, out val)) { Return.frame = val; } Return.address = match.Groups[2].Value; Return.file = match.Groups[3].Value; val = 0; if (Int32.TryParse(match.Groups[4].Value, out val)) { Return.line = val; } break; } match = regexNoSrc.Match(sr.str); if (match.Success) { Return = new LocationInfo(); Return.raw = match.Groups[0].Value; int val = 0; if (Int32.TryParse(match.Groups[1].Value, out val)) { Return.frame = val; } Return.address = match.Groups[2].Value; Return.file = match.Groups[3].Value; break; } } }
public virtual void Execute(int timeout) { GdbEngine.SyncAdapter syncGdb = new GdbEngine.SyncAdapter(gdb); try { res = syncGdb.SendCmd(CommandString, timeout); } catch (TimeoutException ex) { Logger.Instance.Warn(ex.Message); throw ex; } }
void gdb_OnResponseReceived(object sender, GDBMIParser.GDBMIResponse response) { if (sender != gdb) { return; } //Update last response this.response = response; //Signal internal responseEvent responseEvent.Set(); }
protected void Gdb_OnResponseReceived(object sender, GDBMIParser.GDBMIResponse response) { if (OnAsyncResult != null) { try { CheckResponseAndThrowExecutionException(response); //*** OnAsyncResult(this, null); } catch (Exception m) { OnAsyncResult(this, m); } } }
public override void SetReturnValue(GDBMIParser.GDBMIResponse resp) { foreach (GDBMIParser.GDBMIStreamRecord sr in resp.stream) { if (sr.type != GDBMIParser.GDBMIStreamRecord.GDBMIStreamRecordType.console) { continue; } Match match = regexDecl.Match(sr.str); if (match.Success) { Return = match.Groups[2].Value; } } }
/// <summary> /// Receives a response in synchronous mode /// </summary> /// <param name="timeout">If in blocking mode, a timeout value in milliseconds can be specified. /// if this value is reached and no response is received, null will be returned</param> /// <returns></returns> public GDBMIParser.GDBMIResponse SendCmd(string cmd, int timeout) { response = null; responseEvent.Reset(); gdb.SendCmd(cmd, new GdbEngine.ResponseReceivedHandler(gdb_OnResponseReceived)); bool bSet = responseEvent.WaitOne(timeout); if (!bSet) { //timeout Logger.Instance.Warn("SendCmd(" + cmd + ") TIMEOUT, returning null response"); gdb.UnregisterResponseReceivedHandler(); throw new TimeoutException("Timeout while executing: " + cmd); } return(response); }
public override void SetReturnValue(GDBMIParser.GDBMIResponse resp) { foreach (GDBMIParser.GDBMIStreamRecord sr in resp.stream) { if (sr.type != GDBMIParser.GDBMIStreamRecord.GDBMIStreamRecordType.console) { continue; } Match match = regexDecl.Match(sr.str); if (match.Success) { ThreadInfo ti = new ThreadInfo(); ti.raw = match.Groups[0].Value; ti.pid = match.Groups[1].Value; ti.tid = match.Groups[2].Value; Return.Add(ti); } } }
public override void SetReturnValue(GDBMIParser.GDBMIResponse resp) { foreach (GDBMIParser.GDBMIStreamRecord sr in resp.stream) { if (sr.type != GDBMIParser.GDBMIStreamRecord.GDBMIStreamRecordType.console) { continue; } Match match = regex.Match(sr.str); if (match.Success) { Return = new StepLocation(); Return.raw = match.Groups[0].Value; int parsed = 0; if (Int32.TryParse(match.Groups[1].Value, out parsed)) { Return.line = parsed; } } } }
public override void SetReturnValue(GDBMIParser.GDBMIResponse resp) { Return = new List <VariableInfo>(); int level = 0; foreach (GDBMIParser.GDBMIStreamRecord sr in resp.stream) { if (sr.type != GDBMIParser.GDBMIStreamRecord.GDBMIStreamRecordType.console) { continue; } Match match = regexDecl.Match(sr.str); if (match.Success) { if (level <= 0) { VariableInfo var = new VariableInfo(); var.raw = match.Groups[0].Value; var.name = match.Groups[1].Value; Return.Add(var); } } //Skip enclosed types if (sr.str.Trim().EndsWith("{")) { level++; } else if (sr.str.Trim().EndsWith("}")) { level--; } } }
private void ReadStandardOutputCallback(IAsyncResult asyncResult) { int count = gdbProc.StandardOutput.BaseStream.EndRead(asyncResult); string buffer = new string(Encoding.ASCII.GetChars(stdoutBuf, 0, count)); //Logger.Instance.Debug("[gdb] -> " + buffer); stdoutBlock += buffer; string respTerminator = "(gdb) \r\n"; int breakPos = stdoutBlock.IndexOf(respTerminator); while (breakPos >= 0) { string rawResponse = stdoutBlock.Substring(0, breakPos); stdoutBlock = stdoutBlock.Substring(breakPos + respTerminator.Length); GDBMIParser.GDBMIResponse res = null; try { res = ParseRawGdbResponse(rawResponse); } catch (RecognitionException m) { //Parse error. //Construct an appropriate error response to send back. res = new GDBMIParser.GDBMIResponse(); res.result = new GDBMIParser.GDBMIResultRecord(); res.result.cls = GDBMIParser.GDBMIResultRecord.ResultClass.error; res.result["msg"] = m.ToString(); } catch (Exception m) { //Parse error. //Construct an appropriate error response to send back. res = new GDBMIParser.GDBMIResponse(); res.result = new GDBMIParser.GDBMIResultRecord(); res.result.cls = GDBMIParser.GDBMIResultRecord.ResultClass.error; res.result["msg"] = m.ToString(); } //Send the response to the async-mode handler if (responseReceivedCallback != null) { responseReceivedCallback(this, res); } if (Status == StatusEnum.ReplyPending) { Status = StatusEnum.Ready; } gdbReadyEvent.Set(); //Allow thread waiting in SendCmd() to continue breakPos = stdoutBlock.IndexOf(respTerminator); } //Begin next async read operation for stdout if (Status == StatusEnum.Ready || Status == StatusEnum.ReplyPending || count > 0) { gdbProc.StandardOutput.BaseStream.BeginRead(stdoutBuf, 0, stdoutBuf.Length, new AsyncCallback(ReadStandardOutputCallback), null); } }
public override void SetReturnValue(GDBMIParser.GDBMIResponse resp) { int k = 0; for (; k < resp.stream.Count; ++k) { GDBMIParser.GDBMIStreamRecord sr = resp.stream[k]; //If simple value Match match = regexValueDecl.Match(sr.str); if (match.Success) { if (match.Groups["value"].Value.StartsWith("{")) { Return = new VariableValue(new List <VariableValue>()); Return.parent = Return; k++; break; } else { Return = new VariableValue(match.Groups["value"].Value); return; } } } VariableValue cur = Return; for (; k < resp.stream.Count; ++k) { GDBMIParser.GDBMIStreamRecord sr = resp.stream[k]; Match match = regexArrayElementValueDecl.Match(sr.str); if (match.Success) { int index = 0; if (match.Groups["index"].Success) { int.TryParse(match.Groups["index"].Value, out index); } int count = match.Groups["down"].Captures.Count; while (count-- > 0) { VariableValue v = new VariableValue(new List <VariableValue>()); v.parent = cur; v.index = index; cur.Values.Add(v); cur = v; } if (match.Groups["value"].Success) { VariableValue v = new VariableValue(match.Groups["value"].Captures[0].Value); v.parent = cur.parent; v.index = index; cur.Values.Add(v); } count = match.Groups["up"].Captures.Count; while (count-- > 0) { cur = cur.parent; } } else { Logger.Instance.Error("Not matching: " + sr.str); Return = null; break; } } }