Hi, there.
I use cpptools to debug C program, but it always show this error message for me on the top screen. I just test how to use vscode to debug. My C code can compile and execute correctly.
ERROR MESSAGE: Unable to open 'iofopen.c': File not found (/build/glibc-6V9RKT/glibc-2.19/libio/iofopen.c).
FILE *inptr = fopen(infile, "r"); // I set breakpoint at this line, and cpptool always show error message.
PS My OS is debian 8.9 (Linux x64 3.16.0-4-amd64)
Thank you very much^^
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out",
"args": ["arg1"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include/x86_64-linux-gnu/c++/4.9",
"/usr/include/c++/4.9",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"${workspaceRoot}",
"/usr/include/c++/4.9/tr1"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include/x86_64-linux-gnu/c++/4.9",
"/usr/include/c++/4.9",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
This is my code.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: ./recover image\n");
return 1;
}
char *infile = argv[1];
char outfile[10];
FILE *inptr = fopen(infile, "r"); // I set breakpoint at this line, and cpptool always show error message
FILE *outptr = NULL;
int fileNum = 0;
int isOutFileExist = 0;
unsigned char imgBuffer[512];
while (fread(imgBuffer, sizeof(unsigned char), 512, inptr))
{
if (imgBuffer[0] == 0xff &&
imgBuffer[1] == 0xd8 &&
imgBuffer[2] == 0xff &&
(imgBuffer[3] & 0xf0) == 0xe0)
{
if (isOutFileExist)
{
fclose(outptr);
}
isOutFileExist = 1;
sprintf(outfile, "%03i.jpg", fileNum++);
outptr = fopen(outfile, "w");
}
if (isOutFileExist)
{
fwrite(imgBuffer, sizeof(unsigned char), 512, outptr);
}
}
fclose(outptr);
fclose(inptr);
}
@pieandcakes may know more, but I'm pretty sure that is "by design" and/or there's an existing issue on it (I hit that all the time, whenever there's a debug break in code I don't have the source code for, like OS code).
This is by design. When you stop in code that is not owned by you (such as library code in this case, the fopen method), the debugger will return where the library thinks the source should be but since its a glibc library, you probably don't have the source files (which is why it gives the error). You should be able to ignore it and continue debugging.
Thank you for your response. I try to download the glibc library and put it at the place which show in the error massage. Finally, I can debug smoothly. I didn't get the error message. However, I still don't know why gcc can find the library in my computer but the debug tool cannot find the library.
Thank you very much.
gcc compiles against the library. The debugger is looking for the source code that was used to compile the library. At the end of the day, we are just returning what gdb gives us when you are stepping. gdb is expecting the source files for the library to be where they are. In most people's cases they don't have source code for system libraries so it won't be able to find them.
Really disappointing to see this problem still occurs in the recent version of Code. I was quite afflicted by it and what shocked me most was that it was just simply "by design"?
Eventually I solved this problem by setting sourceFIleMap in Launch.js, which replace the file address given by gdb to where I put my glibc source code file folder.
https://github.com/Microsoft/vscode-cpptools/issues/1546
This issue above gave me the inspiration to the solution.
Most helpful comment
Eventually I solved this problem by setting sourceFIleMap in Launch.js, which replace the file address given by gdb to where I put my glibc source code file folder.
https://github.com/Microsoft/vscode-cpptools/issues/1546
This issue above gave me the inspiration to the solution.