25
25
26
26
#include < util/string_utils.h>
27
27
28
+ #include < unistd.h>
29
+
28
30
// / Create a gdb_apit object
29
31
// /
30
32
// / \param binary the binary to run with gdb
@@ -90,6 +92,8 @@ void gdb_apit::create_gdb_process()
90
92
}
91
93
else
92
94
{
95
+ usleep (1000000 );
96
+
93
97
// parent process
94
98
gdb_state = gdb_statet::CREATED; std::cout << " GDB Here 20" << std::endl;
95
99
@@ -102,6 +106,29 @@ void gdb_apit::create_gdb_process()
102
106
// get stream for writing to gdb
103
107
output_stream = fdopen (pipe_input[1 ], " w" ); std::cout << " GDB Here 24" << std::endl;
104
108
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
+
105
132
CHECK_RETURN (most_recent_line_has_tag (R"( ~"done)" )); std::cout << " GDB Here 25" << std::endl;
106
133
107
134
if (log )
@@ -149,6 +176,8 @@ void gdb_apit::write_to_gdb(const std::string &command)
149
176
command_log.push_back (command); std::cout << " GDB Here 40" << std::endl;
150
177
}
151
178
179
+ std::cout << " Command: " << command << std::endl;
180
+
152
181
if (fputs (line.c_str (), output_stream) == EOF)
153
182
{
154
183
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()
183
212
}
184
213
185
214
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;
187
216
188
217
return result; std::cout << " GDB Here 51" << std::endl;
189
218
}
190
219
191
220
result += std::string (buf); std::cout << " GDB Here 52" << std::endl;
221
+ INVARIANT (!result.empty (), " " );
222
+
192
223
} while (result.back () != ' \n ' ); std::cout << " GDB Here 53" << std::endl;
193
224
194
225
return result; std::cout << " GDB Here 54" << std::endl;
@@ -203,6 +234,9 @@ std::string gdb_apit::read_most_recent_line()
203
234
{
204
235
output = line; std::cout << " GDB Here 57" << std::endl;
205
236
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 ());
206
240
} while (line != " (gdb) \n " ); std::cout << " GDB Here 59" << std::endl;
207
241
208
242
return output; std::cout << " GDB Here 60" << std::endl;
0 commit comments