文件结构:
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
#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) leaks命令行工具将报告
像下面这样:
\nProcess: 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\nRun Code Online (Sandbox Code Playgroud)\n我的问题是,如何使用这些信息来实际跟踪并查找源代码中哪些 …