Creating Debug-Ready Code

本文介绍如何使用GCC编译器的-g选项来生成调试信息,并解释了这些信息如何帮助开发者使用调试器逐步执行程序、设置断点及查看变量内容。同时讨论了如何使用strip命令移除这些调试信息。
 

Normally, when we write a program, we want to be able to debug it - that is, test it using a debugger that allows running it step by step, setting a break point before a given command is executed, looking at contents of variables during program execution, and so on. In order for the debugger to be able to relate between the executable program and the original source code, we need to tell the compiler to insert information to the resulting executable program that'll help the debugger. This information is called "debug information". In order to add that to our program, lets compile it differently:

cc -g single_main.c -o single_main

The '-g' flag tells the compiler to use debug info, and is recognized by mostly any compiler out there. You will note that the resulting file is much larger than that created without usage of the '-g' flag. The difference in size is due to the debug information. We may still remove this debug information using the strip command, like this:

strip single_main

You'll note that the size of the file now is even smaller than if we didn't use the '-g' flag in the first place. This is because even a program compiled without the '-g' flag contains some symbol information (function names, for instance), that the strip command removes. You may want to read strip's manual page (man strip) to understand more about what this command does.


[File Watcher (node.js)] Request to start watching: /home/SENSETIME/leisiquan.vendor/.config/Code/User (excludes: <none>, includes: <all>, filter: <none>, correlationId: <none>),/home/SENSETIME/leisiquan.vendor/.config/Code/User/settings.json (excludes: <none>, includes: <all>, filter: <none>, correlationId: <none>) [main 2025-08-01T12:47:02.252Z] [File Watcher (node.js)] ignoring a path for watching who's stat info failed to resolve: /home/SENSETIME/leisiquan.vendor/.config/Code/User/settings.json (error: Error: ENOENT: no such file or directory, stat '/home/SENSETIME/leisiquan.vendor/.config/Code/User/settings.json') [main 2025-08-01T12:47:02.253Z] [File Watcher (node.js)] starting fs.watchFile() on /home/SENSETIME/leisiquan.vendor/.config/Code/User/settings.json (correlationId: undefined) [main 2025-08-01T12:47:02.256Z] Starting VS Code [main 2025-08-01T12:47:02.256Z] from: /usr/share/code/resources/app [main 2025-08-01T12:47:02.256Z] args: { _: [], diff: false, merge: false, add: false, remove: false, goto: false, 'new-window': false, 'reuse-window': false, wait: false, help: false, 'list-extensions': false, 'show-versions': false, 'pre-release': false, 'update-extensions': false, version: false, verbose: true, status: false, 'prof-startup': false, 'no-cached-data': false, 'prof-v8-extensions': false, 'disable-extensions': false, 'disable-lcd-text': false, 'disable-gpu': true, 'disable-chromium-sandbox': false, sandbox: false, telemetry: false, debugRenderer: false, 'enable-smoke-test-driver': false, logExtensionHostCommunication: false, 'skip-release-notes': false, 'skip-welcome': false, 'disable-telemetry': false, 'disable-updates': false, 'use-inmemory-secretstorage': false, 'disable-workspace-trust': false, 'disable-crash-reporter': false, 'crash-reporter-id': '9bc59030-b82d-49d9-9051-898bbb437304', 'skip-add-to-recently-opened': false, 'open-url': false, 'file-write': false, 'file-chmod': false, force: false, 'do-not-sync': false, 'do-not-include-pack-dependencies': false, trace: false, 'trace-memory-infra': false, 'preserve-env': false, 'force-user-env': false, 'force-disable-user-env': false, 'open-devtools': false, 'disable-gpu-sandbox': false, '__enable-file-policy': false, 'enable-coi': false, 'enable-rdp-display-tracking': false, 'disable-layout-restore': false, 'no-proxy-server': false, 'no-sandbox': false, nolazy: false, 'force-renderer-accessibility': false, 'ignore-certificate-errors': false, 'allow-insecure-localhost': false, 'disable-dev-shm-usage': false, 'profile-temp': false, logsPath: '/home/SENSETIME/leisiquan.vendor/.config/Code/logs/20250801T204702' } [main 2025-08-01T12:47:02.258Z] Resolving machine identifier... [main 2025-08-01T12:47:02.262Z] [File Watcher (node.js)] Started watching: '/home/SENSETIME/leisiquan.vendor/.config/Code/User' [49295:0801/204702.266343:WARNING:vaapi_wrapper.cc(1534)] Skipping nVidia device named: nvidia-drm [49295:0801/204702.268231:WARNING:sandbox_linux.cc(420)] InitializeSandbox() called with multiple threads in process gpu-process. [49295:0801/204702.269007:WARNING:viz_main_impl.cc(85)] VizNullHypothesis is disabled (not a warning) [main 2025-08-01T12:47:02.298Z] Resolved machine identifier: 3777bd569b947d43ea914eabe3a61f5de17708a4d53a88839111bf818a20a675 [main 2025-08-01T12:47:02.298Z] Main->SharedProcess#connect [main 2025-08-01T12:47:02.302Z] StorageMainService: creating application storage [main 2025-08-01T12:47:02.306Z] ElectronURLListener: waiting for window to be ready to handle URLs... [main 2025-08-01T12:47:02.306Z] lifecycle (main): phase changed (value: 2) [main 2025-08-01T12:47:02.306Z] windowsManager#open [main 2025-08-01T12:47:02.307Z] windowsManager#open pathsToOpen [ [Object: null prototype] {} ] [main 2025-08-01T12:47:02.307Z] windowsManager#doOpenEmpty { restore: false, remoteAuthority: undefined, filesToOpen: undefined, forceNewWindow: false } [main 2025-08-01T12:47:02.309Z] IPC Object URL: Registered new channel vscode:dc0454f3-919f-4e9a-999c-dc2a526cc059. [main 2025-08-01T12:47:02.309Z] window#validateWindowState: validating window state on 1 display(s) { width: 1200, height: 800, mode: 1, x: 360, y: 140, hasDefaultState: true } [main 2025-08-01T12:47:02.309Z] window#validateWindowState: single monitor working area { x: 72, y: 27, width: 1848, height: 1053 } [main 2025-08-01T12:47:02.309Z] window#ctor: using window state { width: 1200, height: 800, mode: 1, x: 360, y: 140, hasDefaultState: true } [main 2025-08-01T12:47:02.356Z] window#load: attempt to load window (id: 1) [main 2025-08-01T12:47:02.364Z] windowsManager#open used window count 1 (workspacesToOpen: 0, foldersToOpen: 0, emptyToRestore: 0, maybeOpenEmptyWindow: true) [main 2025-08-01T12:47:02.364Z] lifecycle (main): phase changed (value: 3) [main 2025-08-01T12:47:02.364Z] resolveShellEnv(): skipped (VSCODE_CLI is set) [main 2025-08-01T12:47:02.365Z] update#setState idle [main 2025-08-01T12:47:02.407Z] resolveShellEnv(): skipped (VSCODE_CLI is set) [49253:0801/204702.419375:INFO:CONSOLE(3)] "[uncaught exception]: TypeError: Failed to fetch dynamically imported module: vscode-file://vscode-app/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js", source: vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/workbench.js (3) [49253:0801/204702.419453:INFO:CONSOLE(3)] "TypeError: Failed to fetch dynamically imported module: vscode-file://vscode-app/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js", source: vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/workbench.js (3) [49253:0801/204702.419556:INFO:CONSOLE(4)] "Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: vscode-file://vscode-app/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js", source: vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/workbench.js (4) [49253:0801/204702.445759:ERROR:nss_util.cc(227)] Error initializing NSS with a persistent database (sql:/home/SENSETIME/leisiquan.vendor/.pki/nssdb): libsoftokn3.so: 无法打开共享对象文件: 没有那个文件或目录 [49253:0801/204702.445798:ERROR:nss_util.cc(112)] Error initializing NSS without a persistent database: NSS error code: -5925 [49253:0801/204702.445805:FATAL:nss_util.cc(114)] nss_error=-5925, os_error=0 [0801/204702.482445:ERROR:directory_reader_posix.cc(43)] opendir /home/SENSETIME/leisiquan.vendor/.config/Code/Crashpad/attachments/63a4640e-035f-4f73-ac78-2ede9b09a5b9: No such file or directory (2) [49299:0801/204708.716049:ERROR:ssl_client_socket_impl.cc(877)] handshake failed; returned -1, SSL error code 1, net_error -3
08-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值