命令 | 说明 |
---|---|
p a | 打印a |
q | 退出 |
n | 下一行 |
s | 执行下一行(能够进入函数体) |
r | 执行下一行(在函数中时会直接执行到函数返回处) |
w | 打印堆栈信息 |
unt N | 执行到第N行 |
disas | display assembler code |
打印所有属性 p dir(obj)
程序运行到这里就会暂停 并进入pdb调试环境
https://blog.csdn.net/zqqbb7601/article/details/124728867
如果 pdb 显示的结果过长,您可以使用 q
命令来退出当前的 pdb 调试会话,然后使用 less
命令在终端中查看 pdb 输出的结果。例如,您可以在调试会话中使用以下命令:
(Pdb) !less some_file.txt
这将会使用 less
命令来查看名为 some_file.txt
的文件,您可以将 some_file.txt
替换为您要查看的文件名或变量名。在使用 less
命令时,您可以使用 q
键来退出查看模式。
另外,如果您只是想查看变量的值,您可以使用 p
命令来打印变量的值,例如:
(Pdb) p some_var
这将会打印变量 some_var
的值。如果变量的值很长,您可以使用 pprint
模块来格式化打印输出。例如:
(Pdb) import pprint
(Pdb) pprint.pprint(some_var)
这将会使用 pprint
模块来格式化打印变量 some_var
的值。
(Pdb) p opts
<modules.shared.Options object at 0x7fbdc46dad10>
(Pdb) p dir(opts)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add_option', 'cast_value', 'data', 'data_labels', 'dumpjson', 'get_default', 'load', 'onchange', 'reorder', 'same_type', 'save', 'set', 'typemap']
(Pdb) import inspect
(Pdb) inspect.getmembers(opts)
[('__class__', <class 'modules.shared.Options'>), ('__delattr__', <method-wrapper '__delattr__' of Options object at 0x7fbdc46dad10>), ('__dict__', {'data': {'samples_save': True, 'samples_format': 'png', 'samples_filename_pattern': '', 'save_images_add_number': True, 'grid_save': True, 'grid_format': 'png', 'grid_extended_filename': False, 'grid_only_if_multiple': True, 'grid_prevent_empty_spots': False, 'n_rows': -1, 'enable_pnginfo': True, 'save_txt': False, 'save_images_before_face_restoration': True, 'save_images_before_highres_fix': True, 'save_images_before_color_correction': False, 'save_mask': False, 'save_mask_composite': False, 'jpeg_quality': 80, 'webp_lossless': False, 'export_for_4chan': True, 'img_downscale_threshold': 4.0, 'target_side_length': 4000, 'img_max_size_mp': 200, 'use_original_name_batch': True, 'use_upscaler_name_as_suffix': False, 'save_selected_only': True, 'save_init_img': False, 'temp_dir': '', 'clean_temp_dir_at_start': False, 'outdir_samples': '', 'outdir_txt2img_samples': 'outputs/txt2img-images', 'outdir_img2img_samples': 'outputs/img2img-images', 'outdir_extras_samples': 'outputs/extras-images', 'outdir_grids': '', 'outdir_txt2img_grids': 'outputs/txt2img-grids', 'outdir_img2img_grids': 'outputs/img2img-grids', 'outdir_save': 'log/images', 'outdir_init_images': 'outputs/init-images', 'save_to_dirs': True, 'grid_save_to_dirs': True, 'use_save_to_dirs_for_ui': False, 'directories_filename_pattern': '[date]', 'directories_max_prompt_words': 8, 'ESRGAN_tile': 192, 'ESRGAN_tile_overlap': 8, 'realesrgan_enabled_models': ['R-ESRGAN 4x+', 'R-ESRGAN 4x+ Anime6B'], 'upscaler_for_img2img': None, 'face_restoration_model': 'CodeFormer', 'code_former_weight': 0.5, 'face_restoration_unload': False, 'show_warnings': False, 'memmon_poll_rate': 8, 'samples_log_stdout': False, 'multiple_tqdm': True, 'print_hypernet_extra': False, 'list_hidden_files': True, 'unload_models_when_training': False, 'pin_memory': False, 'save_optimizer_state': False, 'save_training_settings_to_txt': True, 'dataset_filename_word_regex': '', 'dataset_filename_join_string': ' ', 'training_image_repeats_per_epoch': 1, 'training_write_csv_every': 500, 'training_xattention_optimizations': False, 'training_enable_tensorboard': False, 'training_tensorboard_save_images': False
~/Downloads/zip$ vim test.cpp
~/Downloads/zip$ gcc test.cpp -o test
~/Downloads/zip$ ./test
段错误
~/Downloads/zip$ gcc test.cpp -g -rdynamic
~/Downloads/zip$ ls
a.out test test.cpp
~/Downloads/zip$ gdb a.out
GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) n
The program is not being run.
(gdb) r
Starting program: /home/pdd/Downloads/zip/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00005555555551a0 in main () at test.cpp:7
7 int main(){
(gdb) q
A debugging session is active.
Inferior 1 [process 9706] will be killed.
Quit anyway? (y or n) y
r | run |
---|---|
print *arr@5 | 将打印指针arr所指向的连续5个元素的值,p sizeof(*hf_adam::opt), print *arr@60 |
n | new line |
continue或c | 继续执行程序直到下一个断点处停止 |
list | 显示后续代码 |
backtrace或bt | 显示当前调用堆栈的完整信息 |
b 7 | 第七行断点 |
b f | f函数断点 |
info | 查看断点 |
s | step into |
watch *0x6fffffffffffffff |
下面是一些"frame"命令的常用子命令和用法:
(gdb) frame
#0 stack_usage_test (tag=171, stack_size=65536, top=0x7ffffffee300 "\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253"...) at /home/pdd/leetcode/untitled1/main.cpp:14
14 return stack_size - unused;
(gdb) info frame
Stack level 0, frame at 0x7fffffffe340:
rip = 0x5555555551d6 in stack_usage_test (/home/pdd/leetcode/untitled1/main.cpp:14); saved rip = 0x555555555392
called by frame at 0x7fffffffe370
source language c++.
Arglist at 0x7fffffffe330, args: tag=171, stack_size=65536, top=0x7ffffffee300 "\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253"...
Locals at 0x7fffffffe330, Previous frame's sp is 0x7fffffffe340
Saved registers:
rbp at 0x7fffffffe330, rip at 0x7fffffffe338
(gdb) info frame
是gdb调试器中用于显示当前执行上下文信息的命令。根据提供的信息,以下是每个字段的解释:
Stack level 0, frame at 0x7fffffffe340:表示当前栈帧的级别,0表示当前栈帧;0x7fffffffe340
是栈帧的地址。
rip = 0x5555555551d6 in stack_usage_test (/home/pdd/leetcode/untitled1/main.cpp:14):表示当前指令的指令指针(程序计数器)的值为 0x5555555551d6
。同时,还提供了函数所在源文件和行号信息(/home/pdd/leetcode/untitled1/main.cpp:14
),表明当前指令位于main.cpp
文件的第14行。
saved rip = 0x555555555392:表示保存着上一个栈帧的返回地址(返回指令指针值)为 0x555555555392
。
called by frame at 0x7fffffffe370:表示当前栈帧被位于 0x7fffffffe370
地址的上一个栈帧调用。
Source language c++:表示该栈帧中代码的编程语言为C++。
Arglist at 0x7fffffffe330, args: tag=171, stack_size=65536, top=0x7ffffffee300 “\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253”:表示函数的参数存储在 0x7fffffffe330
地址处,具体的参数值为 tag=171, stack_size=65536, top=0x7ffffffee300
。
Locals at 0x7fffffffe330:表示函数的局部变量存储在 0x7fffffffe330
地址处。
Previous frame’s sp is 0x7fffffffe340:表示上一个栈帧的栈指针(栈顶指针)值为 0x7fffffffe340
。
Saved registers: 列出在该栈帧中保存的寄存器的值,其中 rbp
的值为 0x7fffffffe330
,rip
的值为 0x7fffffffe338
。
(gdb) info args
tag = 171
stack_size = 65536
top = 0x7ffffffee300 "\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253\253"...
在使用动态分配函数 alloca
分配内存地址时,rip
寄存器的变化方式取决于编译器和平台的具体实现。
alloca
函数用于在栈上动态分配内存,分配的内存空间在函数返回后自动释放。当在函数内部调用 alloca
分配内存时,rip
寄存器的变化通常是增加的。
这是因为 alloca
在大多数编译器和平台上实现为在栈上分配内存。栈的生长方向是向下的,也就是说,栈的高地址是先分配的,低地址是后分配的。而 rip
寄存器则指向当前执行的指令地址,随着指令的执行,它通常会递增,指向下一条指令。因此,当 alloca
在栈上分配内存时,栈的指针会向低地址方向移动,而 rip
寄存器的值会随之增加。
需要注意的是,这是一个一般情况的描述,具体的实现可能会有所不同,特别是在不同的编译器和体系结构上。因此,在实际应用中,如果对 rip
寄存器的值有特定的依赖或需求,建议查阅相关编译器和平台的文档或规范以了解更多细节。
(gdb) i r
rax 0x7fffffffe2d0 140737488347856
rbx 0x0 0
rcx 0x7fffffffe2f0 140737488347888
rdx 0x20 32
rsi 0xa 10
rdi 0x10 16
rbp 0x7fffffffe330 0x7fffffffe330
rsp 0x7fffffffe2d0 0x7fffffffe2d0
r8 0x7ffff7f8ff10 140737353678608
r9 0x7ffff7fc9040 140737353912384
r10 0x7ffff7fc3908 140737353890056
r11 0x7ffff7fde680 140737354000000
r12 0x7fffffffe478 140737488348280
r13 0x555555555573 93824992236915
r14 0x555555557db0 93824992247216
r15 0x7ffff7ffd040 140737354125376
rip 0x55555555528e 0x55555555528e <stack_usage_fill(int, size_t)+174>
eflags 0x202 [ IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
k0 0x10000000 268435456
k1 0x40001 262145
k2 0x0 0
k3 0x0 0
k4 0x0 0
k5 0x0 0
k6 0x0 0
k7 0x0 0
(gdb) i r rsp
rsp 0x7fffffffe2d0 0x7fffffffe2d0
Breakpoint 4, stack_usage_fill (tag=171, stack_size=10) at /home/pdd/valgrind/untitled1/main.cpp:20
20 char* top3 = (char*)alloca(1);
(gdb) i r rsp
rsp 0x7fffffffe2c0 0x7fffffffe2c0