Skip to content

Commit 11cfbd2

Browse files
committed
Fix read_next_line()
1 parent 55bccd1 commit 11cfbd2

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ phases:
88
- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA9EF27F
99
- add-apt-repository ppa:openjdk-r/ppa -y
1010
- apt-get update -y
11-
- apt-get install -y g++-5 flex bison make git libwww-perl patch ccache libc6-dev-i386 jq
11+
- apt-get install -y g++-5 flex bison make git libwww-perl patch ccache libc6-dev-i386 jq gdb
1212
- apt-get install -y openjdk-8-jdk
1313
- update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 1
1414
- update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 1

src/memory-analyzer/gdb_api.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Author: Malte Mues <[email protected]>
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;

unit/memory-analyzer/gdb_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void compile_test_file()
3434

3535
class gdb_api_testt : public gdb_apit
3636
{
37-
explicit gdb_api_testt(const char *binary) : gdb_apit(binary)
37+
explicit gdb_api_testt(const char *binary) : gdb_apit(binary, true)
3838
{
3939
}
4040

0 commit comments

Comments
 (0)