DEBUGDEMO: refactoring & new demo of structured types.
- extract common part for easier demo introducing.
- fixed warning [-Wincompatible-pointer-types]
- demo-types
- this debug info generated for pseudo structure:
1 /* smth here... */
2 A {
3 int a;
4 int b;
5}
0:b-debugger-types:minamoto@unit-703(0)# llvmDebugInfoC/build/exe/demotypes/demotypes
define i32 @main() !dbg !3 {
entry:
ret i32 42
}
!llvm.dbg.cu = !{!0}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "konanc", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "<stdin>", directory: "")
!2 = !{}
!3 = distinct !DISubprogram(name: "main", linkageName: "main", scope: null, file: !1, line: 1, type: !4, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, variables: !2)
!4 = !DISubroutineType(types: !5)
!5 = !{!6}
!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !1, line: 2, size: 64, align: 32, elements: !7)
!7 = !{!8, !10}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !1, line: 3, baseType: !9, size: 32, align: 32)
!9 = !DIBasicType(name: "int", size: 32, align: 4)
!10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !1, line: 4, baseType: !9, size: 32, align: 32, offset: 32)
This commit is contained in:
committed by
vvlevchenko
parent
dc8bcc677a
commit
b1462f8da6
+35
-29
@@ -21,65 +21,71 @@ model {
|
||||
components {
|
||||
debugInfo(NativeLibrarySpec) {
|
||||
sources.cpp.source.srcDirs "src/main/cpp"
|
||||
|
||||
binaries.all {
|
||||
cppCompiler.args "--std=c++11", "-g", "-fPIC", "-I${llvmDir}/include", "-I${projectDir}/src/main/include"
|
||||
linker.args "-L${llvmDir}/lib", "-lLLVMCore", "-lLLVMSupport"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def demoCFlags = ["-g", "-I${llvmDir}/include".toString(),
|
||||
"-I${projectDir}/src/main/include".toString(),
|
||||
"-I${projectDir}/src/demo-common/include".toString()]
|
||||
def demoLdFlagsLinux = ["-L${buildDir}/libs/debugInfo/static".toString(), "-ldebugInfo",
|
||||
"-L${llvmDir}/lib".toString(), "-Wl,-(", "-lLLVMSupport", "-lLLVMAnalysis", "-lLLVMProfileData", "-lLLVMCore", "-Wl,-)",
|
||||
"-L/usr/lib/x86_64-linux-gnu", "-L/lib/x86_64-linux-gnu", "-lncurses", "-lz",
|
||||
"-ldl", "-lpthread"]
|
||||
def demoLdFlagsMac = ["-L${llvmDir}/lib".toString(), "-lLLVMCore", "-lLLVMSupport", "-lLLVMAnalysis", "-lLLVMProfileData",
|
||||
"-lncurses", "-lz", "-L${buildDir}/libs/debugInfo/static".toString(), "-ldebugInfo"]
|
||||
demosimple(NativeExecutableSpec) {
|
||||
//dependsOn project("debugInfoStaticLibrary")
|
||||
sources.c.source.srcDirs "src/demo-simple/c"
|
||||
sources.c.source.srcDirs "src/demo-simple/c", "src/demo-common/c"
|
||||
binaries.all {
|
||||
cCompiler.args "-g", "-I${llvmDir}/include",
|
||||
"-I${projectDir}/src/main/include"
|
||||
cCompiler.args.addAll(demoCFlags)
|
||||
if (targetPlatform.operatingSystem.linux) {
|
||||
linker.args "-L${buildDir}/libs/debugInfo/static", "-ldebugInfo",
|
||||
"-L${llvmDir}/lib", "-Wl,-(", "-lLLVMSupport", "-lLLVMCore", "-Wl,-)",
|
||||
"-L/usr/lib/x86_64-linux-gnu", "-L/lib/x86_64-linux-gnu", "-lncurses",
|
||||
"-ldl", "-lpthread"
|
||||
linker.args.addAll(demoLdFlagsLinux)
|
||||
} else {
|
||||
linker.args "-L${llvmDir}/lib", "-lLLVMCore", "-lLLVMSupport",
|
||||
"-lncurses", "-L${buildDir}/libs/debugInfo/static", "-ldebugInfo"
|
||||
linker.args.addAll(demoLdFlagsMac)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
demogenerated(NativeExecutableSpec) {
|
||||
//dependsOn project("debugInfoStaticLibrary")
|
||||
sources.c.source.srcDirs "src/demo-generated/c"
|
||||
sources.c.source.srcDirs "src/demo-generated/c", "src/demo-common/c"
|
||||
binaries.all {
|
||||
cCompiler.args "-g", "-I${llvmDir}/include",
|
||||
"-I${projectDir}/src/main/include"
|
||||
cCompiler.args.addAll(demoCFlags)
|
||||
if (targetPlatform.operatingSystem.linux) {
|
||||
linker.args "-L${buildDir}/libs/debugInfo/static", "-ldebugInfo",
|
||||
"-L${llvmDir}/lib", "-Wl,-(", "-lLLVMSupport", "-lLLVMAnalysis", "-lLLVMProfileData", "-lLLVMCore", "-Wl,-)",
|
||||
"-L/usr/lib/x86_64-linux-gnu", "-L/lib/x86_64-linux-gnu", "-lncurses", "-lz",
|
||||
"-ldl", "-lpthread"
|
||||
linker.args.addAll(demoLdFlagsLinux)
|
||||
} else {
|
||||
linker.args "-L${llvmDir}/lib", "-lLLVMCore", "-lLLVMSupport",
|
||||
"-lncurses", "-L${buildDir}/libs/debugInfo/static", "-ldebugInfo"
|
||||
linker.args.addAll(demoLdFlagsMac)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
demolocalvariable(NativeExecutableSpec) {
|
||||
//dependsOn project("debugInfoStaticLibrary")
|
||||
sources.c.source.srcDirs "src/demo-local-variable/c"
|
||||
sources.c.source.srcDirs "src/demo-local-variable/c", "src/demo-common/c"
|
||||
binaries.all {
|
||||
cCompiler.args "-g", "-I${llvmDir}/include",
|
||||
"-I${projectDir}/src/main/include"
|
||||
cCompiler.args.addAll(demoCFlags)
|
||||
if (targetPlatform.operatingSystem.linux) {
|
||||
linker.args "-L${buildDir}/libs/debugInfo/static", "-ldebugInfo",
|
||||
"-L${llvmDir}/lib", "-Wl,-(", "-lLLVMSupport", "-lLLVMAnalysis", "-lLLVMProfileData", "-lLLVMCore", "-Wl,-)",
|
||||
"-L/usr/lib/x86_64-linux-gnu", "-L/lib/x86_64-linux-gnu", "-lncurses", "-lz",
|
||||
"-ldl", "-lpthread"
|
||||
linker.args.addAll(demoLdFlagsLinux)
|
||||
} else {
|
||||
linker.args "-L${llvmDir}/lib", "-lLLVMCore", "-lLLVMSupport", "-lLLVMAnalysis", "-lLLVMProfileData",
|
||||
"-lncurses", "-L${buildDir}/libs/debugInfo/static", "-ldebugInfo", "-lz"
|
||||
linker.args.addAll(demoLdFlagsMac)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
demotypes(NativeExecutableSpec) {
|
||||
//dependsOn project("debugInfoStaticLibrary")
|
||||
sources.c.source.srcDirs "src/demo-types/c", "src/demo-common/c"
|
||||
binaries.all {
|
||||
cCompiler.args.addAll(demoCFlags)
|
||||
if (targetPlatform.operatingSystem.linux) {
|
||||
linker.args.addAll(demoLdFlagsLinux)
|
||||
} else {
|
||||
linker.args.addAll(demoLdFlagsMac)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <llvm-c/Analysis.h>
|
||||
#include <DebugInfoC.h>
|
||||
#include <common.h>
|
||||
|
||||
codegen g_codegen;
|
||||
|
||||
void
|
||||
codegen_init() {
|
||||
g_codegen.module = LLVMModuleCreateWithName("test");
|
||||
g_codegen.di_builder = DICreateBuilder(g_codegen.module);
|
||||
g_codegen.di_compile_unit = DICreateCompilationUnit(g_codegen.di_builder, 4,
|
||||
"<stdin>", "",
|
||||
"konanc", 0, "", 0);
|
||||
g_codegen.llvm_builder = LLVMCreateBuilderInContext(LLVMGetModuleContext(g_codegen.module));
|
||||
}
|
||||
|
||||
void
|
||||
codegen_destroy() {
|
||||
DIFinalize(g_codegen.di_builder);
|
||||
LLVMVerifyModule(g_codegen.module, LLVMPrintMessageAction, NULL);
|
||||
LLVMDumpModule(g_codegen.module);
|
||||
LLVMDisposeModule(g_codegen.module);
|
||||
LLVMShutdown();
|
||||
}
|
||||
|
||||
|
||||
static LLVMValueRef
|
||||
create_function(const char* name) {
|
||||
LLVMTypeRef function_type = LLVMFunctionType(LLVMVoidType(), NULL, 0, 0);
|
||||
return LLVMAddFunction(g_codegen.module, name, function_type);
|
||||
}
|
||||
|
||||
void
|
||||
create_function_with_entry(const char *name,
|
||||
location loc,
|
||||
DISubroutineTypeRef subroutine_type,
|
||||
DISubprogramRef *subprogram) {
|
||||
LLVMValueRef function = create_function(name);
|
||||
LLVMBasicBlockRef bb = LLVMAppendBasicBlock(function, "entry");
|
||||
*subprogram = DICreateFunction(g_codegen.di_builder,
|
||||
SCOPE(g_codegen.di_compile_unit),
|
||||
name,
|
||||
name,
|
||||
*loc.file,
|
||||
loc.line,
|
||||
subroutine_type, 0, 1, 0);
|
||||
LLVMPositionBuilderAtEnd(g_codegen.llvm_builder, bb);
|
||||
DIFunctionAddSubprogram(function, *subprogram);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __DEMO_COMMON_H__
|
||||
#define __DEMO_COMMON_H__
|
||||
typedef struct {
|
||||
LLVMModuleRef module;
|
||||
DIBuilderRef di_builder;
|
||||
LLVMBuilderRef llvm_builder;
|
||||
DICompileUnitRef di_compile_unit;
|
||||
} codegen;
|
||||
|
||||
typedef struct {
|
||||
DIFileRef *file;
|
||||
int line;
|
||||
} location;
|
||||
|
||||
codegen g_codegen;
|
||||
|
||||
#define SCOPE(x) ((DIScopeOpaqueRef)(x))
|
||||
#define TYPE(x) ((DITypeOpaqueRef)(x))
|
||||
|
||||
void codegen_init();
|
||||
void codegen_destroy();
|
||||
void create_function_with_entry(const char *, location, DISubroutineTypeRef, DISubprogramRef *);
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <llvm-c/Analysis.h>
|
||||
#include <DebugInfoC.h>
|
||||
#include <common.h>
|
||||
/**
|
||||
* this demo produces bitcode for case when several functions generated from one source code.
|
||||
* e.g. for following source:
|
||||
@@ -37,29 +38,8 @@
|
||||
* return(5:14)
|
||||
*/
|
||||
|
||||
LLVMModuleRef module;
|
||||
DIBuilderRef di_builder;
|
||||
LLVMBuilderRef llvm_builder;
|
||||
DICompileUnitRef di_compile_unit;
|
||||
DIFileRef file;
|
||||
DISubroutineTypeRef subroutine_type;
|
||||
|
||||
static LLVMValueRef
|
||||
create_function(const char* name) {
|
||||
LLVMTypeRef function_type = LLVMFunctionType(LLVMVoidType(), NULL, 0, 0);
|
||||
return LLVMAddFunction(module, name, function_type);
|
||||
}
|
||||
|
||||
static DISubprogramRef
|
||||
create_function_with_entry(const char *name, int line) {
|
||||
LLVMValueRef function = create_function(name);
|
||||
LLVMBasicBlockRef bb = LLVMAppendBasicBlock(function, "entry");
|
||||
DISubprogramRef di_function = DICreateFunction(di_builder, di_compile_unit, name, name, file, line,
|
||||
subroutine_type, 0, 1, 0);
|
||||
LLVMPositionBuilderAtEnd(llvm_builder, bb);
|
||||
DIFunctionAddSubprogram(function, di_function);
|
||||
return di_function;
|
||||
}
|
||||
static DIFileRef file;
|
||||
static DISubroutineTypeRef subroutine_type;
|
||||
|
||||
#define FOO_FUNCTION "foo"
|
||||
#define MAIN_FUNCTION "main"
|
||||
@@ -68,47 +48,45 @@ create_function_with_entry(const char *name, int line) {
|
||||
|
||||
static void
|
||||
create_foo() {
|
||||
DISubprogramRef di = create_function_with_entry(FOO_FUNCTION, 5);
|
||||
LLVMBuilderSetDebugLocation(llvm_builder, 5, 14, di);
|
||||
LLVMBuildRetVoid(llvm_builder);
|
||||
DISubprogramRef di;
|
||||
location loc = {&file, 5};
|
||||
create_function_with_entry(FOO_FUNCTION, loc, subroutine_type, &di);
|
||||
LLVMBuilderSetDebugLocation(g_codegen.llvm_builder, 5, 14, SCOPE(di));
|
||||
LLVMBuildRetVoid(g_codegen.llvm_builder);
|
||||
}
|
||||
|
||||
static void
|
||||
create_main_caller_foo() {
|
||||
DISubprogramRef di = create_function_with_entry(MAIN_CALLER_FOO_FUNCTION, 2);
|
||||
LLVMValueRef fn = LLVMGetNamedFunction(module, FOO_FUNCTION);
|
||||
LLVMBuilderSetDebugLocation(llvm_builder, 5, 2, di);
|
||||
LLVMBuildCall(llvm_builder, fn, NULL, 0, "");
|
||||
LLVMBuilderResetDebugLocation(llvm_builder);
|
||||
LLVMBuildRetVoid(llvm_builder);
|
||||
DISubprogramRef di;
|
||||
location loc = {&file, 2};
|
||||
create_function_with_entry(MAIN_CALLER_FOO_FUNCTION, loc, subroutine_type, &di);
|
||||
LLVMValueRef fn = LLVMGetNamedFunction(g_codegen.module, FOO_FUNCTION);
|
||||
LLVMBuilderSetDebugLocation(g_codegen.llvm_builder, 5, 2, SCOPE(di));
|
||||
LLVMBuildCall(g_codegen.llvm_builder, fn, NULL, 0, "");
|
||||
LLVMBuilderResetDebugLocation(g_codegen.llvm_builder);
|
||||
LLVMBuildRetVoid(g_codegen.llvm_builder);
|
||||
}
|
||||
|
||||
static void
|
||||
create_main() {
|
||||
DISubprogramRef di = create_function_with_entry(MAIN_FUNCTION, 1);
|
||||
LLVMValueRef fn = LLVMGetNamedFunction(module, MAIN_CALLER_FOO_FUNCTION);
|
||||
LLVMBuilderSetDebugLocation(llvm_builder, 2, 12, di);
|
||||
LLVMBuildCall(llvm_builder, fn, NULL, 0, "");
|
||||
LLVMBuilderSetDebugLocation(llvm_builder, 3, 4, di);
|
||||
LLVMBuildRetVoid(llvm_builder);
|
||||
DISubprogramRef di;
|
||||
location loc = {&file, 1};
|
||||
create_function_with_entry(MAIN_FUNCTION, loc, subroutine_type, &di);
|
||||
LLVMValueRef fn = LLVMGetNamedFunction(g_codegen.module, MAIN_CALLER_FOO_FUNCTION);
|
||||
LLVMBuilderSetDebugLocation(g_codegen.llvm_builder, 2, 12, SCOPE(di));
|
||||
LLVMBuildCall(g_codegen.llvm_builder, fn, NULL, 0, "");
|
||||
LLVMBuilderSetDebugLocation(g_codegen.llvm_builder, 3, 4, SCOPE(di));
|
||||
LLVMBuildRetVoid(g_codegen.llvm_builder);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main() {
|
||||
module = LLVMModuleCreateWithName("test");
|
||||
di_builder = DICreateBuilder(module);
|
||||
di_compile_unit = DICreateCompilationUnit(di_builder, 4,
|
||||
"<stdin>", "",
|
||||
"konanc", 0, "", 0);
|
||||
llvm_builder = LLVMCreateBuilderInContext(LLVMGetModuleContext(module));
|
||||
file = DICreateFile(di_builder, "<stdin>", "");
|
||||
subroutine_type = DICreateSubroutineType(di_builder, NULL, 0);
|
||||
codegen_init();
|
||||
file = DICreateFile(g_codegen.di_builder, "<stdin>", "");
|
||||
subroutine_type = DICreateSubroutineType(g_codegen.di_builder, NULL, 0);
|
||||
create_foo();
|
||||
create_main_caller_foo();
|
||||
create_main();
|
||||
DIFinalize(di_builder);
|
||||
|
||||
LLVMVerifyModule(module, LLVMPrintMessageAction, NULL);
|
||||
LLVMDumpModule(module);
|
||||
codegen_destroy();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <llvm-c/Analysis.h>
|
||||
#include <DebugInfoC.h>
|
||||
|
||||
#include <common.h>
|
||||
/**
|
||||
* 0:b-backend-dwarf:minamoto@unit-703(0)# clang -xc -S -g -emit-llvm -o - -
|
||||
* "TERMCAP", line 20, col 1, terminal 'SC': Missing separator
|
||||
@@ -71,63 +71,37 @@
|
||||
* !16 = !DILocation(line: 3, column: 3, scope: !7)
|
||||
*/
|
||||
|
||||
static LLVMModuleRef module;
|
||||
static DIBuilderRef di_builder;
|
||||
static LLVMBuilderRef llvm_builder;
|
||||
static DICompileUnitRef di_compile_unit;
|
||||
static DIFileRef file;
|
||||
static DISubroutineTypeRef subroutine_type;
|
||||
static LLVMTypeRef int_type;
|
||||
static DITypeOpaqueRef di_int_type;
|
||||
|
||||
static LLVMValueRef
|
||||
create_function(const char* name) {
|
||||
LLVMTypeRef function_type = LLVMFunctionType(int_type, NULL, 0, 0);
|
||||
return LLVMAddFunction(module, name, function_type);
|
||||
}
|
||||
|
||||
static DISubprogramRef
|
||||
create_function_with_entry(const char *name, int line) {
|
||||
LLVMValueRef function = create_function(name);
|
||||
LLVMBasicBlockRef bb = LLVMAppendBasicBlock(function, "entry");
|
||||
DISubprogramRef di_function = DICreateFunction(di_builder, di_compile_unit, name, name, file, line,
|
||||
subroutine_type, 0, 1, 0);
|
||||
LLVMPositionBuilderAtEnd(llvm_builder, bb);
|
||||
DIFunctionAddSubprogram(function, di_function);
|
||||
return di_function;
|
||||
}
|
||||
|
||||
static void
|
||||
create_main() {
|
||||
DISubprogramRef di = create_function_with_entry("main", 1);
|
||||
LLVMValueRef address = LLVMBuildAlloca(llvm_builder, int_type, "");
|
||||
DILocationRef location = LLVMBuilderSetDebugLocation(llvm_builder, 2, 1, di);
|
||||
DILocalVariableRef variable_a = DICreateAutoVariable(di_builder, di, "a", file, 2, di_int_type);
|
||||
DIInsertDeclarationWithEmptyExpression(di_builder, address, variable_a, location, LLVMGetInsertBlock(llvm_builder));
|
||||
LLVMBuildStore(llvm_builder, LLVMConstInt(int_type, 42, 1), address);
|
||||
LLVMValueRef value = LLVMBuildLoad(llvm_builder, address, "");
|
||||
LLVMBuildRet(llvm_builder, value);
|
||||
DISubprogramRef di;
|
||||
location loc = {&file, 1};
|
||||
create_function_with_entry("main", loc, subroutine_type, &di);
|
||||
LLVMValueRef address = LLVMBuildAlloca(g_codegen.llvm_builder, int_type, "");
|
||||
DILocationRef location = LLVMBuilderSetDebugLocation(g_codegen.llvm_builder,
|
||||
2, 1, SCOPE(di));
|
||||
DILocalVariableRef variable_a = DICreateAutoVariable(g_codegen.di_builder, SCOPE(di),
|
||||
"a", file, 2, di_int_type);
|
||||
DIInsertDeclarationWithEmptyExpression(g_codegen.di_builder, address, variable_a,
|
||||
location, LLVMGetInsertBlock(g_codegen.llvm_builder));
|
||||
LLVMBuildStore(g_codegen.llvm_builder, LLVMConstInt(int_type, 42, 1), address);
|
||||
LLVMValueRef value = LLVMBuildLoad(g_codegen.llvm_builder, address, "");
|
||||
LLVMBuildRet(g_codegen.llvm_builder, value);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main() {
|
||||
module = LLVMModuleCreateWithName("test");
|
||||
di_builder = DICreateBuilder(module);
|
||||
di_compile_unit = DICreateCompilationUnit(di_builder, 4,
|
||||
"<stdin>", "",
|
||||
"konanc", 0, "", 0);
|
||||
llvm_builder = LLVMCreateBuilderInContext(LLVMGetModuleContext(module));
|
||||
file = DICreateFile(di_builder, "<stdin>", "");
|
||||
subroutine_type = DICreateSubroutineType(di_builder, NULL, 0);
|
||||
codegen_init();
|
||||
file = DICreateFile(g_codegen.di_builder, "<stdin>", "");
|
||||
subroutine_type = DICreateSubroutineType(g_codegen.di_builder, NULL, 0);
|
||||
int_type = LLVMInt32Type();
|
||||
di_int_type = DICreateBasicType(di_builder, "int", 32, 4, 0);
|
||||
di_int_type = TYPE(DICreateBasicType(g_codegen.di_builder, "int", 32, 4, 0));
|
||||
create_main();
|
||||
DIFinalize(di_builder);
|
||||
|
||||
LLVMVerifyModule(module, LLVMPrintMessageAction, NULL);
|
||||
LLVMDumpModule(module);
|
||||
LLVMDisposeBuilder(llvm_builder);
|
||||
LLVMDisposeModule(module);
|
||||
LLVMShutdown();
|
||||
codegen_destroy();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include <DebugInfoC.h>
|
||||
#include <common.h>
|
||||
//clang llvmDebugInfoC/test/demo.c -IllvmDebugInfoC/include/ -Idependencies/all/clang+llvm-3.9.0-darwin-macos/include -c
|
||||
|
||||
//c++ demo.o -Idependencies/all/clang+llvm-3.9.0-darwin-macos/include -Ldependencies/all/clang+llvm-3.9.0-darwin-macos/lib -lLLVMCore -lLLVMSupport -lncurses -o demo
|
||||
@@ -88,31 +89,25 @@
|
||||
// !23 = !DILocation(line: 4, column: 10, scope: !17)
|
||||
// !24 = !DILocation(line: 4, column: 3, scope: !17)
|
||||
|
||||
int main() {
|
||||
LLVMModuleRef module = LLVMModuleCreateWithName("test");
|
||||
DIBuilderRef builder = DICreateBuilder(module);
|
||||
DIFileRef file = DICreateFile(builder, "1.kt", "src");
|
||||
DIModuleRef m = DICreateModule(builder, m, "a.out", "", "", "");
|
||||
DICompileUnitRef cu = DICreateCompilationUnit(builder, 4, "1.kt", "src", "konanc", 0, "", 0);
|
||||
DIBasicTypeRef type0 = DICreateBasicType(builder, "int", 32, 4, 0);
|
||||
DISubroutineTypeRef subroutineType = DICreateSubroutineType(builder, &type0, 1);
|
||||
|
||||
int
|
||||
main() {
|
||||
codegen_init();
|
||||
DIBasicTypeRef type0 = DICreateBasicType(g_codegen.di_builder, "int", 32, 4, 0);
|
||||
DISubroutineTypeRef subroutineType = DICreateSubroutineType(g_codegen.di_builder, (DITypeOpaqueRef *)&type0, 1);
|
||||
const char *functionName = "foo";
|
||||
DIFileRef file = DICreateFile(g_codegen.di_builder, "1.kt", "src");
|
||||
DISubprogramRef diFunction = DICreateFunction(g_codegen.di_builder, SCOPE(g_codegen.di_compile_unit), functionName, "foo:link", file, 66, subroutineType, 0, 1, 0);
|
||||
|
||||
DISubprogramRef diFunction = DICreateFunction(builder, cu, functionName, "foo:link", file, 66, subroutineType, 0, 1, 0);
|
||||
|
||||
//function creation.
|
||||
LLVMBuilderRef llvmBuilder = LLVMCreateBuilderInContext(LLVMGetModuleContext(module));
|
||||
|
||||
LLVMTypeRef intType = LLVMInt32Type();
|
||||
LLVMValueRef functionType = LLVMFunctionType(intType, &intType, 1, 0);
|
||||
LLVMValueRef llvmFunction = LLVMAddFunction(module, functionName, functionType);
|
||||
LLVMValueRef llvmFunction = LLVMAddFunction(g_codegen.module, functionName, functionType);
|
||||
DIFunctionAddSubprogram(llvmFunction, diFunction);
|
||||
LLVMBasicBlockRef bb = LLVMAppendBasicBlock(llvmFunction, "entry");
|
||||
LLVMPositionBuilderAtEnd(llvmBuilder, bb);
|
||||
LLVMBuilderSetDebugLocation(llvmBuilder, 42, 15, diFunction);
|
||||
LLVMValueRef ret = LLVMBuildRet(llvmBuilder, LLVMGetParam(llvmFunction, 0));
|
||||
|
||||
DIFinalize(builder);
|
||||
LLVMDumpModule(module);
|
||||
LLVMPositionBuilderAtEnd(g_codegen.llvm_builder, bb);
|
||||
LLVMBuilderSetDebugLocation(g_codegen.llvm_builder, 42, 15, SCOPE(diFunction));
|
||||
LLVMValueRef ret = LLVMBuildRet(g_codegen.llvm_builder, LLVMGetParam(llvmFunction, 0));
|
||||
codegen_destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <DebugInfoC.h>
|
||||
#include <common.h>
|
||||
/**
|
||||
* 0:b-debugger-types:minamoto@unit-703(0)# clang -g -xc -emit-llvm -S -o - -
|
||||
* struct A{
|
||||
* int a;
|
||||
* int b;
|
||||
* };
|
||||
*
|
||||
* struct A* foo(struct A* a) {
|
||||
* a->a += 1;
|
||||
* return a;
|
||||
* }
|
||||
* ; ModuleID = '-'
|
||||
* source_filename = "-"
|
||||
* target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
||||
* target triple = "x86_64-apple-macosx10.12.0"
|
||||
*
|
||||
* %struct.A = type { i32, i32 }
|
||||
*
|
||||
* ; Function Attrs: nounwind ssp uwtable
|
||||
* define %struct.A* @foo(%struct.A*) #0 !dbg !7 {
|
||||
* %2 = alloca %struct.A*, align 8
|
||||
* store %struct.A* %0, %struct.A** %2, align 8
|
||||
* call void @llvm.dbg.declare(metadata %struct.A** %2, metadata !17, metadata !18), !dbg !19
|
||||
* %3 = load %struct.A*, %struct.A** %2, align 8, !dbg !20
|
||||
* %4 = getelementptr inbounds %struct.A, %struct.A* %3, i32 0, i32 0, !dbg !21
|
||||
* %5 = load i32, i32* %4, align 4, !dbg !22
|
||||
* %6 = add nsw i32 %5, 1, !dbg !22
|
||||
* store i32 %6, i32* %4, align 4, !dbg !22
|
||||
* %7 = load %struct.A*, %struct.A** %2, align 8, !dbg !23
|
||||
* ret %struct.A* %7, !dbg !24
|
||||
* }
|
||||
*
|
||||
* ; Function Attrs: nounwind readnone
|
||||
* declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
|
||||
*
|
||||
* attributes #0 = { nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
* attributes #1 = { nounwind readnone }
|
||||
*
|
||||
* !llvm.dbg.cu = !{!0}
|
||||
* !llvm.module.flags = !{!3, !4, !5}
|
||||
* !llvm.ident = !{!6}
|
||||
*
|
||||
* !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Apple LLVM version 8.1.0 (clang-802.0.36)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
|
||||
* !1 = !DIFile(filename: "-", directory: "/Users/minamoto/ws/.git-trees/debugger-types")
|
||||
* !2 = !{}
|
||||
* !3 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
* !4 = !{i32 2, !"Debug Info Version", i32 700000003}
|
||||
* !5 = !{i32 1, !"PIC Level", i32 2}
|
||||
* !6 = !{!"Apple LLVM version 8.1.0 (clang-802.0.36)"}
|
||||
* !7 = distinct !DISubprogram(name: "foo", scope: !8, file: !8, line: 6, type: !9, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
|
||||
* !8 = !DIFile(filename: "<stdin>", directory: "/Users/minamoto/ws/.git-trees/debugger-types")
|
||||
* !9 = !DISubroutineType(types: !10)
|
||||
* !10 = !{!11, !11}
|
||||
* !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, align: 64)
|
||||
* !12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !8, line: 1, size: 64, align: 32, elements: !13)
|
||||
* !13 = !{!14, !16}
|
||||
* !14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !8, line: 2, baseType: !15, size: 32, align: 32)
|
||||
* !15 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
|
||||
* !16 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !8, line: 3, baseType: !15, size: 32, align: 32, offset: 32)
|
||||
* !17 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !8, line: 6, type: !11)
|
||||
* !18 = !DIExpression()
|
||||
* !19 = !DILocation(line: 6, column: 25, scope: !7)
|
||||
* !20 = !DILocation(line: 7, column: 2, scope: !7)
|
||||
* !21 = !DILocation(line: 7, column: 5, scope: !7)
|
||||
* !22 = !DILocation(line: 7, column: 7, scope: !7)
|
||||
* !23 = !DILocation(line: 8, column: 9, scope: !7)
|
||||
* !24 = !DILocation(line: 8, column: 2, scope: !7)
|
||||
*/
|
||||
static DIFileRef file;
|
||||
static DISubroutineTypeRef subroutine_type;
|
||||
static LLVMTypeRef int_type;
|
||||
|
||||
static void
|
||||
create_main() {
|
||||
DISubprogramRef di;
|
||||
location loc = {&file, 1};
|
||||
create_function_with_entry("main", loc, subroutine_type, &di);
|
||||
LLVMBuildRet(g_codegen.llvm_builder, LLVMConstInt(LLVMInt32Type(), 42, 1));
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main() {
|
||||
codegen_init();
|
||||
DITypeOpaqueRef int_type = TYPE(DICreateBasicType(g_codegen.di_builder, "int", 32, 4, 0));
|
||||
DIDerivedTypeRef elements_int_type[2];
|
||||
file = DICreateFile(g_codegen.di_builder, "<stdin>", "");
|
||||
DICompositeTypeRef tempA = DICreateReplaceableCompositeType(g_codegen.di_builder, "A", SCOPE(g_codegen.di_compile_unit), file, 2);
|
||||
elements_int_type[0] = DICreateMemberType(
|
||||
/* builder = */ g_codegen.di_builder,
|
||||
/* scope = */ SCOPE(tempA), /* note: here dump points to structure ???*/
|
||||
/* name = */ "a",
|
||||
/* file = */ file,
|
||||
/* lineNum = */ 3,
|
||||
/* sizeInBits = */ 32,
|
||||
/* alignInBits = */ 32,
|
||||
/* offsetInBits = */ 0,
|
||||
/* flags = */ 0,
|
||||
/* type = */ int_type);
|
||||
elements_int_type[1] = DICreateMemberType(
|
||||
/* builder = */ g_codegen.di_builder,
|
||||
/* scope = */ SCOPE(tempA),
|
||||
/* name = */ "b",
|
||||
/* file = */ file,
|
||||
/* lineNum = */ 4,
|
||||
/* sizeInBits = */ 32,
|
||||
/* alignInBits = */ 32,
|
||||
/* offsetInBits = */ 32,
|
||||
/* flags = */ 0,
|
||||
/* type = */ int_type);
|
||||
|
||||
DITypeOpaqueRef A_type = TYPE(DICreateStructType(
|
||||
g_codegen.di_builder,
|
||||
g_codegen.di_compile_unit,
|
||||
"A", file, 2, 64, 32, 0, (void *)0, elements_int_type, 2, tempA));
|
||||
subroutine_type = DICreateSubroutineType(g_codegen.di_builder, &A_type, 1);
|
||||
create_main();
|
||||
codegen_destroy();
|
||||
}
|
||||
Reference in New Issue
Block a user