@@ -25,6 +25,8 @@ Author: Malte Mues <mail.mues@gmail.com>
2525
2626#include < util/string_utils.h>
2727
28+ #include < unistd.h>
29+
2830// / Create a gdb_apit object
2931// /
3032// / \param binary the binary to run with gdb
@@ -90,6 +92,8 @@ void gdb_apit::create_gdb_process()
9092 }
9193 else
9294 {
95+ usleep (1000000 );
96+
9397 // parent process
9498 gdb_state = gdb_statet::CREATED; std::cout << " GDB Here 20" << std::endl;
9599
@@ -102,6 +106,29 @@ void gdb_apit::create_gdb_process()
102106 // get stream for writing to gdb
103107 output_stream = fdopen (pipe_input[1 ], " w" ); std::cout << " GDB Here 24" << std::endl;
104108
109+ usleep (1000000 );
110+
111+ // const int r = system("cat gdb.txt");
112+ // CHECK_RETURN(r == 0);
113+
114+ #if 0
115+ std::cout << "Getting lines" << std::endl;
116+ std::ifstream is("gdb.txt");
117+
118+ int count = 0;
119+
120+ while(!is.eof())
121+ {
122+ std::string tmp;
123+ getline(is, tmp);
124+ std::cout << "Line: " << tmp << std::endl;
125+ count++;
126+
127+ if(count > 100)
128+ break;
129+ }
130+ #endif
131+
105132 CHECK_RETURN (most_recent_line_has_tag (R"( ~"done)" )); std::cout << " GDB Here 25" << std::endl;
106133
107134 if (log)
@@ -149,6 +176,8 @@ void gdb_apit::write_to_gdb(const std::string &command)
149176 command_log.push_back (command); std::cout << " GDB Here 40" << std::endl;
150177 }
151178
179+ std::cout << " Command: " << command << std::endl;
180+
152181 if (fputs (line.c_str (), output_stream) == EOF)
153182 {
154183 throw gdb_interaction_exceptiont (" could not write a command to gdb" ); std::cout << " GDB Here 41" << std::endl;
@@ -183,12 +212,14 @@ std::string gdb_apit::read_next_line()
183212 }
184213
185214 INVARIANT (feof (input_stream), " " ); std::cout << " GDB Here 49" << std::endl;
186- INVARIANT (result.back () != ' \n ' , " " ); std::cout << " GDB Here 50" << std::endl;
215+ INVARIANT (result.empty () || result. back () != ' \n ' , " " ); std::cout << " GDB Here 50" << std::endl;
187216
188217 return result; std::cout << " GDB Here 51" << std::endl;
189218 }
190219
191220 result += std::string (buf); std::cout << " GDB Here 52" << std::endl;
221+ INVARIANT (!result.empty (), " " );
222+
192223 } while (result.back () != ' \n ' ); std::cout << " GDB Here 53" << std::endl;
193224
194225 return result; std::cout << " GDB Here 54" << std::endl;
@@ -203,6 +234,9 @@ std::string gdb_apit::read_most_recent_line()
203234 {
204235 output = line; std::cout << " GDB Here 57" << std::endl;
205236 line = read_next_line (); std::cout << " GDB Here 58" << std::endl;
237+ std::cout << " Line: " << line << std::endl;
238+ std::cout << " End line" << std::endl;
239+ CHECK_RETURN (!line.empty ());
206240 } while (line != " (gdb) \n " ); std::cout << " GDB Here 59" << std::endl;
207241
208242 return output; std::cout << " GDB Here 60" << std::endl;
0 commit comments