小编KIY*_*IYZ的帖子

在 VSCode 中构建程序时如何指定包含路径?

假设这是我的项目。

文件结构:

project_root
|-- inc
|   |-- header.h
|-- src
|   |-- helpers.c
|   |-- main.c
Run Code Online (Sandbox Code Playgroud)

header.h

#ifndef HEADER_H
# define HEADER_H

void    func(void);

#endif
Run Code Online (Sandbox Code Playgroud)

helpers.c

void    func()
{
    /* do something */
}
Run Code Online (Sandbox Code Playgroud)

main.c

#include "header.h"

int    main(void)
{
    func();
    return (0);
}
Run Code Online (Sandbox Code Playgroud)

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/inc",
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
Run Code Online (Sandbox Code Playgroud)

tasks.json

    "tasks": [
        {
            "type": …
Run Code Online (Sandbox Code Playgroud)

c compiler-errors visual-studio-code vscode-settings vscode-tasks

6
推荐指数
1
解决办法
2756
查看次数

如何在 VSCode 的调试器模式下查看指针指向的字符串的 char 值

假设我正在使用这个 C 程序。

  • 我有三个字符串存储在动态分配的内存中。
  • 我将这些字符串的地址存储在动态分配的指针变量中。
#include <string.h>
#include <stdlib.h>

int     main(void)
{
    char    *p0 = strdup("red..");
    char    *p1 = strdup("green");
    char    *p2 = strdup("blue.");
    char    *p3 = NULL;
    char    **pp = malloc(sizeof(char *) * 4); /* I want to watch this in VSCode debugger */

    pp[0] = p0;
    pp[1] = p1;
    pp[2] = p2;
    pp[3] = p3;

  /* do something */

    return (0);
}
Run Code Online (Sandbox Code Playgroud)

我想要实现什么

在 VSCode 调试器的监视视图中,如何让它显示每个指针指向的字符串的 char 值(如果可能的话还包括地址),如下所示?

<watch_expression_for_pp>: <address of pp>
   |- pp[0]: [6] <address of pp[0]> …
Run Code Online (Sandbox Code Playgroud)

c debugging visual-studio-code vscode-debugger

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

如何使用leaks命令行工具查找内存泄漏?

leaks命令行工具将报告

\n
    \n
  • 泄漏内存的地址
  • \n
  • 泄漏的大小(以字节为单位)
  • \n
  • 泄漏缓冲区的内容
  • \n
\n

像下面这样:

\n
Process:         checker [84357]\nPath:            /path/to/program\nLoad Address:    0x104703000\nIdentifier:      checker\nVersion:         ???\nCode Type:       X86-64\nParent Process:  zsh [64610]\n\nDate/Time:       2019-11-30 18:43:06.864 -0800\nLaunch Time:     2019-11-30 18:42:58.593 -0800\nOS Version:      Mac OS X 10.13.4 (17E199)\nReport Version:  7\nAnalysis Tool:   /usr/bin/leaks\n\nPhysical footprint:         300K\nPhysical footprint (peak):  300K\n----\n\nleaks Report Version: 3.0\nProcess 84357: 161 nodes malloced for 17 KB\nProcess 84357: 3 leaks for 64 total leaked bytes.\n\nLeak: 0x7fdf5b400350  size=16  zone: DefaultMallocZone_0x10470e000\nLeak: 0x7fdf5b4027c0  size=16  zone: DefaultMallocZone_0x10470e000\nLeak: 0x7fdf5b402810  size=32  zone: DefaultMallocZone_0x10470e000\n
Run Code Online (Sandbox Code Playgroud)\n

我的问题是,如何使用这些信息来实际跟踪并查找源代码中哪些 …

c debugging macos memory-leaks command-line-tool

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