python c++ summary pdb gdb frame registers 调试器,栈帧,寄存器的查看

pdb

  • import pdb
  • pdb.set_trace() # 设置追踪断点
命令说明
p a打印a
q退出
n下一行
s执行下一行(能够进入函数体)
r执行下一行(在函数中时会直接执行到函数返回处)
w打印堆栈信息
unt N执行到第N行
disasdisplay assembler code
  • 打印所有属性 p dir(obj)
    程序运行到这里就会暂停 并进入pdb调试环境
    https://blog.csdn.net/zqqbb7601/article/details/124728867

  • https://docs.python.org/zh-cn/3/library/pdb.html

pdb 显示的结果过长

如果 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 的值。

inspect

  • https://docs.python.org/3/library/inspect.html
(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

gdb

one example

~/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
rrun
print *arr@5将打印指针arr所指向的连续5个元素的值,p sizeof(*hf_adam::opt), print *arr@60
nnew line
continue或c继续执行程序直到下一个断点处停止
list显示后续代码
backtrace或bt显示当前调用堆栈的完整信息
b 7第七行断点
b ff函数断点
info查看断点
sstep into
watch *0x6fffffffffffffff

frame

  • "frame"是GDB命令之一,它的作用是跳转和操作调用栈中的帧(Frame)。通过使用"frame"命令,你可以切换到不同的栈帧,以查看和修改正在调用堆栈中的活动函数。栈帧是函数调用过程中存储局部变量、参数和返回地址的区域。使用"frame"命令可以帮助你在调试过程中深入了解函数调用的细节,并检查变量的状态和执行路径。同时,它还提供了调试乃至修改代码的能力。

下面是一些"frame"命令的常用子命令和用法:

  • test code link
  1. “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;
  1. “frame n”:切换到第n个栈帧,其中n是栈帧的索引号。
  2. “up"或"down”:在栈帧之间进行上下切换。
  3. “info frame”:显示当前栈帧的完整信息。
(gdb) info frame
Stack level 0, frame at 0x7fffffffe340:rip = 0x5555555551d6 in stack_usage_test (/home/pdd/leetcode/untitled1/main.cpp:14); saved rip = 0x555555555392called by frame at 0x7fffffffe370source 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 0x7fffffffe340Saved 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 的值为 0x7fffffffe330rip 的值为 0x7fffffffe338

  1. “info args”:显示当前栈帧的函数参数信息。
(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"...
  1. “info locals”:显示当前栈帧的局部变量信息。

当使用alloca分配地址时,rip的变化时增加还是减少?

在使用动态分配函数 alloca 分配内存地址时,rip 寄存器的变化方式取决于编译器和平台的具体实现。

alloca 函数用于在栈上动态分配内存,分配的内存空间在函数返回后自动释放。当在函数内部调用 alloca 分配内存时,rip 寄存器的变化通常是增加的。

这是因为 alloca 在大多数编译器和平台上实现为在栈上分配内存。栈的生长方向是向下的,也就是说,栈的高地址是先分配的,低地址是后分配的。而 rip 寄存器则指向当前执行的指令地址,随着指令的执行,它通常会递增,指向下一条指令。因此,当 alloca 在栈上分配内存时,栈的指针会向低地址方向移动,而 rip 寄存器的值会随之增加。

需要注意的是,这是一个一般情况的描述,具体的实现可能会有所不同,特别是在不同的编译器和体系结构上。因此,在实际应用中,如果对 rip 寄存器的值有特定的依赖或需求,建议查阅相关编译器和平台的文档或规范以了解更多细节。

gdb 查看 寄存器

  • 可以使用 info registers 命令或 i r 命令查看所有寄存器的值。
(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 命令行中输入 info registers rsp 或者简写为 i r rsp 命令来查看 rsp 寄存器的值。
(gdb) i r rsp
rsp            0x7fffffffe2d0      0x7fffffffe2d0Breakpoint 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
  • 在某些情况下,调用 alloc(1) 分配内存,实际分配的内存大小可能会大于请求的字节数。这通常是由于内存对齐的需要。内存对齐是指在分配内存时,要求按照特定的字节边界对齐数据。在许多系统上,内存对齐的默认边界是 8 字节或 16 字节。这意味着即使请求分配 1 字节的内存,系统也可能分配更多的字节,以满足对齐的要求。因此,当你调用 alloc(1) 分配内存时,返回的指针可能会增加为 16 字节。

core

  • ulimit -a 查看用户的使用限制
  • ulimit -c unlimited // 不限制core大小,也可指定具体大小ulimit -c 5000
  • gdb ./a.out core.***

正在运行的程序

  • gdb -p pid 即可

CG

  • https://sourceware.org/gdb/
  • https://zhuanlan.zhihu.com/p/297925056
  • https://stackoverflow.com/questions/1562074/how-do-i-show-the-value-of-a-define-at-compile-time
  • GDB——使用GDB查看栈帧信息
  • gdb调试之栈帧信息
  • 使用 GDB 查看程序的栈空间 | Linux 中国
  • https://stackoverflow.com/questions/68825866/valgrind-reports-invalid-write-at-x-bytes-below-stack-pointer
  • https://stackoverflow.com/questions/2308581/storing-data-below-the-stack-pointer
  • 栈和帧指针使用方法
  • Valgrind 内存检测错误信息

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/229418.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

c++程序设计编写一个程序,输入N个学生数据,包括学号、姓名、成绩,要求输出这些学生数据并计算平均分

编写一个程序&#xff0c;输入N个学生数据&#xff0c;包括学号、姓名、成绩&#xff0c;要求输出这些学生数据并计算平均分。要求&#xff1a; &#xff08;1&#xff09;设计一个学生类Stud&#xff0c;除了包括no(学号)、name(姓名)和deg(成绩)数据成员外&#xff0c;有两个…

【C语言】cache和程序访问的局部性对程序性能的影响

文章目录 1&#xff0e;源程序比较其性能影响2&#xff0e;内存分配&#xff08;1&#xff09;静态存储区&#xff08;static&#xff09;&#xff1a;&#xff08;2&#xff09;栈区&#xff08;stack&#xff09;&#xff1a;&#xff08;3&#xff09;堆区&#xff08;heap&…

msvcp140.dll丢失怎样修复?全面分析msvcp140.dll的修复方法

在执行特定程序时&#xff0c;有可能遭遇msvcp140.dll文件遗失的困扰&#xff0c;此时该如何处理呢&#xff1f;此次将为您讲述面临此类问题的有效解决方案&#xff0c;涉及到多种修复方法&#xff0c;其中包括利用DLL修复工具进行操作。您可依据个人需求选择相应的修复方式&am…

Linux:时间显示(函数介绍)

文章目录 1、sleep&#xff1a;延迟函数2、time/localtime3、示例&#xff1a;sleep time localtime4、Linux时间调整 1、sleep&#xff1a;延迟函数 函数原型&#xff1a;unsigned int sleep(unsigned int seconds); 功 能&#xff1a;延时 参 数&#xff1a;seconds:秒&am…

LeetCode100123执行操作使频率分数最大(相关话题:滑动窗口,二分法,前缀和)

题目描述 给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。你可以对数组执行 至多 k 次操作&#xff1a; 从数组中选择一个下标 i &#xff0c;将 nums[i] 增加 或者 减少 1 。最终数组的频率分数定义为数组中众数的 频率 。请你返回你可以得到的 最大 频率分数。 众数…

条款5:了解c++默默编写并调用了哪些函数

如果你不自己声明&#xff0c;编译器会替你声明&#xff08;编译器版本的&#xff09;拷贝构造函数、拷贝赋值运算符和析构函数。此外&#xff0c;如果你没有声明任何构造函数&#xff0c;编译器会为你声明一个默认构造函数。 class Empty{};本质上和写成下面这样是一样的: c…

力扣第13题-罗马数字转整数[简单]

题目描述 罗马数字包含以下七种字符: I&#xff0c; V&#xff0c; X&#xff0c; L&#xff0c;C&#xff0c;D 和 M。 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例…

cpp_03_引用_类型转换_温和强转_面向对象

1 引用的应用 1.1 数据传递--值传递 C语言只要涉及数据传递&#xff08;例如&#xff1a;初始化、赋值、传参、返回值&#xff09;&#xff0c; 都为值传递&#xff08;将数据复制一份给到目标内存&#xff09;。 // value.cpp 值传递&#xff1a;将数据复制一份给别人 #in…

删除远端消息, 重进会话仍然取回已删除的消息

用户调用删除函数, 服务器不会判断 对应的 sentTime 是否存在, 仅仅是使用sentTime 直接进行消息删除, 然后返回操作成功; 用户删除远端消息时, 需要保证sentTime的合法性 - (void)deleteRemoteMessage:(RCConversationType)conversationType targetId:(NSString *)targetId me…

Diva配置——Communication Tests

关联文章:CANoe.Diva生成测试用例 Diva目录 一、CANoe.Diva简介二、Communication Tests配置一、CANoe.Diva简介 CANoe.DiVa 是一种 CANoe 选项,用于对 ECU 中的诊断软件实施进行自动化测试。 可以通过CANdelaStudio制作的CDD或ODX文件,经过Diva配置自动生成测试用例和测试脚…

用XPath爬取Crossin教室的文章列表页信息示例

一、背景&#xff1a; 2023.12.12,经过本人的多日权衡比较&#xff0c;我决定购买了crossin老师的Python服务。主要实现了能够通过其编程教室提供的答疑群平台答疑解惑。基于其答疑服务感觉还是不错的。同时能够逐步扎实Python基础与爬虫等相关的技术。今日用xpath完成了一个爬…

jetson nano 编译出现/usr/bin/ld: cannot find -lcudart

问题描述 jetson nano 编译出现/usr/bin/ld: cannot find -lcudart 问题分析 在 Jetson Nano 上编译时遇到 /usr/bin/ld: cannot find -lcudart 错误&#xff0c;表示编译器无法找到名为 libcudart 的 CUDA 运行时库。 CMakeLists.txt 里面添加库路径。 解决办法 要解决这…

【日积月累】Mysql性能优化

目录 【日积月累】Mysql性能优化 1.前言2.MySql性能优化的主要方面2.1硬件和操作系统成面优化2.2架构设计层优化&#xff08;表结构&#xff09;2.3程序配置优化2.5表结构及索引优化2.4sql执行优化 3.总结4.参考 文章所属专区 积月累 1.前言 MySQL是一种常用的开源关系型数据…

33 动态规划和递归求解不同路径II

问题描述&#xff1a;一个机器人位于一个mn网格的左上角(起始点在下图中标记为Start)&#xff0c;机器人每次只能向下或者向右移动一步&#xff0c;机器人试图到达网格的右下角&#xff0c;机器人试图到达网格的右下角&#xff0c;现在考虑网格中有障碍物&#xff0c;那么从左上…

第2章 线性结构

一、选择题 1. 顺序存储结构的优点是&#xff08; A &#xff09; A&#xff0e;存储密度大 B&#xff0e;插入运算方便 C&#xff0e;删除运算方便 D&#xff0e;可用于各种逻辑结构的存储表示 2. 下面关于线性表的叙述中&#xff0c;错误的是&#xff08; B…

ACL原理和配置

一.ACL概述 1.介绍 ACL 访问控制列表&#xff0c;可以通过对网络中报文流的精确识别&#xff0c;与其他技术结合&#xff0c;达到控制网络访问行为、防止网络攻击和提高网络带宽利用率的目的&#xff0c;从而切实保障网络环境的安全性和网络服务质量的可靠性。 2.概述 ACL是…

ShenYu网关注册中心之Zookeeper注册原理

文章目录 1、客户端注册流程1.1、读取配置1.1.1、用于注册的 ZookeeperClientRegisterRepository1.1.2、用于扫描构建 元数据 和 URI 的 SpringMvcClientEventListener 1.2、扫描注解&#xff0c;注册元数据和URI1.2.1、构建URI并写入Disruptor1.2.2、构建元数据并写入Disrupto…

[C语言]大小端及整形输出问题

假设在一个32位little endian 的机器上运行下面的程序&#xff0c;结果是多少 ? 1.1先看以下三个程序 #include <stdio.h> int main() {long long a 1, b 2, c 3;printf("%lld %lld %lld\n", a, b, c); // 1 2 3printf("%d %d %d %d %d %d\n&quo…

LeetCode第376场周赛

文章目录 1.Find Missing and Repeated Values2.Divide Array Into Arrays With Max Difference3.Minimum Cost to Make Array Equalindromic 1.Find Missing and Repeated Values 直接暴力过 class Solution { public:vector<int> findMissingAndRepeatedValues(vecto…

Learning Semantic-Aware Knowledge Guidance forLow-Light Image Enhancement

微光图像增强&#xff08;LLIE&#xff09;研究如何提高照明并生成正常光图像。现有的大多数方法都是通过全局和统一的方式来改善低光图像&#xff0c;而不考虑不同区域的语义信息。如果没有语义先验&#xff0c;网络可能很容易偏离区域的原始颜色。为了解决这个问题&#xff0…