用gdb调试c代码时,显示的汇编代码是
0x000000000040116c main+0 push %rbp
0x000000000040116d main+1 mov %rsp,%rbp
!0x0000000000401170 main+4 movl $0x0,-0x4(%rbp)
0x0000000000401177 main+11 jmp 0x40118d <main+33>
0x0000000000401179 main+13 mov -0x4(%rbp),%eax
0x000000000040117c main+16 mov %eax,%edx
0x000000000040117e main+18 mov -0x4(%rbp),%eax
Run Code Online (Sandbox Code Playgroud)
第一条汇编指令前面的0x000000000040116d是这个函数的虚拟地址吗?main+1 是这个程序集与 main 函数的偏移量吗?下一个程序集是 main+4。这是否意味着第一个mov %rsp,%rbp是三个字节?如果是这样,为什么是movl $0x0,-0x4(%rbp)7 个字节?
我正在使用服务器。版本是:Linux version 4.15.0-122-generic (buildd@lcy01-amd64-010) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)) #124~16.04.1-Ubuntu SMP.
当我使用 vscode 进行 c 和 c++ 调试时,有时需要一些命令行参数(./runFile args1 args2)。如果我直接点击运行,它会显示argv[2]超出范围。这是因为我没有输入参数。但是如果我通过命令行输入参数,似乎无法单步通过vscode。我想到的方法是我argv[]=value在main函数的开头在这里给命令行参数赋值。这样使用会不会有问题?而我只能argv[0]=value argv[1]=value。有没有办法直接给 argv 赋值argv=...?我试过argv[1]=value argv[2]=value。可以正常运行。这里有什么风险吗?比如给argv分配了多少内存?
我遵循了在线教程,并想用它#undef来设计我的调试输出功能。我写了一个debugOut.h文件。内容如下?
#include <stdio.h>
#define NOOP //(void(0))
#undef DEBUG_PRINT
#if DEBUG_OUT
#define DEBUG_PRINT printf
#else
#define DEBUG_PRINT(...) NOOP
#endif
#undef DEBUG_OUT
Run Code Online (Sandbox Code Playgroud)
然后我写了一个main函数来测试我的设计是否正确。
#include<iostream>
#include "Header/debug_out.h"
#define DEBUG_OUT
int main(){
DEBUG_PRINT("module1 debug...\n");
printf("hello,world");
}
Run Code Online (Sandbox Code Playgroud)
但输出结果仅为hello, world. 为什么我定义#define DEBUG_OUT,为什么DEBUG_PRINT不替换为printf
我是根据在线教程编写的。我想基于此为 C++ 编写一个输出函数。但在句子中#define DEBUG_PRINT(...) NOOP,(...)代表什么?有什么办法可以输出宏定义被替换的内容吗?