一个调试信息和一个简单的带参打印输出函数

#include<stdio.h>
#include<stdlib.h>
int main()
{
   #ifdef DEBUG
      printf("Compiled: " __DATE__ " at " __TIME__"\n" );
      printf("This is line %d of file %s\n",__LINE__,__FILE__);
   #endif
   printf("Hello world\n");
   return 0;
}

gcc -o debug_info -DDEBUG debug_info.c

Compiled: May 29 2016 at 21:52:49
This is line 7 of file debug_info.c
Hello world

###可变参数打印函数

#define va_list char*

#define va_start(ap,arg) (ap =(va_list)&arg + sizeof(arg))

#define va_arg(ap,t) ( * (t*)( (ap += sizeof(t)) - sizeof(t)       ))

#define va_end(ap) (ap =(va_list)0)

具体参考 程序员的自我修养—链接 装载与库一书

#include <stdarg.h>

void R_OUTPUT(int dwRTSwitch, int dwDebugLevel, char* pchDebugInfo, ...)

{

    static char achBuf[1024];

    va_list ArgList;

    if ((dwRTSwitch & dwDebugLevel) != 0)

    {

       (void)va_start(ArgList, pchDebugInfo);

       (void)vsprintf(achBuf, pchDebugInfo,ArgList);

       va_end(ArgList);

       printf((char *)achBuf);

    }

}

转载于:https://www.cnblogs.com/hqh-prg2016/p/5540569.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 LLVM IR 中添加调试信息是非常重要的,因为它可以帮助我们更好地理解程序的执行过程。在 LLVM 中,可以使用 DIBuilder 和 setDebugLoc 函数来为自定义 Pass 添加调试信息。 以下是一个简单的示例,演示如何使用 DIBuilder 和 setDebugLoc 函数为 LLVM IR 中的指令添加调试信息: ```cpp #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/Pass.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { struct MyDebugPass : public FunctionPass { static char ID; MyDebugPass() : FunctionPass(ID) {} bool runOnFunction(Function &F) override { LLVMContext &C = F.getContext(); // Create the DIBuilder DIBuilder DIB(C); // Create a DebugLoc for line 1 of the function DebugLoc loc = DebugLoc::get(1, 0, DIB.createFile("test.ll", ".")); // Loop over all instructions in the Function for (auto &BB : F) { for (auto &I : BB) { // Add a DebugLoc to the instruction I.setDebugLoc(loc); // Print the instruction with its DebugLoc errs() << I << "\n"; } } return false; } }; } char MyDebugPass::ID = 0; static RegisterPass<MyDebugPass> X("my-debug-pass", "My Debug Pass"); ``` 在上面的示例中,我们首先使用 DIBuilder 创建一个 DebugLoc 对象,该对象表示源代码中的行号和文件名。然后,我们遍历函数中的所有指令,并使用 setDebugLoc 函数将 DebugLoc 添加到每个指令中。最后,我们打印每个指令及其 DebugLoc。 在运行此 Pass 时,它会输出调试信息的每个指令,例如: ``` %0 = alloca i32, align 4, !dbg !5 ``` 其中 `!dbg` 是 LLVM 中用于表示调试信息的元数据标记。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值