Я очень новичок в программировании на C ++ и пытаюсь отладить программу с использованием GDB через VS Code. Я могу отладить приложение без библиотеки в порядке с моей текущей настройкой, но, включая библиотеку (в данном случае libcurl), я не могу настроить работу GDB.
Я включил и связал libcurl, указав аргументы gcc вручную. Я пытался передать аналогичные аргументы в gdb через код VS, но я не мог заставить что-либо работать, потому что я не в себе, и у меня мало информации по этому вопросу, которую я могу найти.
Ниже приведен код, который я пытаюсь отладить (который прекрасно собирается и работает) и мои файлы VS Code JSON.
curltest.cpp
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <curl/curl.h>
using namespace std;
size_t CurlWrite_CallbackFunc_StdString(void *contents, size_t size, size_t nmemb, string *s)
{
size_t newLength = size*nmemb;
try
{
s->append((char*)contents, newLength);
}
catch(bad_alloc &e)
{
return 0;
}
return newLength;
}
string getRequest(const char *url)
{
CURL *curl;
CURLcode res;
const char *pCACertFile = "cacert.pem";
string outputHTML;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_CAINFO, pCACertFile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &outputHTML);
res = curl_easy_perform(curl);
if (res != CURLE_OK){
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return outputHTML;
}
int main()
{
string outputHTML;
const char *baseUrl = "https://example.com";
outputHTML = getRequest(baseUrl);
cout << outputHTML << endl;
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-I",
"\"C:/bin/curlpp/include/\"",
"-I",
"\"C:/bin/curl/include\"",
"-L",
"\"C:/bin/curl/lib\"",
"-o",
"curltest",
"curltest.cpp",
"-l",
"curl"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "run",
"type": "shell",
"command": "./curltest.exe",
"args": [],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/curltest.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/bin/mingw-w64/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/bin/curlpp/include/",
"C:/bin/curl/include/"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/bin/mingw-w64/mingw64/bin/gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Отладка через эту конфигурацию дает следующий вывод в консоли отладки.
../../../../src/gdb-8.1/gdb/buildsym.c:1039: internal-error: void prepare_for_building(const char*, CORE_ADDR): Assertion `current_subfile == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session?
(y or n) [answered Y; input not from terminal]
../../../../src/gdb-8.1/gdb/buildsym.c:1039: internal-error: void prepare_for_building(const char*, CORE_ADDR): Assertion `current_subfile == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB?
(y or n) [answered Y; input not from terminal]
ERROR: Unable to start debugging. GDB exited unexpectedly with exit code 3 (0x3).
ERROR: GDB exited unexpectedly with exit code 3 (0x3). Debugging will now abort.
The program 'C:\Users\Ethan\Desktop\vscpp\curltest.exe' has exited with code -1 (0xffffffff).