lldb调试C++总结(3)

note

本文将弥补之前的遗漏部分。

continue

前面提到,当设置断点后,使用stepnextfinish,程序会停下来,需要程序继续运行,键入continue, 程序可自动继续向下执行.

设置断点

(lldb) breakpoint set --line 14
Breakpoint 1: where = demo`main + 151 at demo.cpp:14:9, address = 0x0000000000401277

运行程序

(lldb) run  
Process 82513 launched: '/home/xx/demo/libevent_demo/demo' (x86_64)

程序停下来了

Process 82513 stopped
* thread #1, name = 'demo', stop reason = breakpoint 1.1

继续执行

(lldb) continue

完整输出

(lldb) breakpoint set --line 14
Breakpoint 1: where = demo`main + 151 at demo.cpp:14:9, address = 0x0000000000401277
(lldb) run  
Process 82513 launched: '/home/xx/demo/libevent_demo/demo' (x86_64)
ABCDEF

var_a=1

the print following is from call's output

----------------------------

Process 82513 stopped
* thread #1, name = 'demo', stop reason = breakpoint 1.1
    frame #0: 0x0000000000401277 demo`main(argc=1, argv=0x00007fffffffde88, env=0x00007fffffffde98) at demo.cpp:14:9
   11  	    std::cout << "var_a=" << var_a << "\n\n";
   12  	
   13  	    std::cout << "the print following is from call's output\n\n----------------------------\n\n";
-> 14  	    car new_car;
   15  	    new_car.print_name();
   16  	
   17  	
(lldb) continue
Process 82513 resuming
my name is october

Process 82513 exited with status = 0 (0x00000000) 

程序无异常, 退出返回值为0

Process 82513 exited with status = 0 (0x00000000) 

指定文件设置设置断点

准备

这里准备了另一个文件 car.hpp, 源码如下

#ifndef _car_h
#define _car_h
#include <iostream>
class car
{
public:
    car(const car& instance) = delete;
    car(const car&& instance) = delete;
    car& operator = (const car& instance) = delete;
    car& operator = (const car&& instance) = delete;
    
    car(){}
    ~car(){}

    void print_name()
    {
        std::cout << "my name is october\n\n"; 
    }
};

#endif //! _car_h

调用代码如下:

    car new_car;
    new_car.print_name();

使用breakpoint set --file [文件名] --line [行号] 可指定文件设置断点。

(lldb) breakpoint set --file car.hpp --line 18
Breakpoint 2: where = demo`car::print_name() + 12 at car.hpp:18:19, address = 0x00000000004012ec

p/<fmt> 输出

p/t 输出二进制

p/t [变量名] 将输出二进制

(lldb) p/t var_x
(int) $2 = 0b00000000000000000000000000010011

p/o 输出十进制

p/o [变量名] 将输出十进制

(lldb) p/o var_x
(int) $1 = 023

p/o 输出十六进制

p/t [变量名] 将输出十六进制

(lldb) p/x var_x
(int) $0 = 0x00000013

其他进制? 这里

posted @ 2020-12-21 11:30  mohist  阅读(385)  评论(0编辑  收藏  举报