Bir C++ yapısının bir tamsayı alanının başka bir tamsayı sabiti ile bölünmesi durumunda, LLDB'de (Xcode 7.3'te bulunan) bir ifadeyi değerlendirmeye çalıştığımda, LLDB'nin beklendiği gibi değerlendirilmediğini fark ettim :LLDB ifade değerlendirmesinde tamsayı bölümü
(lldb) l 1
1 #include <cstdio>
2
3 typedef struct {
4 int value;
5 } Item;
6
7 int main() {
8
9 Item item;
10 item.value = 1800;
(lldb)
11 printf("%d\n", item.value);
12 return 0;
13 }
(lldb) b 11
Breakpoint 1: where = x`main + 29 at a.cpp:11, address = 0x0000000100000f6d
(lldb) run
Process 44385 launched: '/tmp/x' (x86_64)
Process 44385 stopped
* thread #1: tid = 0x53ad87, 0x0000000100000f6d x`main + 29 at a.cpp:11, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000f6d x`main + 29 at a.cpp:11
8
9 Item item;
10 item.value = 1800;
-> 11 printf("%d\n", item.value);
12 return 0;
13 }
(lldb) p item.value
(int) $0 = 1800
(lldb) p item.value/2
(int) $1 = 0
(lldb) p item.value/2.0
(double) $2 = 900
Not item.value/2
o 0 olarak değerlendirildi ancak item.value/2.0
900. LLDB tasarımında amaçlanan bu davranış mı? Bilinen bir böcek mi?
DÜZENLEME: İşte
ifadesi için günlüğü etkinleştirdikten sonra çıktısı:
(lldb) p item.value/2
== [UserExpression::Evaluate] Parsing expression item.value/2 ==
ClangUserExpression::ScanContext()
Parsing the following code:
#ifndef NULL
#define NULL (__null)
#endif
#ifndef Nil
#define Nil (__null)
#endif
#ifndef nil
#define nil (__null)
#endif
#ifndef YES
#define YES ((BOOL)1)
#endif
#ifndef NO
#define NO ((BOOL)0)
#endif
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef unsigned short unichar;
extern "C"
{
int printf(const char * __restrict, ...);
}
typedef signed char BOOL;
void
$__lldb_expr(void *$__lldb_arg)
{
item.value/2;
}
LayoutRecordType[1] on (ASTContext*)0x7fbedb9aba00 for (RecordDecl*)0x7fbedb9843b0 [name = '_objc_super']
LayoutRecordType[2] on (ASTContext*)0x7fbedb9aba00 for (RecordDecl*)0x7fbedb984680 [name = '_message_ref_t']
ClangExpressionDeclMap::FindExternalVisibleDecls[0] for '$__lldb_arg' in a 'TranslationUnit'
CEDM::FEVD[0] Searching the root namespace
ClangASTSource::FindExternalVisibleDecls[0] on (ASTContext*)0x7fbedb9aba00 for '$__lldb_arg' in a 'TranslationUnit'
CAS::FEVD[0] Searching the root namespace
ClangExpressionDeclMap::FindExternalVisibleDecls[1] for '$__lldb_expr' in a 'TranslationUnit'
CEDM::FEVD[1] Searching the root namespace
ClangASTSource::FindExternalVisibleDecls[1] on (ASTContext*)0x7fbedb9aba00 for '$__lldb_expr' in a 'TranslationUnit'
CAS::FEVD[1] Searching the root namespace
ClangExpressionDeclMap::FindExternalVisibleDecls[2] for 'item' in a 'TranslationUnit'
CEDM::FEVD[2] Searching the root namespace
[ClangASTImporter] Imported (CXXRecordDecl*)0x7fbedb22f128, named (from (Decl*)0x7fbedaa596d8), metadata 0x375
[ClangASTImporter] Decl has no origin information in (ASTContext*)0x7fbedaa50c00
[ClangASTImporter] To is a TagDecl - attributes Lexical [complete->incomplete]
[ClangASTImporter] Imported (TypedefDecl*)0x7fbedb22f260, named Item (from (Decl*)0x7fbedaa59810), metadata 0xffffffffffffffff
[ClangASTImporter] Decl has no origin information in (ASTContext*)0x7fbedaa50c00
CEDM::FEVD[2] Found variable item, returned static Item &item (original Item)
FindExternalLexicalDecls[0] on (ASTContext*)0x7fbedb9aba00 in '' (CXXRecordDecl*)0x7fbedb22f128
FELD[0] Original decl (ASTContext*)0x7fbedaa50c00 (Decl*)0x7fbedaa596d8:
struct {
int value;
}
FELD[0] Adding [to CXXRecordDecl ] lexical FieldDecl int value
[ClangASTImporter] Imported (FieldDecl*)0x7fbedb22f3c8, named value (from (Decl*)0x7fbedaa598e0), metadata 0x379
[ClangASTImporter] Decl has no origin information in (ASTContext*)0x7fbedaa50c00
Last statement is an rvalue with type: int
LayoutRecordType[3] on (ASTContext*)0x7fbedb9aba00 for (RecordDecl*)0x7fbedb22f128 [name = '']
LRT[3] returned:
LRT[3] Original = (RecordDecl*)0x7fbedaa596d8
LRT[3] Size = 32
LRT[3] Alignment = 32
LRT[3] Fields:
LRT[3] (FieldDecl*)0x7fbedb22f3c8, Name = 'value', Offset = 0 bits
LRT[3] Bases:
Found function _Z12$__lldb_exprPv for $__lldb_expr
Module as passed in to IRForTarget:
"; ModuleID = '$__lldb_module'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
%struct.anon = type { i32 }
@"_ZZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i32 0, align 4
@"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i8 0, align 1
@_ZL4item = external constant %struct.anon*, align 8
; Function Attrs: nounwind
define void @"_Z12$__lldb_exprPv"(i8* %"$__lldb_arg") #0 {
%1 = alloca i8*, align 8, !clang.decl.ptr !8
store i8* %"$__lldb_arg", i8** %1, align 8
%2 = load i8, i8* @"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result", align 1
%3 = icmp eq i8 %2, 0
br i1 %3, label %4, label %9
; <label>:4 ; preds = %0
%5 = load %struct.anon*, %struct.anon** @_ZL4item, align 8
%6 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 0
%7 = load i32, i32* %6, align 4
%8 = sdiv i32 %7, 2
store i32 %8, i32* @"_ZZ12$__lldb_exprPvE19$__lldb_expr_result", align 4
store i8 1, i8* @"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result", align 1
br label %9
; <label>:9 ; preds = %4, %0
ret void
}
attributes #0 = { nounwind "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-nans-fp-math"="false" "stack-protector-buffer-size"="0" "target-features"="+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
!clang.global.decl.ptrs = !{!0, !1, !0, !2}
!llvm.module.flags = !{!3, !4, !5, !6}
!llvm.ident = !{!7}
!0 = !{i32* @"_ZZ12$__lldb_exprPvE19$__lldb_expr_result", i64 140457697014984}
!1 = !{void (i8*)* @"_Z12$__lldb_exprPv", i64 140457697013856}
!2 = !{%struct.anon** @_ZL4item, i64 140457697014568}
!3 = !{i32 1, !"Objective-C Version", i32 2}
!4 = !{i32 1, !"Objective-C Image Info Version", i32 0}
!5 = !{i32 1, !"Objective-C Image Info Section", !"__DATA, __objc_imageinfo, regular, no_dead_strip"}
!6 = !{i32 4, !"Objective-C Garbage Collection", i32 0}
!7 = !{!"Apple LLVM version 3.8.0 (clang-703.0.29)"}
!8 = !{i64 140457704716640}
"
Result name: "_ZZ12$__lldb_exprPvE19$__lldb_expr_result"
Found result in the IR: "@"_ZZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i32 0, align 4"
Found result decl: "static int $__lldb_expr_resultitem.value/2"
Result decl type: "int"
Creating a new result global: "$RESULT_NAME" with size 0x4
Replacing "@"_ZZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i32 0, align 4" with "@"$RESULT_NAME" = external global i32"
[ClangASTImporter] DeportType called on (BuiltinType*)0x7fbedb983dc0 from (ASTContext*)0x7fbedb9aba00 to (ASTContext*)0x7fbedab3fa00
Examining non-declaration function _Z12$__lldb_exprPv
Examining _ZGVZ12$__lldb_exprPvE19$__lldb_expr_result, DeclForGlobalValue returns 0x0
Examining _ZL4item, DeclForGlobalValue returns 0x7fbedb22f328
MaybeHandleVariable (@_ZL4item = external constant %struct.anon*, align 8)
Type of "item" is [clang "Item &", llvm "%struct.anon**"] [size 8, align 8]
Adding value for (NamedDecl*)0x7fbedb22f328 [item - item] to the structure
Placed at 0x8
Examining reloc_placeholder, DeclForGlobalValue returns 0x0
Examining $RESULT_NAME, DeclForGlobalValue returns 0x7fbedb22f4c8
MaybeHandleVariable (@"$RESULT_NAME" = external global i32)
Type of "$__lldb_expr_result" is [clang "int *", llvm "i32**"] [size 8, align 8]
Adding value for (NamedDecl*)0x7fbedb22f4c8 [$__lldb_expr_result - $RESULT_NAME] to the structure
Already placed at 0x0
Placed at 0x0
Element arrangement:
Arg: "i8* %"$__lldb_arg""
"item" ("item") placed at 8
Replacing [@_ZL4item = external constant %struct.anon*, align 8]
"$RESULT_NAME" ("$__lldb_expr_result") placed at 0
Replacing [@"$RESULT_NAME" = external global i32]
Total structure [align 8, size 16]
Did remove @"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i8 0, align 1
Did remove @reloc_placeholder = internal global i8 0
== ClangASTMetrics output ==
-- Global metrics --
Number of visible Decl queries by name : 5
Number of lexical Decl queries : 1
Number of imports initiated by LLDB : 1
Number of imports conducted by Clang : 3
Number of Decls completed : 0
Number of records laid out : 4
-- Local metrics --
Number of visible Decl queries by name : 5
Number of lexical Decl queries : 1
Number of imports initiated by LLDB : 1
Number of imports conducted by Clang : 3
Number of Decls completed : 0
Number of records laid out : 3
[ClangASTImporter] Forgetting destination (ASTContext*)0x7fbedb9aba00
[ClangASTImporter] Forgetting source->dest (ASTContext*)0x7fbedb9aba00->(ASTContext*)0x7fbedab3fa00
== [UserExpression::Evaluate] Executing expression ==
IRMemoryMap::Malloc (16, 0x8, 0x3, eAllocationPolicyHostOnly) -> 0x100036000
IRMemoryMap::Malloc (524288, 0x8, 0x3, eAllocationPolicyHostOnly) -> 0x100037000
IRMemoryMap::Malloc process_sp=0x7fbedaa59e00, process_sp->CanJIT()=true, process_sp->IsAlive()=true
IRMemoryMap::Malloc (4, 0x4, 0x3, eAllocationPolicyMirror) -> 0x100036010
IRMemoryMap::WriteMemory (0x100036000, 0x7fff5f586850, 0x8) went to [0x100036000..0x100036010)
EntityVariable::Materialize [address = 0x100036008, m_variable_sp = item]
IRMemoryMap::WriteMemory (0x100036008, 0x7fff5f586650, 0x8) went to [0x100036000..0x100036010)
Materializer::Materialize (frame_sp = 0x7fbed9ff8f20, process_address = 0x100036000) materialized:
IRMemoryMap::ReadMemory (0x100036000, 0x7fbed9e22270, 0x8) came from [0x100036000..0x100036010)
IRMemoryMap::ReadMemory (0x100036010, 0x7fbed9e2e0b0, 0x4) came from [0x100036010..0x100036014)
0x100036000: EntityResultVariable
Pointer:
0x100036000: 10 60 03 00 01 00 00 00
Temporary allocation:
0x100036010: 00 00 00 00
IRMemoryMap::ReadMemory (0x100036008, 0x7fbed9e22270, 0x8) came from [0x100036000..0x100036010)
0x100036008: EntityVariable
Pointer:
0x100036008: a8 fb bf 5f ff 7f 00 00
Points to process memory:
Module as passed in to IRInterpreter::Interpret:
"; ModuleID = '$__lldb_module'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
%struct.anon = type { i32 }
; Function Attrs: nounwind
define void @"_Z12$__lldb_exprPv"(i8* %"$__lldb_arg") #0 {
%1 = getelementptr i8, i8* %"$__lldb_arg", i32 8
%2 = bitcast i8* %1 to %struct.anon**
%3 = getelementptr i8, i8* %"$__lldb_arg", i32 0
%4 = bitcast i8* %3 to i32**
%5 = load i32*, i32** %4
%6 = alloca i8*, align 8, !clang.decl.ptr !9
store i8* %"$__lldb_arg", i8** %6, align 8
%7 = icmp eq i8 0, 0
br i1 %7, label %8, label %13
; <label>:8 ; preds = %0
%9 = load %struct.anon*, %struct.anon** %2, align 8
%10 = getelementptr inbounds %struct.anon, %struct.anon* %9, i32 0, i32 0
%11 = load i32, i32* %10, align 4
%12 = sdiv i32 %11, 2
store i32 %12, i32* %5, align 4
br label %13
; <label>:13 ; preds = %8, %0
ret void
}
attributes #0 = { nounwind "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-nans-fp-math"="false" "stack-protector-buffer-size"="0" "target-features"="+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
!clang.global.decl.ptrs = !{!0, !1, !0, !2, !3}
!llvm.module.flags = !{!4, !5, !6, !7}
!llvm.ident = !{!8}
!0 = distinct !{null, i64 140457697014984}
!1 = !{void (i8*)* @"_Z12$__lldb_exprPv", i64 140457697013856}
!2 = !{null, i64 140457697014568}
!3 = !{null, i64 140457697014984}
!4 = !{i32 1, !"Objective-C Version", i32 2}
!5 = !{i32 1, !"Objective-C Image Info Version", i32 0}
!6 = !{i32 1, !"Objective-C Image Info Section", !"__DATA, __objc_imageinfo, regular, no_dead_strip"}
!7 = !{i32 4, !"Objective-C Garbage Collection", i32 0}
!8 = !{!"Apple LLVM version 3.8.0 (clang-703.0.29)"}
!9 = !{i64 140457704716640}
"
IRMemoryMap::WriteMemory (0x1000b6ff8, 0x7fff5f585940, 0x8) went to [0x100037000..0x1000b7000)
Made an allocation for argument i8* %"$__lldb_arg"
Data region : 100036000
Ref region : 1000b6ff8
Interpreting %1 = getelementptr i8, i8* %"$__lldb_arg", i32 8
IRMemoryMap::WriteMemory (0x1000b6ff0, 0x7fbed9debe20, 0x8) went to [0x100037000..0x1000b7000)
Interpreted a GetElementPtrInst
P : i8* %"$__lldb_arg" 0x1000b6ff8
Poffset : %1 = getelementptr i8, i8* %"$__lldb_arg", i32 8 0x1000b6ff0
Interpreting %2 = bitcast i8* %1 to %struct.anon**
IRMemoryMap::WriteMemory (0x1000b6fe8, 0x7fbed9debe20, 0x8) went to [0x100037000..0x1000b7000)
Interpreting %3 = getelementptr i8, i8* %"$__lldb_arg", i32 0
IRMemoryMap::WriteMemory (0x1000b6fe0, 0x7fbed9debe20, 0x8) went to [0x100037000..0x1000b7000)
Interpreted a GetElementPtrInst
P : i8* %"$__lldb_arg" 0x1000b6ff8
Poffset : %3 = getelementptr i8, i8* %"$__lldb_arg", i32 0 0x1000b6fe0
Interpreting %4 = bitcast i8* %3 to i32**
IRMemoryMap::WriteMemory (0x1000b6fd8, 0x7fbed9debe20, 0x8) went to [0x100037000..0x1000b7000)
Interpreting %5 = load i32*, i32** %4
IRMemoryMap::ReadMemory (0x1000b6fd8, 0x7fbed9debe20, 0x8) came from [0x100037000..0x1000b7000)
IRMemoryMap::ReadMemory (0x100036000, 0x7fbed9debe20, 0x8) came from [0x100036000..0x100036010)
IRMemoryMap::WriteMemory (0x1000b6fd0, 0x7fbed9debe20, 0x8) went to [0x100037000..0x1000b7000)
Interpreted a LoadInst
P : 0x1000b6fd8
R : 0x100036000
D : 0x1000b6fd0
Interpreting %6 = alloca i8*, align 8, !clang.decl.ptr !9
IRMemoryMap::WriteMemory (0x1000b6fc0, 0x7fff5f5859e0, 0x8) went to [0x100037000..0x1000b7000)
Interpreted an AllocaInst
R : 0x1000b6fc8
P : 0x1000b6fc0
Interpreting store i8* %"$__lldb_arg", i8** %6, align 8
IRMemoryMap::ReadMemory (0x1000b6fc0, 0x7fbed9dec010, 0x8) came from [0x100037000..0x1000b7000)
IRMemoryMap::ReadMemory (0x1000b6ff8, 0x7fbed9dec010, 0x8) came from [0x100037000..0x1000b7000)
IRMemoryMap::WriteMemory (0x1000b6fc8, 0x7fbed9dec010, 0x8) went to [0x100037000..0x1000b7000)
Interpreted a StoreInst
D : 0x1000b6ff8
P : 0x1000b6fc0
R : 0x1000b6fc8
Interpreting %7 = icmp eq i8 0, 0
IRMemoryMap::WriteMemory (0x1000b6fbf, 0x7fbed9dec010, 0x1) went to [0x100037000..0x1000b7000)
Interpreted an ICmpInst
L : i8 0
R : i8 0
= : %7 = icmp eq i8 0, 0 0x1000b6fbf
Interpreting br i1 %7, label %8, label %13
Interpreted a BrInst with a condition
cond : %7 = icmp eq i8 0, 0 0x1000b6fbf
Interpreting %9 = load %struct.anon*, %struct.anon** %2, align 8
IRMemoryMap::ReadMemory (0x1000b6fe8, 0x7fbed9dec010, 0x8) came from [0x100037000..0x1000b7000)
IRMemoryMap::ReadMemory (0x100036008, 0x7fbed9dec010, 0x8) came from [0x100036000..0x100036010)
IRMemoryMap::WriteMemory (0x1000b6fb0, 0x7fbed9dec010, 0x8) went to [0x100037000..0x1000b7000)
Interpreted a LoadInst
P : 0x1000b6fe8
R : 0x100036008
D : 0x1000b6fb0
Interpreting %10 = getelementptr inbounds %struct.anon, %struct.anon* %9, i32 0, i32 0
IRMemoryMap::WriteMemory (0x1000b6fa8, 0x7fbed9dec010, 0x8) went to [0x100037000..0x1000b7000)
Interpreted a GetElementPtrInst
P : %9 = load %struct.anon*, %struct.anon** %2, align 8 0x1000b6fb0
Poffset : %10 = getelementptr inbounds %struct.anon, %struct.anon* %9, i32 0, i32 0 0x1000b6fa8
Interpreting %11 = load i32, i32* %10, align 4
IRMemoryMap::ReadMemory (0x1000b6fa8, 0x7fbed9dec010, 0x8) came from [0x100037000..0x1000b7000)
IRMemoryMap::WriteMemory (0x1000b6fa4, 0x7fbed9dec010, 0x4) went to [0x100037000..0x1000b7000)
Interpreted a LoadInst
P : 0x1000b6fa8
R : 0x7fff5fbffba8
D : 0x1000b6fa4
Interpreting %12 = sdiv i32 %11, 2
IRMemoryMap::WriteMemory (0x1000b6fa0, 0x7fbed9e23180, 0x4) went to [0x100037000..0x1000b7000)
Interpreted a sdiv
L : %11 = load i32, i32* %10, align 4 0x1000b6fa4
R : i32 2
= : %12 = sdiv i32 %11, 2 0x1000b6fa0
Interpreting store i32 %12, i32* %5, align 4
IRMemoryMap::ReadMemory (0x1000b6fd0, 0x7fbed9e23180, 0x8) came from [0x100037000..0x1000b7000)
IRMemoryMap::ReadMemory (0x1000b6fa0, 0x7fbed9e23180, 0x4) came from [0x100037000..0x1000b7000)
IRMemoryMap::WriteMemory (0x100036010, 0x7fbed9e23180, 0x4) went to [0x100036010..0x100036014)
Interpreted a StoreInst
D : 0x1000b6fa0
P : 0x1000b6fd0
R : 0x100036010
Interpreting br label %13
Interpreted a BrInst with no condition
Interpreting ret void
-- [UserExpression::FinalizeJITExecution] Dematerializing after execution --
Materializer::Dematerialize (frame_sp = 0x7fbed9ff8f20, process_address = 0x100036000) about to dematerialize:
IRMemoryMap::ReadMemory (0x100036000, 0x7fbed9e2e0b0, 0x8) came from [0x100036000..0x100036010)
IRMemoryMap::ReadMemory (0x100036010, 0x7fbed9e2e0b0, 0x4) came from [0x100036010..0x100036014)
0x100036000: EntityResultVariable
Pointer:
0x100036000: 10 60 03 00 01 00 00 00
Temporary allocation:
0x100036010: 00 00 00 00
IRMemoryMap::ReadMemory (0x100036008, 0x7fbed9e2e0b0, 0x8) came from [0x100036000..0x100036010)
0x100036008: EntityVariable
Pointer:
0x100036008: a8 fb bf 5f ff 7f 00 00
Points to process memory:
IRMemoryMap::ReadMemory (0x100036000, 0x7fbed9e2e0b0, 0x8) came from [0x100036000..0x100036010)
IRMemoryMap::ReadMemory (0x100036010, 0x7fbed9e23180, 0x4) came from [0x100036010..0x100036014)
IRMemoryMap::Free (0x100036010) freed [0x100036010..0x100036014)
EntityVariable::Dematerialize [address = 0x100036008, m_variable_sp = item]
== [UserExpression::Evaluate] Execution completed normally with result 0 ==
IRMemoryMap::Free (0x100036000) freed [0x100036000..0x100036010)
IRMemoryMap::Free (0x100037000) freed [0x100037000..0x1000b7000)
(int) $0 = 0
EDIT2: Bu sorun indirilen Ubuntu 14.04 için Swift 2.2 sürümünde birlikte LLDB içinde reproduced olduğunu swift.org.
Bunu LLDB sürümümde yeniden oluşturamıyorum. İfade değerlendirici günlüğünü 'log enable lldb expression' ile etkinleştirebilir ve hangi kodu ürettiğini görebilirdiniz? – TartanLlama