Good day, I am trying to debug this C code which interacts with XDMA device:
#include <fstream>
#include <iostream>
#include <unistd.h>
int main()
{
std::ofstream output_;
const char* output_name = "/dev/xdma/card0/h2c0";
output_.exceptions(std::ios::failbit | std::ios::badbit);
output_.rdbuf()->pubsetbuf(nullptr, 0);
output_.open(output_name, std::ios::binary | std::ios::out);
std::streamoff offset = 0x1e00000;
output_.seekp(offset, std::ios::beg);
const char buf[1] = "";
std::streamsize size = 1;
auto pos = output_.tellp();
output_.write(buf, size); // <--- IOSTREAM ERROR
output_.seekp(pos size, std::ios::beg);
return 0;
}
But this program fails on output_.write(buf, size);
- with quite a vague error message:
terminate called after throwing an instance of 'std::__ios_failure'
what(): basic_ios::clear: iostream error
Aborted (core dumped)
And, if I wrap this output_.write(buf, size);
in a try & catch block:
try {
output_.write(buf, size);
}
catch (std::system_error& e) {
std::cerr << e.code().message() << "(" << e.code().value() << ")\n";
return 1;
}
it changes to iostream error(1)
. This doesn't tell a failure reason... I know for sure that I can write to 0x1e00000 offset, because the alternative C code is working flawlessly. So the error is in C code or library. How to get more debug info?
CodePudding user response:
Although I didn't succeed in getting more debug info, the solution was to downgrade the XDMA driver, which provides /dev/xdma/card0/h2c0
device, from v2017.1.47
to the older v2017.0.45
version (which needed a custom patch to work on new OS). Unfortunately these new drivers are really buggy...