lldb调试C++总结(1) 您所在的位置:网站首页 c语言如何设置断点调试 lldb调试C++总结(1)

lldb调试C++总结(1)

2024-07-03 14:12| 来源: 网络整理| 查看: 265

Note

好记性不如烂笔头。时间一长,lldb的基本功快忘本了。

本文将介绍使用 lldb 调试 C++程序的基本用法。 演示基于 Ubuntu + lldb lldb + clang(++) 版本

源码编译,可能和你使用的不一样,but, lldb的语法差不多的。

lldb help USAGE: lldb [options] ATTACHING: --attach-name Tells the debugger to attach to a process with the given name. --attach-pid Tells the debugger to attach to a process with the given pid. -n Alias for --attach-name -p Alias for --attach-pid --wait-for Tells the debugger to wait for a process with the given pid or name to launch before attaching. -w Alias for --wait-for COMMANDS: --batch Tells the debugger to run the commands from -s, -S, -o & -O, and then quit. -b Alias for --batch -K Alias for --source-on-crash -k Alias for --one-line-on-crash --local-lldbinit Allow the debugger to parse the .lldbinit files in the current working directory, unless --no-lldbinit is passed. --no-lldbinit Do not automatically parse any '.lldbinit' files. --one-line-before-file Tells the debugger to execute this one-line lldb command before any file provided on the command line has been loaded. --one-line-on-crash When in batch mode, tells the debugger to run this one-line lldb command if the target crashes. --one-line Tells the debugger to execute this one-line lldb command after any file provided on the command line has been loaded. -O Alias for --one-line-before-file -o Alias for --one-line -Q Alias for --source-quietly --source-before-file Tells the debugger to read in and execute the lldb commands in the given file, before any file has been loaded. --source-on-crash When in batch mode, tells the debugger to source this file of lldb commands if the target crashes. --source-quietly Tells the debugger to execute this one-line lldb command before any file has been loaded. --source Tells the debugger to read in and execute the lldb commands in the given file, after any file has been loaded. -S Alias for --source-before-file -s Alias for --source -x Alias for --no-lldbinit OPTIONS: --arch Tells the debugger to use the specified architecture when starting and running the program. -a Alias for --arch --capture-path Tells the debugger to use the given filename for the reproducer. --capture Tells the debugger to capture a reproducer. --core Tells the debugger to use the full path to as the core file. -c Alias for --core --debug Tells the debugger to print out extra information for debugging itself. -d Alias for --debug --editor Tells the debugger to open source files using the host's "external editor" mechanism. -e Alias for --editor --file Tells the debugger to use the file as the program to be debugged. -f Alias for --file --help Prints out the usage information for the LLDB debugger. -h Alias for --help --no-use-colors Do not use colors. --replay Tells the debugger to replay a reproducer from . --reproducer-skip-version-check Skip the reproducer version check. --version Prints out the current version number of the LLDB debugger. -v Alias for --version -X Alias for --no-use-color REPL: -r= Alias for --repl= --repl-language Chooses the language for the REPL. --repl= Runs lldb in REPL mode with a stub process with the given flags. --repl Runs lldb in REPL mode with a stub process. -R Alias for --repl-language -r Alias for --repl SCRIPTING: -l Alias for --script-language --python-path Prints out the path to the lldb.py file for this version of lldb. -P Alias for --python-path --script-language Tells the debugger to use the specified scripting language for user-defined scripts. EXAMPLES: The debugger can be started in several modes. Passing an executable as a positional argument prepares lldb to debug the given executable. Arguments passed after -- are considered arguments to the debugged executable. lldb --arch x86_64 /path/to/program -- --arch arvm7 Passing one of the attach options causes lldb to immediately attach to the given process. lldb -p lldb -n Passing --repl starts lldb in REPL mode. lldb -r Passing --core causes lldb to debug the core file. lldb -c /path/to/core Command options can be combined with these modes and cause lldb to run the specified commands before or after events, like loading the file or crashing, in the order provided on the command line. lldb -O 'settings set stop-disassembly-count 20' -o 'run' -o 'bt' lldb -S /source/before/file -s /source/after/file lldb -K /source/before/crash -k /source/after/crash Note: In REPL mode no file is loaded, so commands specified to run after loading the file (via -o or -s) will be ignored.

下面进入正题。

c++代码demo

准备了一份C++代码,用作演示。

提示: clang++编译需要使用 -g 参数,生成调试信息。

#include int print(const char *parr) { if (nullptr != parr) std::cout


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有