相关疑难解决方法(0)

什么是分段错误?

什么是分段错误?C和C++有什么不同吗?分段错误和悬空指针是如何相关的?

c c++ segmentation-fault

530
推荐指数
9
解决办法
55万
查看次数

什么是调试器,它如何帮助我诊断问题?

这是一个通用的问题,以帮助有程序问题的新程序员,但不知道如何使用调试器来诊断问题的原因.

这个问题涉及两类更具体的问题:

  • 当我运行我的程序时,它不会产生我期望的输出我给它的输出.
  • 当我运行我的程序时,它会崩溃并给我一个堆栈跟踪.我已经检查了堆栈跟踪,但我仍然不知道问题的原因,因为堆栈跟踪不能为我提供足够的信息.
  • 当我运行程序时,由于分段错误(SEGV)而崩溃.

[What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173)

language-agnostic debugging

72
推荐指数
2
解决办法
7433
查看次数

分段错误的行号

我可以设置任何gcc选项,它会给我分段错误的行号吗?

我知道我可以:

  1. 逐行调试
  2. 将printfs放入代码中以缩小范围.

编辑:

  1. bt/ where在gdb上给出无堆栈.
  2. 有用的建议

debugging gcc gdb segmentation-fault

47
推荐指数
4
解决办法
9万
查看次数

libcurl:使用 WriteMemoryCallback 时 curl_easy_perform 上的分段错误

我使用以下代码成功地使用 C 和 libcurl 发出了 json-rpc 请求

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>

void post_rpc(CURL *curl_handle)
{
    CURLcode res;

    char JSONRPC_BASE_URL[] = "https://api.betfair.com/exchange/betting/json-rpc/v1";
    char rpc_request[]="{\"jsonrpc\": \"2.0\", \"method\": \"SportsAPING/v1.0/listEventTypes\", \"params\": {\"filter\":{ }}, \"id\": 1}";  
    char session_token[]= "MY_ACTIVE_SESSION_STRING";
    char session_header[100+sizeof(session_token)];

    strcpy(session_header, "X-Authentication:");
    strcat(session_header, session_token);

    struct curl_slist * headers = NULL;
    headers = curl_slist_append(headers, "X-Application: MY_API_KEY");
    headers = curl_slist_append(headers, session_header);
    headers = curl_slist_append(headers, "content-type : application/json");

    /* init the curl session */
    curl_handle = curl_easy_init();

    /*  HEADERS */
    curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); …
Run Code Online (Sandbox Code Playgroud)

c libcurl segmentation-fault

5
推荐指数
1
解决办法
8562
查看次数

使用 GDB 远程调试 MPI

我正在尝试从 pi 的远程访问组中调试我使用 MPI 编写的代码。我无法直接访问 Pi 以便能够使用 GUI 来调试代码。

我已经尝试过使用此问题中显示的类似屏幕,但每当我尝试使用屏幕时,我都会收到以下消息:

There are not enough slots available in the system to satisfy the 2 slots
that were requested by the application:
  screen

Either request fewer slots for your application, or make more slots available
for use.
Run Code Online (Sandbox Code Playgroud)

如果我尝试告诉它只使用 1 个屏幕,mpiexec 会失败

mpiexec -N 16 --host 10.0.0.3 -np 1 screen -oversubscribe batSRTest3 shortpass.bat
--------------------------------------------------------------------------
mpiexec was unable to find the specified executable file, and therefore
did not launch the job.  This error …
Run Code Online (Sandbox Code Playgroud)

c debugging gdb mpi raspberry-pi

2
推荐指数
1
解决办法
2762
查看次数