如何使用调试模式在LLVM中编译某些模块,其他模块是否具有发布模式?

时间:2017-03-19 01:27:03

标签: llvm

完整的调试编译需要太多内存。我的机器只有4GB的内存。我想使用调试编译器调试模块,其他模块使用发布编译。

通常,我使用以下命令在调试模式或发布模式下构建LLVM:

description

构建类型的选择会影响整个构建过程。完整的调试版本不便于调试,因为它需要大约13GB的内存。我只想调试一小部分代码。

示例:我想进行<?php include('connect.php'); $error=""; if(isset($_POST['btnsave'])) { $carreras_id=$_POST['txtcarreras_id']; $subject=$_POST['txtsubject']; $descripcion=$_POST['txtdescripcion']; $carga_horaria=$_POST['txtcarga_horaria']; if($_POST['txtid']=="0") { $a_sql=mysql_query("INSERT INTO subjects VALUES('','$carreras_id','$subject','$descripcion','$carga_horaria')"); if($a_sql) { header("location:index.php"); } }else{ echo "Actualizar"; } } ?> <h2 align="center">ADD NEW SUBJECT</h2> <form method="Post"> <table align="center"> <tr> <td>Career:</td> <td> <input type='text' name='txtcarreras_id' /> <input type="hidden" name="txtid" value="0" /> </td> </tr> <tr> <td>Subject:</td> <td> <input type='text' name='txtsubject' /> </td> </tr> <tr> <td>Description:</td> <td> <input type='text' name='txtdescripcion' /> </td> </tr> <tr> <td>Hours:</td> <td> <input type='text' name='txtcarga_horaria' /> </td> </tr> <tr> <td></td> <td> <input type='submit' value=save name='btnsave' /> </td> </tr> </table> </form> 模块调试构建。如何修改cmake /home/llvm380 -DCMAKE_BUILD_TYPE="Release" cmake /home/llvm380 -DCMAKE_BUILD_TYPE="Debug" 中的llvm/lib/IR

1 个答案:

答案 0 :(得分:2)

LLVM与CMake一起使用,因此要在特定模块上启用调试模式,您需要在特定文件上启用-g标志或在整个构建目标上启用它。您很可能需要:

COMPILE_FLAGSCOMPILE_DEFITIONS目标媒体资源(请参阅Difference between COMPILE_FLAGS and COMPILE_OPTIONS)或COMPILE_FLAGS源文件属性。

我已经在一个项目上快速尝试了这个,无论是文件级还是目标级,都可以确认它是可行的。

假设您有一个文件MySourceFile.cpp和一个构建目标MyTarget。下面我要添加-hack-target-hack-file,以便更好地了解这会带来什么结果。

set(my_source_files
  MySourceFile.cpp
)

add_library(MyTarget SHARED ${my_source_files} ...)

在目标级别添加-g标志:

get_target_property(my_target_compile_flags MyTarget COMPILE_FLAGS)
if (NOT my_target_compile_flags)
  set(my_target_compile_flags "")
endif()
set_target_properties(MyTarget
                      PROPERTIES COMPILE_OPTIONS  
                      "${my_target_compile_options} -g -hack-target")

在源文件级别添加-g标志:

get_source_file_property(my_source_file_compile_flags
                         MySource.cpp
                         COMPILE_FLAGS)

if (NOT my_source_file_compile_flags)
  set(my_source_file_compile_flags "")
endif()
set_source_files_properties(MySource.cpp
                            PROPERTIES
                            COMPILE_FLAGS
                            "${my_source_file_compile_flags} -g -hack-file")

从以上几行可以看出,CMake帮助函数可以方便您在所需内容上启用-g标记。

我可以谈谈Ninja和Xcode的工作原理:

<强>忍

$ grep -ri "hack-" BuildNinja

BuildNinja//build.ninja:  FLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -fPIC    -g -hack-target -std=c++11  -g -hack-file

<强>的Xcode

在目标级别的Xcode -g中转到&#34;生成调试符号&#34;属性:

Xcode target with -g flag enabled in Release Xcode target without -g flag enabled in Release

这是标志的样子:

目标一:enter image description here

文件一:enter image description here

相关问题