From db78b5ea0eb86d4b3b17f5c5ecf96065df7758c9 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Thu, 24 Apr 2003 15:20:45 +0000 Subject: [PATCH] new file to parse "info program" --- .../debug/mi/core/command/MIInfoProgram.java | 40 +++++++++++ .../mi/core/output/MIInfoProgramInfo.java | 70 +++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java new file mode 100644 index 00000000000..9b1e89e2d21 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIInfoProgram.java @@ -0,0 +1,40 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ + +package org.eclipse.cdt.debug.mi.core.command; + +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.mi.core.output.MIInfo; +import org.eclipse.cdt.debug.mi.core.output.MIInfoProgramInfo; +import org.eclipse.cdt.debug.mi.core.output.MIOutput; + +/** + * + * info threads + * + */ +public class MIInfoProgram extends CLICommand +{ + public MIInfoProgram() { + super("info program"); + } + + public MIInfoProgramInfo getMIInfoProgramInfo() throws MIException { + return (MIInfoProgramInfo)getMIInfo(); + } + + public MIInfo getMIInfo() throws MIException { + MIInfo info = null; + MIOutput out = getMIOutput(); + if (out != null) { + info = new MIInfoProgramInfo(out); + if (info.isError()) { + throw new MIException(info.getErrorMsg()); + } + } + return info; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java new file mode 100644 index 00000000000..6eb250fbeaa --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIInfoProgramInfo.java @@ -0,0 +1,70 @@ +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + */ +package org.eclipse.cdt.debug.mi.core.output; + +import java.util.StringTokenizer; + + +/** + * GDB/MI info program parsing. +(gdb) +info program +&"info program\n" +~"\tUsing the running image of child process 21301.\n" +~"Program stopped at 0x804853f.\n" +~"It stopped at breakpoint 1.\n" +~"Type \"info stack\" or \"info registers\" for more information.\n" +^done +(gdb) + + */ +public class MIInfoProgramInfo extends MIInfo { + + int pid; + + public MIInfoProgramInfo(MIOutput out) { + super(out); + parse(); + } + + public int getPID() { + return pid; + } + + void parse() { + if (isDone()) { + MIOutput out = getMIOutput(); + MIOOBRecord[] oobs = out.getMIOOBRecords(); + for (int i = 0; i < oobs.length; i++) { + if (oobs[i] instanceof MIConsoleStreamOutput) { + MIStreamRecord cons = (MIStreamRecord) oobs[i]; + String str = cons.getString(); + // We are interested in the signal info + parseLine(str); + } + } + } + } + + void parseLine(String str) { + if (str != null && str.length() > 0) { + str = str.replace('.', ' '); + str = str.trim(); + if (str.startsWith("Using")) { + StringTokenizer st = new StringTokenizer(str); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + if (Character.isDigit(s.charAt(0))) { + try { + pid = Integer.decode(s).intValue(); + break; + } catch (NumberFormatException e) { + } + } + } + } + } + } +}