athirumu@torrent:~/git/lldb$ cd tools/lldb/test/lang/c/strings athirumu@torrent:~/git/lldb/tools/lldb/test/lang/c/strings$ make make: `a.out' is up to date. athirumu@torrent:~/git/lldb/tools/lldb/test/lang/c/strings$ lldb a.out Current executable set to 'a.out' (x86_64). (lldb) breakpoint set -f main.c -l 25 Breakpoint 1: where = a.out`main + 28 at main.c:24, address = 0x000000000040058c (lldb) r Process 3999 launched: '/home/athirumu/git/lldb/tools/lldb/test/lang/c/strings/a.out' (x86_64) Process 3999 stopped * thread #1: tid = 0x0f9f, 0x00000000004005b1 a.out`main + 65 at main.c:25, stop reason = step over frame #0: 0x00000000004005b1 a.out`main + 65 at main.c:25 22 const char *z = "vwxyz"; 23 24 printf("%s %d", a, (int)do_test(a)); // breakpoint 1 -> 25 } (lldb) expr (size_t)strlen("hello") (size_t) $1 = 140509107248080 (lldb) log enable lldb expr (lldb) expr (long)strlen("hello") == [ClangUserExpression::Evaluate] Parsing expression (long)strlen("hello") == ClangUserExpression::ScanContext() Parsing the following code: #undef NULL #undef Nil #undef nil #undef YES #undef NO #define NULL ((int)0) #define Nil ((Class)0) #define nil ((id)0) #define YES ((BOOL)1) #define NO ((BOOL)0) typedef int BOOL; typedef unsigned short unichar; void $__lldb_expr(void *$__lldb_arg) { (long)strlen("hello"); } LayoutRecordType[6] on (RecordDecl*)0xb8e190 [name = '_objc_super'] LayoutRecordType[7] on (RecordDecl*)0xb8e190 [name = '_message_ref_t'] FindExternalLexicalDecls[3] on (ASTContext*)0xb8e190 in (TranslationUnitDecl*)0xbe5f80 with null predicate ClangExpressionDeclMap::FindExternalVisibleDecls[18] for '$__lldb_arg' in a 'TranslationUnit' CEDM::FEVD[18] Searching the root namespace ClangASTSource::FindExternalVisibleDecls[18] on (ASTContext*)0xb8e190 for '$__lldb_arg' in a 'TranslationUnit' CAS::FEVD[18] Searching the root namespace ClangExpressionDeclMap::FindExternalVisibleDecls[19] for '$__lldb_expr' in a 'TranslationUnit' CEDM::FEVD[19] Searching the root namespace ClangASTSource::FindExternalVisibleDecls[19] on (ASTContext*)0xb8e190 for '$__lldb_expr' in a 'TranslationUnit' CAS::FEVD[19] Searching the root namespace ClangExpressionDeclMap::FindExternalVisibleDecls[20] for 'strlen' in a 'TranslationUnit' CEDM::FEVD[20] Searching the root namespace CEDM::FEVD[20] Found generic function strlen (description libc.so.6`strlen), returned static strlen(...) ClangASTSource::FindExternalVisibleDecls[20] on (ASTContext*)0xb8e190 for 'strlen' in a 'TranslationUnit' CAS::FEVD[20] Searching the root namespace Last statement is an rvalue with type: long Found function _Z12$__lldb_exprPv for $__lldb_expr Module as passed in to IRForTarget: "; ModuleID = '$__lldb_module' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64--linux" @"_ZZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i64 0, align 8 @"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i8 0 @.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1 define void @"_Z12$__lldb_exprPv"(i8* %"$__lldb_arg") nounwind { entry: %"$__lldb_arg.addr" = alloca i8*, align 8, !clang.decl.ptr !7 store i8* %"$__lldb_arg", i8** %"$__lldb_arg.addr", align 8 %0 = load i8* @"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result", align 1 %guard.uninitialized = icmp eq i8 %0, 0 br i1 %guard.uninitialized, label %init.check, label %init.end init.check: ; preds = %entry %call = call i64 (...)* @_ZL6strlenz(i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0)) store i64 %call, i64* @"_ZZ12$__lldb_exprPvE19$__lldb_expr_result", align 8 store i8 1, i8* @"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result" br label %init.end init.end: ; preds = %init.check, %entry ret void } declare i64 @_ZL6strlenz(...) !clang.global.decl.ptrs = !{!0, !1, !2, !0} !llvm.module.flags = !{!3, !4, !5, !6} !0 = metadata !{i64* @"_ZZ12$__lldb_exprPvE19$__lldb_expr_result", i64 12945312} !1 = metadata !{i64 (...)* @_ZL6strlenz, i64 12944496} !2 = metadata !{void (i8*)* @"_Z12$__lldb_exprPv", i64 12944272} !3 = metadata !{i32 1, metadata !"Objective-C Version", i32 2} !4 = metadata !{i32 1, metadata !"Objective-C Image Info Version", i32 0} !5 = metadata !{i32 1, metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip"} !6 = metadata !{i32 4, metadata !"Objective-C Garbage Collection", i32 0} !7 = metadata !{i64 12944080} " Result name: "_ZZ12$__lldb_exprPvE19$__lldb_expr_result" Found result in the IR: "@"_ZZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i64 0, align 8" Found result decl: "static long $__lldb_expr_result(long)strlen("hello")" Result decl type: "long" Creating a new result global: "$3" with size 0x8 Replacing "@"_ZZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i64 0, align 8" with "@"$3" = external global i64" Created persistent variable with flags 0x15 Unsupported instruction: %call = call i64 (...)* @_ZL6strlenz(i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0)) Examining non-declaration function _Z12$__lldb_exprPv Examining declaration function _ZL6strlenz Found "_ZL6strlenz" at 0x7fcad35f40a0 MaybeHandleCallArguments( %call = call i64 (...)* inttoptr (i64 140509106356384 to i64 (...)*)(i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0)), !lldb.call.realName !8) MaybeHandleVariable (i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0)) MaybeHandleVariable (@.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1) Examining _ZGVZ12$__lldb_exprPvE19$__lldb_expr_result, DeclForGlobalValue returns (nil) Examining reloc_placeholder, DeclForGlobalValue returns (nil) Examining $3, DeclForGlobalValue returns 0xc587a0 MaybeHandleVariable (@"$3" = external global i64) Type of "$__lldb_expr_result" is [clang "long *", llvm "i64**"] [size 8, align 8] Adding value for (NamedDecl*)0xc587a0 [$__lldb_expr_result - $3] to the structure Element arrangement: Arg: "i8* %"$__lldb_arg"" "$3" ("$__lldb_expr_result") placed at 0 Replacing [@"$3" = external global i64] Total structure [align 8, size 8] Allocated static data at 0x7fcad3b47000 Did remove @"_ZGVZ12$__lldb_exprPvE19$__lldb_expr_result" = internal global i8 0 Instrumenting load/store instruction: %2 = load i64** %1 Instrumenting load/store instruction: store i8* %"$__lldb_arg", i8** %"$__lldb_arg.addr", align 8 Instrumenting load/store instruction: store i64 %call, i64* %3, align 8 Module being sent to JIT: ; ModuleID = '$__lldb_module' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64--linux" define void @"_Z12$__lldb_exprPv"(i8* %"$__lldb_arg") nounwind { entry: %0 = getelementptr i8* %"$__lldb_arg", i32 0 %1 = bitcast i8* %0 to i64** %2 = bitcast i64** %1 to i8* call void (i8*, ...)* inttoptr (i64 140509111934976 to void (i8*, ...)*)(i8* %2) %3 = load i64** %1 %"$__lldb_arg.addr" = alloca i8*, align 8, !clang.decl.ptr !7 %4 = bitcast i8** %"$__lldb_arg.addr" to i8* call void (i8*, ...)* inttoptr (i64 140509111934976 to void (i8*, ...)*)(i8* %4) store i8* %"$__lldb_arg", i8** %"$__lldb_arg.addr", align 8 %guard.uninitialized = icmp eq i8 0, 0 br i1 %guard.uninitialized, label %init.check, label %init.end init.check: ; preds = %entry %call = call i64 (...)* inttoptr (i64 140509106356384 to i64 (...)*)(i8* getelementptr inbounds ([6 x i8]* inttoptr (i64 140509111939072 to [6 x i8]*), i32 0, i32 0)), !lldb.call.realName !8 %5 = bitcast i64* %3 to i8* call void (i8*, ...)* inttoptr (i64 140509111934976 to void (i8*, ...)*)(i8* %5) store i64 %call, i64* %3, align 8 br label %init.end init.end: ; preds = %init.check, %entry ret void } declare i64 @_ZL6strlenz(...) !clang.global.decl.ptrs = !{!0, !1, !2, !0, !0} !llvm.module.flags = !{!3, !4, !5, !6} !0 = metadata !{null, i64 12945312} !1 = metadata !{i64 (...)* inttoptr (i64 140509106356384 to i64 (...)*), i64 12944496} !2 = metadata !{void (i8*)* @"_Z12$__lldb_exprPv", i64 12944272} !3 = metadata !{i32 1, metadata !"Objective-C Version", i32 2} !4 = metadata !{i32 1, metadata !"Objective-C Image Info Version", i32 0} !5 = metadata !{i32 1, metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip"} !6 = metadata !{i32 4, metadata !"Objective-C Garbage Collection", i32 0} !7 = metadata !{i64 12944080} !8 = metadata !{[12 x i8] c"_ZL6strlenz\00"} RecordingMemoryManager::allocateCodeSection(Size=0x62, Alignment=16, SectionID=0) = 0x7f3a985e0008 [0x7f3a985e0008+0x62]->0x0 (alignment 16, section ID 0) RecordingMemoryManager::CommitAllocations() committed an allocation [0x7f3a985e0008+0x62]->0x7fcad3b46120 (alignment 16, section ID 0) RecordingMemoryManager::CommitAllocations() wrote an allocation [0x7f3a985e0008+0x62]->0x7fcad3b46120 (alignment 16, section ID 0) Code can be run in the target. Found function, has local address 0x7f3a985e0008 and remote address 0x7fcad3b46120 Function's code range is [0x7fcad3b46120+0x62] Function data has contents: 0x7fcad3b46120: 55 41 57 41 56 53 50 48 89 fb 40 30 ed 49 bf 00 0x7fcad3b46130: 60 b4 d3 ca 7f 00 00 30 c0 41 ff d7 4c 8b 33 48 0x7fcad3b46140: 8d 3c 24 30 c0 41 ff d7 48 89 1c 24 40 84 ed 75 0x7fcad3b46150: 26 48 b9 a0 40 5f d3 ca 7f 00 00 48 bf 00 70 b4 0x7fcad3b46160: d3 ca 7f 00 00 30 c0 ff d1 48 89 c3 4c 89 f7 30 0x7fcad3b46170: c0 41 ff d7 49 89 1e 48 83 c4 08 5b 41 5e 41 5f 0x7fcad3b46180: 5d c3 Function disassembly: 0x7fcad3b46120: 55 pushq %rbp 0x7fcad3b46121: 41 57 pushq %r15 0x7fcad3b46123: 41 56 pushq %r14 0x7fcad3b46125: 53 pushq %rbx 0x7fcad3b46126: 50 pushq %rax 0x7fcad3b46127: 48 89 fb movq %rdi, %rbx 0x7fcad3b4612a: 40 30 ed xorb %bpl, %bpl 0x7fcad3b4612d: 49 bf 00 60 b4 d3 ca 7f 00 00 movabsq$140509111934976, %r15 0x7fcad3b46137: 30 c0 xorb %al, %al 0x7fcad3b46139: 41 ff d7 callq *%r15 0x7fcad3b4613c: 4c 8b 33 movq (%rbx), %r14 0x7fcad3b4613f: 48 8d 3c 24 leaq (%rsp), %rdi 0x7fcad3b46143: 30 c0 xorb %al, %al 0x7fcad3b46145: 41 ff d7 callq *%r15 0x7fcad3b46148: 48 89 1c 24 movq %rbx, (%rsp) 0x7fcad3b4614c: 40 84 ed testb %bpl, %bpl 0x7fcad3b4614f: 75 26 jne 0x7fcad3b46177 0x7fcad3b46151: 48 b9 a0 40 5f d3 ca 7f 00 00 movabsq$140509106356384, %rcx 0x7fcad3b4615b: 48 bf 00 70 b4 d3 ca 7f 00 00 movabsq$140509111939072, %rdi 0x7fcad3b46165: 30 c0 xorb %al, %al 0x7fcad3b46167: ff d1 callq *%rcx 0x7fcad3b46169: 48 89 c3 movq %rax, %rbx 0x7fcad3b4616c: 4c 89 f7 movq %r14, %rdi 0x7fcad3b4616f: 30 c0 xorb %al, %al 0x7fcad3b46171: 41 ff d7 callq *%r15 0x7fcad3b46174: 49 89 1e movq %rbx, (%r14) 0x7fcad3b46177: 48 83 c4 08 addq $8, %rsp 0x7fcad3b4617b: 5b popq %rbx 0x7fcad3b4617c: 41 5e popq %r14 0x7fcad3b4617e: 41 5f popq %r15 0x7fcad3b46180: 5d popq %rbp 0x7fcad3b46181: c3 ret Data buffer contents: 0x7fcad3b47000: 68 65 6c 6c 6f 00 hello. == [ClangUserExpression::Evaluate] Executing expression == Allocating memory for materialized argument struct Found result member in the struct Materializing persistent variable with flags 0x15 Allocated $3 (0x7fcad3b47040) sucessfully Materialized $3 into 0x7fcad3b47040 -- [ClangUserExpression::PrepareToExecuteJITExpression] Materializing for execution -- Function address : 0x7fcad3b46120 Structure address : 0x7fcad3b47010 Structure contents: [$3] 0x7fcad3b47010: 40 70 b4 d3 ca 7f 00 00 @p...... ABISysV_x86_64::PrepareTrivialCall ( thread = 0x7f3a840008c0 sp = 0x7fffa85c0040 func_addr = 0x7fcad3b46120 return_addr = 0x400460 arg1_ptr = 0x7fff27f7f990 (0x7fcad3b47010) arg2_ptr = (nil) (0x0) arg3_ptr = (nil) (0x0) ) About to write arg1 (0x7fcad3b47010) into rdi 16-byte aligning SP: 0x7fffa85c0040 to 0x7fffa85c0040 Pushing the return address onto the stack: new SP 0x7fffa85c0038, return address 0x400460 Writing SP (0x7fffa85c0038) down Writing new IP (0x7fcad3b46120) down -- [ClangUserExpression::Execute] Execution of expression begins -- -- [ClangUserExpression::Execute] Execution of expression completed -- -- [ClangUserExpression::FinalizeJITExecution] Dematerializing after execution -- Structure contents: [$3] 0x7fcad3b47010: 40 70 b4 d3 ca 7f 00 00 @p...... Found result member in the struct Dematerializing persistent variable with flags 0x15 Dematerializing $3 from 0x7fcad3b47040 (size = 8) == [ClangUserExpression::Evaluate] Execution completed normally with result 140509107248080 == [ClangASTImporter] Forgetting destination (ASTContext*)0xb8e190 [ClangASTImporter] Forgetting source->dest (ASTContext*)0xb8e190->(ASTContext*)0xb31560 (long) $3 = 140509107248080 (lldb)