001    package nl.cwi.sen1.tide.adapters.gdb;
002    
003    import java.util.regex.Matcher;
004    import java.util.regex.Pattern;
005    
006    public class ContinueCmd extends Command
007    {
008            private static Pattern patternStoppedKnown;
009            private static Pattern patternStoppedUnknown;
010            private static Pattern patternFrame;
011            private GdbProcess process;
012    
013            static {
014                    patternStoppedKnown = Pattern.compile("\032\032([^:]+):([0-9]+):.*");
015                    patternStoppedUnknown = Pattern.compile("0x[0-9a-f]+\\sin\\s.+()");
016                    patternFrame          = Pattern.compile("#([0-9]+)\\s+.*");
017            }
018            
019            public ContinueCmd(GdbAdapter adapter, GdbProcess process)
020            {
021                    super(adapter);
022                    this.process = process;
023            }
024    
025            public String command()
026            {
027                    switch(adapter.calcRunMode()) {
028                            case GdbAdapter.MODE_STEP_INTO:
029                                    System.err.println("single stepping...");
030                                    return "step\n";
031                            case GdbAdapter.MODE_STEP_OVER:
032                                    System.err.println("stepping over...");
033                                    return "next\n";
034                            case GdbAdapter.MODE_RUN:
035                                    System.err.println("running...");
036                                    return "cont\n";
037                            default:
038                                    throw new RuntimeException("illegal run-mode!");
039                    }
040            }
041    
042            public boolean response(String line)
043            {
044                    if(line.startsWith("Breakpoint")) {
045                            return false;
046                    } 
047                    
048                    Matcher matcher;
049                    
050                    matcher = patternFrame.matcher(line);
051                    
052                    if(matcher.matches()) {
053                            int level = Integer.parseInt(matcher.group(1));
054                            process.setStackLevel(level);
055                            debugMsg("*** stack level: " + level);
056                            return false;
057                    } 
058                    
059                    matcher = patternStoppedKnown.matcher(line);
060                    if(matcher.matches()) {
061                            String file = matcher.group(1);
062                            int linenr = Integer.parseInt(matcher.group(2));
063                            debugMsg("execution stopped: file=" + file + ",line=" + linenr);
064                            process.setCpe(file, linenr);
065                            return true;
066                    }
067                    
068                    matcher = patternStoppedUnknown.matcher(line);
069                    if(matcher.matches()) {
070                            debugMsg("execution stopped at unknown: " + line);
071                            process.setCpe(null, 0);
072                            return true;
073                    } 
074                    
075                    if (line.startsWith("Program exited normally")) {
076                            process.setCpe(null, 0);
077                            return true;
078                    }
079                    
080            System.out.println("line '" + line + "' does not match with patternStopped");
081                    return false;
082            }
083    }